MCP Resources
Relevant source files
The following files were used as context for generating this wiki page:
MCP Resources expose structured infrastructure data from Infrahub to AI assistants via URI templates. They allow agents to read schema definitions, branch metadata, and GraphQL details as context without executing tool calls. These resources follow the Model Context Protocol (MCP) standards for structured data exposure.
Resources are mounted as sub-applications onto the main server and are typically consumed as context to guide agent behavior. For example, the infrahub://schema resource helps agents discover node kinds before they attempt to query or modify data using MCP Tools.
Sources: src/infrahub_mcp/server.py:228-230, dev/knowledge/architecture.md:76-81, dev/constitution.md:27-28
Resource Architecture and Flow
Resources are registered using FastMCP's composition pattern. The server mounts resource modules located in src/infrahub_mcp/resources/ during initialization. When a client requests a resource URI, the server fetches the corresponding data from Infrahub using the SDK and returns it in a structured format (JSON or plain text).
The diagram shows the request flow where the MCP Server mediates between the client and the Infrahub backend to serve resource data.
Sources: src/infrahub_mcp/server.py:228-230, dev/knowledge/architecture.md:8-16, dev/constitution.md:38-46
Available Resources
The Infrahub MCP Server provides three primary static resources and one dynamic resource template.
| Resource Name | URI / Template | Format | Description |
|---|---|---|---|
| Schema Catalog | infrahub://schema | JSON | Lists all available non-internal node kinds and their human-readable labels. |
| GraphQL Schema | infrahub://graphql-schema | Plain Text | Provides the full GraphQL SDL for the Infrahub instance. |
| Branches | infrahub://branches | JSON | Lists all branches, including the active session branch and the default branch. |
| Schema Kind Detail | infrahub://schema/{kind} | Plain Text | Detailed schema for a specific kind, including attributes, relationships, and filters. |
Sources: CAPABILITIES.md:213-248, src/infrahub_mcp/server.py:204-211
Schema Resources
The infrahub://schema resource serves as the entry point for data model discovery. It allows agents to understand what types of objects (nodes) exist in the system. For specific details on a node kind, the infrahub://schema/{kind} template provides a TOON-encoded (Token-Oriented Object Notation) table containing attribute types and valid filter keys.
Relationship expansion in the schema detail resource is controlled by the INFRAHUB_MCP_SCHEMA_EXPAND_PEERS configuration setting. If enabled, the resource inlines one level of peer schemas for relationships.
Sources: CAPABILITIES.md:213-222, CAPABILITIES.md:241-248, src/infrahub_mcp/server.py:200-203
Branch Resources
The infrahub://branches resource provides visibility into the version control state of the infrastructure. It identifies which branch is the instance default (e.g., main) and lists any active session branches created during the current interaction.
This relationship diagram illustrates the logical structure of the data exposed through MCP Resources.
Sources: CAPABILITIES.md:229-236, src/infrahub_mcp/resources/branches.py, src/infrahub_mcp/resources/schema.py
Implementation Details
Resources are defined in src/infrahub_mcp/resources/. The implementation uses the AppContext to access the shared InfrahubClient.
Caching and Performance
Schema and list operations are optimized via ResponseCachingMiddleware. This middleware provides TTL-based caching to reduce the number of round-trips to the Infrahub API for static or slow-changing data like schema definitions.
Sources: dev/knowledge/architecture.md:52-64, dev/constitution.md:129-130
Security and Access Control
Resources are read-only by nature. However, the server enforces branch-safety and isolation. Read operations default to the main branch unless a specific branch is contextually relevant. Pass-through authentication ensures that the agent only sees resources they are authorized to access in the underlying Infrahub instance.
Sources: dev/constitution.md:47-59, src/infrahub_mcp/server.py:108-112
Summary
MCP Resources provide the essential "knowledge base" for AI agents interacting with Infrahub. By exposing the schema, GraphQL structure, and branch state through standard URIs, the server enables agents to discover the data model dynamically. This discovery phase is critical for ensuring that subsequent tool calls for reading or writing data are accurate and valid.