
Polymarket
STDIOHigh-performance MCP server for Polymarket prediction market data with real-time prices and betting information
High-performance MCP server for Polymarket prediction market data with real-time prices and betting information
A high-performance Model Context Protocol (MCP) server for Polymarket prediction market data, built with Rust. This server provides real-time market data, prices, and betting information from Polymarket through MCP tools, resources, and prompts.
Download the latest release for your platform:
Configure Claude Desktop:
Edit your Claude Desktop configuration file:
~/Library/Application Support/Claude/claude_desktop_config.json
%APPDATA%\Claude\claude_desktop_config.json
~/.config/Claude/claude_desktop_config.json
Add the Polymarket MCP server:
{ "mcpServers": { "polymarket": { "command": "/path/to/polymarket-mcp/target/release/polymarket-mcp", "env": { "RUST_LOG": "info" } } } }
Restart Claude Desktop to load the new MCP server.
Clone and build:
git clone https://github.com/0x79de/polymarket-mcp cd polymarket-mcp cargo build --release
Use the binary at target/release/polymarket-mcp
in your Claude Desktop configuration.
Build Docker image:
docker build -t polymarket-mcp:latest .
Configure Claude Desktop for Docker:
Edit your Claude Desktop configuration file:
# macOS vim ~/Library/Application\ Support/Claude/claude_desktop_config.json # Windows notepad %APPDATA%\Claude\claude_desktop_config.json # Linux nano ~/.config/Claude/claude_desktop_config.json
Add the Docker configuration:
{ "mcpServers": { "polymarket": { "command": "docker", "args": [ "run", "-i", "--rm", "-e", "RUST_LOG=info", "-e", "POLYMARKET_CACHE_TTL=300", "polymarket-mcp:latest" ], "env": { "RUST_LOG": "info" } } } }
Restart Claude Desktop to load the new MCP server.
cargo install --git https://github.com/0x79de/polymarket-mcp
The binary will be installed to ~/.cargo/bin/polymarket-mcp
.
The server works out-of-the-box with sensible defaults. No configuration is required for basic usage.
Create a .env
file for custom configuration:
# API Configuration POLYMARKET_API_BASE_URL=https://gamma-api.polymarket.com # POLYMARKET_API_KEY=your_key_here # Optional - not needed for public data # Performance Settings POLYMARKET_CACHE_ENABLED=true POLYMARKET_CACHE_TTL=60 # Cache TTL in seconds POLYMARKET_RESOURCE_CACHE_TTL=300 # Resource cache TTL # Logging POLYMARKET_LOG_LEVEL=info # trace, debug, info, warn, error RUST_LOG=info # Alternative log level setting # Advanced Settings (rarely needed) POLYMARKET_API_TIMEOUT=30 # API timeout in seconds POLYMARKET_API_MAX_RETRIES=3 # Retry attempts POLYMARKET_API_RETRY_DELAY=100 # Retry delay in ms
Alternatively, copy config.toml.example
to config.toml
and customize:
[server] name = "Polymarket MCP Server" timeout_seconds = 30 [api] base_url = "https://gamma-api.polymarket.com" # api_key = "your_key_here" # Optional timeout_seconds = 30 max_retries = 3 retry_delay_ms = 100 [cache] enabled = true ttl_seconds = 60 max_entries = 1000 resource_cache_ttl_seconds = 300 [logging] level = "info" format = "pretty" enable_colors = true
Configuration is loaded in this order (highest to lowest priority):
POLYMARKET_LOG_LEVEL=debug
)config.toml
, polymarket-mcp.toml
, etc.)After installing and configuring the MCP server, you can interact with Polymarket data directly through Claude Desktop. Try these example prompts:
🔍 Market Discovery:
- "Show me the top 10 active prediction markets"
- "Search for markets about 'AI' or 'artificial intelligence'"
- "What are the trending markets with highest volume?"
📊 Market Analysis:
- "Get details for market ID 12345"
- "What are the current prices for the Trump 2024 market?"
- "Analyze the sentiment of markets about cryptocurrency"
🤖 AI-Powered Insights:
- "Find arbitrage opportunities in election markets"
- "Give me a summary of the top 5 political prediction markets"
- "Analyze market 67890 for trading opportunities"
search_markets
tool with keyword "AI"analyze_market
prompt for deep insights# Quick test (requires Rust) cargo run # With debug logging RUST_LOG=debug cargo run # Run all tests cargo test # Check code quality cargo clippy # Docker development docker build -t polymarket-mcp:latest . docker run -it --rm -e RUST_LOG=debug polymarket-mcp:latest # Test MCP protocol manually echo '{"jsonrpc":"2.0","method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"test","version":"1.0.0"}},"id":0}' | cargo run
This server implements the full MCP specification with 5 tools, 3 resources, and 3 prompts.
Tool | Description | Parameters |
---|---|---|
get_active_markets | Fetch currently active prediction markets | limit (optional, default: 50) |
get_market_details | Get detailed information about a specific market | market_id (required) |
search_markets | Search markets by keyword in questions/descriptions | keyword (required), limit (optional, default: 20) |
get_market_prices | Get current yes/no prices for a market | market_id (required) |
get_trending_markets | Get markets with highest trading volume | limit (optional, default: 10) |
Auto-refreshing data resources that Claude can access:
Resource | Description | Refresh Rate |
---|---|---|
markets:active | List of currently active markets | Every 5 minutes |
markets:trending | Markets sorted by trading volume | Every 5 minutes |
market:{id} | Specific market details by ID | Every 5 minutes |
AI-powered analysis prompts for intelligent market insights:
Prompt | Description | Arguments |
---|---|---|
analyze_market | Comprehensive market analysis with trading insights | market_id (required) |
find_arbitrage | Detect arbitrage opportunities across related markets | keyword (required), limit (optional, default: 10) |
market_summary | Overview of top markets with recommendations | category (optional), limit (optional, default: 5) |
{ "id": "0x123...", "slug": "market-slug", "question": "Will X happen by Y date?", "description": "Detailed market description", "active": true, "closed": false, "liquidity": 50000.0, "volume": 125000.0, "end_date": "2024-12-31T23:59:59Z", "outcomes": ["Yes", "No"], "outcome_prices": ["0.65", "0.35"], "category": "Politics" }
The server implements robust error handling:
src/
├── main.rs # MCP server implementation and request handling
├── lib.rs # Library exports
├── config.rs # Configuration management with env/file support
├── models.rs # Data structures and Polymarket API types
├── polymarket_client.rs # HTTP client with caching and retry logic
└── error.rs # Error types and handling
This project maintains high code quality standards:
# Run all tests (11 tests total) cargo test # Check for compilation warnings (should be zero) cargo check # Run clippy lints (should pass clean) cargo clippy --all-targets --all-features -- -D warnings -A clippy::pedantic # Format code cargo fmt # Build optimized release cargo build --release
Current Status:
The project uses minimal, focused dependencies:
# Core MCP and async runtime rmcp = { git = "https://github.com/modelcontextprotocol/rust-sdk" } tokio = { version = "1.0", features = ["rt-multi-thread", "macros", "sync", "time", "signal", "io-std"] } # HTTP client and serialization reqwest = { version = "0.12", features = ["json", "gzip", "rustls-tls"] } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" # Configuration and utilities config = "0.14" dotenv = "0.15" clap = { version = "4.0", features = ["derive"] } fastrand = "2.0" # For request jitter # Date/time and errors chrono = { version = "0.4", features = ["serde"] } anyhow = "1.0" thiserror = "1.0" uuid = { version = "1.0", features = ["v4"] } # Logging tracing = "0.1" tracing-subscriber = { version = "0.3", features = ["env-filter"] }
Create docker-compose.yml
:
version: '3.8' services: polymarket-mcp: build: . image: polymarket-mcp:latest container_name: polymarket-mcp restart: unless-stopped environment: - RUST_LOG=info - POLYMARKET_CACHE_TTL=300 - POLYMARKET_MAX_CONCURRENT_REQUESTS=10 healthcheck: test: ["CMD", "polymarket-mcp", "--health"] interval: 30s timeout: 10s retries: 3 start_period: 40s
# Deploy with docker-compose docker-compose up -d # View logs docker-compose logs -f polymarket-mcp # Update and restart docker-compose pull docker-compose up -d
For Linux servers, create /etc/systemd/system/polymarket-mcp.service
:
[Unit] Description=Polymarket MCP Server After=network.target [Service] Type=simple User=polymarket ExecStart=/usr/local/bin/polymarket-mcp Restart=always RestartSec=10 Environment=RUST_LOG=info EnvironmentFile=/etc/polymarket-mcp/.env [Install] WantedBy=multi-user.target
Check these steps:
ls -la /path/to/target/release/polymarket-mcp
./target/release/polymarket-mcp --help
RUST_LOG=debug cargo run
Troubleshooting:
claude_desktop_config.json
syntax is valid JSON~/Library/Logs/Claude/mcp.log
(macOS)Common solutions:
RUST_LOG=debug
Enable debug logging for detailed output:
{ "mcpServers": { "polymarket": { "command": "/path/to/polymarket-mcp/target/release/polymarket-mcp", "env": { "RUST_LOG": "debug" } } } }
~/Library/Logs/Claude/mcp.log
(macOS)~/Library/Logs/Claude/main.log
(macOS)The server is optimized for performance:
We welcome contributions! Please follow these steps:
cargo test # All tests must pass cargo clippy --all-targets --all-features -- -D warnings -A clippy::pedantic cargo fmt --check # Code must be formatted cargo check # No compilation warnings
This project is licensed under the MIT License - see the LICENSE file for details.
io-std
feature to tokio for stdin/stdout support