Define MCP Tools


You can manually define the GraphQL operations that are exposed by Apollo MCP Server as MCP tools. You can define these operations using:

  • Local operation files

  • Operation collections

  • Persisted query manifests

  • GraphOS-managed persisted queries

Alternatively, you can let an AI model read your graph schema via GraphQL introspection and have it determine the available operations.

Define GraphQL operations for tools

From operation files

An operation file is a .graphql file containing a single GraphQL operation.

GraphQL
Example operation GetForecast
1query GetForecast($coordinate: InputCoordinate!) {
2  forecast(coordinate: $coordinate) {
3    detailed
4  }
5}
GraphQL
Example operation GetWeatherData
1query GetAllWeatherData($coordinate: InputCoordinate!, $state: String!) {
2  forecast(coordinate: $coordinate) {
3    detailed
4  }
5  alerts(state: $state) {
6    severity
7    description
8    instruction
9  }
10}

Use the operations option to provide the MCP Server with a list of operation files. For each operation file you provide, the MCP Server creates an MCP tool that calls the corresponding GraphQL operation.

You can also use the operations option to specify a directory. The server then loads all files with a .graphql extension in that directory as operations.

Files and directories specified with operations are hot reloaded. When you specify a file, the MCP tool is updated when the file contents are modified. When you specify a directory, operations exposed as MCP tools are updated when files are added, modified, or removed from the directory.

From operation collections

For graphs managed by GraphOS, Apollo MCP Server can retrieve operations from an operation collection.

Use GraphOS Studio Explorer to create and manage operation collections.

Configuring the MCP Server to use a GraphOS operation collection

To use a GraphOS operation collection, you must set your graph credentials (APOLLO_GRAPH_REF and APOLLO_KEY) as environment variables.

Each graph variant has its own default MCP Tools Collection, but you can specify any shared collection by using operations.source: collection.

Specify the collection to use with the operations.id option. To view the ID of a collection, click the ••• button next to its entry, select View details, and copy the Collection ID.

Each graph variant has its own default collection called Default MCP Tools. To use this default collection, specify operations.id: default. Apollo MCP Server automatically fetches the default collection if no ID is specified.

YAML
Example config file for using a GraphOS operation collection
1operations:
2  source: collection
3  id: default

The MCP Server supports hot reloading of the GraphOS operation collection, so it automatically picks up changes from GraphOS without restarting.

Setting operation collection variables

When saving operation collections, remove any dynamic variables from the Variables panel of Explorer. This enables the LLM to modify the variables when calling the operation.

Any variables set to any valid value (even null) in the Variables panel of a saved operation are used as a hardcoded override for that operation's variable.

For example, if you create the following operation for an operation collection:

GraphQL
1query GetProduct($productId: ID!) {
2  product(id: $productId) {
3    id
4    description
5  }
6}

And the Variables panel has productId set to 1234:

JSON
1{
2  "productId": "1234"
3}

Then, every time the LLM calls the GetProduct operation, the productId variable is always set to 1234. The same is true if productId is set to null.

If you want to use dynamic variables that the LLM can modify, remove any variables from the Variables panel and save that operation to the collection.

From persisted query manifests

Apollo MCP Server supports reading GraphQL operations from Apollo-formatted persisted query manifest files.

Set the persisted query manifest file for the MCP Server with the operations option. The MCP Server supports hot reloading of persisted query manifests, so changes to manifests are applied without restarting.

An example manifest is available in the GitHub repo.

YAML
Example config for using persisted query manifest
1operations:
2  source: manifest
3  path: <PATH/TO/persisted-queries-manifest.json>

From GraphOS-managed persisted queries

For graphs managed by GraphOS, Apollo MCP Server can get operations by reading persisted queries from GraphOS. The MCP Server uses Apollo Uplink to access the persisted queries.

To use GraphOS persisted queries, you must set your graph credentials APOLLO_GRAPH_REF and APOLLO_KEY as environment variables.

Use the operations.source: uplink option to specify that tools should be loaded from GraphOS-managed persisted queries.

tip
Use a contract variant with a persisted query list associated with that variant, so you can control what AI can consume from your graph. Learn more.
YAML
Example config using GraphOS-managed persisted queries
1operations:
2  source: uplink

The MCP Server supports hot reloading of GraphOS-managed persisted queries, so it can automatically pick up changes from GraphOS without restarting.

If you register a persisted query with a specific client name instead of null, you must configure the MCP Server to send the necessary header indicating the client name to the router.

Use the headers option when running the MCP Server to pass the header to the router. The default name of the header expected by the router is apollographql-client-name. To use a different header name, configure telemetry.apollo.client_name_header in router YAML configuration.

YAML
Example config using GraphOS-managed persisted queries
1headers:
2  "apollographql-client-name": "my-web-app"
3operations:
4  source: uplink

Introspection tools

In addition to defining specific tools for pre-defined GraphQL operations, Apollo MCP Server supports introspection tools that enable AI agents to explore the graph schema and execute operations dynamically.

You can enable the following introspection tools:

  • introspect: allows the AI model to introspect the schema of the GraphQL API by providing a specific type name to get information about, and a depth parameter to determine how deep to traverse the subtype hierarchy. The AI model can start the introspection by looking up the top-level Query or Mutation type.

  • search: allows the AI model to search for type information by providing a set of search terms. This can result in fewer tool calls than introspect, especially if the desired type is deep in the type hierarchy of the schema. Search results include all the parent type information needed to construct operations involving the matching type.

  • validate: validates a GraphQL operation against the schema without executing it. This allows AI models to verify that their operations are syntactically correct and conform to the schema before execution, preventing unintended side effects. Operations should be validated prior to calling the execute tool.

  • execute: executes an operation on the GraphQL endpoint

The MCP client can use these tools to provide schema information to the model and its context window, and allow the model to execute GraphQL operations based on that schema.

Minification

Both the introspect and search tools support minification of their results through the minify option. These options help optimize context window usage for AI models.

  • Reduces context window usage: Minified GraphQL SDL takes up significantly less space in the AI model's context window, allowing for more complex schemas or additional context

  • Uses compact notation: Type definitions use prefixed compact syntax and common scalar types are shortened

  • Preserves functionality: All essential type information is retained, just in a more compact format

  • Includes legend in tool descriptions: When minify is enabled, the tool descriptions automatically include a legend explaining the notation

Minification format:

  • Type prefixes: T=type, I=input, E=enum, U=union, F=interface

  • Scalar abbreviations: s=String, i=Int, f=Float, b=Boolean, d=ID

  • Directive abbreviations: @D=deprecated

  • Type modifiers: !=required, []=list, <>=implements

Example comparison:

Regular output:

GraphQL
1type User {
2  id: ID!
3  name: String
4  email: String!
5  posts: [Post]
6}

Minified output:

Text
1T:User:id:d!,name:s,email:s!,posts:[Post]
tip
Use a contract variant so you can control the parts of your graph that AI can introspect. Learn more
YAML
Example config using introspection
1introspection:
2  execute:
3    enabled: true
4  introspect:
5    enabled: true
6    minify: true
7  search:
8    enabled: true
9    minify: true
10    index_memory_bytes: 50000000
11    leaf_depth: 1
12  validate:
13    enabled: true
Feedback

Edit on GitHub

Ask Community