Supports configuration via environment variables loaded from .env files for API credentials, trading configurations, and server settings.
Built using the Rust programming language and the official MCP Rust SDK for performance, safety, and reliability.
Allows configuration via TOML files for server settings, API connections, caching, and logging preferences.
Polymarket MCP Server
A Model Context Protocol (MCP) server for Polymarket prediction market data, built with Rust and the official MCP Rust SDK. This server provides real-time market data, prices, and betting information from Polymarket through MCP tools, resources, and prompts.
Features
- Real-time Market Data: Fetch active markets, trending markets, and market details
- Market Search: Search markets by keywords across questions, descriptions, and categories
- Price Information: Get current yes/no prices for any market
- MCP Resources: Auto-refreshing market data resources
- MCP Prompts: AI-powered market analysis and arbitrage detection
- Caching: Built-in caching with configurable TTL for performance
- Configuration: Flexible configuration via environment variables or TOML files
Prerequisites
- Rust 1.70+ (install via rustup)
- Polymarket API credentials (optional for basic read-only access)
Installation
For Claude Desktop
- Clone the repository:
- Build the release binary:
- Configure Claude Desktop:Edit your Claude Desktop configuration file at:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json
- Windows:
%APPDATA%\Claude\claude_desktop_config.json
- Linux:
~/.config/Claude/claude_desktop_config.json
Add the Polymarket MCP server:
- macOS:
- Restart Claude Desktop to load the new MCP server.
Optional Configuration
Set up environment variables for enhanced functionality:
Configuration
Environment Variables
Copy .env.example
to .env
and configure as needed:
Configuration File
Alternatively, create a config.toml
file:
Usage
Claude Desktop Integration
To use with Claude Desktop, configure your claude_desktop_config.json
:
Configuration file location:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json
- Windows:
%APPDATA%\Claude\claude_desktop_config.json
- Linux:
~/.config/Claude/claude_desktop_config.json
Building for Production
Standalone Server (Development)
MCP Tools
The server provides the following MCP tools:
get_active_markets
Fetch currently active prediction markets.
Parameters:
limit
(optional): Maximum number of markets to return (default: 50)
Example:
get_market_details
Get detailed information about a specific market.
Parameters:
market_id
(required): The ID of the market
Example:
search_markets
Search markets by keyword.
Parameters:
keyword
(required): Search termlimit
(optional): Maximum results (default: 20)
Example:
get_market_prices
Get current yes/no prices for a market.
Parameters:
market_id
(required): The ID of the market
get_trending_markets
Get markets with highest trading volume.
Parameters:
limit
(optional): Maximum number of markets (default: 10)
MCP Resources
Auto-refreshing data resources:
markets:active
- List of active marketsmarkets:trending
- Trending markets by volumemarket:{id}
- Specific market details
MCP Prompts
AI-powered analysis prompts:
analyze_market
Comprehensive market analysis including sentiment, liquidity, and trading opportunities.
Arguments:
market_id
(required): Market to analyze
find_arbitrage
Detect arbitrage opportunities across related markets.
Arguments:
keyword
(required): Search term for related marketslimit
(optional): Number of markets to analyze
market_summary
Overview of top prediction markets with trading recommendations.
Arguments:
category
(optional): Filter by categorylimit
(optional): Number of markets to include
API Documentation
Market Object Structure
Error Handling
The server implements comprehensive error handling:
- Network Errors: Automatic retry with exponential backoff
- Rate Limiting: Built-in rate limiting with configurable limits
- Data Validation: All API responses are validated
- Caching: Prevents redundant API calls
Development
Running Tests
Code Structure
Adding New Features
- New Tools: Add methods to
PolymarketMcpServer
inmain.rs
- New Models: Define structures in
models.rs
- API Endpoints: Extend
PolymarketClient
inpolymarket_client.rs
- Configuration: Add options to
Config
inconfig.rs
Deployment
Docker
Systemd Service
Create /etc/systemd/system/polymarket-mcp.service
:
Troubleshooting
Common Issues
JSON Parsing Errors in Claude Desktop Logs
Error: Unexpected token '', " [2m2025-0"... is not valid JSON
Solution: This indicates logs are being written to stdout instead of stderr. The server has been configured to write all logs to stderr to avoid interfering with MCP JSON communication.
MCP Validation Errors
Error: Invalid input
, Expected string, received null
in id
field
Solution: The server now properly handles JSON-RPC notifications (like notifications/initialized
) by not responding to them, which is the correct behavior.
Server Connection Issues
Error: Server disconnected
or Server transport closed unexpectedly
Troubleshooting steps:
- Verify the binary path in your
claude_desktop_config.json
- Check that the binary exists:
ls -la /path/to/target/release/polymarket-mcp
- Test the binary manually:
echo '{"jsonrpc":"2.0","method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"test","version":"1.0.0"}},"id":0}' | /path/to/target/release/polymarket-mcp
- Check logs in Claude Desktop:
~/Library/Logs/Claude/mcp.log
(macOS)
Build Issues
Error: cannot find function 'stdin' in module 'tokio::io'
Solution: Ensure tokio
has the io-std
feature enabled in Cargo.toml
:
Debug Mode
Enable debug logging to see detailed MCP communication:
Log Locations
- Claude Desktop MCP Logs:
~/Library/Logs/Claude/mcp.log
(macOS) - Claude Desktop Main Logs:
~/Library/Logs/Claude/main.log
(macOS) - Server stderr output: Appears in Claude Desktop MCP logs
Monitoring
The server provides structured logging and can be monitored using:
- Logs: JSON or pretty-printed logs with configurable levels (written to stderr)
- Metrics: Built-in caching metrics and API call tracking
- Health: Connection pooling and retry statistics
- MCP Protocol: Full request/response logging in debug mode
Contributing
- Fork the repository
- Create a feature branch:
git checkout -b feature-name
- Make your changes and add tests
- Run tests:
cargo test
- Run lints:
cargo clippy
- Format code:
cargo fmt
- Submit a pull request
Security
- API keys are handled securely and never logged
- Private keys are optional and only used for trading operations
- All HTTP connections use TLS
- Input validation prevents injection attacks
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support
- Issues: GitHub Issues
- Documentation: MCP Specification
- Polymarket API: Official Documentation
Changelog
v0.1.1 (Current)
- Fixed: JSON parsing errors in Claude Desktop by redirecting logs to stderr
- Fixed: MCP validation errors with notification handling
- Fixed: Added
io-std
feature to tokio for stdin/stdout support - Improved: Proper JSON-RPC protocol compliance
- Added: Comprehensive troubleshooting documentation
- Added: Claude Desktop integration guide
v0.1.0
- Initial release with core MCP functionality
- Support for market data fetching and searching
- MCP resources and prompts implementation
- Comprehensive configuration system
- Built-in caching and error handling
This server cannot be installed
A Model Context Protocol (MCP) server for Polymarket prediction markets, providing real-time market data, prices, and AI-powered analysis tools for Claude Desktop integration.
Related MCP Servers
- -securityFlicense-qualityA Model Context Protocol (MCP) server that provides onchain tools for Claude AI, allowing it to interact with the Polygon PoS blockchain to call contract functions, manage ERC20 tokens, and check gas prices.Last updated -68TypeScript
- -securityFlicense-qualityAn MCP server that enables AI models like Claude to interact with the Trading Simulator API for checking balances, viewing prices, and executing trades with automatic chain detection.Last updated -TypeScript
- AsecurityFlicenseAqualityA Model Context Protocol (MCP) server that allows Claude AI to interact with custom tools, enabling extension of Claude's capabilities through the MCP framework.Last updated -TypeScript
- AsecurityFlicenseAqualityA Model Context Provider (MCP) server that exposes your automated API tools to MCP-compatible clients like Claude Desktop, allowing you to interact with APIs using natural language.Last updated -3