MCP Polymarket
An MCP server for interacting with the Polymarket prediction market
- Package:
@iqai/mcp-polymarket - Purpose: Interacting with the Polymarket prediction market for trading and market analysis.
Usage with ADK TypeScript
import {McpPolymarket} from "@iqai/adk";
const toolset = McpPolymarket({
env: {
FUNDER_ADDRESS: process.env.FUNDER_ADDRESS,
POLYMARKET_PRIVATE_KEY: process.env.POLYMARKET_PRIVATE_KEY,
},
})
const tools = await toolset.getTools()import {McpToolset} from "@iqai/adk";
const toolset = new McpToolset({
name: "Polymarket MCP Client",
description: "Client for Polymarket prediction market operations",
transport: {
mode: "stdio",
command: "pnpm",
args: ["dlx", "@iqai/mcp-polymarket"],
env: {
FUNDER_ADDRESS: process.env.FUNDER_ADDRESS,
POLYMARKET_PRIVATE_KEY: process.env.POLYMARKET_PRIVATE_KEY,
PATH: process.env.PATH || "",
},
},
})
const tools = await toolset.getTools(){
"mcpServers": {
"polymarket-mcp-server": {
"command": "pnpm",
"args": ["dlx", "@iqai/mcp-polymarket"],
"env": {
"FUNDER_ADDRESS": "your_funder_address_here",
"POLYMARKET_PRIVATE_KEY": "your_private_key_here"
}
}
}
}Features
- Interact with Polymarket prediction markets
- Trade prediction market positions
- Access market data and analytics
- Manage positions and orders
Environment Variables
Security
Private keys are used for trading operations. Handle with care and never commit them to version control.
FUNDER_ADDRESS: Required. Available to copy from the user menu dropdown on the Polymarket website (different from the wallet address used to log in).POLYMARKET_PRIVATE_KEY: Required. Private key of the wallet that interacts with Polymarket.
Usage Examples
Here's a complete example of using MCP Polymarket with an ADK agent:
import { McpPolymarket, AgentBuilder } from "@iqai/adk";
import dotenv from "dotenv";
dotenv.config();
async function main() {
// Initialize Polymarket MCP toolset
const toolset = McpPolymarket({
env: {
FUNDER_ADDRESS: process.env.FUNDER_ADDRESS,
POLYMARKET_PRIVATE_KEY: process.env.POLYMARKET_PRIVATE_KEY,
},
debug: false,
retryOptions: {
maxRetries: 3,
initialDelay: 500,
},
});
// Get available tools
const polymarketTools = await toolset.getTools();
// Create agent with Polymarket tools
const { runner } = await AgentBuilder.create("polymarket_agent")
.withModel("gemini-2.5-flash")
.withDescription("An agent that interacts with Polymarket prediction markets")
.withTools(...polymarketTools)
.build();
try {
// Example queries
const response = await runner.ask("Show me available markets on Polymarket");
console.log(response);
} finally {
// Clean up resources
await toolset.close();
}
}
main().catch(console.error);Getting Your Credentials
Funder Address
- Log in to Polymarket
- Click on your user menu (dropdown)
- Copy the Funder Address (this is different from your wallet address)
Private Key
The POLYMARKET_PRIVATE_KEY is the private key of the wallet you use to interact with Polymarket. Ensure this wallet has sufficient funds for trading operations.
Important
Never share your private key or commit it to version control. Always use environment variables or secure secret management systems.
Best Practices
- Security: Store private keys in environment variables, never hardcode them
- Resource Cleanup: Always call
await toolset.close()when done to properly close connections - Error Handling: Implement proper error handling for trading operations
- Rate Limits: Be aware of Polymarket API rate limits and implement appropriate retry logic
Error Handling
Error Scenarios
The server handles various error scenarios gracefully.
🚨 Missing credentials: Ensure both FUNDER_ADDRESS and POLYMARKET_PRIVATE_KEY are set
💸 Insufficient balance: Ensure your wallet has sufficient funds for trading operations
🔄 Invalid market identifiers: Verify market IDs are correct
🌐 Network issues: Check your internet connection and Polymarket API status
🛑 Transaction failures: Review transaction details and ensure proper gas settings
Resources
- Polymarket - Polymarket prediction market platform
- Model Context Protocol - MCP specification and standards
How is this guide?