GyanPrakash2483/CryptoMCP
If you are the rightful owner of CryptoMCP and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to dayong@mcphub.com.
A Model Context Protocol (MCP) server for fetching real-time and historical cryptocurrency market data from CoinMarketCap API.
Crypto MCP Server
A Model Context Protocol (MCP) server for fetching real-time and historical cryptocurrency market data from CoinMarketCap API.
Overview
This MCP server provides tools for accessing cryptocurrency market data, including:
- Real-time price quotes and market statistics
- Cryptocurrency metadata and information
- Global market metrics
- Price conversion between cryptocurrencies and fiat
- Market summaries and analysis prompts
Architecture & Approach
Design Decisions
- FastMCP Framework: Used for rapid MCP server development with minimal boilerplate
- HTTP Client:
httpxfor synchronous HTTP requests with proper timeout handling - Error Handling: Comprehensive try-catch blocks to gracefully handle API failures
- Response Formatting: Converts API responses to readable string format for LLM consumption
- Separation of Concerns: Each tool handles a specific API endpoint with clear parameters
Tool Categories
- Market Data Tools: Fetch listings, quotes, and global metrics
- Information Tools: Get cryptocurrency metadata and descriptions
- Utility Tools: Price conversion calculator
- Resources: Pre-configured market summary endpoint
- Prompts: Template generators for crypto analysis
Setup Instructions
Prerequisites
- Python 3.10 or higher
uvpackage manager installed
Installation
# Clone or create project directory
mkdir crypto-mcp
cd crypto-mcp
# Initialize uv project (optional)
uv init
# Install dependencies
uv add fastmcp httpx
# For testing
uv add pytest pytest-mock --dev
Configuration
-
Get API Key (for production use):
- Sign up at https://pro.coinmarketcap.com
- Copy your API key from the Developer Portal
- Replace in
server.py:CMC_BASE_URL = "https://pro-api.coinmarketcap.com" CMC_API_KEY = "YOUR_API_KEY_HERE"
-
For Testing (sandbox):
- The default configuration uses sandbox API with mock data
- No API key required for development/testing
Running the Server
# Direct execution
uv run server.py
# With MCP Inspector (recommended for testing)
npx @modelcontextprotocol/inspector uv run server.py
Testing
Running Tests
# Run all tests
uv run pytest test.py -v
# Run with coverage
uv add pytest-cov --dev
uv run pytest test.py -v --cov=server --cov-report=html
# Run specific test class
uv run pytest test.py::TestCryptocurrencyQuotes -v
# Skip integration tests (that require real API)
uv run pytest test.py -v -m "not integration"
Test Structure
- Unit Tests: Mock HTTP responses, test tool logic
- Edge Cases: Network errors, invalid inputs, malformed data
- Integration Tests: Optional real API calls (requires valid key)
Usage Examples
In MCP Inspector
-
Get Top Cryptocurrencies:
Tool: get_cryptocurrency_listings Parameters: {"limit": 5} -
Get Bitcoin Price:
Tool: get_cryptocurrency_quotes Parameters: {"symbol": "BTC"} -
Convert Crypto Amount:
Tool: convert_price Parameters: {"amount": 0.5, "symbol": "BTC", "convert": "USD"} -
Get Market Summary:
Resource: crypto://market-summary
With Claude Desktop
Once integrated, you can ask Claude:
- "What's the current Bitcoin price?"
- "Show me the top 10 cryptocurrencies by market cap"
- "Convert 2.5 ETH to USD"
- "Give me a detailed analysis of Ethereum"
Assumptions & Limitations
Assumptions
- API Availability: Assumes CoinMarketCap API is accessible and responsive
- Rate Limits: Free tier allows 30 calls/minute, 10,000/month
- USD Default: All conversions default to USD unless specified
- Symbol Uniqueness: When using symbols, returns highest market cap match
Limitations
- Sandbox Data: Default configuration uses mock data for testing
- No Caching: Each tool call makes a fresh API request (consider implementing caching)
- Synchronous Only: Uses synchronous HTTP calls (no async support)
- Limited Historical Data: Free tier only provides latest data, not historical
- No WebSocket: Real-time streaming not supported, polling only
- Error Messages: Returns string errors rather than structured error objects
Known Issues
- Sandbox API: Returns gibberish/mock data - must use production API for real data
- Rate Limiting: No built-in rate limit handling or retry logic
- Large Responses: Paginated endpoints may return large strings that could exceed context limits
- No Validation: Parameter values not validated before API calls
Possible Enhancements
- Add response caching to reduce API calls
- Implement exponential backoff for rate limiting
- Add async/await support for better performance
- Support for historical OHLCV data (requires higher tier)
- Add exchange-specific market data tools
- Implement data validation for parameters
- Add streaming updates via WebSocket
- Create visualization tools for price charts
- Add portfolio tracking capabilities
- Support for DeFi protocols and DEX data
Troubleshooting
Common Issues
"Module not found" error in tests:
# Run with PYTHONPATH
PYTHONPATH=. uv run pytest test_server.py -v
"API returns garbage data":
- You're using the sandbox API - switch to production URL and real API key
"Rate limit exceeded":
- Wait 60 seconds for minute limit reset
- Upgrade to higher tier plan
- Implement request caching
"Connection timeout":
- Check network connectivity
- Verify API endpoint URLs
- Increase timeout in httpx.Client()