Skip to content

Subgraph mcp #949

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 36 commits into from
May 21, 2025
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
dd98b33
Claude initial draft
MichaelMacaulay May 9, 2025
ebafea3
Initial structure
MichaelMacaulay May 9, 2025
d60f8d6
Updating & scaffolding
MichaelMacaulay May 12, 2025
780b7df
Latest edits
MichaelMacaulay May 13, 2025
0223551
Update website/src/pages/en/resources/claud-mcp.mdx
MichaelMacaulay May 14, 2025
01809b1
Update website/src/pages/en/resources/claud-mcp.mdx
MichaelMacaulay May 14, 2025
847714c
Update website/src/pages/en/resources/claud-mcp.mdx
MichaelMacaulay May 14, 2025
bd33950
Update website/src/pages/en/resources/claud-mcp.mdx
MichaelMacaulay May 14, 2025
11d5213
Update website/src/pages/en/resources/claud-mcp.mdx
MichaelMacaulay May 14, 2025
683b76c
Update website/src/pages/en/resources/claud-mcp.mdx
MichaelMacaulay May 14, 2025
bfc1e9a
Update website/src/pages/en/subgraphs/mcp/claude.mdx
MichaelMacaulay May 14, 2025
a819891
Update website/src/pages/en/subgraphs/mcp/cursor.mdx
MichaelMacaulay May 14, 2025
12aecba
Update website/src/pages/en/subgraphs/mcp/cursor.mdx
MichaelMacaulay May 14, 2025
f1b3419
Update website/src/pages/en/resources/claud-mcp.mdx
MichaelMacaulay May 14, 2025
babe814
Update website/src/pages/en/resources/claud-mcp.mdx
MichaelMacaulay May 14, 2025
f1726e7
Update website/src/pages/en/resources/claud-mcp.mdx
MichaelMacaulay May 14, 2025
c371fb6
Update website/src/pages/en/subgraphs/mcp/claude.mdx
MichaelMacaulay May 14, 2025
0250363
Update website/src/pages/en/subgraphs/mcp/claude.mdx
MichaelMacaulay May 14, 2025
4e9ccc8
Update website/src/pages/en/subgraphs/mcp/claude.mdx
MichaelMacaulay May 14, 2025
77ef47f
Edits
MichaelMacaulay May 14, 2025
9dfb8f3
Latest updates
MichaelMacaulay May 14, 2025
43d9dc5
Final tweak
MichaelMacaulay May 14, 2025
64c454c
Update website/src/pages/en/resources/claud-mcp.mdx
MichaelMacaulay May 14, 2025
b460b6e
Update website/src/pages/en/resources/claud-mcp.mdx
MichaelMacaulay May 14, 2025
6796735
Update website/src/pages/en/resources/claud-mcp.mdx
MichaelMacaulay May 14, 2025
cc380a4
Update website/src/pages/en/resources/claud-mcp.mdx
MichaelMacaulay May 14, 2025
f2e1bb7
Update website/src/pages/en/subgraphs/mcp/claude.mdx
MichaelMacaulay May 14, 2025
ed669c4
Update website/src/pages/en/subgraphs/mcp/claude.mdx
MichaelMacaulay May 14, 2025
2c3a32d
Edits
MichaelMacaulay May 14, 2025
010631d
Merge branch 'Subgraph-MCP' of https://github.com/graphprotocol/docs …
MichaelMacaulay May 14, 2025
4aa4bd4
Edits
MichaelMacaulay May 14, 2025
83759e5
Update website/src/pages/en/subgraphs/mcp/cline.mdx
MichaelMacaulay May 14, 2025
d81bb7f
Update website/src/pages/en/subgraphs/mcp/cursor.mdx
MichaelMacaulay May 14, 2025
696f5b7
Check fix
MichaelMacaulay May 14, 2025
2521141
Fix build
benface May 14, 2025
5154ab1
Merge branch 'main' into Subgraph-MCP
MichaelMacaulay May 20, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions website/src/pages/en/resources/_meta.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ export default {
roles: titles.roles,
'migration-guides': titles['migration-guides'],
'subgraph-studio-faq': '',
'claud-mcp': '',
}
123 changes: 123 additions & 0 deletions website/src/pages/en/resources/claud-mcp.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
---
title: Claude MCP
---

