加密货币价格服务

一个基于JSON-RPC协议和CCXT库的加密货币价格查询服务,提供实时和历史价格数据。

  • by ts-31
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 ts-31/mcp-crypto-server

使用说明

MCP Crypto Server

Requirements

  • Python 3.10+
  • Install dependencies: pip install -r requirements.txt

Project Structure

  • src/server.py: Stdio JSON-RPC loop.
  • src/endpoints/: Tool logic (async functions).
  • src/utils/: CCXT wrapper, cache, errors.
  • src/mcp/protocol.py: MCP dispatcher and tool registry.
  • tests/: Pytest cases with CCXT mocks.

How to Run the MCP Server

  1. Navigate to project root.
  2. Run: python -m src.server
    • Server runs as subprocess via stdio. It reads JSON-RPC requests from stdin and writes responses to stdout.
    • Use with an MCP-compatible host (e.g., Claude Desktop, Cursor) that launches it as a tool server.

The server closes CCXT connections on exit.

Test It

List tools:

echo '{"jsonrpc":"2.0","method":"mcp/listTools","params":{},"id":1}' | python -m src.server

Get BTC price:

echo '{"jsonrpc":"2.0","method":"mcp/callTool","params":{"name":"get_current_price","args":{"symbol":"BTC/USDT"}},"id":2}' | python -m src.server

Tools

  • get_current_price(symbol): Current ticker.
  • get_historical_ohlcv(symbol, timeframe='1h', limit=100): OHLCV candles.
  • subscribe_realtime(symbol): Poll for updates (call every 10s).

Tests

pytest tests/

Structure

  • src/server.py: Stdio loop.
  • src/endpoints/: Tool functions.
  • src/utils/: CCXT, cache, errors.
  • src/mcp/protocol.py: JSON-RPC handler.