TypeScriptADK-TS

MCP Opinion

An MCP server for interacting with Opinion.trade prediction market

  • Package: @iqai/mcp-opinion
  • Purpose: Interacting with the Opinion.trade prediction market for market data and analysis.

Usage with ADK TypeScript

import {McpOpinion} from "@iqai/adk";

const toolset = McpOpinion({
  env: {
    OPINION_API_KEY: process.env.OPINION_API_KEY,
  },
})

const tools = await toolset.getTools()
import {McpToolset} from "@iqai/adk";

const toolset = new McpToolset({
  name: "Opinion MCP Client",
  description: "Client for Opinion.trade prediction market",
  transport: {
    mode: "stdio",
    command: "pnpm",
    args: ["dlx", "@iqai/mcp-opinion"],
    env: {
      OPINION_API_KEY: process.env.OPINION_API_KEY,
      PATH: process.env.PATH || "",
    },
  },
})

const tools = await toolset.getTools()
{
  "mcpServers": {
    "opinion-mcp-server": {
      "command": "pnpm",
      "args": ["dlx", "@iqai/mcp-opinion"],
      "env": {
        "OPINION_API_KEY": "your_opinion_api_key"
      }
    }
  }
}

Available Tools

GET_MARKETS
limit:numberstatus:numbermarketType:numberpage:number

Description

Get a list of prediction markets from Opinion.trade with optional filters for status and market type

GET_MARKET_DETAILS
marketId:number

Description

Get detailed information about a specific prediction market by its ID

SEARCH_MARKETS
query:stringlimit:numberstatus:number

Description

Search for prediction markets by keyword in the market title

GET_ORDERBOOK
tokenId:string

Description

Get the order book (bids and asks) for a specific prediction market token

GET_PRICE_HISTORY
tokenId:stringinterval:string

Description

Get historical price data for a prediction market token

GET_LATEST_PRICE
tokenId:string

Description

Get the current/latest trade price for a prediction market token

GET_POSITIONS
walletAddress:stringlimit:numberpage:number

Description

Get the current prediction market positions held by a wallet address

GET_TRADE_HISTORY
walletAddress:stringlimit:numberpage:number

Description

Get the trade history for a wallet address on Opinion.trade

GET_QUOTE_TOKENS

No parameters

Description

Get the list of available quote tokens (currencies) that can be used for trading on Opinion.trade

Environment Variables

  • OPINION_API_KEY: Required. Your Opinion.trade API key.

Usage Examples

Here's a complete example of using MCP Opinion with an ADK agent:

import { McpOpinion, AgentBuilder } from "@iqai/adk";
import dotenv from "dotenv";

dotenv.config();

async function main() {
  // Initialize Opinion MCP toolset
  const toolset = McpOpinion({
    env: {
      OPINION_API_KEY: process.env.OPINION_API_KEY,
    },
    debug: false,
    retryOptions: {
      maxRetries: 3,
      initialDelay: 500,
    },
  });

  // Get available tools
  const opinionTools = await toolset.getTools();

  // Create agent with Opinion tools
  const { runner } = await AgentBuilder.create("opinion_agent")
    .withModel("gemini-2.5-flash")
    .withDescription(
      "An agent that interacts with Opinion.trade prediction markets",
    )
    .withTools(...opinionTools)
    .build();

  try {
    // Example queries
    const response = await runner.ask(
      "Show me trending markets on Opinion.trade",
    );
    console.log(response);
  } finally {
    // Clean up resources
    await toolset.close();
  }
}

main().catch(console.error);

Getting Your Credentials

  1. Sign up at Opinion.trade
  2. Navigate to your account settings
  3. Generate an API key

Best Practices

  • Security: Store API 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 market data requests
  • Rate Limits: Be aware of API rate limits and implement appropriate retry logic

Error Handling

Error Scenarios

The server handles various error scenarios gracefully.

🚨 Missing credentials: Ensure OPINION_API_KEY is set šŸ”„ Invalid market identifiers: Verify market IDs are correct 🌐 Network issues: Check your internet connection and API status

Resources