Skip to main content
Glama

delete_corpus

Read-onlyIdempotent

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

TableJSON Schema
NameRequiredDescriptionDefault
nameYesCorpus slug — alphanumeric + dash + underscore, ≤64 chars, must start with a letter or digit

Implementation Reference

  • 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;
        }
      },
    );
  • 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',
      );
  • 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;
    }
  • 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;
    }
Behavior1/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

The description claims a destructive action ('Remove'), but annotation 'destructiveHint' is false, creating a contradiction. No additional behavioral context is provided beyond the contradictory annotation.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is concise, front-loaded, and includes essential return information without superfluous words.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a simple delete operation, the description covers the action and return value adequately, but the contradiction with annotations reduces completeness.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The single parameter 'name' is fully described in the schema (coverage 100%). The description does not add any extra meaning beyond the schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states that it removes a corpus, specifying what is removed (manifest + packed body) and the return format. This distinguishes it from sibling tools like 'build_corpus' or 'list_corpora'.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided on when to use this tool versus alternatives, or any prerequisites/conditions for deletion.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/nikolai-vysotskyi/trace-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server