get_historical_apy
Retrieve historical APY data for a specific market by providing market details and time range to analyze performance over intervals like hour, day, week, or month.
Instructions
Get historical APY data for a specific market.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| chainId | No | ||
| endTimestamp | Yes | ||
| interval | Yes | ||
| marketUniqueKey | Yes | ||
| startTimestamp | Yes |
Implementation Reference
- src/index.ts:1144-1187 (handler)The core handler logic for the 'get_historical_apy' tool. Constructs a GraphQL query to the Morpho API to fetch historical supply and borrow APY data for a given market over a time range at specified interval, validates the response, and returns it as formatted JSON.if (name === GET_HISTORICAL_APY_TOOL) { try { const { marketUniqueKey, chainId = 1, startTimestamp, endTimestamp, interval } = params as HistoricalApyParams; const query = ` query MarketApys { marketByUniqueKey( uniqueKey: "${marketUniqueKey}" chainId: ${chainId} ) { uniqueKey historicalState { supplyApy(options: { startTimestamp: ${startTimestamp} endTimestamp: ${endTimestamp} interval: ${interval} }) { x y } borrowApy(options: { startTimestamp: ${startTimestamp} endTimestamp: ${endTimestamp} interval: ${interval} }) { x y } } } }`; const response = await axios.post(MORPHO_API_BASE, { query }); const validatedData = HistoricalApyResponseSchema.parse(response.data); return { content: [{ type: 'text', text: JSON.stringify(validatedData.data.marketByUniqueKey, null, 2) }], }; } catch (error: any) { return { isError: true, content: [{ type: 'text', text: `Error retrieving historical APY: ${error.message}` }], }; } }
- src/index.ts:701-717 (registration)Tool registration in the MCP server's ListTools handler, defining the tool name, description, and input schema for validation.name: GET_HISTORICAL_APY_TOOL, description: 'Get historical APY data for a specific market.', inputSchema: { type: 'object', properties: { marketUniqueKey: { type: 'string' }, chainId: { type: 'number' }, startTimestamp: { type: 'number' }, endTimestamp: { type: 'number' }, interval: { type: 'string', enum: ['HOUR', 'DAY', 'WEEK', 'MONTH'] } }, required: ['marketUniqueKey', 'startTimestamp', 'endTimestamp', 'interval'] }, },
- src/index.ts:275-285 (schema)Zod schema used to validate and parse the GraphQL response data from the Morpho API for historical APY.const HistoricalApyResponseSchema = z.object({ data: z.object({ marketByUniqueKey: z.object({ uniqueKey: z.string(), historicalState: z.object({ supplyApy: z.array(TimeseriesPointSchema), borrowApy: z.array(TimeseriesPointSchema), }), }), }), });
- src/index.ts:325-329 (schema)TypeScript type for the tool's input parameters, used for type-checking in the handler.type HistoricalApyParams = { marketUniqueKey: string; chainId?: number; } & TimeseriesParams;
- src/index.ts:311-311 (helper)Constant string defining the exact tool name used in registration and handler dispatch.const GET_HISTORICAL_APY_TOOL = 'get_historical_apy';