Skip to main content

Configuration reference

The Infrahub MCP server is configured entirely through environment variables. All middleware features are opt-in — the server works out of the box with only the required connection variables set.

Connection

VariableDescriptionDefault
INFRAHUB_ADDRESSURL of your Infrahub instancerequired
INFRAHUB_API_TOKENAPI token used by the MCP server to call Infrahub (not needed in token-passthrough auth mode)
MCP_HOSTBind address for the HTTP server0.0.0.0
MCP_PORTPort for the HTTP server8001

Username/password authentication against Infrahub is not supported. Use OIDC when you need per-user identity.

Server behavior

VariableDescriptionDefault
INFRAHUB_MCP_READ_ONLYDisable all write operations (true, 1, or yes)false
INFRAHUB_MCP_BRANCH_PATTERNBranch naming pattern. Supports {date}, {hex}, {user} placeholders. Fixed names (no placeholders) must not already exist.mcp/session-{date}-{hex}
INFRAHUB_MCP_MAX_BRANCH_RETRIESMax collision retries when generating branch names (1–20)5
INFRAHUB_MCP_LOG_LEVELSet to debug for verbose logging with tracebacksinfo

Rate limiting

Token bucket rate limiter that protects the server from abuse. Disabled by default.

VariableDescriptionDefault
INFRAHUB_MCP_RATE_LIMIT_RPSMax sustained requests per second (0 = disabled)0
INFRAHUB_MCP_RATE_LIMIT_BURSTToken bucket burst capacity (0 = auto: 2x RPS)0
# Allow 10 requests/sec with bursts up to 20
INFRAHUB_MCP_RATE_LIMIT_RPS=10
INFRAHUB_MCP_RATE_LIMIT_BURST=20

Retry

Automatic retry with exponential backoff for transient failures (ConnectionError, TimeoutError, OSError). Disabled by default.

VariableDescriptionDefault
INFRAHUB_MCP_RETRY_MAX_ATTEMPTSMax retry attempts (0 = disabled)0
INFRAHUB_MCP_RETRY_BASE_DELAYInitial delay between retries in seconds1.0

Response caching

TTL-based caching for schema discovery and list operations. Reduces load on Infrahub for repeated schema lookups.

VariableDescriptionDefault
INFRAHUB_MCP_CACHE_ENABLEDEnable response caching (true/false)false
INFRAHUB_MCP_CACHE_LIST_TTLTTL for list operations (tools, resources, prompts) in seconds300
INFRAHUB_MCP_CACHE_READ_TTLTTL for read operations (resources, tool calls) in seconds3600

Only the get_schema tool is cached for tool calls — node queries and writes are never cached.

Authentication and authorization

The MCP server supports four authentication modes controlled by INFRAHUB_MCP_AUTH_MODE:

none (default)

No identity gate. Any client that reaches the MCP server gets access using the shared INFRAHUB_API_TOKEN. Works with both stdio and HTTP transports.

oidc

External Identity Provider authentication via OpenID Connect. When enabled, the MCP server uses FastMCP's OIDCProxy to authenticate users against providers like Google, Okta, or Microsoft Entra. This provides:

  • Identity — who is calling (for audit logs and {user} branch placeholder)
  • Role gating — two roles: read-only (read tools only) and read-write (all tools)

Infrahub API calls still use the shared env var credentials. The OIDC token is for MCP-level access control only. Streamable HTTP transport is required (OIDC is not supported over stdio).

token-passthrough

Each client sends their own Infrahub API token in the HTTP request header. The server creates a per-request InfrahubClient using that token — no shared server-side credentials required. Every request must carry a valid token (fail-closed). Streamable HTTP transport is required.

basic-passthrough

Same fail-closed per-request model as token-passthrough, but the client sends an Authorization: Basic <base64(user:pass)> header. The server decodes the header and constructs a fresh InfrahubClient with those credentials for each request. Streamable HTTP transport is required.

