|
1 | | -# Apollo MCP Server |
2 | | - |
3 | | -An MCP Server to expose a pre-defined set of GraphQL operations as MCP tools. Optionally provides introspection |
4 | | -tools to allow an LLM to generate and execute its own ad hoc operations. |
5 | | - |
6 | | -# Running the Example |
7 | | - |
8 | | -The repo has an example schema in `graphql/weather/weather.graphql`, and an example set of operations in `graphql/weather/operations/*.graphql`. |
9 | | - |
10 | | -First, build the repo with: |
11 | | - |
12 | | -```sh |
13 | | -cargo build |
14 | | -``` |
15 | | - |
16 | | -Next, run the graph in the Apollo Router: |
17 | | - |
18 | | -```sh |
19 | | -rover dev --supergraph-config ./graphql/weather/supergraph.yaml |
20 | | -``` |
21 | | - |
22 | | -## MCP Inspector |
23 | | - |
24 | | -You can run the MCP Server with [MCP Inspector](https://modelcontextprotocol.io/docs/tools/inspector). |
25 | | - |
26 | | -### Stdio Transport |
27 | | - |
28 | | -You can run the MCP inspector with the stdio transport as follows: |
29 | | - |
30 | | -```sh |
31 | | -npx @modelcontextprotocol/inspector \ |
32 | | - target/debug/apollo-mcp-server \ |
33 | | - --directory <absolute path to this git repo> \ |
34 | | - -s graphql/weather/api.graphql \ |
35 | | - -o graphql/weather/operations/forecast.graphql graphql/weather/operations/alerts.graphql graphql/weather/operations/all.graphql |
36 | | -``` |
37 | | - |
38 | | -Press "Connect" in the MCP Inspector and "List Tools" to see the list of available tools. |
39 | | - |
40 | | -### HTTP+SSE Transport |
41 | | - |
42 | | -To use the SSE transport with MCP Inspector, first start the MCP server in SEE mode: |
43 | | - |
44 | | -```sh |
45 | | -target/debug/apollo-mcp-server \ |
46 | | - --directory <absolute path to this git repo> \ |
47 | | - --sse-port 5000 -s graphql/weather/api.graphql \ |
48 | | - -o graphql/weather/operations/forecast.graphql graphql/weather/operations/alerts.graphql graphql/weather/operations/all.graphql |
49 | | -``` |
50 | | - |
51 | | -Now start the MCP Inspector: |
52 | | - |
53 | | -```sh |
54 | | -npx @modelcontextprotocol/inspector |
55 | | -``` |
56 | | - |
57 | | -Set the transport to SSE in the inspector and the URL to `http://localhost:5000/sse`, then press "Connect" in MCP Inspector. |
58 | | - |
59 | | -## MCP Client |
60 | | - |
61 | | -You can use the MCP Server with your favorite MCP client. |
62 | | - |
63 | | -### Client Configuration |
64 | | - |
65 | | -For Claude Desktop, the configuration file is in the following location on MacOS: |
66 | | - |
67 | | -```sh |
68 | | -~/Library/Application\ Support/Claude/claude_desktop_config.json |
69 | | -``` |
70 | | - |
71 | | -For Cursor, you can find the file by opening the MCP tab in Settings. |
72 | | - |
73 | | -#### Stdio Transport |
74 | | - |
75 | | -To use the stdio transport, add the following to the MCP configuration file for you client, using the absolute path to this Git repo: |
76 | | - |
77 | | -```json |
78 | | -{ |
79 | | - "mcpServers": { |
80 | | - "weather": { |
81 | | - "command": "<absolute path to repo>/target/debug/apollo-mcp-server", |
82 | | - "args": [ |
83 | | - "--directory", |
84 | | - "<absolute path to repo>", |
85 | | - "--schema", |
86 | | - "graphql/weather/api.graphql", |
87 | | - "--operations", |
88 | | - "graphql/weather/operations/forecast.graphql", |
89 | | - "graphql/weather/operations/alerts.graphql", |
90 | | - "graphql/weather/operations/all.graphql" |
91 | | - ] |
92 | | - } |
93 | | - } |
94 | | -} |
95 | | -``` |
96 | | - |
97 | | -#### HTTP+SEE Transport |
98 | | - |
99 | | -To use the HTTP+SSE transport, first start the MCP server as described above for MCP Inspector. |
100 | | - |
101 | | -For Claude Desktop, you can use [`mcp-remote`](https://www.npmjs.com/package/mcp-remote/v/latest?activeTab=readme) to give Claude access to the MCP Server over SSE: |
| 1 | +<div align="center"> |
| 2 | +<a href="https://www.apollographql.com/"><img src="https://raw.githubusercontent.com/apollographql/apollo-client-devtools/main/assets/apollo-wordmark.svg" height="100" alt="Apollo Client"></a> |
| 3 | +</div> |
102 | 4 |
|
103 | | -```json |
104 | | -{ |
105 | | - "mcpServers": { |
106 | | - "weather": { |
107 | | - "command": "npx", |
108 | | - "args": [ |
109 | | - "mcp-remote", |
110 | | - "http://127.0.0.1:5000/sse", |
111 | | - "--transport", |
112 | | - "sse-first" |
113 | | - ] |
114 | | - } |
115 | | - } |
116 | | -} |
117 | | -``` |
118 | | - |
119 | | -For Cursor, you can directly specify the SSE URL: |
120 | | - |
121 | | -```json |
122 | | -{ |
123 | | - "mcpServers": { |
124 | | - "weather": { |
125 | | - "url": "http://127.0.0.1:5000/sse" |
126 | | - } |
127 | | - } |
128 | | -} |
129 | | -``` |
130 | | - |
131 | | -### Usage |
132 | | - |
133 | | -Restart your AI agent. You should now see the tools successfully registered. For example, in Claude Desktop, you should see a small hammer icon with the number of tools next to it. |
134 | | - |
135 | | -You can now issue prompts related to weather forecasts and alerts, which will call out to the tools and invoke the GraphQL operations. |
136 | | - |
137 | | -**Note** that due to current limitations of Apollo Connectors, the schema is using a hard-coded weather forecast link, so the forecast will be for a fixed location. |
138 | | - |
139 | | -#### Persisted Queries Manifests |
140 | | - |
141 | | -The MCP server also supports reading operations from an |
142 | | -[Apollo](https://www.apollographql.com/docs/graphos/platform/security/persisted-queries#manifest-format) formatted |
143 | | -persisted query manifest file through the use of the `--manifest` flag. |
144 | | - |
145 | | -An example is included in `graphql/weather/persisted_queries`. |
146 | | - |
147 | | -```sh |
148 | | -target/debug/apollo-mcp-server \ |
149 | | - --directory <absolute path to this git repo> \ |
150 | | - -s graphql/weather/api.graphql \ |
151 | | - --header "apollographql-client-name:my-web-app" \ |
152 | | - --manifest graphql/weather/persisted_queries/apollo.json |
153 | | -``` |
154 | | - |
155 | | -Note that when using persisted queries, if your queries are registered with a specific client name instead of `null`, |
156 | | -you will need to configure the MCP server to send the necessary header indicating the client name to the router. This |
157 | | -header is `apollographql-client-name` by default, but can be overridden in the router config by setting |
158 | | -`telemetry.apollo.client_name_header`. Note that in the example persisted query manifest file, the client name |
159 | | -is `my-web-app`. |
160 | | - |
161 | | -This supports hot-reloading, so changes to the persisted query manifest file will be picked up by the MCP server |
162 | | -without restarting. |
163 | | - |
164 | | -#### Uplink |
165 | | - |
166 | | -The MCP server can also read persisted queries from Uplink using the `--uplink` option. This supports hot-reloading, |
167 | | -so it will pick up changes from GraphOS automatically, without restarting the MCP server. |
168 | | - |
169 | | -You must set the `APOLLO_KEY` and `APOLLO_GRAPH_REF` environment variables to use Uplink. It is recommended to use |
170 | | -a contract variant of your graph, with a PQ list associated with that variant. That way, you control exactly what |
171 | | -persisted queries are available to the MCP server. |
172 | | - |
173 | | -```sh |
174 | | -target/debug/apollo-mcp-server \ |
175 | | - --directory <absolute path to this git repo> \ |
176 | | - -s graphql/weather/api.graphql \ |
177 | | - --header "apollographql-client-name:my-web-app" \ |
178 | | - --uplink |
179 | | -``` |
180 | | - |
181 | | -# Running Your Own Graph |
182 | | - |
183 | | -You can easily run the server with your own GraphQL schema and operations. For example with the stdio transport: |
184 | | - |
185 | | -```json |
186 | | -{ |
187 | | - "mcpServers": { |
188 | | - "<name for your server>": { |
189 | | - "command": "<absolute path to repo>/target/debug/apollo-mcp-server", |
190 | | - "args": [ |
191 | | - "--directory", |
192 | | - "<absolute path to the directory containing your schema and operations file>", |
193 | | - "--schema", |
194 | | - "<relative path from the directory specified above to the schema>", |
195 | | - "--operations", |
196 | | - "<relative path from the directory specified above to the operation files>", |
197 | | - "--endpoint", |
198 | | - "<your GraphQL endpoint>" |
199 | | - ] |
200 | | - } |
201 | | - } |
202 | | -} |
203 | | -``` |
204 | | - |
205 | | -The operation files are just `.graphql` files, with each file containing a single operation. Make sure to give your operations meaningful names, and document your schema as much as possible. |
206 | | - |
207 | | -Run your schema in Apollo Router at the endpoint given in your configuration file. |
208 | | - |
209 | | -Use MCP Inspector, or in Claude Desktop, click the hammer icon to see the description generated for your tools. |
210 | | - |
211 | | -# Introspection |
212 | | - |
213 | | -You can optionally enable support for allowing the AI model to introspect the schema and formulate its own queries. It is recommended that this only be done with a Contract variant schema, so you can control what parts of your schema are exposed to the model. |
214 | | - |
215 | | -To enable this mode, add `--introspect` to the MCP server command line. |
216 | | - |
217 | | -Two new tools will be exposed by the server: |
218 | | - |
219 | | -* `introspect` - returns information about GraphQL schema types |
220 | | -* `execute` - executes an operation on the GraphQL endpoint |
221 | | - |
222 | | -The MCP client can then use these tools to provide schema information to the model, and allow the model to execute GraphQL operations based on that schema. |
223 | | - |
224 | | -# Running in a Container |
225 | | - |
226 | | -The MCP server is also available as a standalone docker container. The following command |
227 | | -demonstrates how to use the container. Refer to previous sections for all valid |
228 | | -server arguments. |
| 5 | +# Apollo MCP Server |
229 | 6 |
|
230 | | -By default, the container expects all schema files to be present in the |
231 | | -`/data` folder within the container, so make sure to mount your files there. The |
232 | | -example below uses the provided weather example for reference |
| 7 | +An [MCP](https://modelcontextprotocol.io/) Server to expose GraphQL operations as MCP tools. |
233 | 8 |
|
234 | | -```sh |
235 | | -docker run \ |
236 | | - -it --rm \ |
237 | | - --name apollo-mcp-server \ |
238 | | - -p 5000:5000 \ |
239 | | - -v $PWD/graphql/weather:/data \ |
240 | | - ghcr.io/apollographql/apollo-mcp:latest \ |
241 | | - --sse-port 5000 \ |
242 | | - -s api.graphql \ |
243 | | - # Other MCP server options... |
244 | | -``` |
| 9 | +See [the documentation](https://www.apollographql.com/docs/apollo-mcp-server/) for details. |
245 | 10 |
|
246 | 11 | # Licensing |
247 | 12 |
|
|
0 commit comments