Skip to content

Commit dd0a2f5

Browse files
authored
Add support for MCP Inspector and update README (#23)
1 parent 7a1d88f commit dd0a2f5

File tree

2 files changed

+92
-6
lines changed

2 files changed

+92
-6
lines changed

README.md

+84-5
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,54 @@ First, build the repo with:
1212
cargo build
1313
```
1414

15-
Next, start the Apollo Router:
15+
Next, run the graph in the Apollo Router:
1616

1717
```sh
1818
rover dev --supergraph-config ./graphql/weather/supergraph.yaml
1919
```
2020

21-
Then, register the MCP Server with your AI agent.
21+
## MCP Inspector
22+
23+
You can run the MCP Server with [MCP Inspector](https://modelcontextprotocol.io/docs/tools/inspector).
24+
25+
### Stdio Transport
26+
27+
You can run the MCP inspector with the stdio transport as follows:
28+
29+
```sh
30+
npx @modelcontextprotocol/inspector \
31+
target/debug/mcp-apollo-server \
32+
--directory <absolute path to this git repo> \
33+
-s graphql/weather/api.graphql \
34+
-o graphql/weather/operations/forecast.graphql graphql/weather/operations/alerts.graphql graphql/weather/operations/all.graphql
35+
```
36+
37+
Press "Connect" in the MCP Inspector and "List Tools" to see the list of available tools.
38+
39+
### HTTP+SSE Transport
40+
41+
To use the SSE transport with MCP Inspector, first start the MCP server in SEE mode:
42+
43+
```sh
44+
target/debug/mcp-apollo-server \
45+
--directory <absolute path to this git repo> \
46+
--sse-port 5000 -s graphql/weather/api.graphql \
47+
-o graphql/weather/operations/forecast.graphql graphql/weather/operations/alerts.graphql graphql/weather/operations/all.graphql
48+
```
49+
50+
Now start the MCP Inspector:
51+
52+
```sh
53+
npx @modelcontextprotocol/inspector
54+
```
55+
56+
Set the transport to SSE in the inspector and the URL to `http://localhost:5000/sse`, then press "Connect" in MCP Inspector.
57+
58+
## MCP Client
59+
60+
You can use the MCP Server with your favorite MCP client.
61+
62+
### Client Configuration
2263

2364
For Claude Desktop, the configuration file is in the following location on MacOS:
2465

@@ -28,7 +69,9 @@ For Claude Desktop, the configuration file is in the following location on MacOS
2869

2970
For Cursor, you can find the file by opening the MCP tab in Settings.
3071

31-
Add the following to this file, using the absolute path to this Git repo:
72+
#### Stdio Transport
73+
74+
To use the stdio transport, add the following to the MCP configuration file for you client, using the absolute path to this Git repo:
3275

3376
```json
3477
{
@@ -50,15 +93,38 @@ Add the following to this file, using the absolute path to this Git repo:
5093
}
5194
```
5295

96+
#### HTTP+SEE Transport
97+
98+
To use the HTTP+SSE transport, first start the MCP server as described above for MCP Inspector.
99+
100+
Set the following in the MCP configuration file for your client:
101+
102+
```json
103+
{
104+
"mcpServers": {
105+
"weather": {
106+
"command": "npx",
107+
"args": [
108+
"mcp-remote",
109+
"http://127.0.0.1:5000/sse"
110+
]
111+
}
112+
}
113+
}
114+
```
115+
116+
### Usage
117+
53118
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.
54119

55120
You can now issue prompts related to weather forecasts and alerts, which will call out to the tools and invoke the GraphQL operations.
56121

57122
**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.
58123

124+
59125
# Running Your Own Graph
60126

61-
You can easily run the server with your own GraphQL schema and operations in the AI agent configuration file:
127+
You can easily run the server with your own GraphQL schema and operations. For example with the stdio transport:
62128

63129
```json
64130
{
@@ -84,4 +150,17 @@ The operation files are just `.graphql` files, with each file containing a singl
84150

85151
Run your schema in Apollo Router at the endpoint given in your configuration file.
86152

87-
In Claude Desktop, click the hammer icon to see the description generated for your tools.
153+
Use MCP Inspector, or in Claude Desktop, click the hammer icon to see the description generated for your tools.
154+
155+
# Introspection
156+
157+
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.
158+
159+
To enable this mode, add `--introspect` to the MCP server command line.
160+
161+
Two new tools will be exposed by the server:
162+
163+
* `schema` - returns the GraphQL schema
164+
* `execute` - executes an operation on the GraphQL endpoint
165+
166+
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.

crates/mcp-apollo-server/src/server.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use buildstructor::buildstructor;
88
use reqwest::header::{CONTENT_TYPE, HeaderMap, HeaderName, HeaderValue};
99
use rmcp::model::{
1010
CallToolRequestParam, CallToolResult, Content, ErrorCode, ListToolsResult,
11-
PaginatedRequestParam,
11+
PaginatedRequestParam, ServerCapabilities, ServerInfo,
1212
};
1313
use rmcp::serde_json::Value;
1414
use rmcp::service::RequestContext;
@@ -161,6 +161,13 @@ impl ServerHandler for Server {
161161
.collect(),
162162
})
163163
}
164+
165+
fn get_info(&self) -> ServerInfo {
166+
ServerInfo {
167+
capabilities: ServerCapabilities::builder().enable_tools().build(),
168+
..Default::default()
169+
}
170+
}
164171
}
165172

166173
fn tool_not_found(name: &str) -> McpError {

0 commit comments

Comments
 (0)