Skip to main content
Glama

infura-mcp

by deflang
getClientVersion.ts2.08 kB
import { z } from "zod"; import { CallToolResult } from "@modelcontextprotocol/sdk/types"; import { INFURA_CHAIN_URLS } from "../../config/chains.js"; interface JsonRpcResponse<T = unknown> { jsonrpc: string; id: number; result?: T; error?: { code?: number; message: string }; } export const getClientVersion = { name: "eth_get_web3_client_version", description: "Returns the current client version string.", schema: { chainid: z .number() .optional() .describe("EVM chain ID (default: 1 for Ethereum mainnet)"), }, handler: async ({ chainid, }: { chainid?: number; }): Promise<CallToolResult> => { try { const selectedChainId = chainid ?? 1; const url = INFURA_CHAIN_URLS[selectedChainId]; if (!url) { return { content: [ { type: "text", text: `Unsupported chain ID: ${selectedChainId}` }, ], }; } const body = { jsonrpc: "2.0", method: "web3_clientVersion", params: [], id: 1, }; const res = await fetch(url, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(body), }); const data: JsonRpcResponse<string> = await res.json(); if (data.result === undefined) { return { content: [ { type: "text", text: `Error fetching client version: ${ data.error?.message || "Unknown error" }`, }, ], }; } return { content: [ { type: "text", text: `Client version: ${data.result}`, }, ], }; } catch (err: unknown) { const message = err instanceof Error ? err.message : typeof err === "string" ? err : JSON.stringify(err); return { content: [ { type: "text", text: `Error fetching client version: ${message}` }, ], }; } }, };

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/deflang/infura-mcp'

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