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
| Name | Required | Description | Default |
|---|---|---|---|
| key | No | Key to put in the KV store | |
| value | No | Value to put in the KV store |
Implementation Reference
- src/tools/consulTools.ts:405-417 (handler)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}` }] }; } }
- src/tools/consulTools.ts:401-404 (schema)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"), },
- src/tools/consulTools.ts:398-418 (registration)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}` }] }; } } );