Opinion.trade MCP Server

Opinion.trade MCP Server

Enables interaction with Opinion.trade decentralized prediction markets on BNB Chain, supporting market data queries in read-only mode and full trading capabilities (placing orders, managing positions, viewing balances) with EIP712 signing when configured with a private key.

Category
访问服务器

README

Opinion.trade MCP Server

Model Context Protocol (MCP) server for Opinion.trade - a decentralized prediction markets platform on BNB Chain.

Features

Dual-Mode Operation

  • Read-Only Mode: Market data access with API key only
  • Trading Mode: Full trading capabilities with private key for EIP712 signing

Available Tools (13 Total)

Public API Tools (6 - API key only)

  1. get_markets - List prediction markets with filtering
  2. get_market_details - Get detailed market information
  3. get_token_price - Current token/outcome prices
  4. get_orderbook - Order book depth (bids/asks)
  5. get_price_history - Historical OHLCV data
  6. search_markets - Search markets by keyword

Trading Tools (7 - Requires private key)

  1. place_order - Place limit/market orders with EIP712 signing
  2. cancel_order - Cancel specific order
  3. cancel_all_orders - Cancel all open orders
  4. get_open_orders - List user's open orders
  5. get_positions - Get positions with P&L
  6. get_trade_history - Executed trades history
  7. get_balances - Account balances (available + locked)

Installation

Prerequisites

  • Python 3.10 or higher
  • Opinion.trade API key (Get one here)

Install from source

# Clone or navigate to the directory
cd mcp-opinion-trade

# Install in development mode
pip install -e .

Configuration

1. Create .env file

cp .env.example .env

2. Configure environment variables

Minimum configuration (read-only mode):

OPINION_API_KEY=your_api_key_here

Full configuration (trading mode):

# Required
OPINION_API_KEY=your_api_key_here

# Trading mode (optional)
OPINION_PRIVATE_KEY=0x...  # Your Ethereum private key

# Network (optional)
OPINION_CHAIN_ID=56  # 56=BNB mainnet, 97=BNB testnet

3. Configure Claude Code

Add to your Claude Code MCP settings:

{
  "mcpServers": {
    "opinion-trade": {
      "command": "python",
      "args": ["-m", "mcp_opinion"],
      "env": {
        "OPINION_API_KEY": "your_api_key_here"
      }
    }
  }
}

Or use the installed command:

{
  "mcpServers": {
    "opinion-trade": {
      "command": "mcp-opinion-trade"
    }
  }
}

Usage Examples

Read-Only Mode (Market Data)

User: What are the top prediction markets on Opinion.trade?
Claude: Let me check the top markets on Opinion.trade.
→ Uses get_markets tool

User: What's the current price for token ABC123?
Claude: I'll get the current price for that token.
→ Uses get_token_price tool

User: Show me the orderbook for token XYZ789
Claude: I'll fetch the orderbook depth.
→ Uses get_orderbook tool

Trading Mode (Requires Private Key)

User: Place a limit buy order for 100 units of token ABC123 at price 0.55
Claude: I'll place that limit buy order for you.
→ Uses place_order tool with EIP712 signing

User: What are my current positions?
Claude: Let me get your open positions.
→ Uses get_positions tool

User: Cancel all my open orders
Claude: I'll cancel all your open orders.
→ Uses cancel_all_orders tool

Security Best Practices

API Keys

  • Never commit your .env file to version control
  • Store API keys securely using environment variables
  • Rotate API keys periodically

Private Keys

  • NEVER share your private key
  • NEVER commit private keys to version control
  • Use hardware wallets for production trading
  • Consider using a dedicated trading wallet with limited funds
  • The private key is used for EIP712 signing (not transmitted to API)

Environment

  • Use .env files for local development
  • Use secure secret management for production
  • Verify you're on the correct network (mainnet vs testnet)

Architecture

Dual-Mode Design

The server automatically detects trading mode based on private key presence:

# Read-only mode (API key only)
config = OpinionConfig(api_key="...", private_key=None)
# → Only 6 public API tools available

# Trading mode (API key + private key)
config = OpinionConfig(api_key="...", private_key="0x...")
# → All 13 tools available (6 public + 7 trading)

Components

  • PublicClient: Handles market data via REST API (httpx)
  • TradingClient: Wraps opinion_clob_sdk for trading with EIP712 signing
  • OpinionConfig: Environment-based configuration with validation
  • Pydantic Models: Type-safe request validation
  • MCP Server: Tool registration and routing with error handling

API Response Format

Opinion.trade API responses follow this structure:

{
  "code": 0,
  "msg": "success",
  "result": {
    "data": {...} // or "list": [...]
  }
}
  • code: 0 for success, non-zero for errors
  • msg: Human-readable message
  • result: Contains either data (single object) or list (array)

Error Handling

The server provides detailed error messages:

{
  "error": "Order placement failed: Insufficient balance",
  "error_code": "INSUFFICIENT_BALANCE",
  "status_code": 400,
  "is_error": true
}

Common error codes:

  • VALIDATION_ERROR: Invalid input parameters
  • API_ERROR: Opinion.trade API error
  • TRADING_DISABLED: Trading tools called without private key
  • INTERNAL_ERROR: Unexpected server error

Development

Running Tests

# Install development dependencies
pip install -e ".[dev]"

# Run tests
pytest

# Run with coverage
pytest --cov=mcp_opinion --cov-report=term-missing

Code Formatting

# Format code
black src/

# Lint code
ruff check src/

Troubleshooting

"API key is required" error

  • Ensure OPINION_API_KEY is set in .env
  • Verify .env file is in the project root directory
  • Check that python-dotenv is installed

"Trading tools not available" error

  • Set OPINION_PRIVATE_KEY in .env to enable trading mode
  • Ensure private key starts with 0x
  • Verify private key corresponds to a funded BNB Chain wallet

"opinion-clob-sdk not found" error

  • Install the SDK: pip install opinion-clob-sdk>=0.4.1
  • Verify it's listed in your requirements.txt or pyproject.toml

Network errors

  • Check your internet connection
  • Verify API host is reachable: https://proxy.opinion.trade:8443
  • Check if Opinion.trade API is operational

Resources

License

MIT License - See LICENSE file for details

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Disclaimer

This is an unofficial MCP server for Opinion.trade. Use at your own risk. Always verify transactions before signing. The authors are not responsible for any losses incurred through the use of this software.


Version: 0.1.0 Status: Beta Chain: BNB Chain (Chain ID: 56)

推荐服务器

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选