CryptoMCP

GyanPrakash2483/CryptoMCP

3.2

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.

Tools
3
Resources
0
Prompts
0

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

  1. FastMCP Framework: Used for rapid MCP server development with minimal boilerplate
  2. HTTP Client: httpx for synchronous HTTP requests with proper timeout handling
  3. Error Handling: Comprehensive try-catch blocks to gracefully handle API failures
  4. Response Formatting: Converts API responses to readable string format for LLM consumption
  5. 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
  • uv package 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

  1. 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"
      
  2. 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

  1. Get Top Cryptocurrencies:

    Tool: get_cryptocurrency_listings
    Parameters: {"limit": 5}
    
  2. Get Bitcoin Price:

    Tool: get_cryptocurrency_quotes
    Parameters: {"symbol": "BTC"}
    
  3. Convert Crypto Amount:

    Tool: convert_price
    Parameters: {"amount": 0.5, "symbol": "BTC", "convert": "USD"}
    
  4. 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

  1. API Availability: Assumes CoinMarketCap API is accessible and responsive
  2. Rate Limits: Free tier allows 30 calls/minute, 10,000/month
  3. USD Default: All conversions default to USD unless specified
  4. Symbol Uniqueness: When using symbols, returns highest market cap match

Limitations

  1. Sandbox Data: Default configuration uses mock data for testing
  2. No Caching: Each tool call makes a fresh API request (consider implementing caching)
  3. Synchronous Only: Uses synchronous HTTP calls (no async support)
  4. Limited Historical Data: Free tier only provides latest data, not historical
  5. No WebSocket: Real-time streaming not supported, polling only
  6. Error Messages: Returns string errors rather than structured error objects

Known Issues

  1. Sandbox API: Returns gibberish/mock data - must use production API for real data
  2. Rate Limiting: No built-in rate limit handling or retry logic
  3. Large Responses: Paginated endpoints may return large strings that could exceed context limits
  4. 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()

Resources