Skip to main content
Glama

put-kv

Store key-value pairs in the Consul KV store using the MCP server interface for efficient data management and retrieval.

Instructions

Put a value in the KV store

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
keyNoKey to put in the KV store
valueNoValue to put in the KV store

Implementation Reference

  • The handler function for the 'put-kv' tool. It takes key and value parameters, calls consul.kv.set(key, value), and returns a success or error message in the standard MCP format.
    async ({ key, value }) => {
      try {
        const success = await consul.kv.set(key, value);
        if (!success) {
          return { content: [{ type: "text", text: `Failed to put value for key: ${key}` }] };
        }
        
        return { content: [{ type: "text", text: `Successfully put value for key: ${key}` }] };
      } catch (error) {
        console.error("Error putting KV:", error);
        return { content: [{ type: "text", text: `Error putting value for key: ${key}` }] };
      }
    }
  • Zod schema defining the input parameters for the 'put-kv' tool: key (string) and value (string).
    {
      key: z.string().default("").describe("Key to put in the KV store"),
      value: z.string().default("").describe("Value to put in the KV store"),
    },
  • Registration of the 'put-kv' tool using server.tool(), including name, description, schema, and handler.
    server.tool(
      "put-kv",
      "Put a value in the KV store",
      {
        key: z.string().default("").describe("Key to put in the KV store"),
        value: z.string().default("").describe("Value to put in the KV store"),
      },
      async ({ key, value }) => {
        try {
          const success = await consul.kv.set(key, value);
          if (!success) {
            return { content: [{ type: "text", text: `Failed to put value for key: ${key}` }] };
          }
          
          return { content: [{ type: "text", text: `Successfully put value for key: ${key}` }] };
        } catch (error) {
          console.error("Error putting KV:", error);
          return { content: [{ type: "text", text: `Error putting value for key: ${key}` }] };
        }
      }
    );

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