Skip to main content
Glama
PaulieB14

graph-polymarket-mcp

get_user_positions

Retrieve a user's current positions from Polymarket's P&L subgraph. Automatically falls back if indexers are lagging.

Instructions

Get a user's current positions from the Slimmed P&L subgraph. Falls back gracefully if indexers are behind.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
accountYesEthereum address of the user (lowercase)

Implementation Reference

  • src/index.ts:209-257 (registration)
    Tool registration for 'get_user_positions'. Uses server.registerTool to define the tool name, input schema (account as Ethereum address), and handler function. The handler queries the Slimmed P&L subgraph for user positions and cross-references with the Orderbook subgraph for reliability warnings.
    server.registerTool(
      "get_user_positions",
      {
        description:
          "Get a user's current positions from the Slimmed P&L subgraph. Falls back gracefully if indexers are behind.",
        inputSchema: {
          account: z.string().describe("Ethereum address of the user (lowercase)"),
        },
      },
      async ({ account }) => {
        try {
          const addr = account.toLowerCase();
          const posQuery = `{
            userPositions(where: { user: "${addr}" }, first: 100) {
              id user tokenId amount avgPrice realizedPnl totalBought
            }
          }`;
          const obQuery = `{
            account(id: "${addr}") {
              id totalVolume tradesQuantity totalFees
            }
          }`;
          const [posData, obData] = await Promise.all([
            querySubgraph(SUBGRAPHS.slimmed_pnl.ipfsHash, posQuery),
            querySubgraph(SUBGRAPHS.orderbook.ipfsHash, obQuery).catch(() => null),
          ]);
          const pd = posData as { userPositions?: Array<{ totalBought: string }> };
          const totalBought = (pd.userPositions ?? []).reduce(
            (sum, p) => sum + parseFloat(p.totalBought || "0"), 0
          );
          const od = obData as { account?: { totalVolume?: string; tradesQuantity?: string } } | null;
          const obVolume = parseFloat(od?.account?.totalVolume || "0");
          const obTrades = parseInt(od?.account?.tradesQuantity || "0");
          let reliabilityWarning: string | undefined;
          if (obVolume > 0 && totalBought === 0) {
            reliabilityWarning = `⚠ orderbook-only entry — no split collateral detected. OB volume: $${obVolume.toFixed(2)} across ${obTrades} trades. P&L from totalBought/avgPrice fields is unreliable.`;
          } else if (obVolume > 0 && obVolume > totalBought * 2 && obVolume - totalBought > 1000) {
            reliabilityWarning = `⚠ mixed entry — OB volume ($${obVolume.toFixed(2)}) significantly exceeds split collateral ($${totalBought.toFixed(2)}). Some positions entered via orderbook buys; P&L may be understated.`;
          }
          return textResult({
            positions: pd.userPositions ?? [],
            orderbookAccount: od?.account ?? null,
            ...(reliabilityWarning ? { reliabilityWarning } : {}),
          });
        } catch (error) {
          return errorResult(error);
        }
      }
    );
  • Handler function for get_user_positions. Queries 'userPositions' from the slimmed_pnl subgraph filtered by the user's address, and also fetches account data from the orderbook subgraph. Computes totalBought from positions, checks OB volume vs split collateral to produce reliability warnings (e.g., 'orderbook-only entry' or 'mixed entry'). Returns positions, orderbook account data, and optional warnings.
      async ({ account }) => {
        try {
          const addr = account.toLowerCase();
          const posQuery = `{
            userPositions(where: { user: "${addr}" }, first: 100) {
              id user tokenId amount avgPrice realizedPnl totalBought
            }
          }`;
          const obQuery = `{
            account(id: "${addr}") {
              id totalVolume tradesQuantity totalFees
            }
          }`;
          const [posData, obData] = await Promise.all([
            querySubgraph(SUBGRAPHS.slimmed_pnl.ipfsHash, posQuery),
            querySubgraph(SUBGRAPHS.orderbook.ipfsHash, obQuery).catch(() => null),
          ]);
          const pd = posData as { userPositions?: Array<{ totalBought: string }> };
          const totalBought = (pd.userPositions ?? []).reduce(
            (sum, p) => sum + parseFloat(p.totalBought || "0"), 0
          );
          const od = obData as { account?: { totalVolume?: string; tradesQuantity?: string } } | null;
          const obVolume = parseFloat(od?.account?.totalVolume || "0");
          const obTrades = parseInt(od?.account?.tradesQuantity || "0");
          let reliabilityWarning: string | undefined;
          if (obVolume > 0 && totalBought === 0) {
            reliabilityWarning = `⚠ orderbook-only entry — no split collateral detected. OB volume: $${obVolume.toFixed(2)} across ${obTrades} trades. P&L from totalBought/avgPrice fields is unreliable.`;
          } else if (obVolume > 0 && obVolume > totalBought * 2 && obVolume - totalBought > 1000) {
            reliabilityWarning = `⚠ mixed entry — OB volume ($${obVolume.toFixed(2)}) significantly exceeds split collateral ($${totalBought.toFixed(2)}). Some positions entered via orderbook buys; P&L may be understated.`;
          }
          return textResult({
            positions: pd.userPositions ?? [],
            orderbookAccount: od?.account ?? null,
            ...(reliabilityWarning ? { reliabilityWarning } : {}),
          });
        } catch (error) {
          return errorResult(error);
        }
      }
    );
  • Input schema for get_user_positions: requires a single parameter 'account' (string, Ethereum address), validated via Zod's z.string().
    description:
      "Get a user's current positions from the Slimmed P&L subgraph. Falls back gracefully if indexers are behind.",
    inputSchema: {
      account: z.string().describe("Ethereum address of the user (lowercase)"),
    },
Behavior3/5

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

No annotations are provided, so the description carries full burden. It adds the fallback behavior but lacks details on rate limits, authentication, side effects, or response caching.

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. Every sentence earns its place.

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?

No output schema exists, and the description does not explain the return format or fields. For a tool returning positions, more detail on the response structure would be helpful.

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 already clearly describes the single parameter. The description adds no additional meaning beyond the schema.

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 action (Get), object (user's current positions), and source (Slimmed P&L subgraph), distinguishing it from sibling tools like get_market_positions.

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?

Only minimal guidance is provided: mentions graceful fallback when indexers are behind, but no explicit when-to-use vs alternatives or when not to use.

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