create_collection
Creates a new database collection to organize and store data in your Codehooks.io project.
Instructions
Create a new collection
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| collection | Yes | Name of collection to create |
Implementation Reference
- src/index.ts:108-110 (schema)Zod schema definition for create_collection tool. Defines a 'collection' string parameter describing the name of the collection to create.
const createCollectionSchema = z.object({ collection: z.string().describe("Name of collection to create"), }); - src/index.ts:328-339 (registration)Tool registration in the tools array. Registers 'create_collection' with description 'Create a new collection' and its inputSchema referencing createCollectionSchema.
{ name: "create_collection", description: "Create a new collection", schema: createCollectionSchema, inputSchema: { type: "object", properties: { collection: { type: "string", description: "Name of collection to create" } }, required: ["collection"] } }, - src/index.ts:979-997 (handler)Handler implementation for create_collection. Extracts the 'collection' argument, builds CLI args calling 'coho createcollection' with project, space, and collection name, then executes the command and returns the result.
case "create_collection": { const { collection } = args as CreateCollectionArgs; const createCollArgs = [ 'createcollection', '--project', config.projectId, '--space', config.space, collection ]; const result = await executeCohoCommand(createCollArgs); return { content: [ { type: "text", text: result } ], isError: false }; } - src/index.ts:529-564 (helper)Helper function executeCohoCommand that all tool handlers use to run the coho CLI. Handles execution, error sanitization (admin token redaction), and timeout.
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}`); } }