Skip to main content
Glama
kocierik
by kocierik

get-kv

Retrieve specific values from the Consul MCP Server's key-value (KV) store by specifying the desired key, enabling quick access to stored data.

Instructions

Get a value from the KV store

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
keyNoKey to get from the KV store

Implementation Reference

  • The handler function that executes the get-kv tool logic: retrieves the KV value using consul.kv.get(key), handles errors, formats with formatKVPair, and returns formatted text.
    async ({ key }) => {
      try {
        const data = await consul.kv.get(key);
        if (!data) {
          return { content: [{ type: "text", text: `No value found for key: ${key}` }] };
        }
        
        const kvText = formatKVPair(data);
        return { content: [{ type: "text", text: kvText }] };
      } catch (error) {
        console.error("Error getting KV:", error);
        return { content: [{ type: "text", text: `Error getting value for key: ${key}` }] };
      }
    }
  • Registration of the get-kv tool via server.tool within registerKVStore function, including description, input schema, and handler.
    server.tool(
      "get-kv",
      "Get a value from the KV store",
      {
        key: z.string().default("").describe("Key to get from the KV store"),
      },
      async ({ key }) => {
        try {
          const data = await consul.kv.get(key);
          if (!data) {
            return { content: [{ type: "text", text: `No value found for key: ${key}` }] };
          }
          
          const kvText = formatKVPair(data);
          return { content: [{ type: "text", text: kvText }] };
        } catch (error) {
          console.error("Error getting KV:", error);
          return { content: [{ type: "text", text: `Error getting value for key: ${key}` }] };
        }
      }
    );
  • Zod input schema for the get-kv tool defining the 'key' parameter.
    {
      key: z.string().default("").describe("Key to get from the KV store"),
  • Helper function formatKVPair used in the get-kv handler to format the retrieved KV pair, decoding base64-encoded value.
    export function formatKVPair(pair: KVPair): string {
      // Decode base64 value if it exists
      let value = "No value";
      if (pair.Value !== null && pair.Value !== undefined) {
        try {
          // Consul stores values as base64 encoded strings
          value = atob(pair.Value);
        } catch (e) {
          value = pair.Value;
        }
      }
      
      return [
        `Key: ${pair.Key || "Unknown"}`,
        `Value: ${value}`,
        `Flags: ${pair.Flags || 0}`,
        `Last Modified Index: ${pair.ModifyIndex || "Unknown"}`,
        "---",
      ].join("\n");
    }
  • src/server.ts:41-41 (registration)
    Invocation of registerKVStore which registers the get-kv tool (among others) on the MCP server.
    registerKVStore(server, consul);

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv1.0.0

TDQS

B3.1/5.0
Behavior2/5

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

No annotations provided; description fails to mention behavior when key is missing, read-only nature, or return value format.

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?

Single sentence with no waste, but could include more detail without being overly verbose.

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

Completeness2/5

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

With no output schema and no return value description, the agent lacks context on what the tool outputs, especially for error cases.

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?

Schema coverage is 100%; the description adds no extra meaning beyond the schema's parameter description.

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

Purpose5/5

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

The description clearly states the action ('Get') and resource ('KV store'), distinguishing it from siblings like put-kv, delete-kv, and list-kv.

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?

No guidance on when to use this tool versus alternatives (e.g., list-kv for multiple keys) or what key format is expected.

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