VariableRequiredDefaultDescription
INFRAHUB_MCP_AUTH_MODENononeAuthentication mode (none, oidc, token-passthrough, basic-passthrough)
INFRAHUB_MCP_OIDC_CONFIG_URLYes (oidc)OIDC discovery endpoint URL
INFRAHUB_MCP_OIDC_CLIENT_IDYes (oidc)OAuth client ID registered with the IdP
INFRAHUB_MCP_OIDC_CLIENT_SECRETNoOAuth client secret (omit for PKCE flow)
INFRAHUB_MCP_OIDC_BASE_URLYes (oidc)Public URL where the MCP server is accessible
INFRAHUB_MCP_OIDC_AUDIENCENoToken audience claim
INFRAHUB_MCP_OIDC_USER_CLAIMNoemailJWT claim used for user identity
INFRAHUB_MCP_AUTH_SCOPES_WRITENowriteScopes required for write operations (comma-separated)
INFRAHUB_MCP_TOKEN_PASSTHROUGH_HEADERNoAuthorizationHTTP header carrying the Infrahub API token (token-passthrough mode)

Scope-based write authorization

When INFRAHUB_MCP_AUTH_SCOPES_WRITE is configured (in either auth mode over HTTP transport), tools tagged write are filtered from discovery and blocked at call time unless the access token contains all required scopes. STDIO connections skip auth checks.

# Require "infrahub:write" scope for node_upsert, node_delete, etc.
INFRAHUB_MCP_AUTH_SCOPES_WRITE=infrahub:write

Observability

OpenTelemetry tracing

Wraps every MCP request in an OpenTelemetry span (mcp.<method>). Requires the opentelemetry-api package — degrades gracefully to a no-op if not installed.

VariableDescriptionDefault
INFRAHUB_MCP_OTEL_ENABLEDEnable OpenTelemetry tracingfalse

Prometheus metrics

The /metrics endpoint returns JSON by default. Enable Prometheus exposition format for scraping by Prometheus, Grafana Agent, or Datadog.

VariableDescriptionDefault
INFRAHUB_MCP_PROMETHEUS_ENABLEDReturn Prometheus text format from /metricsfalse

Metrics exposed:

  • infrahub_mcp_requests_total{method} — total requests by MCP method
  • infrahub_mcp_errors_total{method} — total errors by MCP method
  • infrahub_mcp_latency_ms_total{method} — cumulative latency in milliseconds

The JSON format also includes error_stats (per-exception-type counts from error handling) and cache statistics when caching is enabled.

Client compatibility

VariableDescriptionDefault
INFRAHUB_MCP_DEREFERENCE_SCHEMASInline $ref in JSON schemas for clients that do not handle references (for example, VS Code Copilot)false
INFRAHUB_MCP_PING_INTERVAL_MSSend periodic pings to keep HTTP connections alive, in milliseconds (0 = disabled, max 300000)0

Middleware stack

The server applies middleware in registration order. The full stack when all features are enabled:

LayerMiddlewareAlways on
1RequestIdMiddleware — unique correlation ID per requestyes
2MetricsMiddleware — request/error/latency counters for /metricsyes
3OTelTracingMiddleware — OpenTelemetry spansno
4ErrorHandlingMiddleware — exception-to-MCP-error mapping with error trackingyes
5InfrahubConnectionMiddleware — friendly errors for unreachable/unresponsive Infrahubyes
6RetryMiddleware — exponential backoff for transient failuresno
7RateLimitingMiddleware — token bucket rate limitingno
8StructuredLoggingMiddleware — JSON logs with token estimatesyes
9DetailedTimingMiddleware — per-operation timing breakdownyes
10AuthMiddleware — scope-based write tool authorization (HTTP only)no
11TokenPassthroughMiddleware — fail-closed gate for token/basic passthrough modesno
12ReadOnlyMiddleware — tag-based write tool blockingno
13AuditMiddleware — structured audit trail for tool/resource accessyes
14ResponseCachingMiddleware — TTL-based response cachingno
15DereferenceRefsMiddleware — inline $ref in JSON schemasno
16PingMiddleware — periodic keepalive pingsno
17ResponseLimitingMiddleware — truncates responses over 500 KByes

Endpoints

PathMethodDescription
/mcpPOSTMCP Streamable HTTP transport
/healthGETHealth check — returns {"status": "healthy"} or 503
/metricsGETRequest counts, error counts, latency (JSON or Prometheus format)
/.well-known/*GETOAuth discovery — returns RFC 6749 JSON 404 when OIDC is not enabled