AI Suite > Subgraph MCP
2 minutes
Cursor
This guide walks you through the integration of Subgraph Model Context Protocol (MCP) to access Subgraph data through natural language conversations with Cline.
Prerequisites
- Cursor installed (latest version)
- A Gateway API key from Subgraph Studio
npx
orbunx
installed and available in your path
Configuration Steps
1. Open Configuration File
Create or edit your ~/.cursor/mcp.json
file.
Cursor Settings > MCP > Add new global MCP Server
2. Add Configuration
1{2 "mcpServers": {3 "subgraph": {4 "command": "npx",5 "args": ["mcp-remote", "--header", "Authorization:${AUTH_HEADER}", "https://subgraphs.mcp.thegraph.com/sse"],6 "env": {7 "AUTH_HEADER": "Bearer GATEWAY_API_KEY"8 }9 }10 }11}
3. Add Your API Key
Replace GATEWAY_API_KEY
with your API key from Subgraph Studio.
4. Restart Cursor
Restart Cursor, and start a new chat.
Available Subgraph 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
Benefits of Natural Language Queries
One of the most powerful features of the Subgraph MCP integration is the ability to ask questions in natural language. Cursor will:
- Understand your goal (lookup, find Subgraphs, query, get schema)
- Find relevant deployments if needed
- Fetch and interpret the Subgraph schema
- Convert your question into an appropriate GraphQL query
- Execute the query and present the results in a readable format
Example Natural Language Queries
1What are the pairs with maximum volume on deployment 0xde0a7b5368f846f7d863d9f64949b688ad9818243151d488b4c6b206145b9ea3?
1Which tokens have the highest market cap in this Subgraph?
1Show 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