Skip to main content
Glama
kocierik
by kocierik

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}` : ""}` }] };
        }
      }
    );

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv1.0.0

TDQS

C2.9/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description must cover behavioral traits. It only states 'List keys', implying a read operation, but lacks details on pagination, rate limits, or any side effects. Given the lack of annotations, more context about what 'list' entails (e.g., returns all keys or a subset) is needed.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is concise and front-loaded with the key action. It is one sentence with no wasted words. However, it could be slightly expanded to include the optional filtering aspect without losing conciseness.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a simple listing tool, the description is adequate but minimal. It does not mention the output format (e.g., returns an array of key names) or any limitations. Given the simplicity and the presence of a well-described schema parameter, it is minimally complete but could benefit from a bit more context.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema description coverage is 100% for the single parameter 'prefix', with a clear description in the schema. The tool description adds no additional meaning beyond what the schema already provides, so the score is at baseline 3.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description uses a specific verb 'list' and identifies the resource as 'keys in the KV store'. It clearly distinguishes from sibling tools like get-kv (retrieve a specific key) and delete-kv (remove keys). However, it does not specify that listing includes all keys or the optional filtering capability, leaving some ambiguity.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. For example, it does not mention that list-kv is for enumerating keys while get-kv is for retrieving a single key's value. An AI agent would have to infer usage from the tool name alone.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.