fetch_quote
Retrieve real-time token prices using a specified slug for accurate market data on EVM chains.
Instructions
Get the price of a token
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| slug | Yes |
Input Schema (JSON Schema)
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"additionalProperties": false,
"properties": {
"slug": {
"type": "string"
}
},
"required": [
"slug"
],
"type": "object"
}
Implementation Reference
- src/tools/FetchQuote.ts:10-16 (handler)The primary handler function that executes the logic for the 'fetch_quote' tool. It destructures the slug from options, fetches crypto data using the helper getCryptoDataLite, and returns the price from the statistics.export const fetchQuote = async (options: FetchQuoteOptions) => { const { slug } = options; const data = await getCryptoDataLite(slug); return data.data.statistics.price; };
- src/tools/FetchQuote.ts:5-8 (schema)Zod schema defining the input for the 'fetch_quote' tool (requires a 'slug' string) and the inferred TypeScript type.export const FetchQuoteSchema = z.object({ slug: z.string(), }); export type FetchQuoteOptions = z.infer<typeof FetchQuoteSchema>;
- src/index.ts:50-54 (registration)Registration of the 'fetch_quote' tool in the ListToolsRequestHandler response, including name, description, and input schema reference.{ name: "fetch_quote", description: "Get the price of a token", inputSchema: z.toJSONSchema(FetchQuoteSchema), },
- src/index.ts:142-155 (handler)Server-side dispatch handler case for 'fetch_quote' in the CallToolRequestHandler. Parses arguments using the schema, calls the fetchQuote function, and formats the response as MCP content.case "fetch_quote": { const args = FetchQuoteSchema.parse(request.params.arguments); const result = await fetchQuote(args); return { content: [ { type: "text", text: result.toString(), description: "The price of the token in USD", }, ], }; }
- src/services/cmc.ts:17-28 (helper)Supporting helper utility called by fetchQuote to retrieve lightweight cryptocurrency data (including price) from the CoinMarketCap API using the provided slug.export const getCryptoDataLite = async (slug: string) => { const response = await fetch( `https://api.coinmarketcap.com/data-api/v3/cryptocurrency/detail/lite?slug=${slug}` ); if (!response.ok) { throw new Error("Failed to fetch crypto data"); } const data = await response.json(); return data as GetCryptoDataLiteResponse; };