get_token_data
Retrieve detailed token data by contract address on specified blockchain networks, including optional top pools information, for DeFi trading and analysis.
Instructions
Get specific token data by contract address
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| address | Yes | Token contract address | |
| include | No | Attributes to include: 'top_pools' (optional) | |
| network | Yes | Network ID (e.g., 'eth', 'bsc', 'polygon_pos') |
Input Schema (JSON Schema)
{
"properties": {
"address": {
"description": "Token contract address",
"type": "string"
},
"include": {
"description": "Attributes to include: 'top_pools' (optional)",
"enum": [
"top_pools"
],
"type": "string"
},
"network": {
"description": "Network ID (e.g., 'eth', 'bsc', 'polygon_pos')",
"type": "string"
}
},
"required": [
"network",
"address"
],
"type": "object"
}
Implementation Reference
- src/toolService.js:298-317 (handler)The primary handler function for the 'get_token_data' tool. Validates input parameters, delegates to CoinGeckoApiService, and returns a formatted response with success message, data, summary, and included attributes.async getTokenData(network, address, options = {}) { if (!network || !address) { throw new Error("Missing required parameters: network, address"); } const result = await this.coinGeckoApi.getTokenData( network, address, options ); return { message: `Token data for ${address} on ${network} retrieved successfully`, data: result, summary: `Retrieved data for token ${ result.data?.attributes?.symbol || address }`, includes: options.include ? options.include.split(",") : [], }; }
- src/index.js:473-494 (schema)Input schema definition for the 'get_token_data' tool, registered in the MCP server's ListTools handler. Specifies required 'network' and 'address' parameters, optional 'include' for top_pools.name: TOOL_NAMES.GET_TOKEN_DATA, description: "Get specific token data by contract address", inputSchema: { type: "object", properties: { network: { type: "string", description: "Network ID (e.g., 'eth', 'bsc', 'polygon_pos')", }, address: { type: "string", description: "Token contract address", }, include: { type: "string", description: "Attributes to include: 'top_pools' (optional)", enum: ["top_pools"], }, }, required: ["network", "address"], }, },
- src/index.js:1084-1088 (registration)Registration/dispatch logic in the MCP server's CallTool handler switch statement. Maps 'get_token_data' tool calls to the toolService.getTokenData method.case TOOL_NAMES.GET_TOKEN_DATA: result = await toolService.getTokenData(args.network, args.address, { include: args.include, }); break;
- Helper function in CoinGeckoApiService that performs the actual HTTP request to CoinGecko's onchain API for token data (/networks/{network}/tokens/{address}), handles query params like 'include', and error handling.async getTokenData(network, address, options = {}) { try { const queryParams = new URLSearchParams(); if (options.include) queryParams.append('include', options.include); const url = `${this.baseUrl}/networks/${network}/tokens/${address}${queryParams.toString() ? '?' + queryParams.toString() : ''}`; const response = await fetch(url, { headers: { 'x-cg-demo-api-key': this.apiKey } }); if (!response.ok) { throw new Error(`HTTP ${response.status}: ${response.statusText}`); } return await response.json(); } catch (error) { throw new Error(`Failed to get token data: ${error.message}`); } }