list-kv
Filter and list keys in the Consul KV store using a specified prefix to organize and retrieve stored data efficiently.
Instructions
List keys in the KV store
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| prefix | No | Prefix to filter keys by |
Implementation Reference
- src/tools/consulTools.ts:381-394 (handler)The handler function that implements the logic for listing keys in the Consul KV store. It calls consul.kv.keys(prefix), handles empty results and errors, and formats the output as text.async ({ prefix = "" }) => { try { const data = await consul.kv.keys(prefix); if (!data || data.length === 0) { return { content: [{ type: "text", text: `No keys found${prefix ? ` with prefix: ${prefix}` : ""}` }] }; } const keysText = `Keys in KV store${prefix ? ` with prefix: ${prefix}` : ""}:\n\n${data.join("\n")}`; return { content: [{ type: "text", text: keysText }] }; } catch (error) { console.error("Error listing KV keys:", error); return { content: [{ type: "text", text: `Error listing keys${prefix ? ` with prefix: ${prefix}` : ""}` }] }; } }
- src/tools/consulTools.ts:378-380 (schema)Zod schema defining the input parameter 'prefix' as an optional string.{ prefix: z.string().default("").optional().describe("Prefix to filter keys by"), },
- src/tools/consulTools.ts:375-395 (registration)The server.tool() call that registers the 'list-kv' tool, including its name, description, input schema, and handler function.server.tool( "list-kv", "List keys in the KV store", { prefix: z.string().default("").optional().describe("Prefix to filter keys by"), }, async ({ prefix = "" }) => { try { const data = await consul.kv.keys(prefix); if (!data || data.length === 0) { return { content: [{ type: "text", text: `No keys found${prefix ? ` with prefix: ${prefix}` : ""}` }] }; } const keysText = `Keys in KV store${prefix ? ` with prefix: ${prefix}` : ""}:\n\n${data.join("\n")}`; return { content: [{ type: "text", text: keysText }] }; } catch (error) { console.error("Error listing KV keys:", error); return { content: [{ type: "text", text: `Error listing keys${prefix ? ` with prefix: ${prefix}` : ""}` }] }; } } );