使用说明
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
- Navigate to project root.
- 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.