How apollographql/apollo-mcp-server works
1. This is a Rust workspace centered on an Apollo MCP Server binary. The server’s job is to translate a configured GraphQL surface into MCP tools/resources that an LLM client can call. The repo is split into a runtime-facing server crate plus supporting libraries for schema indexing, registry syncing, and Rhai scripting.
2. The main entrypoint is crates/apollo-mcp-server, which contains the executable (main.rs) and most of the application logic. Its startup path is modeled as a state machine under server/states, moving through configuration, schema setup, operation setup, telemetry setup, and finally the running state.
3. The core request flow is: MCP client connects to the server, the server exposes tool definitions, the client invokes a tool, and the server executes the corresponding GraphQL operation against the configured backend. The important boundary is between MCP-facing tool metadata and backend GraphQL execution.
4. GraphQL operation handling lives under operations/. This layer owns operation parsing, raw operation representation, execution, source selection, mutation behavior, private-field filtering, and schema walking. It is the main adapter between a GraphQL document set and the MCP tool surface.
5. Schema intelligence is a separate concern. The server has introspection and schema-walking modules that derive output shapes, validate tool definitions, and generate searchable/introspectable views of schemas. The apollo-schema-index crate provides reusable schema traversal/search primitives for this purpose.
6. Schema and operation inputs can come from multiple sources. The runtime/schema_source.rs, runtime/schemas.rs, and related modules suggest support for local schemas, GraphOS/Uplink-backed schemas, and introspection-based schema resolution. Likewise, runtime/operation_source.rs and the operations modules indicate support for local operation files and persisted-query manifests.
7. There is a dedicated GraphOS/Uplink integration path. The apollo-mcp-registry crate contains GraphQL documents, pollers, and event models for schema streams and persisted query manifests, plus a platform_api layer. This crate is the remote-control plane for syncing registry metadata from Apollo services.
8. Authentication and policy enforcement are explicit subsystems. Under auth/ the server includes protected-resource handling, token validation, and WWW-Authenticate support. cors.rs, host_validation.rs, and headers.rs define the HTTP-facing security boundary around who can talk to the server and from where.
9. Observability is first-class. runtime/telemetry.rs, meter.rs, and runtime/logging/ handle logging and metrics, while runtime/filtering_exporter.rs and the OTLP-related tests show support for exporting telemetry to external collectors. A separate health.rs module exposes liveness/readiness-style health checks.
10. The repo also supports runtime customization through Rhai scripts in apollo-mcp-rhai. That crate exposes startup and operation-execution checkpoints plus helper functions for env, HTTP, JSON, regex, and hashing. Architecturally, this is an extension layer that can influence behavior without changing the core server.
11. User-facing packaging is handled by the apps/ and prompts/ areas in the server crate. These modules define MCP app manifests, resources, and tools, and also load prompt files that can be shipped alongside tool definitions. This is how higher-level “application bundles” are represented in the server.
12. The repository includes concrete deployment and validation boundaries: examples/ for sample configurations, e2e/ for end-to-end scenarios, docs/ for the published architecture and usage model, and GitHub workflows/Dockerfile for release and container packaging. Those pieces are not runtime subsystems, but they show how the server is built, tested, and distributed.
Main entry points: states.rs Server States · runtime.rs Runtime · lib.rs Registry Sync · operations.rs Operations
Components 22
Apollo MCP Server
Runtime-facing MCP server crate and its internal subsystems.
- Main · Executable entrypoint and startup wiring.
crates/apollo-mcp-server/src/main.rs - Server States · Coordinates configuration, schema setup, operations setup, telemetry, and running.
crates/apollo-mcp-server/src/server/states.rs - Runtime · Builds the effective runtime from config, endpoint, schema, operation, and override inputs.
crates/apollo-mcp-server/src/runtime.rs - Schema Source · Selects and loads schemas from local, introspection, or GraphOS-backed sources.
crates/apollo-mcp-server/src/runtime/schema_source.rs - Schemas · Holds schema representations used by the server and operation layers.
crates/apollo-mcp-server/src/runtime/schemas.rs - Operation Source · Loads operation documents from files or persisted-query manifests.
crates/apollo-mcp-server/src/runtime/operation_source.rs - Operations · Maps GraphQL documents into MCP tool behavior and execution.
crates/apollo-mcp-server/src/operations.rs - Schema Walker · Derives tool-friendly output shapes and walks GraphQL types.
crates/apollo-mcp-server/src/operations/schema_walker.rs - Introspection · Builds search, validate, execute, and introspection tools from schema data.
crates/apollo-mcp-server/src/introspection.rs - Apps · Represents MCP app bundles, manifests, resources, and tools.
crates/apollo-mcp-server/src/apps/mod.rs - Prompts · Loads prompt files shipped alongside app and tool definitions.
crates/apollo-mcp-server/src/prompts/mod.rs - Auth · Protected-resource handling, token validation, and auth challenges.
crates/apollo-mcp-server/src/auth.rs - HTTP Security · CORS, host validation, and header handling for inbound requests.
crates/apollo-mcp-server/src/cors.rs - Telemetry · Logging, metrics, sampling, and exporter setup.
crates/apollo-mcp-server/src/runtime/telemetry.rs - Health · Liveness/readiness-style endpoint support.
crates/apollo-mcp-server/src/health.rs
Registry Sync
Remote GraphOS/Uplink integration for schemas and persisted queries.
- Registry Sync · Apollo registry integration for schema streams and persisted query manifests.
crates/apollo-mcp-registry/src/lib.rs - Uplink · Polls and consumes GraphOS schema stream events.
crates/apollo-mcp-registry/src/uplink.rs - PQ Manifest · Fetches and tracks persisted-query manifests from Apollo services.
crates/apollo-mcp-registry/src/uplink/persisted_queries/manifest_poller.rs - Platform API · GraphQL documents and event models for registry-side APIs.
crates/apollo-mcp-registry/src/platform_api.rs
Rhai Extensibility
Script runtime used to customize startup and operation execution.
- Rhai Engine · Script engine and checkpoint orchestration for startup and execution hooks.
crates/apollo-mcp-rhai/src/engine.rs
Schema Index
Reusable schema traversal and search primitives.
- Schema Index · Reusable schema traversal and search primitives.
crates/apollo-schema-index/src/lib.rs
Packaging & Examples
Documentation, examples, and validation/deployment assets.
- Docs & Examples · Architecture docs, examples, and end-to-end scenarios that exercise the server.
docs/source/index.mdx
Connections 25
- Main → Server States: boot · Executable enters the server startup state machine.
- Server States → Runtime: assemble · State machine builds the effective runtime configuration.
- Runtime → Schema Source: resolve schema · Runtime selects the active schema source.
- Runtime → Operation Source: resolve ops · Runtime selects the active operation source.
- Schema Source → Schemas: load · Schema source populates runtime schema models.
- Operation Source → Operations: feed docs · Operation documents are adapted into runnable operations.
- Schemas → Operations: shape tools · Schemas constrain tool generation and execution shapes.
- Operations → Schema Walker: derive output · Operation layer uses schema walking to produce tool outputs.
- Schema Walker → Schema Index: traverse · Walker delegates traversal/search primitives to the shared schema index crate.
- Operations → Introspection: expose · Operations and schema data are surfaced as MCP introspection tools.
- Introspection → Schema Index: search · Introspection tools rely on schema indexing for lookup.
- Apps → Prompts: bundle · App manifests can include prompt resources.
- Auth → HTTP Security: guard · Inbound request security boundary complements auth checks.
- Server States → Auth: enforce · Startup config wires authentication into the server.
- Server States → Telemetry: instrument · Telemetry is configured during startup.
- Server States → Health: serve · Health endpoints are brought up with the server.
- Runtime → Rhai Engine: hook scripts · Runtime can attach Rhai checkpoints and helpers.
- Rhai Engine → Operations: customize exec · Scripts can influence GraphQL operation execution.
- Registry Sync → Uplink: sync schema · Registry crate manages schema stream polling.
- Registry Sync → PQ Manifest: sync manifests · Registry crate manages persisted-query manifest polling.
- Registry Sync → Platform API: query API · Registry crate uses GraphQL platform documents.
- Runtime → Registry Sync: remote source · Runtime can source schema and operation metadata from Apollo services.
- Docs & Examples → Apps: describe · Docs explain app manifests and resource structure.
- Docs & Examples → Rhai Engine: document · Docs cover Rhai lifecycle and functions.
- Docs & Examples → Registry Sync: illustrate · Examples and docs cover registry sync and persisted queries.