Skip to main content
Glama
PaulieB14

graph-polymarket-mcp

get_market_positions

Query largest token holders and their profit and loss for a Polymarket outcome token, sortable by realized or unrealized PnL or value bought.

Instructions

Get the top positions for a specific market token from the Beefy P&L subgraph. Shows who holds the largest positions and their P&L.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
tokenIdYesThe outcome token ID — same value as clobTokenIds from search_markets/get_market_info, token_id from get_clob_market, or makerAssetId/takerAssetId from get_orderbook_trades
firstNoNumber of positions to return
orderByNoField to sort byvalueBought

Implementation Reference

  • src/index.ts:546-588 (registration)
    Registration of the 'get_market_positions' MCP tool. Defines the tool name, description, input schema (tokenId, first, orderBy), and the handler function that queries the Beefy P&L subgraph for top positions by market token.
    // Tool 12: get_market_positions
    // ---------------------------------------------------------------------------
    server.registerTool(
      "get_market_positions",
      {
        description:
          "Get the top positions for a specific market token from the Beefy P&L subgraph. Shows who holds the largest positions and their P&L.",
        inputSchema: {
          tokenId: z
            .string()
            .describe(
              "The outcome token ID — same value as clobTokenIds from search_markets/get_market_info, token_id from get_clob_market, or makerAssetId/takerAssetId from get_orderbook_trades"
            ),
          first: z.number().min(1).max(100).default(20).describe("Number of positions to return"),
          orderBy: z
            .enum(["realizedPnl", "unrealizedPnl", "valueBought"])
            .default("valueBought")
            .describe("Field to sort by"),
        },
      },
      async ({ tokenId, first, orderBy }) => {
        try {
          const query = `{
            marketPositions(
              first: ${first},
              orderBy: ${orderBy},
              orderDirection: desc,
              where: { id_contains: "${tokenId}" }
            ) {
              id
              realizedPnl
              unrealizedPnl
              valueBought
              valueSold
            }
          }`;
          const data = await querySubgraph(SUBGRAPHS.beefy_pnl.ipfsHash, query);
          return textResult(data);
        } catch (error) {
          return errorResult(error);
        }
      }
    );
  • Handler function for get_market_positions. Takes tokenId, first (default 20), and orderBy (realizedPnl/unrealizedPnl/valueBought, default valueBought). Queries the Beefy P&L subgraph for marketPositions filtered by id_contains tokenId, returning id, realizedPnl, unrealizedPnl, valueBought, valueSold.
      async ({ tokenId, first, orderBy }) => {
        try {
          const query = `{
            marketPositions(
              first: ${first},
              orderBy: ${orderBy},
              orderDirection: desc,
              where: { id_contains: "${tokenId}" }
            ) {
              id
              realizedPnl
              unrealizedPnl
              valueBought
              valueSold
            }
          }`;
          const data = await querySubgraph(SUBGRAPHS.beefy_pnl.ipfsHash, query);
          return textResult(data);
        } catch (error) {
          return errorResult(error);
        }
      }
    );
  • Input schema for get_market_positions. Defines tokenId (string, outcome token ID), first (number 1-100, default 20), and orderBy (enum of realizedPnl, unrealizedPnl, valueBought, default valueBought).
      inputSchema: {
        tokenId: z
          .string()
          .describe(
            "The outcome token ID — same value as clobTokenIds from search_markets/get_market_info, token_id from get_clob_market, or makerAssetId/takerAssetId from get_orderbook_trades"
          ),
        first: z.number().min(1).max(100).default(20).describe("Number of positions to return"),
        orderBy: z
          .enum(["realizedPnl", "unrealizedPnl", "valueBought"])
          .default("valueBought")
          .describe("Field to sort by"),
      },
    },
Behavior3/5

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

No annotations are provided, so the description must convey behavioral traits. It honestly describes a read operation, but lacks details on data freshness, pagination, or potential side effects. It is adequate but not rich.

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 short, clear sentences with no unnecessary words. The key information is front-loaded.

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?

With no output schema, the description does not detail the return format (e.g., fields of positions). It implies P&L but is vague. Adequate given the parameter richness.

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?

Input schema has 100% description coverage, so the schema already explains each parameter. The description adds no additional meaning for the parameters beyond the schema. 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?

The description clearly states the tool retrieves top positions for a specific market token, using a specific verb ('Get') and resource. It distinguishes from sibling tools like get_user_positions or get_account_pnl which focus on individual accounts.

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

Usage Guidelines3/5

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

The description mentions 'from the Beefy P&L subgraph' but does not provide explicit guidance on when to use this tool vs alternatives, nor any prerequisites or exclusions. The context signals show many sibling tools, but no comparison is given.

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