get-crypto-price
Retrieve real-time cryptocurrency prices and 24-hour market statistics by inputting a specific cryptocurrency symbol. Powered by CoinCap API v3 for accurate data.
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-38 (handler)Main execution handler for the 'get-crypto-price' tool. Parses input using Zod schema, fetches cryptocurrency assets from CoinCap service, finds the matching asset, and returns formatted price information.export async function handleGetPrice(args: unknown) { const { symbol } = GetPriceArgumentsSchema.parse(args); const upperSymbol = symbol.toUpperCase(); 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) }], }; }
- src/tools/price.ts:5-7 (schema)Zod schema used in the handler for validating the tool's input argument 'symbol'.export const GetPriceArgumentsSchema = z.object({ symbol: z.string().min(1), });
- src/index.ts:31-44 (registration)Registration of the 'get-crypto-price' tool in the ListToolsRequestSchema handler, including name, description, and MCP-compatible input schema.{ name: "get-crypto-price", description: "Get current price and 24h stats for a cryptocurrency", inputSchema: { type: "object", properties: { symbol: { type: "string", description: "Cryptocurrency symbol (e.g., BTC, ETH)", }, }, required: ["symbol"], }, },
- src/index.ts:93-94 (registration)Dispatch logic in the CallToolRequestSchema handler that routes 'get-crypto-price' calls to the handleGetPrice function.case "get-crypto-price": return await handleGetPrice(args);