Skip to main content
Glama
getBlockHeights.ts2.06 kB
import axios from "axios"; import { AxiosResponse } from "axios"; import { baseUri, chainName } from "../../constants"; import z from "zod"; interface items { extra_data: string; gas_limit: number; gas_used: number; hash: string; miner: string; number: number; parent_hash: string; timestamp: string; } interface BlockHeightsResponse { count: number; cursor: string; items: items[]; } export default function(server: any) { server.tool( "getBlockHeights", "Get all block heights between two dates", { chainName: z.literal(chainName), startDate: z.string().describe("Start date in YYYY-MM-DD format"), endDate: z.string().describe("End date in YYYY-MM-DD format"), authToken: z .string() .describe("Authorization token for accessing the Somnia API"), }, { title: "Get Block Heights", readOnlyHint: true, description: "Fetch all block heights between two dates.", destructiveHint: false, }, async (args:any) => { const { chainName, startDate, endDate, authToken } = args; try { const response: AxiosResponse<BlockHeightsResponse> = await axios.get( `${baseUri}/${chainName}/v1/blocks/${startDate}/${endDate}`, { headers: { "Authorization": `Bearer ${authToken}`, "Content-Type": "application/json", "Accept": "application/json", }, params: { startDate, endDate, }, } ); return { content: [ { type: "text", text: `Block Heights Data: ${JSON.stringify(response.data)}`, }, ], _meta: { blockHeightsData: response.data, }, }; } catch (error) { return { content: [ { type: "text", text: `Error fetching block heights: ${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/vastavikadi/somnia-mcp'

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