> ## Documentation Index
> Fetch the complete documentation index at: https://docs.chainstream.io/llms.txt
> Use this file to discover all available pages before exploring further.

# MCP 配置指南

> 5 分钟完成 ChainStream MCP Server 配置

本指南帮助你快速配置 ChainStream MCP Server。

***

## 前提条件

| 要求             | 详情                               | 如何获取                                       |
| -------------- | -------------------------------- | ------------------------------------------ |
| ChainStream 账号 | 已注册账号                            | [注册](https://www.chainstream.io/dashboard) |
| API Key        | 用于认证的 `X-API-KEY`                | Dashboard → 应用 → 创建应用                      |
| AI 客户端         | Claude Desktop / Cursor / 自定义客户端 | 已安装                                        |

***

## MCP 端点

ChainStream 提供托管的 MCP Server，无需本地安装 — 直接连接：

```
https://mcp.chainstream.io/mcp
```

***

## 配置步骤

<Steps>
  <Step title="获取 API Key">
    1. 登录 [ChainStream Dashboard](https://www.chainstream.io/dashboard)
    2. 进入 **Applications**
    3. 点击 **Create New App** 并复制你的 API Key
  </Step>

  <Step title="配置 AI 客户端">
    <Tabs>
      <Tab title="Claude Desktop">
        **配置文件路径**：

        * macOS：`~/Library/Application Support/Claude/claude_desktop_config.json`
        * Windows：`%APPDATA%\Claude\claude_desktop_config.json`

        **方式 A — 云端端点（推荐）**：

        ```json theme={null}
        {
          "mcpServers": {
            "chainstream": {
              "url": "https://mcp.chainstream.io/mcp",
              "headers": {
                "X-API-KEY": "your_api_key"
              }
            }
          }
        }
        ```

        **方式 B — 本地 npm 包（stdio）**：

        ```json theme={null}
        {
          "mcpServers": {
            "chainstream": {
              "command": "npx",
              "args": ["@chainstream-io/mcp"],
              "env": {
                "CHAINSTREAM_API_KEY": "your_api_key"
              }
            }
          }
        }
        ```

        <Note>
          如果文件不存在，请手动创建。如果已有其他 MCP Server 配置，将 `chainstream` 配置添加到现有的 `mcpServers` 对象中。
        </Note>
      </Tab>

      <Tab title="Cursor IDE">
        **配置文件路径**：`.cursor/mcp.json`（项目级）或 Cursor 设置 → Features → MCP Servers

        **方式 A — 云端端点**：

        ```json theme={null}
        {
          "mcpServers": {
            "chainstream": {
              "url": "https://mcp.chainstream.io/mcp",
              "headers": {
                "X-API-KEY": "your_api_key"
              }
            }
          }
        }
        ```

        **方式 B — 本地 npm 包（stdio）**：

        ```json theme={null}
        {
          "mcpServers": {
            "chainstream": {
              "command": "npx",
              "args": ["@chainstream-io/mcp"],
              "env": {
                "CHAINSTREAM_API_KEY": "your_api_key"
              }
            }
          }
        }
        ```
      </Tab>

      <Tab title="自定义客户端">
        通过 HTTP 连接云端端点：

        | 端点     | URL                              | 方法   |
        | ------ | -------------------------------- | ---- |
        | MCP 端点 | `https://mcp.chainstream.io/mcp` | POST |

        **认证**：通过 `X-API-KEY` 请求头传递 API Key。

        **示例代码**：

        ```javascript theme={null}
        import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js';
        import { Client } from '@modelcontextprotocol/sdk/client/index.js';

        const transport = new StreamableHTTPClientTransport(
          new URL('https://mcp.chainstream.io/mcp'),
          {
            requestInit: {
              headers: {
                'X-API-KEY': process.env.CHAINSTREAM_API_KEY
              }
            }
          }
        );

        const client = new Client({
          name: 'my-client',
          version: '1.0.0'
        });

        await client.connect(transport);

        const { tools } = await client.listTools();
        console.log('Available tools:', tools.map(t => t.name));
        ```
      </Tab>
    </Tabs>
  </Step>

  <Step title="重启客户端">
    配置完成后，完全退出并重启 AI 客户端使配置生效。

    * **Claude Desktop**：完全退出（不是最小化），然后重新打开
    * **Cursor**：重启 IDE
  </Step>
</Steps>

***

## 验证配置

### 测试命令

在 AI 客户端中输入以下测试问题：

```
Solana 上的 SOL 代币是什么？安全吗？
```

### 预期结果

如果配置成功，AI 应该：

1. 调用 `tokens_search` 查找 SOL 代币
2. 调用 `tokens_analyze` 获取安全和持有者数据
3. 返回自然语言摘要

<Note>
  如果 AI 没有调用工具或返回错误，请参考下方[常见问题](#常见问题)。
</Note>

***

## 常见问题

<AccordionGroup>
  <Accordion title="认证失败" icon="key">
    **可能原因**：

    1. **API Key 输入错误**
       * 检查是否有多余空格
       * 确认完整复制

    2. **API Key 已撤销或过期**
       * 在 Dashboard 检查 Key 状态
       * 如需要可创建新 Key

    3. **请求头名称错误**
       * 云端端点：使用 `X-API-KEY` 请求头
       * npm 包：使用 `CHAINSTREAM_API_KEY` 环境变量

    **解决方案**：

    * 在 Dashboard → Applications 中验证 Key
    * 直接测试：`curl -H "X-API-KEY: your_key" https://api.chainstream.io/v2/blockchain`
  </Accordion>

  <Accordion title="连接失败" icon="plug-circle-xmark">
    **可能原因**：

    1. **网络问题**
       * 检查网络连接
       * 确认可以访问 `https://mcp.chainstream.io`

    2. **配置格式错误**
       * 检查 JSON 格式是否正确
       * 确认 URL 拼写正确

    **解决方案**：

    ```bash theme={null}
    curl -I https://mcp.chainstream.io/mcp
    ```
  </Accordion>

  <Accordion title="配置文件不生效" icon="file-circle-xmark">
    **可能原因**：

    1. **配置文件路径错误**
       * macOS：`~/Library/Application Support/Claude/claude_desktop_config.json`
       * Windows：`%APPDATA%\Claude\claude_desktop_config.json`

    2. **JSON 格式错误**
       * 使用 JSON 验证工具检查

    3. **客户端未重启**
       * 完全退出后重启

    **解决方案**：

    ```bash theme={null}
    cat ~/Library/Application\ Support/Claude/claude_desktop_config.json | python -m json.tool
    ```
  </Accordion>

  <Accordion title="工具调用失败：配额超限" icon="gauge-low">
    **可能原因**：

    1. 套餐配额已耗尽
    2. 请求频率过高，触发限流

    **解决方案**：

    * 在 Dashboard 查看配额使用情况
    * 升级套餐获取更多配额
  </Accordion>

  <Accordion title="数据返回延迟或超时" icon="clock">
    **可能原因**：

    1. 网络延迟
    2. 查询数据量过大

    **解决方案**：

    * 检查网络连接
    * 减少单次查询数据量
    * 稍后重试
  </Accordion>
</AccordionGroup>

***

## 下一步

<CardGroup cols={2}>
  <Card title="工具目录" icon="wrench" href="/cn/docs/ai-agents/mcp-server/tools">
    查看所有可用工具和使用示例
  </Card>

  <Card title="AI Agent 教程" icon="graduation-cap" href="/cn/docs/tutorials/ai-agent-with-mcp">
    构建 AI 交易助手
  </Card>
</CardGroup>
