Skip to main content
Glama
demwick

Polymarket Agent Mcp

analysis.compare

Compare up to five Polymarket markets at once. View price, spread, order book depth, volume, and quality score to identify the optimal market for your trade.

Instructions

Compare 2-5 Polymarket markets side by side. Shows price, spread, order book depth, volume, and quality score for each market. Useful for choosing the best market to trade among similar options.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
condition_idsYes2-5 condition IDs to compare

Implementation Reference

  • The main handler function that executes the analysis.compare tool logic. It takes 2-5 condition IDs, fetches price, order book depth, spread, and quality metrics for each, then formats a comparison table with a best-liquidity recommendation.
    export async function handleCompareMarkets(input: z.infer<typeof compareMarketsSchema>): Promise<string> {
      log("info", `Comparing ${input.condition_ids.length} markets`);
    
      const results = await Promise.all(input.condition_ids.map(async (cid) => {
        const priceInfo = await getMarketPriceByCondition(cid);
        if (!priceInfo) return { cid, error: true };
    
        const [book, quality] = await Promise.all([
          getMarketPrice(priceInfo.tokenId),
          checkMarketQuality(priceInfo.tokenId),
        ]);
    
        return {
          cid,
          error: false,
          price: priceInfo.price,
          bid: book?.bid ?? 0,
          ask: book?.ask ?? 0,
          spread: book?.spread ?? 0,
          quality: quality.pass,
          bidDepth: quality.metrics.bidDepth,
          askDepth: quality.metrics.askDepth,
        };
      }));
    
      const valid = results.filter((r) => !r.error);
      if (valid.length === 0) return "Could not resolve any of the provided markets.";
    
      let output = `## Market Comparison (${valid.length})\n\n`;
      output += `| Metric |`;
      for (const r of valid) output += ` ${r.cid.slice(0, 10)}.. |`;
      output += `\n|--------|`;
      for (const _ of valid) output += `------------|`;
      output += `\n`;
    
      output += `| Price |`;
      for (const r of valid) output += ` $${(r as any).price.toFixed(4)} |`;
      output += `\n`;
    
      output += `| Bid |`;
      for (const r of valid) output += ` $${(r as any).bid.toFixed(4)} |`;
      output += `\n`;
    
      output += `| Ask |`;
      for (const r of valid) output += ` $${(r as any).ask.toFixed(4)} |`;
      output += `\n`;
    
      output += `| Spread |`;
      for (const r of valid) output += ` ${((r as any).spread * 100).toFixed(1)}% |`;
      output += `\n`;
    
      output += `| Bid Depth |`;
      for (const r of valid) output += ` $${(r as any).bidDepth.toFixed(0)} |`;
      output += `\n`;
    
      output += `| Ask Depth |`;
      for (const r of valid) output += ` $${(r as any).askDepth.toFixed(0)} |`;
      output += `\n`;
    
      output += `| Quality |`;
      for (const r of valid) output += ` ${(r as any).quality ? "PASS" : "FAIL"} |`;
      output += `\n`;
    
      // Best pick
      const best = valid.reduce((a, b) => ((a as any).spread < (b as any).spread ? a : b));
      output += `\n**Best liquidity:** ${(best as any).cid.slice(0, 12)}.. (tightest spread)\n`;
    
      return output;
    }
  • Zod schema defining the input for analysis.compare: an array of 2-5 condition IDs (strings).
    export const compareMarketsSchema = z.object({
      condition_ids: z.array(z.string()).min(2).max(5).describe("2-5 condition IDs to compare"),
    });
  • src/index.ts:463-468 (registration)
    Registration of the 'analysis.compare' tool with the MCP server, including description, schema, and handler invocation via safe().
    server.tool(
      "analysis.compare",
      "Compare 2-5 Polymarket markets side by side. Shows price, spread, order book depth, volume, and quality score for each market. Useful for choosing the best market to trade among similar options.",
      compareMarketsSchema.shape,
      safe("markets.compare", async (input) => ({ content: [{ type: "text" as const, text: await handleCompareMarkets(compareMarketsSchema.parse(input)) }] }))
    );
  • Imports of helper utilities: zod for validation, getMarketPriceByCondition/getMarketPrice from price-service, checkMarketQuality from market-filter, and logger.
    import { z } from "zod";
    import { getMarketPriceByCondition, getMarketPrice } from "../services/price-service.js";
    import { checkMarketQuality } from "../services/market-filter.js";
    import { log } from "../utils/logger.js";
    
    export const compareMarketsSchema = z.object({
      condition_ids: z.array(z.string()).min(2).max(5).describe("2-5 condition IDs to compare"),
    });
    
    export async function handleCompareMarkets(input: z.infer<typeof compareMarketsSchema>): Promise<string> {
      log("info", `Comparing ${input.condition_ids.length} markets`);
    
      const results = await Promise.all(input.condition_ids.map(async (cid) => {
        const priceInfo = await getMarketPriceByCondition(cid);
        if (!priceInfo) return { cid, error: true };
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations provided; description carries full burden. It lists outputs (price, spread, depth, volume, quality score) but does not mention whether data is real-time, whether it is read-only (implied), or any side effects. Adequate but not thorough.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Two sentences: first states function, second lists outputs and use case. No waste, perfectly front-loaded.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

With one parameter and no output schema, description adequately covers purpose and outputs. Could mention format of condition_ids or return structure, but overall sufficient for tool selection.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100% with a well-described parameter. Description adds minimal value beyond schema ('Compare 2-5 Polymarket markets' and output fields). Baseline 3 is appropriate.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

Description clearly states verb (compare), resource (Polymarket markets), and scope (2-5). It distinguishes from siblings like analysis.opportunity or analysis.quality which focus on single markets or different aspects.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Description says 'Useful for choosing the best market to trade among similar options,' which implies when to use it. It does not explicitly mention when not to use or alternatives, but the context of sibling tools provides clear differentiation.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/demwick/polymarket-agent-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server