项目简介

Subgraph MCP 服务器是一个基于 Model Context Protocol (MCP) 构建的应用后端,允许大型语言模型 (LLM) 通过它与 The Graph Network 上可用的 subgraph 进行交互,获取链上数据和 schema。

主要功能点

该服务器提供以下核心功能:

  • 获取 Subgraph Schema: 通过 deployment ID、subgraph ID 或 IPFS hash 获取任何 subgraph 的 GraphQL schema。
  • 执行 GraphQL 查询: 对指定的 subgraph deployment (通过 ID 或 hash) 或最新的 subgraph (通过 subgraph ID) 执行 GraphQL 查询。
  • 查找热门 Subgraph: 根据合约地址和链查找索引该合约的热门 subgraph deployment。
  • 支持 MCP 功能: 完全实现了 MCP 的资源、工具和 Prompt 能力,使 LLM 客户端能够标准地利用这些功能。

安装步骤

  1. 安装 Rust 编程语言的最新稳定版本(建议 1.75+)。
  2. 从 GitHub 克隆仓库:
    git clone [email protected]:graphops/subgraph-mcp.git
    cd subgraph-mcp
  3. 构建项目:
    cargo build --release
    构建成功后,可在 'target/release/' 目录下找到可执行文件 'subgraph-mcp'。

服务器配置

要将 Subgraph MCP 服务器连接到支持 MCP 的 LLM 客户端(如 Claude Desktop),您需要在客户端的配置中添加服务器信息。典型的配置需要指定服务器的名称、可执行文件的路径以及必要的环境变量(如 The Graph Gateway API Key)。例如:

  • 服务器名称: 自定义,例如 'subgraph'。
  • 命令 (command): 指向您编译生成的 'subgraph-mcp' 可执行文件的完整路径(例如 '/path/to/your/subgraph-mcp')。
  • 环境变量 (env): 必须设置 'GATEWAY_API_KEY' 环境变量,值为您的 The Graph Gateway API Key。

配置完成后,重新启动 LLM 客户端,并在聊天会话中添加或引用 Subgraph MCP 服务器提供的资源(例如 'graphql://subgraph'),以便 LLM 了解可用的工具和上下文信息。

基本使用方法

连接并配置服务器后,您可以通过自然语言直接向 LLM 提问,例如:

  • 获取特定 subgraph 的 schema:'Get the schema for subgraph deployment 0xYourDeploymentIdHere'
  • 执行查询:'Run this query against subgraph 5zvR82YourSubgraphIdHere: { users(first: 1) { id } }'
  • 查找与合约相关的 subgraph:'Find the top subgraphs for contract 0x1f98431c8ad98523631ae4a59f267346ea31f984 on arbitrum-one'

LLM 将根据您的提问,自动调用 Subgraph MCP 服务器提供的工具,与 The Graph Network 进行交互并返回结果。务必根据需要在 LLM 客户端中手动添加服务器提供的资源(例如 'graphql://subgraph')到当前会话上下文,以确保其能利用服务器功能。

信息

分类

网页与API