代币API MCP服务器

这是一个MCP服务器,通过Claude等AI助手暴露The Graph的Token API,自动生成OpenAPI工具并支持热重载,用于查询EVM网络、Solana和TRON上的代币余额、转账、NFT数据和DEX交换。

  • by pinax-network
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 pinax-network/mcp-token-api-rest

使用说明

Token API MCP Server

An MCP server that exposes The Graph's Token API through Claude and other AI assistants. This server automatically generates tools from the Token API's OpenAPI specification and supports hot-reloading when the API is updated.

The Token API provides blockchain data for EVM networks (Ethereum, Arbitrum, Base, etc.), Solana, and TRON, including token balances, transfers, NFT data, and DEX swaps.

The MCP client is required to interact with the MCP server: https://github.com/pinax-network/pinax-mcp

Other useful links:

  • URL: https://token-api.thegraph.com/
  • Getting started: https://thegraph.com/docs/en/token-api/quick-start/
  • Repo: https://github.com/pinax-network/token-api

Installation

Install using uv (recommended):

uv pip install git+https://github.com/pinax-network/mcp-token-api-rest.git

Or with pip:

pip install git+https://github.com/pinax-network/mcp-token-api-rest.git

For development, clone the repository and install in editable mode:

git clone https://github.com/pinax-network/mcp-token-api-rest.git
cd mcp-token-api-rest
uv pip install -e .

Usage

Start the MCP server:

python -m src.server

The server will connect to the Token API at http://localhost:8000 by default and expose its endpoints as MCP tools. You can customize the connection using environment variables:

export TOKEN_API_BASE_URL=https://token-api.thegraph.com
python -m src.server

Once running, the server listens on http://localhost:8080 and provides tools for querying blockchain data. For example, through Claude you could ask "What's Vitalik's ETH balance on mainnet?" and it would use the appropriate Token API endpoints.

The server checks for API updates every 5 minutes (configurable) and hot-reloads the OpenAPI specification without requiring a restart.

Docker

Build and run with Docker:

docker build -t mcp-token-api .
docker run -p 8080:8080 -e TOKEN_API_BASE_URL=http://your-token-api:8000 mcp-token-api

Configuration

Configuration is done through environment variables:

  • TOKEN_API_BASE_URL sets the Token API endpoint (default: http://localhost:8000)
  • MCP_HOST and MCP_PORT control where the MCP server listens (default: 0.0.0.0:8080)
  • VERSION_CHECK_INTERVAL sets how often to check for API updates in seconds (default: 300)
  • MCP_STATELESS_HTTP serves each request without a server-side session (default: true). Stateful mode keeps every session until the client sends DELETE, so clients that never do leak memory

Testing

TOKEN_API_AUTH_TOKEN provides authentication if required (for tests)

Run the test suite:

pytest tests/test_server.py -v

Skip integration tests that require a running Token API:

pytest tests/test_server.py -v -m "not integration"

License

Apache-2.0