query-network
Execute custom network queries against chain APIs using gRPC Gateway when standard tools fail. Verify available queries via OpenAPI specification before sending requests with specified HTTP methods, paths, and parameters.
Instructions
Execute a generic network gRPC Gateway query against chain APIs when you cannot find the required information from other tools. You MUST first check the available query/service by reading the openapi specification from the resource openapi://{networkName} to understand available query/service, methods, required parameters and body structure.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| body | No | Request body for POST/PUT requests | |
| method | Yes | HTTP method to use for the request | |
| networkName | Yes | Name of the network to use - must first check what networks are available through the mantrachain-mcp server by accessing the networks resource `networks://all` before you pass this arguments | |
| path | Yes | API endpoint path from the OpenAPI spec, e.g., '/cosmos/bank/v1beta1/balances/{address}' | |
| pathParams | No | Path parameters to substitute in the URL path | |
| queryParams | No | Query parameters to add to the request |
Implementation Reference
- src/tools/network.ts:95-147 (handler)Handler function that executes the 'query-network' tool logic: initializes the Mantra client, builds the gRPC Gateway API URL with path/query parameters, performs an HTTP fetch request, and returns the JSON response.async ({ networkName, path, method, pathParams, queryParams, body }) => { try { await mantraClient.initialize(networkName); // Build the URL with path parameters let url = networks[networkName].apiEndpoint; // Remove trailing slash from base URL if present if (url.endsWith('/')) { url = url.slice(0, -1); } // Add path (substitute path parameters if provided) if (pathParams) { let substitutedPath = path; Object.entries(pathParams).forEach(([key, value]) => { substitutedPath = substitutedPath.replace(`{${key}}`, encodeURIComponent(String(value))); }); url += substitutedPath; } else { url += path; } // Add query parameters if (queryParams && Object.keys(queryParams).length > 0) { const params = new URLSearchParams(); Object.entries(queryParams).forEach(([key, value]) => { params.append(key, String(value)); }); url += `?${params.toString()}`; } // Execute request const response = await fetch(url, { method, headers: { 'Content-Type': 'application/json', 'Accept': 'application/json', }, body: body ? JSON.stringify(body) : undefined, }); const data = await response.json(); return { content: [ {type: "text", text: JSON.stringify(data)} ], }; } catch (error) { throw new Error(`Failed to execute network query: ${error instanceof Error ? error.message : String(error)}`); } }
- src/tools/network.ts:85-94 (schema)Zod input schema defining parameters for the 'query-network' tool: networkName, path, method, pathParams, queryParams, body.{ networkName: z.string().refine(val => Object.keys(networks).includes(val), { message: "Must be a valid network name" }).describe("Name of the network to use - must first check what networks are available by accessing the networks resource `networks://all` before you pass this arguments. Defaults to `mantra-dukong-1` testnet."), path: z.string().describe("API endpoint path from the OpenAPI spec, e.g., '/cosmos/bank/v1beta1/balances/{address}'"), method: z.enum(["GET", "POST", "PUT", "DELETE"]).describe("HTTP method to use for the request"), pathParams: z.record(z.string()).optional().describe("Path parameters to substitute in the URL path"), queryParams: z.record(z.string()).optional().describe("Query parameters to add to the request"), body: z.any().optional().describe("Request body for POST/PUT requests"), },
- src/tools/network.ts:82-148 (registration)Registration of the 'query-network' MCP tool using server.tool(), including description, input schema, and handler function.server.tool( "query-network", "Execute a generic network gRPC Gateway query against chain APIs when you cannot find the required information from other tools. You MUST first check the available query/service by reading the openapi specification from the resource `openapi://{networkName}` to understand available query/service, methods, required parameters and body structure.", { networkName: z.string().refine(val => Object.keys(networks).includes(val), { message: "Must be a valid network name" }).describe("Name of the network to use - must first check what networks are available by accessing the networks resource `networks://all` before you pass this arguments. Defaults to `mantra-dukong-1` testnet."), path: z.string().describe("API endpoint path from the OpenAPI spec, e.g., '/cosmos/bank/v1beta1/balances/{address}'"), method: z.enum(["GET", "POST", "PUT", "DELETE"]).describe("HTTP method to use for the request"), pathParams: z.record(z.string()).optional().describe("Path parameters to substitute in the URL path"), queryParams: z.record(z.string()).optional().describe("Query parameters to add to the request"), body: z.any().optional().describe("Request body for POST/PUT requests"), }, async ({ networkName, path, method, pathParams, queryParams, body }) => { try { await mantraClient.initialize(networkName); // Build the URL with path parameters let url = networks[networkName].apiEndpoint; // Remove trailing slash from base URL if present if (url.endsWith('/')) { url = url.slice(0, -1); } // Add path (substitute path parameters if provided) if (pathParams) { let substitutedPath = path; Object.entries(pathParams).forEach(([key, value]) => { substitutedPath = substitutedPath.replace(`{${key}}`, encodeURIComponent(String(value))); }); url += substitutedPath; } else { url += path; } // Add query parameters if (queryParams && Object.keys(queryParams).length > 0) { const params = new URLSearchParams(); Object.entries(queryParams).forEach(([key, value]) => { params.append(key, String(value)); }); url += `?${params.toString()}`; } // Execute request const response = await fetch(url, { method, headers: { 'Content-Type': 'application/json', 'Accept': 'application/json', }, body: body ? JSON.stringify(body) : undefined, }); const data = await response.json(); return { content: [ {type: "text", text: JSON.stringify(data)} ], }; } catch (error) { throw new Error(`Failed to execute network query: ${error instanceof Error ? error.message : String(error)}`); } } );