get-wallet-balance
Retrieve cryptocurrency balance data for a wallet address on a specified blockchain network using the CoinStats MCP Server.
Instructions
Get the balance data for a provided wallet address on a specific blockchain network.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| address | Yes | Wallet address | |
| connectionId | Yes | The identifier of connection, which you received from /wallet/blockchains call response. |
Implementation Reference
- src/tools/toolConfigs.ts:165-174 (schema)Defines the schema (Zod parameters), endpoint, method, and description for the 'get-wallet-balance' tool.{ name: 'get-wallet-balance', description: 'Get the balance data for a provided wallet address on a specific blockchain network.', endpoint: '/wallet/balance', method: 'GET', parameters: { address: z.string().describe('Wallet address'), connectionId: z.string().describe('The identifier of connection, which you received from /wallet/blockchains call response.'), }, },
- src/tools/toolFactory.ts:19-79 (registration)Registers the 'get-wallet-balance' tool (and others) on the MCP server by calling server.tool with the config's name, description, parameters schema, and a generic handler that calls universalApiHandler.export function registerTools(server: McpServer, toolConfigs: ToolConfig<any>[]) { toolConfigs.forEach((config) => { server.tool(config.name, config.description, config.parameters, async (params: Record<string, any>) => { // Handle local operations if (config.isLocal) { // Handle specific local tools if (config.name === 'save-share-token') { await saveToCache('shareToken', params.shareToken); return { content: [ { type: 'text', text: 'Share token saved successfully', }, ], }; } if (config.name === 'get-share-token') { const shareToken = await getFromCache('shareToken'); return { content: [ { type: 'text', text: shareToken ? shareToken : 'No share token found in cache', isError: !shareToken, }, ], }; } // Future local tools can be added here // Default response for unhandled local tools return { content: [ { type: 'text', text: 'Operation completed', }, ], }; } // Handle API operations const basePath = config.basePath || COINSTATS_API_BASE; const method = config.method || 'GET'; // Methods that typically have a request body const bodyMethods = ['POST', 'PUT', 'PATCH', 'DELETE']; // For GET/DELETE requests, all params go in the URL // For POST/PUT/PATCH, send params as the body if (bodyMethods.includes(method.toUpperCase())) { return universalApiHandler(basePath, config.endpoint, method, {}, params); } else { return universalApiHandler(basePath, config.endpoint, method, params); } }); }); }
- src/services/request.ts:35-97 (handler)Core handler function that executes the API request: substitutes path parameters, builds URL with query params, performs fetch to CoinStats API using makeRequestCsApi, and returns MCP-formatted response (JSON string or error). Called by the tool handler for get-wallet-balance.export async function universalApiHandler<T>( basePath: string, endpoint: string, method: string = 'GET', params: Record<string, any> = {}, body?: any ): Promise<{ content: Array<{ type: 'text'; text: string; isError?: boolean }>; }> { try { // Handle path parameters - replace {paramName} in endpoint with actual values let processedEndpoint = endpoint; let processedParams = { ...params }; // Find all path parameters in the endpoint (e.g., {coinId}, {id}, {type}) const pathParamMatches = endpoint.match(/\{([^}]+)\}/g); if (pathParamMatches) { for (const match of pathParamMatches) { const paramName = match.slice(1, -1); // Remove { and } if (processedParams[paramName] !== undefined) { // Replace the placeholder with the actual value processedEndpoint = processedEndpoint.replace(match, processedParams[paramName]); // Remove the parameter from query params since it's now part of the path delete processedParams[paramName]; } else { throw new Error(`Required path parameter '${paramName}' is missing`); } } } // MCP clients might not support '~' in parameter names, so we replace '-' with '~' specifically for the /coins endpoint before making the request. if (endpoint === '/coins') { processedParams = Object.entries(processedParams).reduce((acc, [key, value]) => { acc[key.replace(/-/g, '~')] = value; return acc; }, {} as Record<string, any>); } const url = `${basePath}${processedEndpoint}`; const data = await makeRequestCsApi<T>(url, method, processedParams, body); if (!data) { return { content: [{ type: 'text', text: 'Something went wrong', isError: true }], }; } return { content: [ { type: 'text', text: JSON.stringify(data), }, ], }; } catch (error) { return { content: [{ type: 'text', text: `Error: ${error}`, isError: true }], }; } }
- src/index.ts:17-18 (registration)Calls registerTools with allToolConfigs to register the 'get-wallet-balance' tool on the MCP server instance.// Register all tools from configurations registerTools(server, allToolConfigs);