Skip to main content
Glama
jwaresolutions

Polygon MCP Server

get_aggregates

Retrieve aggregated financial market data for a specific ticker symbol over defined time periods. Specify ticker, time range, and interval to access historical price bars for analysis.

Instructions

Get aggregate bars for a ticker

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
tickerYesTicker symbol (e.g., AAPL)
timespanYesSize of the time window
fromYesStart date (YYYY-MM-DD format)
toYesEnd date (YYYY-MM-DD format)
adjustedNoWhether to adjust for splits (default: true)
sortNoSort order (default: asc)
limitNoNumber of results (default: 120, max: 50000)

Implementation Reference

  • The async handler function that implements the 'get_aggregates' tool logic, calling the Polygon API to retrieve aggregate bars (OHLCV data) for a ticker over a specified date range and timespan.
    get_aggregates: async (args: { 
      ticker: string; 
      timespan: string; 
      from: string; 
      to: string;
      adjusted?: boolean;
      sort?: string;
      limit?: number;
    }) => {
      try {
        const params: any = {
          adjusted: args.adjusted !== false,
          sort: args.sort || 'asc',
          limit: args.limit || 120
        };
    
        const response = await polygonApi.get(
          `/v2/aggs/ticker/${args.ticker}/range/1/${args.timespan}/${args.from}/${args.to}`,
          { params }
        );
        return {
          content: [{
            type: "text",
            text: JSON.stringify(response.data, null, 2)
          }]
        };
      } catch (error: any) {
        return {
          content: [{
            type: "text",
            text: `Error getting aggregates: ${error.response?.data?.message || error.message}`
          }],
          isError: true
        };
      }
    },
  • The input schema definition for the 'get_aggregates' tool, specifying parameters like ticker, timespan, date range, and options for the API call.
    inputSchema: {
      type: "object",
      properties: {
        ticker: {
          type: "string",
          description: "Ticker symbol (e.g., AAPL)"
        },
        timespan: {
          type: "string",
          enum: ["minute", "hour", "day", "week", "month", "quarter", "year"],
          description: "Size of the time window"
        },
        from: {
          type: "string",
          description: "Start date (YYYY-MM-DD format)"
        },
        to: {
          type: "string",
          description: "End date (YYYY-MM-DD format)"
        },
        adjusted: {
          type: "boolean",
          description: "Whether to adjust for splits (default: true)"
        },
        sort: {
          type: "string",
          enum: ["asc", "desc"],
          description: "Sort order (default: asc)"
        },
        limit: {
          type: "number",
          description: "Number of results (default: 120, max: 50000)"
        }
      },
      required: ["ticker", "timespan", "from", "to"]
    }
  • src/index.ts:272-311 (registration)
    The tool registration in the ListTools response, including name, description, and input schema.
    {
      name: "get_aggregates",
      description: "Get aggregate bars for a ticker",
      inputSchema: {
        type: "object",
        properties: {
          ticker: {
            type: "string",
            description: "Ticker symbol (e.g., AAPL)"
          },
          timespan: {
            type: "string",
            enum: ["minute", "hour", "day", "week", "month", "quarter", "year"],
            description: "Size of the time window"
          },
          from: {
            type: "string",
            description: "Start date (YYYY-MM-DD format)"
          },
          to: {
            type: "string",
            description: "End date (YYYY-MM-DD format)"
          },
          adjusted: {
            type: "boolean",
            description: "Whether to adjust for splits (default: true)"
          },
          sort: {
            type: "string",
            enum: ["asc", "desc"],
            description: "Sort order (default: asc)"
          },
          limit: {
            type: "number",
            description: "Number of results (default: 120, max: 50000)"
          }
        },
        required: ["ticker", "timespan", "from", "to"]
      }
    },
  • src/index.ts:405-407 (registration)
    The dynamic dispatch mechanism in the CallToolRequest handler that routes calls to the appropriate tool handler based on name.
    if (name in toolHandlers) {
      return await (toolHandlers as any)[name](args || {});
    }

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/jwaresolutions/polygon-mcp-server'

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