contentrain_model_delete
Delete a model and its content/meta from Contentrain MCP, with changes auto-committed to git. Use to remove models and associated data.
Instructions
Delete a model and its content/meta. Changes are auto-committed to git — do NOT manually edit .contentrain/ files.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| model | Yes | Model ID to delete | |
| confirm | Yes | Must be true to confirm deletion |
Implementation Reference
- packages/mcp/src/tools/model.ts:148-234 (handler)The tool `contentrain_model_delete` is defined and implemented as an anonymous async function within the `registerModelTools` function, handling the deletion of a model and its associated data.
server.tool( 'contentrain_model_delete', 'Delete a model and its content/meta. Changes are auto-committed to git — do NOT manually edit .contentrain/ files.', { model: z.string().describe('Model ID to delete'), confirm: z.literal(true).describe('Must be true to confirm deletion'), }, async ({ model: modelId }) => { const config = await readConfig(projectRoot) if (!config) { return { content: [{ type: 'text' as const, text: JSON.stringify({ error: 'Project not initialized.' }) }], isError: true, } } // Check model exists const existing = await readModel(projectRoot, modelId) if (!existing) { return { content: [{ type: 'text' as const, text: JSON.stringify({ error: `Model "${modelId}" not found` }) }], isError: true, } } // Branch health gate const deleteHealth = await checkBranchHealth(projectRoot) if (deleteHealth.blocked) { return { content: [{ type: 'text' as const, text: JSON.stringify({ error: deleteHealth.message, action: 'blocked', hint: 'Merge or delete old contentrain/* branches before creating new ones.', }, null, 2) }], isError: true, } } // Check references const refs = await checkReferences(projectRoot, modelId) if (refs.length > 0) { return { content: [{ type: 'text' as const, text: JSON.stringify({ deleted: false, error: 'REFERENCED_MODEL', referenced_by: refs, next_steps: ['Remove relation fields from referencing models first'], }, null, 2) }], } } const branch = buildBranchName('model', modelId) const tx = await createTransaction(projectRoot, branch) try { let filesRemoved: string[] = [] await tx.write(async (wt) => { filesRemoved = await deleteModel(wt, modelId) }) await tx.commit(`[contentrain] delete: ${modelId}`) const gitResult = await tx.complete({ tool: 'contentrain_model_delete', model: modelId }) return { content: [{ type: 'text' as const, text: JSON.stringify({ status: 'committed', message: 'Model deleted and committed to git. Do NOT manually edit .contentrain/ files.', deleted: true, git: { branch, action: gitResult.action, commit: gitResult.commit }, files_removed: filesRemoved, context_updated: true, }, null, 2) }], } } catch (error) { await tx.cleanup() return { content: [{ type: 'text' as const, text: JSON.stringify({ error: `Delete failed: ${error instanceof Error ? error.message : String(error)}`, }) }], isError: true, } } finally { await tx.cleanup() } }, )