Skip to main content
Glama
PaulieB14

graph-polymarket-mcp

get_account_pnl

Access a trader's profit and loss (P&L) and performance data on Polymarket using their Ethereum address.

Instructions

Get a trader's P&L and performance metrics from the Beefy P&L subgraph

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
accountYesEthereum address of the trader (lowercase)

Implementation Reference

  • src/index.ts:168-204 (registration)
    Tool registration for 'get_account_pnl' using server.registerTool. Registers the tool with input schema (zod: 'account' as Ethereum address string) and the handler function.
    server.registerTool(
      "get_account_pnl",
      {
        description: "Get a trader's P&L and performance metrics from the Beefy P&L subgraph",
        inputSchema: {
          account: z.string().describe("Ethereum address of the trader (lowercase)"),
        },
      },
      async ({ account }) => {
        try {
          const query = `{
            account(id: "${account.toLowerCase()}") {
              id
              creationTimestamp
              lastTradedTimestamp
              isActive
              numTrades
              collateralVolume
              totalRealizedPnl
              totalUnrealizedPnl
              totalFeesPaid
              winRate
              profitFactor
              maxDrawdown
              numWinningPositions
              numLosingPositions
              totalProfitsSum
              totalLossesSum
            }
          }`;
          const data = await querySubgraph(SUBGRAPHS.beefy_pnl.ipfsHash, query);
          return textResult(data);
        } catch (error) {
          return errorResult(error);
        }
      }
    );
  • Handler function for get_account_pnl. Accepts { account }, builds a GraphQL query against the Beefy P&L subgraph's 'account' entity, and returns P&L metrics including totalRealizedPnl, totalUnrealizedPnl, totalFeesPaid, winRate, profitFactor, maxDrawdown, numWinningPositions, numLosingPositions, totalProfitsSum, totalLossesSum.
    async ({ account }) => {
      try {
        const query = `{
          account(id: "${account.toLowerCase()}") {
            id
            creationTimestamp
            lastTradedTimestamp
            isActive
            numTrades
            collateralVolume
            totalRealizedPnl
            totalUnrealizedPnl
            totalFeesPaid
            winRate
            profitFactor
            maxDrawdown
            numWinningPositions
            numLosingPositions
            totalProfitsSum
            totalLossesSum
          }
        }`;
        const data = await querySubgraph(SUBGRAPHS.beefy_pnl.ipfsHash, query);
        return textResult(data);
      } catch (error) {
        return errorResult(error);
      }
    }
  • Input schema for get_account_pnl: expects 'account' as a zod string (Ethereum address). No output schema defined — results are JSON-stringified.
    inputSchema: {
      account: z.string().describe("Ethereum address of the trader (lowercase)"),
    },
  • The tool queries the 'beefy_pnl' subgraph (IPFS hash QmbHwcGkumWdyTK2jYWXV3vX4WyinftEGbuwi7hDkhPWqG) via the querySubgraph helper.
    const data = await querySubgraph(SUBGRAPHS.beefy_pnl.ipfsHash, query);
  • The querySubgraph helper function used by the handler to execute the GraphQL query against the Graph API gateway.
    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 provided, and the description does not disclose behavioral traits such as read-only nature, required permissions, rate limits, or side effects. The agent has no information beyond the tool name and description.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, concise sentence that covers the core purpose. It is front-loaded and contains no redundant information. However, it could be slightly expanded to include more context without becoming verbose.

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 only one parameter and no output schema, the description is minimal. It does not specify what performance metrics are included or how the results are formatted. Given the complexity of P&L data, more context would be helpful for agent decision-making.

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?

The input schema already describes the account parameter as 'Ethereum address of the trader (lowercase)' with 100% coverage. The description adds no additional meaning beyond what the schema provides, so a baseline of 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?

Description clearly states the tool gets a trader's P&L and performance metrics from a specific subgraph. The verb 'Get' and resource 'P&L and performance metrics' are specific, and the source 'Beefy P&L subgraph' distinguishes it from other trader-related tools like get_trader_profile or get_user_positions.

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 vs alternatives. For instance, it doesn't clarify whether this should be used over get_trader_profile or get_user_positions for P&L-related queries. No context about prerequisites or use cases.

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