execute-prepared-query
Run predefined queries on the Consul MCP Server to retrieve specific data or configurations using a query ID. Streamlines access to Consul services, health checks, KV stores, and more.
Instructions
Execute a prepared query
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | No | ID of the prepared query |
Implementation Reference
- src/tools/consulTools.ts:625-634 (handler)The core handler function for the 'execute-prepared-query' tool. It takes the prepared query ID, executes it via consul.query.execute(id), stringifies the results, and returns them in the MCP content format. Includes error handling.async ({ id }) => { try { // @ts-ignore - The Consul type definitions are incomplete const results = await consul.query.execute(id); return { content: [{ type: "text", text: `Query results:\n\n${JSON.stringify(results, null, 2)}` }] }; } catch (error) { console.error("Error executing prepared query:", error); return { content: [{ type: "text", text: `Error executing prepared query: ${id}` }] }; } }
- src/tools/consulTools.ts:622-624 (schema)Zod input schema defining the 'id' parameter as a required string for the prepared query ID.{ id: z.string().default("").describe("ID of the prepared query"), },
- src/tools/consulTools.ts:619-635 (registration)Registration of the 'execute-prepared-query' tool on the MCP server within the registerPreparedQueryTools function, including name, description, input schema, and inline handler.server.tool( "execute-prepared-query", "Execute a prepared query", { id: z.string().default("").describe("ID of the prepared query"), }, async ({ id }) => { try { // @ts-ignore - The Consul type definitions are incomplete const results = await consul.query.execute(id); return { content: [{ type: "text", text: `Query results:\n\n${JSON.stringify(results, null, 2)}` }] }; } catch (error) { console.error("Error executing prepared query:", error); return { content: [{ type: "text", text: `Error executing prepared query: ${id}` }] }; } } );