getMarketRiskPremium
Retrieve the market risk premium for any date to calculate the additional expected return from stock market investments over risk-free assets, aiding investment decisions.
Instructions
Access the market risk premium for specific dates with the FMP Market Risk Premium API. Use this key financial metric to assess the additional return expected from investing in the stock market over a risk-free investment.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/tools/economics.ts:128-152 (handler)MCP tool registration and handler for 'getMarketRiskPremium'. Registers the tool with no input schema, calls economicsClient.getMarketRiskPremium(), and returns the results as JSON.
server.tool( "getMarketRiskPremium", "Access the market risk premium for specific dates with the FMP Market Risk Premium API. Use this key financial metric to assess the additional return expected from investing in the stock market over a risk-free investment.", {}, async () => { try { const results = await economicsClient.getMarketRiskPremium(); return { content: [{ type: "text", text: JSON.stringify(results, null, 2) }], }; } catch (error) { return { content: [ { type: "text", text: `Error: ${ error instanceof Error ? error.message : String(error) }`, }, ], isError: true, }; } } ); - EconomicsClient.getMarketRiskPremium() method that calls the FMP API endpoint '/market-risk-premium' via the base FMPClient.get<T>() method.
async getMarketRiskPremium( options?: { signal?: AbortSignal; context?: FMPContext; } ): Promise<MarketRiskPremium[]> { return super.get<MarketRiskPremium[]>( "/market-risk-premium", {}, options ); } - src/api/economics/types.ts:36-41 (schema)MarketRiskPremium interface defining the return type: country, continent, countryRiskPremium, and totalEquityRiskPremium.
export interface MarketRiskPremium { country: string; continent: string; countryRiskPremium: number; totalEquityRiskPremium: number; } - src/tools/economics.ts:10-13 (registration)registerEconomicsTools function which registers the 'getMarketRiskPremium' tool (and others) on the MCP server.
export function registerEconomicsTools( server: McpServer, accessToken?: string ): void { - src/api/FMPClient.ts:42-80 (helper)FMPClient.get<T>() base method that handles HTTP GET requests, API key injection from context/instance/env, abort signals, and error handling for all API clients.
protected async get<T>( endpoint: string, params: Record<string, any> = {}, options?: { signal?: AbortSignal; context?: { config?: { FMP_ACCESS_TOKEN?: string } }; } ): Promise<T> { try { // Try to get API key from context first, fall back to instance API key const apiKey = this.getApiKey(options?.context); const config: AxiosRequestConfig = { params: { ...params, apikey: apiKey, }, }; if (options?.signal) { config.signal = options.signal; } const response = await this.client.get<T>(endpoint, config); return response.data; } catch (error: unknown) { if (axios.isAxiosError(error)) { const axiosError = error as AxiosError<FMPErrorResponse>; throw new Error( `FMP API Error: ${ axiosError.response?.data?.message || axiosError.message }`, { cause: error } ); } throw new Error( `Unexpected error: ${ error instanceof Error ? error.message : String(error) }`, { cause: error } );