Graph-Based Representation of Infraestructure-as-Code: Enabling Semantic Reasoning for Containerized Systems.
This project was developed as part of the Master's program at PPGC β Programa de PΓ³s-GraduaΓ§Γ£o em ComputaΓ§Γ£o, Universidade Federal do Rio Grande do Sul (UFRGS).
This project implements a system that parses Infrastructure-as-Code (specifically Docker Compose definition files) into a Knowledge Graph (Neo4j) using a custom OWL ontology. It then exposes this graph to Large Language Models (LLMs) via the Model Context Protocol (MCP), enabling AI agents to reason about topology, detect port conflicts, and analyze service dependencies with high factual accuracy.
-
Semantic Parsing: Converts static YAML files into a dynamic Graph Database, mapping Services, Networks, Volumes, Ports, and Environment Variables.
-
Two-Pass Ingestion: Robust Python parser that handles forward references and ensures idempotency (prevents duplicate nodes).
-
Scope Isolation: Unique URI generation strategy to prevent property collisions between similar services in different environments (e.g., Production vs. Test).
-
Conflict Detection: Automatically identifies critical issues like Host Port Collisions across different compose files.
-
MCP Integration: Exposes semantic tools (find_dependencies, inspect_network, check_port_conflicts) to LLMs like Claude, enabling natural language auditing.
compose-kg-mcp/
βββ mcp_server/
β βββ server.py # The MCP Server implementation
βββ parser_neo4j/ \
β βββ docker_composes/ # Folder with docker compose files for parsing onto neo4j
β βββ parser.py # The ETL script (YAML -> Neo4j)
βββ ontology/
β βββ base_ontology.ttl # The OWL Ontology definition
βββ docker_compose.yaml # Neo4j docker compose
βββ requirements.txt # Python dependencies
βββ .env # Environment variables (GitIgnored)
βββ README.md \
The Knowledge Graph schema is based on the Docker Infrastructure Ontology, defined in docker_infra.ttl. Key classes include:
-
:Service -
:Image -
:PortMapping (with properties hostPort, protocol) -
:EnvironmentVariable (Scoped by Service URI) -
:Network -
:Volume
Once connected, you can ask Claude questions like:
-
"Analyze the dependency chain for the kibana service."
-
"Check if there are any critical port conflicts on the host."
-
"List all services connected to the elastic network."