get-crypto-price
Fetch current price and 24-hour statistics for any cryptocurrency by providing its symbol. Access real-time data for informed market analysis.
Instructions
Get current price and 24h stats for a cryptocurrency
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| symbol | Yes | Cryptocurrency symbol (e.g., BTC, ETH) |
Implementation Reference
- src/tools/price.ts:9-48 (handler)The handler function that executes the get-crypto-price tool logic: parses input symbol, fetches assets from CoinCap, finds the asset, formats price info, handles errors.export async function handleGetPrice(args: unknown) { const { symbol } = GetPriceArgumentsSchema.parse(args); const upperSymbol = symbol.toUpperCase(); try { const assetsData = await getAssets(); if (!assetsData) { return { content: [{ type: "text", text: "Failed to retrieve cryptocurrency data" }], }; } const asset = assetsData.data.find( (a: { symbol: string; }) => a.symbol.toUpperCase() === upperSymbol ); if (!asset) { return { content: [ { type: "text", text: `Could not find cryptocurrency with symbol ${upperSymbol}`, }, ], }; } return { content: [{ type: "text", text: formatPriceInfo(asset) }], }; } catch (error) { return { content: [{ type: "text", text: error instanceof Error ? error.message : `Failed to retrieve cryptocurrency data: ${String(error)}` }], }; } }
- src/tools/price.ts:5-7 (schema)Zod input schema defining the 'symbol' parameter for the tool.export const GetPriceArgumentsSchema = z.object({ symbol: z.string().min(1), });
- src/index.ts:38-49 (registration)Registers the 'get-crypto-price' tool on the MCP server with title, description, input schema, and handler.server.registerTool( "get-crypto-price", { title: "Get Crypto Price", description: "Get current price and 24h stats for a cryptocurrency", inputSchema: GetPriceArgumentsSchema.shape, }, async (args, _extra) => { const result = await handleGetPrice(args); return result as any; } );