Skip to main content
Glama
PaulieB14

graph-polymarket-mcp

get_market_data

Retrieve Polymarket market data including outcomes, volumes, and conditions from the Main subgraph. Use order and pagination to customize results.

Instructions

Get Polymarket market/condition data including outcomes and volumes from the Main subgraph

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
firstNoNumber of markets to return (1-100)
orderByNoField to order byid
orderDirectionNoSort directiondesc

Implementation Reference

  • src/index.ts:132-163 (registration)
    Tool 'get_market_data' is registered via server.registerTool on line 134. It accepts optional parameters (first, orderBy, orderDirection) and queries the Main subgraph for conditions data.
    // Tool 4: get_market_data
    // ---------------------------------------------------------------------------
    server.registerTool(
      "get_market_data",
      {
        description: "Get Polymarket market/condition data including outcomes and volumes from the Main subgraph",
        inputSchema: {
          first: z.number().min(1).max(100).default(10).describe("Number of markets to return (1-100)"),
          orderBy: z.string().default("id").describe("Field to order by"),
          orderDirection: z.enum(["asc", "desc"]).default("desc").describe("Sort direction"),
        },
      },
      async ({ first, orderBy, orderDirection }) => {
        try {
          const query = `{
            conditions(first: ${first}, orderBy: ${orderBy}, orderDirection: ${orderDirection}) {
              id
              oracle
              questionId
              outcomeSlotCount
              resolutionTimestamp
              payoutNumerators
              payoutDenominator
            }
          }`;
          const data = await querySubgraph(SUBGRAPHS.main.ipfsHash, query);
          return textResult(data);
        } catch (error) {
          return errorResult(error);
        }
      }
    );
  • The handler function (async callback) executes the tool logic: it constructs a GraphQL query against the Main subgraph's 'conditions' entity, calls querySubgraph, and returns the result.
    async ({ first, orderBy, orderDirection }) => {
      try {
        const query = `{
          conditions(first: ${first}, orderBy: ${orderBy}, orderDirection: ${orderDirection}) {
            id
            oracle
            questionId
            outcomeSlotCount
            resolutionTimestamp
            payoutNumerators
            payoutDenominator
          }
        }`;
        const data = await querySubgraph(SUBGRAPHS.main.ipfsHash, query);
        return textResult(data);
      } catch (error) {
        return errorResult(error);
      }
    }
  • Input schema for the tool: 'first' (number, 1-100, default 10), 'orderBy' (string, default 'id'), 'orderDirection' (enum asc/desc, default 'desc') — defined via Zod.
    {
      description: "Get Polymarket market/condition data including outcomes and volumes from the Main subgraph",
      inputSchema: {
        first: z.number().min(1).max(100).default(10).describe("Number of markets to return (1-100)"),
        orderBy: z.string().default("id").describe("Field to order by"),
        orderDirection: z.enum(["asc", "desc"]).default("desc").describe("Sort direction"),
      },
    },
  • The querySubgraph function used by the handler to execute the GraphQL query against The Graph's decentralized network.
    export async function querySubgraph(
      ipfsHash: string,
      query: string,
      variables?: Record<string, unknown>
    ): Promise<unknown> {
      const apiKey = process.env.GRAPH_API_KEY;
      if (!apiKey) {
        throw new GraphClientError(
          "GRAPH_API_KEY environment variable is required. " +
            "Get one at https://thegraph.com/studio/apikeys/"
        );
      }
    
      const url = `https://gateway.thegraph.com/api/${apiKey}/deployments/id/${ipfsHash}`;
    
      const body: Record<string, unknown> = { query };
      if (variables && Object.keys(variables).length > 0) {
        body.variables = variables;
      }
    
      const response = await fetch(url, {
        method: "POST",
        headers: { "Content-Type": "application/json" },
        body: JSON.stringify(body),
      });
    
      if (!response.ok) {
        throw new GraphClientError(
          `Graph API returned HTTP ${response.status}: ${response.statusText}`,
          response.status
        );
      }
    
      const json = (await response.json()) as {
        data?: unknown;
        errors?: unknown[];
      };
    
      if (json.errors && json.errors.length > 0) {
        throw new GraphClientError(
          `GraphQL errors: ${JSON.stringify(json.errors)}`,
          undefined,
          json.errors
        );
      }
    
      return json.data;
    }
Behavior2/5

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

No annotations are provided, and the description does not disclose any behavioral traits like permissions, rate limits, or data scope beyond the minimal 'outcomes and volumes'.

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?

Single sentence efficiently conveys the tool's purpose with no unnecessary words, well-structured.

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?

Description is adequate but does not elaborate on how this tool differs from the many sibling get_* tools; lacks completeness in guiding selection choice.

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 covers all parameters with descriptions, so the description adds no extra meaning beyond what the schema already 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?

Description clearly states the tool gets market/condition data including outcomes and volumes, specifying the source subgraph, which distinguishes it from siblings like get_market_info.

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

Usage Guidelines2/5

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

No guidance on when to use this tool versus alternatives such as get_market_info or search_markets; the description lacks any contextual usage advice.

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