Skip to content

Commit dd98b33

Browse files
Claude initial draft
1 parent 92488fc commit dd98b33

File tree

1 file changed

+200
-0
lines changed

1 file changed

+200
-0
lines changed
Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
---
2+
title: Subgraph MCP
3+
---
4+
5+
## Using Claude Desktop to Access Subgraphs via MCP
6+
7+
The Subgraph Model Context Protocol (MCP) server enables Claude to interact directly with subgraphs on The Graph Network. This integration allows you to explore subgraph schemas, execute GraphQL queries, and find relevant subgraphs for specific contracts—all through natural language conversations with Claude.
8+
9+
### What You Can Do
10+
11+
With the Subgraph MCP integration, you can:
12+
13+
- Access the GraphQL schema for any subgraph on The Graph Network
14+
- Execute GraphQL queries against any subgraph deployment
15+
- Find top subgraph deployments for a contract address on a specific chain
16+
- Ask natural language questions about subgraph data without writing GraphQL queries manually
17+
18+
### Requirements
19+
20+
Before setting up the Subgraph MCP server, make sure you have:
21+
22+
- **Claude Desktop**: Latest version installed
23+
- **Rust**: Latest stable version (1.75+)
24+
- **Gateway API key**: An API key from The Graph Network
25+
26+
## Installation
27+
28+
### Step 1: Install Rust (if not already installed)
29+
30+
```bash
31+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
32+
```
33+
34+
Follow the on-screen instructions. For other platforms, see the [official Rust installation guide](https://www.rust-lang.org/tools/install).
35+
36+
### Step 2: Install the Subgraph MCP Server
37+
38+
```bash
39+
# Clone the repository
40+
git clone [email protected]:graphops/subgraph-mcp.git
41+
cd subgraph-mcp
42+
43+
# Build the project
44+
cargo build --release
45+
```
46+
47+
### Step 3: Get your Gateway API Key
48+
49+
You'll need an API key from [Subgraph Studio](https://thegraph.com/studio/) to authenticate requests to The Graph Network.
50+
51+
## Configuration
52+
53+
### Configure Claude Desktop
54+
55+
1. Open Claude Desktop and click on the top left corner to access Settings
56+
2. Add the Subgraph MCP server to your `claude_desktop_config.json`
57+
58+
Here's how to set up your configuration:
59+
60+
```json
61+
{
62+
"mcpServers": {
63+
"subgraph": {
64+
"command": "/path/to/your/subgraph-mcp/target/release/subgraph-mcp",
65+
"env": {
66+
"GATEWAY_API_KEY": "your-api-key-here"
67+
}
68+
}
69+
}
70+
}
71+
```
72+
73+
#### Finding the Command Path
74+
75+
After building the project, you need to specify the absolute path to the compiled binary:
76+
77+
1. Navigate to your `subgraph-mcp` directory in the terminal
78+
2. Run `pwd` to get the full path to the directory
79+
3. Add `/target/release/subgraph-mcp` to that path
80+
81+
For example, if `pwd` outputs `/Users/username/subgraph-mcp`, your full command path would be: `/Users/username/subgraph-mcp/target/release/subgraph-mcp`
82+
83+
### Troubleshooting Installation
84+
85+
If you encounter issues with the setup:
86+
87+
1. Clean any existing build and rebuild:
88+
89+
```bash
90+
cd subgraph-mcp
91+
cargo clean
92+
cargo build --release
93+
```
94+
95+
2. Ensure the executable has proper permissions:
96+
```bash
97+
chmod +x target/release/subgraph-mcp
98+
```
99+
100+
## Using The Graph Resource in Claude
101+
102+
After configuring Claude Desktop:
103+
104+
1. Restart Claude Desktop
105+
2. Start a new conversation
106+
3. Click on the context menu (top right)
107+
4. Add "The Graph" resource by adding `graphql://subgraph` to your chat context
108+
109+
**Important**: Claude Desktop may not automatically utilize the Subgraph MCP. You must manually add "The Graph" resource to your chat context for each conversation where you want to use it.
110+
111+
## Available Tools and Usage
112+
113+
The Subgraph MCP provides several tools for interacting with subgraphs:
114+
115+
### Schema Retrieval Tools
116+
117+
- **Get schema by deployment ID**: Access the GraphQL schema using a deployment ID (0x...)
118+
- **Get schema by subgraph ID**: Access the schema for the current deployment of a subgraph (5zvR82...)
119+
- **Get schema by IPFS hash**: Access the schema using a subgraph's IPFS manifest hash (Qm...)
120+
121+
### Query Execution Tools
122+
123+
- **Execute query by deployment ID**: Run GraphQL queries against specific, immutable deployments
124+
- **Execute query by subgraph ID**: Run GraphQL queries against the latest version of a subgraph
125+
126+
### Discovery Tools
127+
128+
- **Get top subgraph deployments**: Find the top 3 subgraph deployments indexing a specific contract on a particular chain
129+
130+
## Natural Language Queries
131+
132+
One of the most powerful features of the Subgraph MCP integration is the ability to ask questions in natural language. Claude will:
133+
134+
1. Understand your goal (lookup, find subgraphs, query, get schema)
135+
2. Find relevant deployments if needed
136+
3. Fetch and interpret the subgraph schema
137+
4. Convert your question into an appropriate GraphQL query
138+
5. Execute the query and present the results in a readable format
139+
140+
### Example Natural Language Queries
141+
142+
```
143+
What are the pairs with maximum volume on 0xde0a7b5368f846f7d863d9f64949b688ad9818243151d488b4c6b206145b9ea3?
144+
145+
Which tokens have the highest market cap in this subgraph?
146+
147+
Show me the most recent 5 swaps for the USDC/ETH pair
148+
```
149+
150+
## Using Both Token API MCP and Subgraph MCP Together
151+
152+
You can configure Claude Desktop to use both the Token API MCP and Subgraph MCP simultaneously:
153+
154+
```json
155+
{
156+
"mcpServers": {
157+
"token-api": {
158+
"command": "path-to-bunx",
159+
"args": ["@pinax/mcp", "--sse-url", "https://token-api.thegraph.com/sse"],
160+
"env": {
161+
"ACCESS_TOKEN": "access-token-from-graph-market"
162+
}
163+
},
164+
"subgraph": {
165+
"command": "/path/to/subgraph-mcp/target/release/subgraph-mcp",
166+
"env": {
167+
"GATEWAY_API_KEY": "api-key-from-subgraph-studio"
168+
}
169+
}
170+
}
171+
}
172+
```
173+
174+
For Token API access tokens, visit [The Graph Market](https://thegraph.com/explorer). For Subgraph Gateway API keys, visit [Subgraph Studio](https://thegraph.com/studio/).
175+
176+
## Key Identifier Types
177+
178+
When working with subgraphs, you'll encounter different types of identifiers:
179+
180+
- **Subgraph ID** (e.g., `5zvR82...`): Logical identifier for a subgraph
181+
- **Deployment ID** (e.g., `0x4d7c...`): Identifier for a specific, immutable deployment
182+
- **IPFS Hash** (e.g., `QmTZ8e...`): Identifier for the manifest of a specific deployment
183+
184+
## Example Interactions
185+
186+
Here are some examples of how you can interact with Claude once the Subgraph MCP is set up:
187+
188+
```
189+
Get the schema for subgraph deployment 0xYourDeploymentIdHere
190+
191+
Run this query against subgraph 5zvR82YourSubgraphIdHere: { users(first: 1) { id } }
192+
193+
Find the top subgraphs for contract 0x1f98431c8ad98523631ae4a59f267346ea31f984 on arbitrum-one
194+
```
195+
196+
## Additional Resources
197+
198+
- [The Graph Documentation](https://thegraph.com/docs/)
199+
- [Subgraph MCP GitHub Repository](https://github.com/graphops/subgraph-mcp)
200+
- [Token API MCP Documentation](https://thegraph.com/docs/en/token-api/mcp/claude/)

0 commit comments

Comments
 (0)