Skip to main content
Glama
PaulieB14

graph-polymarket-mcp

search_markets_enriched

Search Polymarket markets and automatically enrich results with live CLOB prices and on-chain resolution status in one call.

Instructions

Power tool: search Polymarket markets then auto-enrich each result with live CLOB prices and on-chain resolution status. Combines Gamma API + CLOB API + The Graph in one call — no need to chain tools manually.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesSearch text (e.g. 'Trump', 'Bitcoin', 'World Cup')
limitNoNumber of results (1-20, kept small for enrichment speed)
activeNoFilter: only active markets
closedNoFilter: only closed/resolved markets

Implementation Reference

  • Handler for search_markets_enriched: searches Polymarket markets via Gamma API, then enriches each result with live CLOB prices (via getClobMarket) and on-chain resolution status (via the resolution subgraph) in parallel.
    server.registerTool(
      "search_markets_enriched",
      {
        description:
          "Power tool: search Polymarket markets then auto-enrich each result with live CLOB prices and on-chain resolution status. Combines Gamma API + CLOB API + The Graph in one call — no need to chain tools manually.",
        inputSchema: {
          query: z.string().describe("Search text (e.g. 'Trump', 'Bitcoin', 'World Cup')"),
          limit: z.number().min(1).max(20).default(5).describe("Number of results (1-20, kept small for enrichment speed)"),
          active: z.boolean().optional().describe("Filter: only active markets"),
          closed: z.boolean().optional().describe("Filter: only closed/resolved markets"),
        },
      },
      async ({ query, limit, active, closed }) => {
        try {
          const markets = await searchMarkets(query, { limit, active, closed, orderBy: "volume" });
    
          // Enrich each market with CLOB prices and resolution status in parallel
          const enriched = await Promise.all(
            markets.map(async (m) => {
              const base = {
                question: m.question,
                slug: m.slug,
                conditionId: m.conditionId,
                active: m.active,
                closed: m.closed,
                volume: m.volume,
                liquidity: m.liquidity,
                endDate: m.endDate,
                outcomes: m.outcomes,
                outcomePrices: m.outcomePrices,
                clobTokenIds: m.clobTokenIds,
              };
    
              // Fetch CLOB market data + resolution status in parallel
              const [clobData, resolutionData] = await Promise.all([
                m.conditionId
                  ? getClobMarket(m.conditionId).catch(() => null)
                  : Promise.resolve(null),
                m.conditionId
                  ? querySubgraph(
                      SUBGRAPHS.resolution.ipfsHash,
                      `{ marketResolutions(where: { id: "${m.conditionId.toLowerCase()}" }, first: 1) { status flagged wasDisputed proposedPrice price lastUpdateTimestamp } }`
                    ).catch(() => null)
                  : Promise.resolve(null),
              ]);
    
              const cd = clobData as {
                tokens?: Array<{ token_id: string; outcome: string; price: number; winner: boolean }>;
                minimum_tick_size?: string;
                accepting_orders?: boolean;
              } | null;
    
              const rd = resolutionData as {
                marketResolutions?: Array<{
                  status: string;
                  flagged: boolean;
                  wasDisputed: boolean;
                  proposedPrice: string;
                  price: string;
                  lastUpdateTimestamp: string;
                }>;
              } | null;
    
              return {
                ...base,
                liveTokens: cd?.tokens ?? null,
                acceptingOrders: cd?.accepting_orders ?? null,
                tickSize: cd?.minimum_tick_size ?? null,
                resolution: rd?.marketResolutions?.[0] ?? null,
              };
            })
          );
    
          return textResult({ count: enriched.length, markets: enriched });
        } catch (error) {
          return errorResult(error);
        }
      }
    );
  • src/index.ts:1292-1370 (registration)
    Registration of the 'search_markets_enriched' tool via server.registerTool on the MCP server instance.
    server.registerTool(
      "search_markets_enriched",
      {
        description:
          "Power tool: search Polymarket markets then auto-enrich each result with live CLOB prices and on-chain resolution status. Combines Gamma API + CLOB API + The Graph in one call — no need to chain tools manually.",
        inputSchema: {
          query: z.string().describe("Search text (e.g. 'Trump', 'Bitcoin', 'World Cup')"),
          limit: z.number().min(1).max(20).default(5).describe("Number of results (1-20, kept small for enrichment speed)"),
          active: z.boolean().optional().describe("Filter: only active markets"),
          closed: z.boolean().optional().describe("Filter: only closed/resolved markets"),
        },
      },
      async ({ query, limit, active, closed }) => {
        try {
          const markets = await searchMarkets(query, { limit, active, closed, orderBy: "volume" });
    
          // Enrich each market with CLOB prices and resolution status in parallel
          const enriched = await Promise.all(
            markets.map(async (m) => {
              const base = {
                question: m.question,
                slug: m.slug,
                conditionId: m.conditionId,
                active: m.active,
                closed: m.closed,
                volume: m.volume,
                liquidity: m.liquidity,
                endDate: m.endDate,
                outcomes: m.outcomes,
                outcomePrices: m.outcomePrices,
                clobTokenIds: m.clobTokenIds,
              };
    
              // Fetch CLOB market data + resolution status in parallel
              const [clobData, resolutionData] = await Promise.all([
                m.conditionId
                  ? getClobMarket(m.conditionId).catch(() => null)
                  : Promise.resolve(null),
                m.conditionId
                  ? querySubgraph(
                      SUBGRAPHS.resolution.ipfsHash,
                      `{ marketResolutions(where: { id: "${m.conditionId.toLowerCase()}" }, first: 1) { status flagged wasDisputed proposedPrice price lastUpdateTimestamp } }`
                    ).catch(() => null)
                  : Promise.resolve(null),
              ]);
    
              const cd = clobData as {
                tokens?: Array<{ token_id: string; outcome: string; price: number; winner: boolean }>;
                minimum_tick_size?: string;
                accepting_orders?: boolean;
              } | null;
    
              const rd = resolutionData as {
                marketResolutions?: Array<{
                  status: string;
                  flagged: boolean;
                  wasDisputed: boolean;
                  proposedPrice: string;
                  price: string;
                  lastUpdateTimestamp: string;
                }>;
              } | null;
    
              return {
                ...base,
                liveTokens: cd?.tokens ?? null,
                acceptingOrders: cd?.accepting_orders ?? null,
                tickSize: cd?.minimum_tick_size ?? null,
                resolution: rd?.marketResolutions?.[0] ?? null,
              };
            })
          );
    
          return textResult({ count: enriched.length, markets: enriched });
        } catch (error) {
          return errorResult(error);
        }
      }
    );
  • Input schema definition for search_markets_enriched: accepts query string, limit (1-20, default 5), optional active/closed booleans.
    inputSchema: {
      query: z.string().describe("Search text (e.g. 'Trump', 'Bitcoin', 'World Cup')"),
      limit: z.number().min(1).max(20).default(5).describe("Number of results (1-20, kept small for enrichment speed)"),
      active: z.boolean().optional().describe("Filter: only active markets"),
      closed: z.boolean().optional().describe("Filter: only closed/resolved markets"),
    },
  • The searchMarkets helper function called by search_markets_enriched to query the Gamma API for market search results.
    export async function searchMarkets(
      query: string,
      opts: { limit?: number; active?: boolean; closed?: boolean; orderBy?: string; ascending?: boolean } = {}
    ): Promise<GammaMarket[]> {
      const params = new URLSearchParams();
      params.set("_limit", String(opts.limit ?? 10));
      if (query) params.set("_q", query);
      if (opts.active !== undefined) params.set("active", String(opts.active));
      if (opts.closed !== undefined) params.set("closed", String(opts.closed));
      if (opts.orderBy) {
        params.set("_sort", opts.orderBy);
        params.set("_order", opts.ascending ? "asc" : "desc");
      }
      return fetchJson<GammaMarket[]>(`${GAMMA_BASE}/markets?${params}`);
    }
  • The getClobMarket helper function called by search_markets_enriched to fetch live CLOB data for each market.
    export async function getClobMarket(conditionId: string): Promise<ClobMarket> {
      return fetchJson<ClobMarket>(
        `${CLOB_BASE}/markets/${encodeURIComponent(conditionId)}`
      );
    }
Behavior3/5

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

With no annotations, the description carries full burden. It discloses combining three APIs but does not mention failure modes, rate limits, or partial failures during enrichment.

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, front-loaded with purpose, no wasted words.

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

Completeness3/5

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

Given complexity of multi-API enrichment and no output schema, the description explains what enrichment includes but lacks details on output structure or potential errors.

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%, and schema descriptions are adequate. The description adds minimal extra meaning beyond what schema provides.

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?

The description clearly states the tool searches Polymarket markets and enriches them with CLOB prices and resolution status. It explicitly distinguishes from manual chaining and sibling tools like search_markets (basic).

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?

The description says 'no need to chain tools manually,' implying use when enrichment is needed. However, it does not provide explicit when-not-to-use guidance or alternative tools for simpler cases.

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/PaulieB14/graph-polymarket-mcp'

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