Skip to main content
Glama

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

TableJSON Schema
NameRequiredDescriptionDefault
bodyNoRequest body for POST/PUT requests
methodYesHTTP method to use for the request
networkNameYesName 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
pathYesAPI endpoint path from the OpenAPI spec, e.g., '/cosmos/bank/v1beta1/balances/{address}'
pathParamsNoPath parameters to substitute in the URL path
queryParamsNoQuery parameters to add to the request

Implementation Reference

  • 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)}`); } }
  • 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"), },
  • 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)}`); } } );

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/allthatjazzleo/mantrachain-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server