call_endpoint
Execute API calls to Grove's blockchain endpoints across 70+ networks including Ethereum, Solana, and Cosmos. Send requests with path parameters, query strings, and request bodies for accessing blockchain data.
Instructions
Call a Grove endpoint for Pocket Network with optional parameters
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| body | No | Request body for POST/PUT/PATCH requests | |
| endpointId | Yes | The ID of the endpoint to call | |
| pathParams | No | Path parameters (e.g., {id: "123"} for /users/:id) | |
| queryParams | No | Query parameters to append to the URL |
Implementation Reference
- Handler for the 'call_endpoint' tool within the switch statement of handleEndpointTool. Extracts parameters from input arguments and invokes endpointManager.fetchEndpoint to execute the HTTP request, returning the JSON-formatted result.case 'call_endpoint': { const endpointId = args?.endpointId as string; const pathParams = args?.pathParams as Record<string, string> | undefined; const queryParams = args?.queryParams as Record<string, string> | undefined; const body = args?.body as any; const result = await endpointManager.fetchEndpoint(endpointId, { pathParams, queryParams, body, }); return { content: [ { type: 'text', text: JSON.stringify(result, null, 2), }, ], isError: !result.success, }; }
- src/handlers/endpoint-handlers.ts:42-67 (registration)Tool registration object returned by registerEndpointHandlers, defining name, description, and inputSchema for 'call_endpoint'. This is collected in src/index.ts for the MCP server's tool list.{ name: 'call_endpoint', description: "Call a Pocket Network endpoint with optional parameters", inputSchema: { type: 'object', properties: { endpointId: { type: 'string', description: 'The ID of the endpoint to call', }, pathParams: { type: 'object', description: 'Path parameters (e.g., {id: "123"} for /users/:id)', }, queryParams: { type: 'object', description: 'Query parameters to append to the URL', }, body: { type: 'object', description: 'Request body for POST/PUT/PATCH requests', }, }, required: ['endpointId'], }, },
- Supporting method in EndpointManager class that implements the actual HTTP fetch logic for the endpoint. Handles URL construction with path/query params, fetch with method/headers/body, JSON parsing, and structured response with success/data/error fields.async fetchEndpoint( endpointId: string, options?: { pathParams?: Record<string, string>; queryParams?: Record<string, string>; body?: any; } ): Promise<EndpointResponse> { const endpoint = this.getEndpointById(endpointId); if (!endpoint) { return { success: false, error: `Endpoint not found: ${endpointId}` }; } try { const url = new URL(this.buildEndpointUrl(endpointId, options?.pathParams)); // Add query parameters if (options?.queryParams) { Object.entries(options.queryParams).forEach(([key, value]) => { url.searchParams.append(key, value); }); } const fetchOptions: RequestInit = { method: endpoint.method, headers: { 'Content-Type': 'application/json', 'Accept': 'application/json' } }; if (options?.body && endpoint.method !== 'GET') { fetchOptions.body = JSON.stringify(options.body); } const response = await fetch(url.toString(), fetchOptions); const data = await response.json(); return { success: response.ok, data: response.ok ? data : undefined, error: response.ok ? undefined : data.message || `HTTP ${response.status}`, metadata: { timestamp: new Date().toISOString(), endpoint: url.toString() } }; } catch (error) { return { success: false, error: error instanceof Error ? error.message : 'Unknown error', metadata: { timestamp: new Date().toISOString(), endpoint: endpointId } }; } }