预测市场数据服务

PolyMarket MCP Server是一个提供预测市场数据访问的模型上下文协议服务器,通过标准接口实现市场信息、价格和历史数据的检索。

  • by berlinbra
  • Python
  • 本地部署
  • 144 星标
  • 更新于
在 GitHub 查看 berlinbra/polymarket-mcp

使用说明

PolyMarket MCP服务器

模型上下文协议(MCP)服务器,通过PolyMarket API提供对预测市场数据的访问。该服务器实现了一个标准化的接口,用于从预测市场中检索市场信息、价格和历史数据。

特性

  • 实时预测市场数据,包括当前价格和概率
  • 详细的市场信息,包括类别、处置日期和描述
  • 历史价格和交易量数据,可定制时间范围(1d、7d、30d,全部)
  • 内置错误处理和速率限制管理
  • 干净的数据格式,便于使用

安装

通过Smithery安装

通过以下方式自动安装克劳德桌面版PolyMarket Predictions 史密瑟里:

npx -y @smithery/cli install polymarket_mcp --client claude

克劳德桌面

  • 在MacOS上: ~/Library/Application\ Support/Claude/claude_desktop_config.json
  • 在Windows上: %APPDATA%/Claude/claude_desktop_config.json
Development/Unpublished Servers Configuration
    "mcpServers": {
        "polymarket-mcp": {
            "command": "uv",
            "args": [
            "--directory",
            "/Users/{INSERT_USER}/YOUR/PATH/TO/polymarket-mcp",
            "run",
            "polymarket-mcp" //or src/polymarket_mcp/server.py
            ],
            "env": {
                "KEY": "<insert poly market api key>",
                "FUNDER": "<insert polymarket wallet address>"
            }
        }
    }

本地运行

  1. 克隆存储库并安装依赖项:

安装库

uv pip install -e .

跑步

通过json文件将Claude客户端与MCP工具连接并安装包后,Claude应该看到服务器的MCP工具:

您可以通过以下方式自行运行服务器: 在polymarket mcp回购中:

uv run src/polymarket_mcp/server.py

*如果你想和服务器一起运行服务器检查器:

npx @modelcontextprotocol/inspector uv --directory C:\\Users\\{INSERT_USER}\\YOUR\\PATH\\TO\\polymarket-mcp run src/polymarket_mcp/server.py
  1. 创建一个 .env 使用您的PolyMarket API密钥存档:
Key=your_api_key_here
Funder=poly market wallet address

通过json文件将Claude客户端与MCP工具连接后,运行服务器: 在alpha优势mcp仓库中: uv run src/polymarket_mcp/server.py

可用工具

服务器实现了四个工具:

  • get-market-info:获取特定预测市场的详细信息
  • list-markets:列出具有过滤选项的可用预测市场
  • get-market-prices:获取当前价格和交易信息
  • get-market-history:获取历史价格和交易量数据

获取市场信息

输入架构:

{
    "market_id": {
        "type": "string",
        "description": "Market ID or slug"
    }
}

示例响应:

Title: Example Market
Category: Politics
Status: Open
Resolution Date: 2024-12-31
Volume: $1,234,567.89
Liquidity: $98,765.43
Description: This is an example prediction market...
---

上市市场

输入架构:

{
    "status": {
        "type": "string",
        "description": "Filter by market status",
        "enum": ["open", "closed", "resolved"]
    },
    "limit": {
        "type": "integer",
        "description": "Number of markets to return",
        "default": 10,
        "minimum": 1,
        "maximum": 100
    },
    "offset": {
        "type": "integer",
        "description": "Number of markets to skip (for pagination)",
        "default": 0,
        "minimum": 0
    }
}

示例响应:

Available Markets:

ID: market-123
Title: US Presidential Election 2024
Status: Open
Volume: $1,234,567.89
---

ID: market-124
Title: Oscar Best Picture 2024
Status: Open
Volume: $234,567.89
---

获取市场价格

输入架构:

{
    "market_id": {
        "type": "string",
        "description": "Market ID or slug"
    }
}

示例响应:

Current Market Prices for US Presidential Election 2024

Outcome: Democratic
Price: $0.6500
Probability: 65.0%
---

Outcome: Republican
Price: $0.3500
Probability: 35.0%
---

获取市场历史

输入架构:

{
    "market_id": {
        "type": "string",
        "description": "Market ID or slug"
    },
    "timeframe": {
        "type": "string",
        "description": "Time period for historical data",
        "enum": ["1d", "7d", "30d", "all"],
        "default": "7d"
    }
}

示例响应:

Historical Data for US Presidential Election 2024
Time Period: 7d

Time: 2024-01-20T12:00:00Z
Price: $0.6500
Volume: $123,456.78
---

Time: 2024-01-19T12:00:00Z
Price: $0.6300
Volume: $98,765.43
---

错误处理

该服务器包括针对各种场景的全面错误处理:

  • 速率限制(429个错误)
  • API密钥无效(403个错误)
  • 无效的市场ID(404错误)
  • 网络连接问题
  • API超时条件(30秒超时)
  • 响应格式错误

错误消息以清晰易读的格式返回。

先决条件

  • Python 3.9或更高版本
  • httpx>=0.24.0
  • mcp核心
  • python dotenv>=1.0.0

贡献

欢迎投稿!请随时提交拉取请求。对于重大更改,请先打开一个问题来讨论您想要更改的内容。