delete_corpus
Remove a saved corpus (manifest + packed body) using its slug. Returns JSON with deletion status.
Instructions
Remove a saved corpus (manifest + packed body). Returns JSON: { deleted: bool, name }.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | Corpus slug — alphanumeric + dash + underscore, ≤64 chars, must start with a letter or digit |
Implementation Reference
- src/tools/register/knowledge.ts:264-286 (handler)The tool handler for 'delete_corpus'. Registers an MCP tool that reads the corpus name via Zod schema, calls corpora.delete(name), and returns a JSON response { deleted: boolean, name }. Catches CorpusValidationError from the corpora store.
// ── delete_corpus ────────────────────────────────────────────────── server.tool( 'delete_corpus', 'Remove a saved corpus (manifest + packed body). Returns JSON: { deleted: bool, name }.', { name: NAME_SCHEMA, }, async ({ name }) => { try { const removed = corpora.delete(name); return { content: [{ type: 'text', text: j({ deleted: removed, name }) }] }; } catch (err) { if (err instanceof CorpusValidationError) { return { isError: true, content: [{ type: 'text', text: j({ error: err.message }) }], }; } throw err; } }, ); - src/tools/register/knowledge.ts:266-286 (registration)Registration of 'delete_corpus' via server.tool() with name, description, Zod schema (NAME_SCHEMA), and handler callback.
server.tool( 'delete_corpus', 'Remove a saved corpus (manifest + packed body). Returns JSON: { deleted: bool, name }.', { name: NAME_SCHEMA, }, async ({ name }) => { try { const removed = corpora.delete(name); return { content: [{ type: 'text', text: j({ deleted: removed, name }) }] }; } catch (err) { if (err instanceof CorpusValidationError) { return { isError: true, content: [{ type: 'text', text: j({ error: err.message }) }], }; } throw err; } }, ); - NAME_SCHEMA - Zod validation for the corpus name slug (alphanumeric + dash/underscore, 1-64 chars, must start with letter/digit). Used by delete_corpus as its only input parameter.
const NAME_SCHEMA = z .string() .min(1) .max(64) .describe( 'Corpus slug — alphanumeric + dash + underscore, ≤64 chars, must start with a letter or digit', ); - src/memory/corpus-store.ts:209-222 (helper)CorpusStore.delete() - The underlying implementation that deletes both the manifest (.json) and packed body (.pack.md) files from disk. Returns true if any file was removed, false otherwise.
delete(name: string): boolean { const manifestPath = corpusManifestPath(this.rootDir, name); const packPath = corpusPackPath(this.rootDir, name); let removed = false; for (const target of [manifestPath, packPath]) { try { fs.unlinkSync(target); removed = true; } catch { /* missing is fine */ } } return removed; } - src/memory/corpus-store.ts:72-101 (helper)Validation helpers corpusManifestPath/corpusPackPath and validateCorpusName. Validates the name against a strict pattern and performs path-traversal hardening to ensure files stay within the corpora directory.
export function validateCorpusName(name: string): void { if (typeof name !== 'string' || name.length === 0) { throw new CorpusValidationError('Corpus name must be a non-empty string'); } if (!NAME_PATTERN.test(name)) { throw new CorpusValidationError( `Invalid corpus name "${name}": must match /^[a-zA-Z0-9][a-zA-Z0-9_-]{0,63}$/`, ); } } function corpusManifestPath(corporaDir: string, name: string): string { validateCorpusName(name); const target = path.resolve(path.join(corporaDir, `${name}.json`)); // Defence in depth — even if validateCorpusName lets something pass we // refuse to leave the corpora directory. if (path.relative(corporaDir, target).startsWith('..')) { throw new CorpusValidationError(`Corpus path escapes corpora dir: ${target}`); } return target; } function corpusPackPath(corporaDir: string, name: string): string { validateCorpusName(name); const target = path.resolve(path.join(corporaDir, `${name}.pack.md`)); if (path.relative(corporaDir, target).startsWith('..')) { throw new CorpusValidationError(`Corpus path escapes corpora dir: ${target}`); } return target; }