get_crypto_price
Retrieve real-time cryptocurrency prices from CoinCap's API to monitor market values and track specific coin performance.
Instructions
Get realtime crypto price on crypto
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "get_crypto_price"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | No | Name of the crypto coin |
Implementation Reference
- src/tools/GetCryptoPrice.ts:23-48 (handler)The `toolCall` method that executes the core logic: extracts crypto name from arguments, fetches price data from Coincap API endpoint, returns JSON data or error response.
async toolCall(request: z.infer<typeof CallToolRequestSchema>) { try { const cryptoName = request.params.arguments?.name; if (!cryptoName) { throw new Error("Missing crypto name"); } const url = CONSTANTS.CRYPTO_PRICE_URL + cryptoName; const response = await fetch(url); if (!response.ok) { throw new Error("Error fetching coincap data"); } const body = await response.json(); return { content: [{ type: "text", text: JSON.stringify(body.data) }], }; } catch (error) { return { content: [ { type: "error", text: JSON.stringify((error as any).message) }, ], }; } } - src/tools/GetCryptoPrice.ts:9-21 (schema)Tool definition including name, description, and input schema specifying a required 'name' string for the cryptocurrency.
toolDefinition: Tool = { name: this.name, description: "Get realtime crypto price on crypto", inputSchema: { type: "object", properties: { name: { type: "string", description: "Name of the crypto coin", }, }, }, }; - src/utils/toolLoader.ts:90-92 (registration)Creates a Map of tools keyed by their name (including 'get_crypto_price') for lookup during tool calls.
export function createToolsMap(tools: BaseTool[]): Map<string, BaseTool> { return new Map(tools.map((tool) => [tool.name, tool])); } - src/constants.ts:2-6 (helper)Defines CRYPTO_PRICE_URL constant used by the get_crypto_price handler to construct the API endpoint.
export const CONSTANTS = { CRYPTO_PRICE_URL: "https://api.coincap.io/v2/assets/", PROJECT_NAME: "coincap-mcp", PROJECT_VERSION: "0.9.2", }; - src/tools/GetCryptoPrice.ts:51-51 (registration)Exports the GetCryptoPrice class for dynamic loading and instantiation by the tool loader.
export default GetCryptoPrice;