Skip to main content
Glama
jackdark425

Financial Modeling Prep (FMP) MCP Server

by jackdark425

get_historical_chart

Retrieve historical stock price data with customizable time intervals to analyze market trends and performance over specific periods.

Instructions

Get historical price data with flexible time intervals

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
symbolYesStock ticker symbol
intervalYesTime interval
fromNoStart date in YYYY-MM-DD format (optional)
toNoEnd date in YYYY-MM-DD format (optional)

Implementation Reference

  • The 'get_historical_chart' tool is registered and implemented here, using the HistoricalChartSchema for input validation and calling fetchFMP to retrieve data.
    server.registerTool(
      'get_historical_chart',
      {
        description: 'Get historical price data with flexible time intervals',
        inputSchema: HistoricalChartSchema,
      },
      async (args: z.infer<typeof HistoricalChartSchema>) => {
        try {
          let endpoint = `/historical-chart/${args.interval}?symbol=${args.symbol.toUpperCase()}`;
          if (args.from) endpoint += `&from=${args.from}`;
          if (args.to) endpoint += `&to=${args.to}`;
          const data = await fetchFMP<HistoricalPrice[]>(endpoint);
          return jsonResponse(data);
        } catch (error) {
          return errorResponse(error);
        }
      }
    );
  • Validation schema for the input arguments of the get_historical_chart tool.
    const HistoricalChartSchema = z.object({
      symbol: z.string().describe('Stock ticker symbol'),
      interval: IntervalSchema.describe('Time interval'),
      from: z.string().optional().describe('Start date in YYYY-MM-DD format (optional)'),
      to: z.string().optional().describe('End date in YYYY-MM-DD format (optional)'),
    });
  • Tool registration function that includes the get_historical_chart tool definition.
    export function registerTechnicalTools(server: any) {
      // RSI
      server.registerTool(
        'get_technical_indicator_rsi',
        {
          description: 'Get Relative Strength Index (RSI) technical indicator',
          inputSchema: TechnicalIndicatorSchema,
        },
        async (args: z.infer<typeof TechnicalIndicatorSchema>) => {
          try {
            const period = args.period || 14;
            const data = await fetchFMP<TechnicalIndicator[]>(
              `/technical-indicators/rsi?symbol=${args.symbol.toUpperCase()}&timeframe=${args.timeframe}&periodLength=${period}`
            );
            return jsonResponse(data);
          } catch (error) {
            return errorResponse(error);
          }
        }
      );
    
      // SMA
      server.registerTool(
        'get_technical_indicator_sma',
        {
          description: 'Get Simple Moving Average (SMA) technical indicator',
          inputSchema: TechnicalIndicatorSchema,
        },
        async (args: z.infer<typeof TechnicalIndicatorSchema>) => {
          try {
            const period = args.period || 10;
            const data = await fetchFMP<TechnicalIndicator[]>(
              `/technical-indicators/sma?symbol=${args.symbol.toUpperCase()}&timeframe=${args.timeframe}&periodLength=${period}`
            );
            return jsonResponse(data);
          } catch (error) {
            return errorResponse(error);
          }
        }
      );
    
      // EMA
      server.registerTool(
        'get_technical_indicator_ema',
        {
          description: 'Get Exponential Moving Average (EMA) technical indicator',
          inputSchema: TechnicalIndicatorSchema,
        },
        async (args: z.infer<typeof TechnicalIndicatorSchema>) => {
          try {
            const period = args.period || 10;
            const data = await fetchFMP<TechnicalIndicator[]>(
              `/technical-indicators/ema?symbol=${args.symbol.toUpperCase()}&timeframe=${args.timeframe}&periodLength=${period}`
            );
            return jsonResponse(data);
          } catch (error) {
            return errorResponse(error);
          }
        }
      );
    
      // Historical Chart
      server.registerTool(
        'get_historical_chart',
        {
          description: 'Get historical price data with flexible time intervals',
          inputSchema: HistoricalChartSchema,
        },
        async (args: z.infer<typeof HistoricalChartSchema>) => {
          try {
            let endpoint = `/historical-chart/${args.interval}?symbol=${args.symbol.toUpperCase()}`;
            if (args.from) endpoint += `&from=${args.from}`;
            if (args.to) endpoint += `&to=${args.to}`;
            const data = await fetchFMP<HistoricalPrice[]>(endpoint);
            return jsonResponse(data);
          } catch (error) {
            return errorResponse(error);
          }
        }
      );
    }

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/jackdark425/aigroup-fmp-mcp'

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