---
title: Claude Desktop
---

This guide walks you through the integration of Subgraph [Model Context Protocol](https://modelcontextprotocol.io/introduction) (MCP) to access Subgraph data via natural language conversations with Claude.

## Prerequisites

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

## Installation Options

### Option 1: Using npx (Recommended)

#### Configuration Steps using npx

#### 1. Open Configuration File

Navigate to 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`

#### 2. Add Configuration

Paste the following settings into your config file:

```json
{
  "mcpServers": {
    "subgraph": {
      "command": "npx",
      "args": ["mcp-remote", "--header", "Authorization:${AUTH_HEADER}", "https://subgraphs.mcp.thegraph.com/sse"],
      "env": {
        "AUTH_HEADER": "Bearer GATEWAY_API_KEY"
      }
    }
  }
}
```

#### 3. Add Your Gateway API Key

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

#### 4. Save and Restart

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

### Option 2: Building from Source

#### Requirements

- Rust (latest stable version recommended: 1.75+)
  ```bash
  curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
  ```
  Follow the on-screen instructions. For other platforms, see the [official Rust installation guide](https://www.rust-lang.org/tools/install).

#### Installation Steps

1. **Clone and Build the Repository**

   ```bash
   git clone git@github.com:graphops/subgraph-mcp.git
   cd subgraph-mcp
   cargo build --release
   ```

2. **Find the Command Path**

   After building, the executable will be located at `target/release/subgraph-mcp` inside your project directory.
   - Navigate to your `subgraph-mcp` directory in terminal
   - Run `pwd` to get the full path
   - Combine the output with `/target/release/subgraph-mcp`

3. **Configure Claude Desktop**

   Open your `claude_desktop_config.json` file as described above and add:

   ```json
   {
     "mcpServers": {
       "subgraph": {
         "command": "/path/to/your/subgraph-mcp/target/release/subgraph-mcp",
         "env": {
           "GATEWAY_API_KEY": "your-api-key-here"
         }
       }
     }
   }
   ```

   Replace `/path/to/your/subgraph-mcp/target/release/subgraph-mcp` with the actual path to the compiled binary.

## 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 "Subgraph Server Instructions" as a resource by adding `graphql://subgraph` to your chat context

> **Important**: Claude Desktop may not automatically utilize the Subgraph MCP. You must manually add "Subgraph Server Instructions" resource to your chat context for each conversation where you want to use it.

## Troubleshooting

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

## 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/IPFS hash**: Run GraphQL queries against specific, immutable deployments
- **Execute query by Subgraph ID**: Run GraphQL queries against the latest version of a Subgraph

### Discovery Tools

- **Search subgraphs by keyword**: Find subgraphs by keyword in their display names, ordered by signal
- **Get deployment 30-day query counts**: Get aggregate query count over the last 30 days for multiple subgraph deployments
- **Get top Subgraph deployments for a contract**: Find the top 3 Subgraph deployments indexing a specific contract on a particular chain, ordered by query fees

## Key Identifier Types

- **Subgraph ID** (e.g., `5zvR82...`): Logical identifier for a subgraph. Use `execute_query_by_subgraph_id` or `get_schema_by_subgraph_id`.
- **Deployment ID** (e.g., `0x4d7c...`): Identifier for a specific, immutable deployment. Use `execute_query_by_deployment_id` or `get_schema_by_deployment_id`.
- **IPFS Hash** (e.g., `QmTZ8e...`): Identifier for the manifest of a specific, immutable deployment. Use `execute_query_by_deployment_id` (the gateway treats it like a deployment ID for querying) or `get_schema_by_ipfs_hash`.

## 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. 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
```

```
Find the top subgraphs for contract 0x1f98431c8ad98523631ae4a59f267346ea31f984 on arbitrum-one
```
