Python-based MCP server that exposes real-time and historical cryptocurrency market data using CCXT and FastMCP.
- MCP tools:
health_check– simple server health probe.get_current_price– latest ticker for a symbol (e.g.BTC/USDT) on a given exchange.get_order_book– bids/asks snapshot with configurablelimit.get_historical_ohlcv– historical OHLCV candles for a symbol, timeframe, since, and limit.stream_ticker– polling-based ticker streaming via async generator.
- In-memory TTL cache for:
- ticker, order book, and OHLCV responses.
- Robust error handling:
- custom exceptions for validation, unsupported exchanges/symbols, and upstream API errors.
- Test suite with pytest, pytest-asyncio, and CCXT mocking.
- Python 3.12
- FastMCP – MCP server framework.
- CCXT – crypto exchange market data.
- pytest, pytest-asyncio – testing.
src/mcp_crypto_server/ config.py # Defaults and TTLs cache.py # Simple TTL in-memory cache errors.py # Custom error types and normalization exchanges.py # CCXT wrapper with caching and error mapping schemas.py # Typed dicts for responses tools.py # MCP tools + plain *_impl functions server.py # Entry point (mcp.run()) tests/ test_cache.py test_exchanges.py test_tools.py test_placeholder.py
git clone <YOUR_REPO_URL> cd mcp-crypto-server
python3 -m venv .venv source .venv/bin/activate # Windows: ..venv\Scripts\activate
python -m pip install --upgrade pip python -m pip install -e ".[dev]"
or, if needed: python -m pip install fastmcp ccxt pytest pytest-asyncio
pytest
All tests should pass.
python -m mcp_crypto_server.server
This starts the MCP server over stdio, ready to be used by an MCP-compatible client (Claude Desktop, etc.). Tools available:
health_checkget_current_priceget_order_bookget_historical_ohlcvstream_ticker
- Uses public CCXT endpoints only (no authentication, spot markets only).
- Caching is in-memory; suitable for a single-process server.
stream_tickeruses polling at a configurable interval, not WebSocket streams.- Basic validation on symbols (
BASE/QUOTE), timeframes, and limits.