Polymarket MCP Server

Polymarket MCP Server

MCP server that exposes Polymarket prediction markets via CLI wrapper. Enables AI agents to discover markets, check prices, and place trades programmatically.

Category
访问服务器

README

Polymarket MCP Server

MCP (Model Context Protocol) server that exposes Polymarket prediction markets via CLI wrapper.

Enables AI agents to discover markets, check prices, and place trades programmatically.


Features

Read-Only Tools (No Wallet Required)

  • markets_search — Search markets by keyword
  • markets_get — Get specific market details
  • markets_list — List markets with filters (active, volume, etc.)
  • clob_price — Get current price for token ID
  • clob_midpoint — Get midpoint price
  • clob_book — Get order book depth
  • price_history — Historical prices (1m, 1h, 1d, etc.)

Authenticated Tools (Requires Wallet)

  • create_order — Place limit order (buy/sell at specified price)
  • market_order — Place market order (buy/sell at current price)
  • cancel_order — Cancel existing order
  • positions — Get portfolio positions
  • balance — Get wallet balance (USDC/conditional tokens)

Installation

Prerequisites

  1. Install Polymarket CLI:

    brew tap Polymarket/polymarket-cli https://github.com/Polymarket/polymarket-cli
    brew install polymarket
    
  2. Verify CLI works:

    polymarket markets list --limit 3
    

Install MCP Server

cd polymarket-mcp
npm install
npm run build

Configuration

Environment Variables

Create .env file (see .env.example):

# Required for authenticated operations (trading)
POLYMARKET_PRIVATE_KEY=0x...

# Optional
CHAIN_ID=137                # Polygon mainnet
SIGNATURE_TYPE=proxy        # proxy | eoa | gnosis-safe
POLYGON_RPC_URL=https://polygon-rpc.com

MCP Client Config

Add to your MCP client config (e.g., Claude Desktop, mcporter, Polygent):

{
  "mcpServers": {
    "polymarket": {
      "command": "node",
      "args": ["/path/to/polymarket-mcp/dist/index.js"],
      "env": {
        "POLYMARKET_PRIVATE_KEY": "0x...",
        "CHAIN_ID": "137",
        "SIGNATURE_TYPE": "proxy"
      }
    }
  }
}

Usage Examples

Browse Markets

// Search for Bitcoin markets
markets_search({ query: "bitcoin", limit: 5 })

// Get specific market
markets_get({ market_id: "will-btc-hit-100k" })

// List active markets sorted by volume
markets_list({ active: true, order: "volume_num", limit: 10 })

Check Prices

// Get buy price
clob_price({ token_id: "0xABC...", side: "buy" })

// Get midpoint (average of bid/ask)
clob_midpoint({ token_id: "0xABC..." })

// Get full order book
clob_book({ token_id: "0xABC..." })

// Get price history
price_history({ token_id: "0xABC...", interval: "1d", fidelity: 30 })

Trade (Authenticated)

// Place limit order: buy 10 shares at $0.50
create_order({
  token_id: "0xABC...",
  side: "buy",
  price: 0.50,
  size: 10
})

// Place market order: buy $5 worth at current price
market_order({
  token_id: "0xABC...",
  side: "buy",
  amount: 5
})

// Cancel order
cancel_order({ order_id: "0xORDER..." })

// Check positions
positions({ wallet_address: "0xYOUR_WALLET..." })

// Check balance
balance({ asset_type: "collateral" })

Security

Wallet Key Management

  • Never log private keys — Keys are only used for CLI signing
  • Environment variables only — Keys never hardcoded
  • No key exposure in responses — MCP responses don't include keys

Input Validation

  • All inputs validated with Zod before CLI execution
  • Token IDs must match hex pattern (0x[0-9a-fA-F]+)
  • Wallet addresses validated (0x[0-9a-fA-F]{40})
  • Price bounds enforced (0.01 to 0.99)
  • Positive size/amount validation

Rate Limiting

  • CLI timeout: 30 seconds per command
  • Buffer limit: 10MB max response size
  • Respects Polymarket API rate limits (60 req/min)

Command Injection Protection

  • No shell interpolation of user input
  • Pre-validated arguments passed as array
  • Uses child_process.exec with timeout + buffer limits

Testing

Manual Test (MCP Inspector)

npx @modelcontextprotocol/inspector node dist/index.js

Test Read-Only Tools

# List markets
echo '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"markets_search","arguments":{"query":"bitcoin","limit":3}}}' | node dist/index.js

Test Authenticated Tools

Requires .env with POLYMARKET_PRIVATE_KEY:

# Check balance
echo '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"balance","arguments":{"asset_type":"collateral"}}}' | node dist/index.js

Integration with Polygent

See INTEGRATION.md for detailed integration guide.

Quick start:

  1. Install MCP server on Polygent VPS
  2. Configure mcporter with server path + env vars
  3. Update Polygent agents to call MCP tools
  4. Add health checks for MCP server status

Troubleshooting

"Wallet not configured" error

  • Set POLYMARKET_PRIVATE_KEY in .env or MCP client config
  • Verify key format: 0x + 64 hex characters

"Command not found: polymarket"

  • Install Polymarket CLI: brew install polymarket
  • Verify: which polymarket

"Failed to parse CLI output"

  • Check CLI version: polymarket --version
  • Ensure JSON output mode works: polymarket -o json markets list --limit 1

Rate limit errors (429)

  • Respect 60 req/min limit
  • Add exponential backoff in agent logic
  • Use batch endpoints where available

Architecture

polymarket-mcp/
├── src/
│   ├── index.ts           # MCP server (tool definitions)
│   └── lib/
│       ├── env.ts         # Environment validation (Zod)
│       ├── cli.ts         # CLI wrapper functions
│       └── types.ts       # TypeScript types
├── dist/                  # Compiled output
├── .env.example
├── package.json
├── tsconfig.json
└── README.md

Design:

  • No database — Pure CLI wrapper
  • Fail-fast validation — Env vars checked at startup
  • Structured errors — Always return error objects, never throw
  • Type-safe — Full TypeScript + Zod validation

Related Projects

  • Polymarket CLI: https://github.com/Polymarket/polymarket-cli
  • MCP Specification: https://modelcontextprotocol.io
  • Polygent: https://polygent.market

License

MIT

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选