Grafbase MCP Server Implementation Guide
Explore the Grafbase MCP server implementation guide to learn how to use, configure, and integrate the Model Context Protocol in Grafbase Gateway.
npx -y @crates/mcpOverview
The Grafbase MCP (Model Context Protocol) server is the implementation used by the Grafbase Gateway to expose a Model Context Protocol endpoint for integrating external GraphQL services with Grafbase. MCP provides a simple HTTP endpoint that the Gateway and development tools (like Cursor) can query to retrieve model-specific context from a GraphQL API. This is useful when you want the Gateway or an AI integration to fetch schema-aware context, run read queries, and — optionally — execute mutations against your GraphQL API.
This crate is implemented as part of the Grafbase repository (Rust crate) and is intended primarily for use inside the Grafbase toolchain. Running the MCP server locally makes it easy to wire third-party GraphQL backends into Grafbase-powered features during development, testing, or production deployments where federated access to multiple GraphQL sources is required.
Features
- Lightweight MCP endpoint that proxies/serves model context for a GraphQL API
- CLI-friendly startup via the Grafbase CLI
- Default local listening address for quick local development
- Configurable exposure in the Grafbase Gateway (enable/disable, path, mutation execution)
- Simple project-level registration for developer tools (Cursor)
- Integration-tested as part of the Grafbase test suite
Installation / Configuration
Prerequisites
- Node.js (for the Grafbase CLI wrapper)
- Grafbase CLI available (installed via npm/yarn as npx grafbase …)
- Grafbase repository source (crate available at the GitHub link below) if you need to build or inspect the Rust crate
Start the MCP server (quick start)
Where <url> is the URL of the GraphQL API you want the MCP server to target. By default, the local MCP server listens on:
- Address: http://127.0.0.1:5000/mcp
Registering MCP servers for Cursor (project local) Create a file at .cursor/mcp.json and add entries for one or more MCP servers:
This allows developer tools to discover the MCP server by name.
Configuring the Grafbase Gateway To expose an MCP endpoint from the Gateway, add an [mcp] section to grafbase.toml:
[]
= true # defaults to false
= "/mcp" # path to expose the MCP service (default "/mcp")
= false # whether the MCP server is allowed to execute mutations
Configuration options summary
| Option | Type | Default | Description |
|---|---|---|---|
| enabled | bool | false | Whether to expose the MCP endpoint from the Gateway |
| path | string | “/mcp” | HTTP path where MCP requests are served |
| execute_mutations | bool | false | Allow executing mutations through the MCP server |
Available Resources
- Source repository (implementation): https://github.com/grafbase/grafbase/tree/main/crates/mcp
- Grafbase MCP docs: https://grafbase.com/docs/features/mcp
- Integration tests (gateway MCP): https://github.com/grafbase/grafbase/tree/main/crates/integration-tests/tests/gateway/mcp
These links are useful if you want to inspect the Rust crate, understand the test coverage, or read higher-level usage docs.
Use Cases
Local development for AI integrations
- Start the MCP server against an internal GraphQL API and register it in .cursor/mcp.json. Developer tools or local Gateway instances can fetch model context for LLM-driven resolvers or context augmentation workflows.
Federated GraphQL access
- Use the MCP endpoint to unify context retrieval across federated services. Grafbase Gateway can consult MCP endpoints to prepare model-aware context before executing federated queries or applying policies.
Controlled mutation execution
- In environments where read-only context is required, keep execute_mutations=false. For integrations that must modify state (for example, feedback loops or content updates triggered by an LLM), enable execute_mutations=true in grafbase.toml, but do so only after considering security and transactional implications.
Integration testing
- The crate contains integration tests demonstrating expected behavior. Use these tests as a template when authoring custom MCP integrations or validating behavior across CI environments.
Troubleshooting & Tips
- If the CLI cannot bind to 127.0.0.1:5000, check for port conflicts and firewall rules.
- Ensure the target GraphQL API URL is reachable from where you run the MCP server; the server acts as a proxy/source for queries and mutations.
- Keep execute_mutations disabled unless you explicitly want the MCP endpoint to perform writes.
- Use the integration-tests folder in the repository as a reference for expected request/response patterns and error handling.
For development and deeper customization, review the crate source on GitHub and the Grafbase docs linked above.