This guide walks you through configuring Claude Desktop to use The Graph ecosystem's Model Context Protocol (MCP) resources: Token API and Subgraph. These integrations allow you to interact with blockchain data through natural language conversations with Claude.

## What You Can Do

With these integrations, you can:

- **Token API**: Access token and wallet information across multiple blockchains
- **Subgraph**: Explore Subgraph schemas, execute GraphQL queries, and find relevant Subgraphs for specific contracts

## Prerequisites

- [Node.js](https://nodejs.org/en/download/) installed and available in your path
- [Claude Desktop](https://claude.ai/download) installed
- API keys:
- Token API key from [The Graph Market](https://thegraph.market/)
- Gateway API key from [Subgraph Studio](https://thegraph.com/studio/apikeys/)

## Configuration

Follow these steps to configure both Token API and Subgraph MCP in Claude Desktop:

### Step 1: Open Configuration File

Edit your `claude_desktop_config.json` file:

> **Claude Desktop** > **Settings** > **Developer** > **Edit Config**

File locations by operating system:

- OSX: `~/Library/Application Support/Claude/claude_desktop_config.json`
- Windows: `%APPDATA%\Claude\claude_desktop_config.json`
- Linux: `.config/Claude/claude_desktop_config.json`

### Step 2: Add Configuration

Replace the existing configuration with this template:

```json
{
"mcpServers": {
"token-api": {
"command": "npx",
"args": ["@pinax/mcp", "--sse-url", "https://token-api.thegraph.com/sse"],
"env": {
"ACCESS_TOKEN": "ACCESS_TOKEN"
}
},
"subgraph": {
"command": "npx",
"args": [
"mcp-remote",
"--header",
"Authorization: Bearer GATEWAY_API_KEY",
"https://subgraph-ai.graphops.xyz/sse"
]
}
}
}
```

### Step 3: Add Your API Keys

1. Replace `ACCESS_TOKEN` with your Token API key from [The Graph Market](https://thegraph.market/)
2. Replace `GATEWAY_API_KEY` with your Gateway API key from [Subgraph Studio](https://thegraph.com/studio/apikeys/)

### Step 4: Save and Restart

Save the configuration file and restart Claude Desktop.

## Using The Graph Resources in Claude

After configuration:

1. Start a new conversation in Claude Desktop
2. Click on the context menu (top right)
3. Add "The Graph" resource by entering `graphql://subgraph` for Subgraph MCP and/or `token-api://token-api` for Token API

**Important**: You must manually add The Graph resources to your chat context for each conversation where you want to use them.

## Example Queries

Here are some example queries you can try after setting up the resources:

### Subgraph Queries

```
What are the top pools in Uniswap?
```

```
Top delegators of The Graph Protocol?
```

```
Number of active loans in Compound for the last 7 days? Please make it a bar chart
```

### Token API Queries

```
Show me the current price of ETH
```

```
What are the top tokens by market cap on Ethereum?
```

```
Analyze this wallet address: 0x...
```

## Troubleshooting

If you encounter issues:

1. **Verify Node.js Installation**: Ensure Node.js is correctly installed by running `node -v` in your terminal
2. **Check API Keys**: Verify that your API keys are correctly entered in the configuration file
3. **Enable Verbose Logging**: Add `--verbose true` to the args array in your configuration to see detailed logs
4. **Restart Claude Desktop**: After making changes to the configuration, always restart Claude Desktop
3 changes: 2 additions & 1 deletion website/src/pages/en/subgraphs/_meta-titles.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"querying": "Querying",
"developing": "Developing",
"guides": "How-to Guides",
"best-practices": "Best Practices"
"best-practices": "Best Practices",
"mcp": "MCP"
}
1 change: 1 addition & 0 deletions website/src/pages/en/subgraphs/_meta.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export default {
querying: titles.querying,
developing: titles.developing,
billing: '',
mcp: titles.mcp,
guides: titles.guides,
'best-practices': titles['best-practices'],
}
5 changes: 5 additions & 0 deletions website/src/pages/en/subgraphs/mcp/_meta.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default {
claude: '',
cline: '',
cursor: '',
}
110 changes: 110 additions & 0 deletions website/src/pages/en/subgraphs/mcp/claude.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
---
title: Claude Desktop
---

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.

## What You Can Do

With the Subgraph MCP integration, you can:

- Access the GraphQL schema for any Subgraph on The Graph Network
- Execute GraphQL queries against any Subgraph deployment
- Find top Subgraph deployments for a contract address on a specific chain
- Ask natural language questions about Subgraph data without writing GraphQL queries manually

## Prerequisites

- [Node.js](https://nodejs.org/en) installed and available in your path
- [Claude Desktop](https://claude.ai/download) installed
- A Gateway API key from [Subgraph Studio](https://thegraph.com/studio/)

## Configuration

Edit your `claude_desktop_config.json` file.

> **Settings** > **Developer** > **Edit Config**

- OSX: `~/Library/Application Support/Claude/claude_desktop_config.json`
- Windows: `%APPDATA%\Claude\claude_desktop_config.json`
- Linux: `.config/Claude/claude_desktop_config.json`

Paste the following settings into your config file:

```json label="claude_desktop_config.json"
{
"mcpServers": {
"subgraph": {
"command": "npx",
"args": [
"mcp-remote",
"--header",
"Authorization: Bearer GATEWAY_API_KEY",
"https://subgraph-ai.graphops.xyz/sse"
]
}
}
}
```

Replace `GATEWAY_API_KEY` with your API key from [Subgraph Studio](https://thegraph.com/studio/).

Once you've entered your Gateway API key into your settings, you can save the file, and restart Claude desktop.

## Using The Graph Resource in Claude

After configuring Claude Desktop:

1. Restart Claude Desktop
2. Start a new conversation
3. Click on the context menu (top right)
4. Add "The Graph" resource by adding `graphql://subgraph` to your chat context

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

## Troubleshooting

To enable logs for the MCP, add the `--verbose true` option to your args array.

## Available Tools and Usage

The Subgraph MCP provides several tools for interacting with Subgraphs:

### Schema Retrieval Tools

- **Get schema by deployment ID**: Access the GraphQL schema using a deployment ID (0x...)
- **Get schema by Subgraph ID**: Access the schema for the current deployment of a Subgraph (5zvR82...)
- **Get schema by IPFS hash**: Access the schema using a Subgraph's IPFS manifest hash (Qm...)

### Query Execution Tools

- **Execute query by deployment ID**: Run GraphQL queries against specific, immutable deployments
- **Execute query by Subgraph ID**: Run GraphQL queries against the latest version of a Subgraph

### Discovery Tools

- **Get top Subgraph deployments**: Find the top 3 Subgraph deployments indexing a specific contract on a particular chain

## Natural Language Queries

One of the most powerful features of the Subgraph MCP integration is the ability to ask questions in natural language. Claude will:

1. Understand your goal (lookup, find Subgraphs, query, get schema)
2. Find relevant deployments if needed
3. Fetch and interpret the Subgraph schema
4. Convert your question into an appropriate GraphQL query
5. Execute the query and present the results in a readable format

### Example Natural Language Queries

```
What are the pairs with maximum volume on deployment 0xde0a7b5368f846f7d863d9f64949b688ad9818243151d488b4c6b206145b9ea3?
```

```
Which tokens have the highest market cap in this Subgraph?
```

```
Show me the most recent 5 swaps for the USDC/ETH pair
```
121 changes: 121 additions & 0 deletions website/src/pages/en/subgraphs/mcp/cline.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
---
title: Cline
---

The Subgraph Model Context Protocol (MCP) server enables Cline 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 Cline.

## Prerequisites

- [Cline](https://cline.bot/) installed (latest version)
- A Gateway API key from [Subgraph Studio](https://thegraph.com/studio/)
- [`npx`](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm) or [`bunx`](https://bun.sh/) installed and available in your path

## Configuration

Create or edit your `cline_mcp_settings.json` file.

> **MCP Servers** > **Installed** > **Configure MCP Servers**

```json label="cline_mcp_settings.json"
{
"mcpServers": {
"subgraph": {
"command": "npx",
"args": [
"mcp-remote",
"--header",
"Authorization: Bearer GATEWAY_API_KEY",
"https://subgraph-ai.graphops.xyz/sse"
]
}
}
}
```

Replace `GATEWAY_API_KEY` with your API key from Subgraph Studio.

## Using Both Token API MCP and Subgraph MCP Together

You can configure Cline to use both the Token API MCP and Subgraph MCP simultaneously:

```json label="cline_mcp_settings.json"
{
"mcpServers": {
"token-api": {
"command": "npx",
"args": ["@pinax/mcp", "--sse-url", "https://token-api.thegraph.com/sse"],
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've updated this endpoint to be token-api.**MCP**.thegraph.com/sse. We did this to normalize how we handle MCP domains moving forward.

@0237h , could you please also update the repo with this new endpoint?

Also, @MichaelMacaulay , we're doing the same for GraphOps (which doesn't have a thegraph.com domain yet). This is taking a bit longer than expected as we ran into some issues, but I can update the docs team once that's done.

"env": {
"ACCESS_TOKEN": "ACCESS_TOKEN"
}
},
"subgraph": {
"command": "npx",
"args": [
"mcp-remote",
"--header",
"Authorization: Bearer GATEWAY_API_KEY",
"https://subgraph-ai.graphops.xyz/sse"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

]
}
}
}
```

- 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/)

## Using The Graph Resource in Cline

After configuring Cline:

1. Restart Cline
2. Start a new conversation
3. Enable the Subgraph MCP from the context menu
4. Add "The Graph" resource to your chat context

## Available Tools and Usage

The Subgraph MCP provides several tools for interacting with Subgraphs:

### Schema Retrieval Tools

- **Get schema by deployment ID**: Access the GraphQL schema using a deployment ID (0x...)
- **Get schema by Subgraph ID**: Access the schema for the current deployment of a Subgraph (5zvR82...)
- **Get schema by IPFS hash**: Access the schema using a Subgraph's IPFS manifest hash (Qm...)

### Query Execution Tools

- **Execute query by deployment ID**: Run GraphQL queries against specific, immutable deployments
- **Execute query by Subgraph ID**: Run GraphQL queries against the latest version of a Subgraph

### Discovery Tools

- **Get top Subgraph deployments**: Find the top 3 Subgraph deployments indexing a specific contract on a particular chain

## Natural Language Queries

One of the most powerful features of the Subgraph MCP integration is the ability to ask questions in natural language. Cline will:

1. Understand your goal (lookup, find Subgraphs, query, get schema)
2. Find relevant deployments if needed
3. Fetch and interpret the Subgraph schema
4. Convert your question into an appropriate GraphQL query
5. Execute the query and present the results in a readable format

### Example Natural Language Queries

```
What are the pairs with maximum volume on deployment 0xde0a7b5368f846f7d863d9f64949b688ad9818243151d488b4c6b206145b9ea3?

Which tokens have the highest market cap in this Subgraph?

Show me the most recent 5 swaps for the USDC/ETH pair
```

## Key Identifier Types

When working with Subgraphs, you'll encounter different types of identifiers:

- **Subgraph ID** (e.g., `5zvR82...`): Logical identifier for a Subgraph
- **Deployment ID** (e.g., `0x4d7c...`): Identifier for a specific, immutable deployment
- **IPFS Hash** (e.g., `QmTZ8e...`): Identifier for the manifest of a specific deployment
Loading
Loading