Skip to main content
Glama
PaulieB14

graph-polymarket-mcp

search_markets

Find Polymarket prediction markets by text query. Returns metadata including question, prices, volume, liquidity, and CLOB token IDs for real-time discovery.

Instructions

Search Polymarket prediction markets by text query. Returns market metadata including question, prices, volume, liquidity, and CLOB token IDs. Uses the Gamma API for real-time market discovery. Chain with: get_clob_market(conditionId) for live order books, get_live_prices(clobTokenIds) for token-level pricing, get_market_open_interest for capital locked, or get_market_resolution for oracle status.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesSearch text (e.g. 'Trump', 'Bitcoin', 'World Cup')
limitNoNumber of results (1-100)
activeNoFilter: only active markets
closedNoFilter: only closed/resolved markets
orderByNoSort field
ascendingNoSort ascending (default: descending)

Implementation Reference

  • The actual async function that queries the Gamma API to search Polymarket markets by text query. Builds URL params (_limit, _q, active, closed, _sort, _order) and returns typed GammaMarket[].
    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 GammaMarket interface defines the shape of market data returned by searchMarkets, including fields like question, conditionId, slug, outcomePrices, clobTokenIds, volume, liquidity, etc.
    export interface GammaMarket {
      id: string;
      question: string;
      conditionId: string;
      slug: string;
      resolutionSource: string;
      endDate: string;
      liquidity: string;
      volume: string;
      active: boolean;
      closed: boolean;
      marketMakerAddress: string;
      outcomePrices: string;
      outcomes: string;
      clobTokenIds: string;
      bestBid: string;
      bestAsk: string;
      lastTradePrice: string;
      spread: string;
      description: string;
      [key: string]: unknown;
    }
  • src/index.ts:969-1015 (registration)
    Registers the 'search_markets' tool with the MCP server. Defines the input schema (query, limit, active, closed, orderBy, ascending) and the handler that calls the searchMarkets function from polymarketApi.ts, transforming results into a JSON response.
    server.registerTool(
      "search_markets",
      {
        description:
          "Search Polymarket prediction markets by text query. Returns market metadata including question, prices, volume, liquidity, and CLOB token IDs. Uses the Gamma API for real-time market discovery. Chain with: get_clob_market(conditionId) for live order books, get_live_prices(clobTokenIds) for token-level pricing, get_market_open_interest for capital locked, or get_market_resolution for oracle status.",
        inputSchema: {
          query: z.string().describe("Search text (e.g. 'Trump', 'Bitcoin', 'World Cup')"),
          limit: z.number().min(1).max(100).default(10).describe("Number of results (1-100)"),
          active: z.boolean().optional().describe("Filter: only active markets"),
          closed: z.boolean().optional().describe("Filter: only closed/resolved markets"),
          orderBy: z
            .enum(["volume", "liquidity", "endDate", "startDate", "createdAt"])
            .optional()
            .describe("Sort field"),
          ascending: z.boolean().default(false).describe("Sort ascending (default: descending)"),
        },
      },
      async ({ query, limit, active, closed, orderBy, ascending }) => {
        try {
          const markets = await searchMarkets(query, { limit, active, closed, orderBy, ascending });
          return textResult({
            count: markets.length,
            markets: markets.map((m) => ({
              id: m.id,
              question: m.question,
              slug: m.slug,
              conditionId: m.conditionId,
              active: m.active,
              closed: m.closed,
              outcomePrices: m.outcomePrices,
              outcomes: m.outcomes,
              bestBid: m.bestBid,
              bestAsk: m.bestAsk,
              lastTradePrice: m.lastTradePrice,
              spread: m.spread,
              volume: m.volume,
              liquidity: m.liquidity,
              endDate: m.endDate,
              clobTokenIds: m.clobTokenIds,
              description: m.description,
            })),
          });
        } catch (error) {
          return errorResult(error);
        }
      }
    );
  • The fetchJson helper function used by searchMarkets to make HTTP requests to the Gamma API with proper error handling.
    async function fetchJson<T>(url: string): Promise<T> {
      const response = await fetch(url, {
        headers: { Accept: "application/json" },
      });
      if (!response.ok) {
        throw new PolymarketApiError(
          `HTTP ${response.status}: ${response.statusText}`,
          response.status,
          url
        );
      }
      return response.json() as Promise<T>;
    }
Behavior3/5

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

No annotations are provided, so the description carries full responsibility. It mentions 'real-time market discovery' and uses Gamma API, which is informative. However, it fails to disclose safety (e.g., read-only), limitations, error behavior, or response format beyond listed fields, leaving some transparency gaps.

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?

The description is concise: two sentences and a list of chaining suggestions. It is front-loaded with the main purpose and every sentence adds value. No wasted words.

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?

Given no output schema, the description adequately explains return values (market metadata). It also provides workflow context via chaining. However, it omits default sort order (descending) and pagination details, though the schema covers these. Overall sufficient for a search tool.

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 description coverage is 100%, so the description adds minimal value beyond the schema. It only references the 'query' parameter. The schema already provides clear descriptions for all 6 parameters, including enums and defaults, making the description's marginal contribution limited.

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 prediction markets by text query and returns specific metadata (question, prices, volume, liquidity, CLOB token IDs). It distinguishes from siblings by mentioning chaining with other tools like get_clob_market and get_live_prices, and the presence of search_markets_enriched implies this is a basic search.

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 explicitly says when to use this tool (searching by text query) and provides concrete chaining suggestions for further actions (order books, pricing, etc.). However, it does not explicitly exclude alternatives or state when not to use it, such as preferring search_markets_enriched for more details.

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