add_schema
Adds a JSON schema to a database collection. Specify the schema as a JSON string to enforce structure.
Instructions
Add a JSON schema to a collection. Provide the schema content as a JSON string.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| collection | Yes | Collection name | |
| schema | Yes | JSON schema content as a string (will be written to temporary file for CLI) |
Implementation Reference
- src/index.ts:352-364 (registration)Registration of the 'add_schema' tool in the tools array, including its name, description, and input schema.
{ name: "add_schema", description: "Add a JSON schema to a collection. Provide the schema content as a JSON string.", schema: schemaSchema, inputSchema: { type: "object", properties: { collection: { type: "string", description: "Collection name" }, schema: { type: "string", description: "JSON schema content as a string (will be written to temporary file for CLI)" } }, required: ["collection", "schema"] } }, - src/index.ts:116-119 (schema)Zod validation schema for add_schema: requires a 'collection' (string) and 'schema' (string - JSON schema content).
const schemaSchema = z.object({ collection: z.string().describe("Collection name"), schema: z.string().describe("JSON schema to add"), }); - src/index.ts:1019-1058 (handler)Handler implementation for add_schema: writes schema content to a temp file, calls coho CLI 'add-schema' command, then cleans up the temp file.
case "add_schema": { const { collection, schema } = args as SchemaArgs; // Write schema to temp file const tempSchemaPath = `/tmp/schema-${Date.now()}.json`; try { await fs.writeFile(tempSchemaPath, schema); const schemaArgs = [ 'add-schema', '--project', config.projectId, '--space', config.space, '--collection', collection, '--schema', tempSchemaPath ]; const result = await executeCohoCommand(schemaArgs); // Clean up temp file await fs.unlink(tempSchemaPath); return { content: [ { type: "text", text: result } ], isError: false }; } catch (error) { // Clean up temp file on error try { await fs.unlink(tempSchemaPath); } catch (unlinkError) { // Ignore cleanup errors } throw error; } }