kv_get
Retrieve key-value pairs from a keyspace, with pattern matching using wildcards.
Instructions
Retrieve key-value pair(s) from a space. Supports pattern matching with wildcards.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| key | No | Key to match, or key* to fetch list | * |
| keyspace | No | Keyspace to scan | |
| text | No | Output info as text line |
Implementation Reference
- src/index.ts:149-153 (schema)Zod schema definition for kv_get tool, defining input parameters: key (optional, default '*'), keyspace (optional), and text (optional boolean).
const kvGetSchema = z.object({ key: z.string().optional().default("*").describe("Key to match, or key* to fetch list"), keyspace: z.string().optional().describe("Keyspace to scan"), text: z.boolean().optional().describe("Output info as text line"), }); - src/index.ts:433-445 (registration)Tool registration entry for 'kv_get' in the tools array, with name, description (pattern matching with wildcards), and inputSchema mapping to the kvGetSchema.
{ name: "kv_get", description: "Retrieve key-value pair(s) from a space. Supports pattern matching with wildcards.", schema: kvGetSchema, inputSchema: { type: "object", properties: { key: { type: "string", description: "Key to match, or key* to fetch list", default: "*" }, keyspace: { type: "string", description: "Keyspace to scan" }, text: { type: "boolean", description: "Output info as text line" } } } }, - src/index.ts:1209-1231 (handler)Handler implementation for kv_get: extracts args (key, keyspace, text), builds coho CLI 'get' command with project/space flags, executes via executeCohoCommand, and returns the result as text content.
case "kv_get": { const { key = "*", keyspace, text } = args as KvGetArgs; const getArgs = [ 'get', '--project', config.projectId, '--space', config.space, key ]; if (keyspace) getArgs.push('--keyspace', keyspace); if (text) getArgs.push('--text'); const result = await executeCohoCommand(getArgs); return { content: [ { type: "text", text: result } ], isError: false }; } - src/index.ts:529-564 (helper)Helper function executeCohoCommand that runs the coho CLI tool with given arguments and admin token, sanitizing output to avoid token exposure.
async function executeCohoCommand(args: string[]): Promise<string> { const safeArgs = ['coho', ...args, '--admintoken', '***']; console.error(`Executing command: ${safeArgs.join(' ')}`); try { const { stdout, stderr } = await execFile('coho', [...args, '--admintoken', config.adminToken], { timeout: 120000 // 2 minutes timeout for CLI operations }); if (stderr) { // Sanitize stderr before logging to avoid token exposure const safeSterr = stderr.replace(new RegExp(config.adminToken, 'g'), '***'); console.error(`Command output to stderr:`, safeSterr); } console.error(`Command successful`); const result = stdout || stderr; // Sanitize result to ensure admin token is not exposed return result ? result.replace(new RegExp(config.adminToken, 'g'), '***') : result; } catch (error: any) { // Comprehensive sanitization of all error properties to avoid admin token exposure const sanitizeText = (text: string): string => text ? text.replace(new RegExp(config.adminToken, 'g'), '***') : text; const sanitizedMessage = sanitizeText(error?.message || 'Unknown error'); const sanitizedCmd = sanitizeText(error?.cmd || ''); const sanitizedStdout = sanitizeText(error?.stdout || ''); const sanitizedStderr = sanitizeText(error?.stderr || ''); // Log sanitized error details console.error(`Command failed: ${sanitizedMessage}`); if (sanitizedCmd) console.error(`Command: ${sanitizedCmd}`); if (sanitizedStdout) console.error(`Stdout: ${sanitizedStdout}`); if (sanitizedStderr) console.error(`Stderr: ${sanitizedStderr}`); // Return sanitized error message const errorDetails = [sanitizedMessage, sanitizedStderr].filter(Boolean).join(' - '); throw new McpError(ErrorCode.InvalidRequest, `Command failed: ${errorDetails}`); } } - src/index.ts:199-204 (registration)Type inference for KvGetArgs derived from the Zod schema, used in the handler to type the parsed arguments.
type KvGetArgs = z.infer<typeof kvGetSchema>; type KvSetArgs = z.infer<typeof kvSetSchema>; type KvDelArgs = z.infer<typeof kvDelSchema>; type LogArgs = z.infer<typeof logSchema>; type DocsArgs = z.infer<typeof docsSchema>; type CollectionArgs = z.infer<typeof collectionSchema>;