Skip to main content
Glama

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
NameRequiredDescriptionDefault
prefixNoPrefix to filter keys by

Implementation Reference

  • 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}` : ""}` }] }; } }
  • Zod schema defining the input parameter 'prefix' as an optional string.
    { prefix: z.string().default("").optional().describe("Prefix to filter keys by"), },
  • 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}` : ""}` }] }; } } );

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/kocierik/consul-mcp-server'

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