Skip to main content
Glama
demwick

polymarket-trader-mcp

markets.discover

Find Polymarket prediction markets filtered by resolution deadline and category. Returns market question, price, volume, and end date. Use ending='today' for fast-resolving markets or 'all' for full browse.

Instructions

Find active Polymarket prediction markets filtered by resolution deadline and category. Returns market question, price, volume, and end date. Use ending='today' for fast-resolving markets, or 'all' to browse everything.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
endingNoFilter by resolution deadline: today, this_week, or all active marketstoday
categoryNoFilter by category (e.g. politics, sports, crypto, pop-culture)
min_volumeNoMinimum trading volume in USDC to include a market
limitNoMaximum number of markets to return

Implementation Reference

  • The handleDiscoverMarkets function executes the 'markets.discover' tool logic. It checks for a pro license, constructs a Polymarket Gamma API URL with optional ending/category filters, fetches markets, filters by min_volume, and returns a formatted markdown table of markets.
    export async function handleDiscoverMarkets(input: DiscoverMarketsInput): Promise<string> {
      const isPro = await checkLicense(); if (!isPro) return requirePro("discover_markets");
      const now = new Date();
      let endBefore = "";
    
      if (input.ending === "today") {
        const tomorrow = new Date(now);
        tomorrow.setDate(tomorrow.getDate() + 1);
        tomorrow.setHours(0, 0, 0, 0);
        endBefore = tomorrow.toISOString();
      } else if (input.ending === "this_week") {
        const nextWeek = new Date(now);
        nextWeek.setDate(nextWeek.getDate() + 7);
        endBefore = nextWeek.toISOString();
      }
    
      let url = `${GAMMA_API_BASE}/markets?closed=false&order=volume&ascending=false&limit=${input.limit}`;
      if (endBefore) {
        url += `&end_date_max=${endBefore}`;
      }
      if (input.category) {
        url += `&tag=${input.category}`;
      }
    
      log("info", `Discovering markets: ending=${input.ending}, category=${input.category ?? "all"}`);
    
      try {
        const res = await fetchWithRetry(url);
        if (!res.ok) throw new Error(`API error: ${res.status}`);
        const data = await res.json();
    
        const markets = (data as any[]).filter((m: any) => {
          const vol = parseFloat(m.volume ?? "0");
          return vol >= input.min_volume;
        });
    
        if (markets.length === 0) {
          return "No markets found matching criteria. Try 'this_week' or 'all' for more results.";
        }
    
        let output = `## Markets (${markets.length}) — ending: ${input.ending}\n\n`;
        output += `| # | Market | Condition ID | End Date | Volume | Price |\n`;
        output += `|---|--------|--------------|----------|--------|-------|\n`;
    
        for (let i = 0; i < markets.length; i++) {
          const m = markets[i] as any;
          const q = (m.question ?? "").slice(0, 40);
          const end = (m.endDate ?? "").slice(0, 16).replace("T", " ");
          const vol = parseFloat(m.volume ?? "0");
          const prices = m.outcomePrices ?? "";
          // Exposing conditionId here lets the agent skip a second lookup via
          // search_markets/resolveMarketByConditionId before pre-trade gating.
          const cid = (m.conditionId ?? "").slice(0, 12) + "…";
          output += `| ${i + 1} | ${q} | \`${cid}\` (${m.conditionId ?? ""}) | ${end} | $${vol.toFixed(0)} | ${prices} |\n`;
        }
    
        return output;
      } catch (err) {
        log("error", `Failed to discover markets: ${err}`);
        return "Could not reach the Polymarket API. This may be a temporary issue — try again in a moment.";
      }
    }
  • Zod schema defining input parameters: ending (today/this_week/all), category (optional string), min_volume (default 100), limit (1-50, default 20).
    export const discoverMarketsSchema = z.object({
      ending: z.enum(["today", "this_week", "all"]).optional().default("today").describe("Filter by resolution deadline: today, this_week, or all active markets"),
      category: z.string().optional().describe("Filter by category (e.g. politics, sports, crypto, pop-culture)"),
      min_volume: z.number().optional().default(100).describe("Minimum trading volume in USDC to include a market"),
      limit: z.number().int().min(1).max(50).optional().default(20).describe("Maximum number of markets to return"),
    });
  • src/index.ts:246-251 (registration)
    Registration of 'markets.discover' as an MCP tool via server.tool() with its description, schema, and handler wrapper using safe().
    server.tool(
      "markets.discover",
      "Find active Polymarket prediction markets filtered by resolution deadline and category. Returns market question, price, volume, and end date. Use ending='today' for fast-resolving markets, or 'all' to browse everything.",
      discoverMarketsSchema.shape,
      safe("markets.discover", async (input) => ({ content: [{ type: "text" as const, text: await handleDiscoverMarkets(discoverMarketsSchema.parse(input)) }] }))
    );
  • src/index.ts:46-46 (registration)
    Import of discoverMarketsSchema and handleDiscoverMarkets from the handler module.
    import { discoverMarketsSchema, handleDiscoverMarkets } from "./tools/discover-markets.js";
Behavior3/5

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

With no annotations, description carries full burden. It states outputs (question, price, volume, end date) but omits details like read-only nature, pagination behavior, or rate limits. Adequate but not exhaustive.

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, highly efficient: first sentence defines purpose and outputs, second provides actionable usage tip. 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 4 simple parameters and no output schema, the description covers core purpose, outputs, and parameter guidance. Missing details like sorting order or 'active' definition, but sufficient for tool selection.

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

Parameters4/5

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

Schema coverage is 100% (baseline 3). Description adds value by explaining the 'ending' enum options with practical examples (e.g., 'today' for fast-resolving) and listing example categories for the 'category' parameter.

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?

Clearly states verb 'Find', resource 'active Polymarket prediction markets', and lists returned fields. Distinguishes from siblings like markets.search and markets.featured by its focus on deadline and category filtering.

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?

Provides specific usage tip for the 'ending' parameter ('use ending='today' for fast-resolving markets'), but does not explicitly compare to alternative tools like markets.search or markets.trending.

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-trader-mcp'

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