Skip to main content
Glama

Delete Knowledge File

delete_knowledge_file

Performs permanent removal of outdated or incorrect knowledge documents, including deletion from the search index, for the Knowledge MCP Server. Verify document accuracy and consider alternatives before irreversible deletion.

Instructions

Permanently delete a knowledge document - this action cannot be undone.

When to use this tool:

  • Document is obsolete or incorrect

  • Consolidating duplicate documents

  • Removing outdated information

  • Explicit request to delete

Key features:

  • Complete removal of document

  • Removes from search index

  • Permanent deletion

You should:

  1. Verify document exists first

  2. Check if content should be preserved elsewhere

  3. Confirm filename is correct (with .md extension)

  4. Understand deletion is permanent

  5. Consider if update would be better

DO NOT use when:

  • Document might be useful later

  • Should be updated instead

  • Unsure about the impact

Returns: {success: bool, message?: str, error?: str}

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filenameYesFull filename including .md extension
project_idYesThe project identifier

Implementation Reference

  • Implements the core logic for deleting a knowledge file asynchronously: validates project and file existence, deletes the file using unlink, auto-commits the change, logs success/error, and returns formatted response.
    async deleteKnowledgeFileAsync(params: {
      project_id: z.infer<typeof secureProjectIdSchema>;
      filename: z.infer<typeof secureFilenameSchema>;
    }): Promise<string> {
      const context = this.createContext('delete_knowledge_file', params);
    
      try {
        const { project_id, filename } = params;
        const projectInfo = await getProjectDirectoryAsync(this.storagePath, project_id);
    
        // Project doesn't exist - return error without creating ghost entry
        if (!projectInfo) {
          throw new MCPError(MCPErrorCode.PROJECT_NOT_FOUND, `Project ${project_id} not found`, {
            project_id,
            filename,
            traceId: context.traceId,
          });
        }
    
        const [originalId, projectPath] = projectInfo;
        const knowledgePath = join(projectPath, 'knowledge');
        const filePath = join(knowledgePath, filename);
    
        // Check if file exists
        try {
          await access(filePath);
        } catch (error) {
          if ((error as NodeJS.ErrnoException).code === 'ENOENT') {
            throw new MCPError(
              MCPErrorCode.DOCUMENT_NOT_FOUND,
              `Knowledge file ${filename} not found in project ${originalId}`,
              { project_id, filename, traceId: context.traceId }
            );
          }
          throw error;
        }
    
        // Delete the file
        await unlink(filePath);
    
        // Auto-commit
        await autoCommitAsync(
          this.storagePath,
          `Delete knowledge file ${filename} from ${originalId}`
        );
    
        this.logSuccess('delete_knowledge_file', { project_id, filename }, context);
        return this.formatSuccessResponse({
          message: `Knowledge file ${filename} deleted from project ${originalId}`,
        });
      } catch (error) {
        const mcpError =
          error instanceof MCPError
            ? error
            : new MCPError(
                MCPErrorCode.FILE_SYSTEM_ERROR,
                `Failed to delete knowledge file: ${error instanceof Error ? error.message : String(error)}`,
                {
                  project_id: params.project_id,
                  filename: params.filename,
                  traceId: context.traceId,
                }
              );
        this.logError(
          'delete_knowledge_file',
          {
            project_id: params.project_id,
            filename: params.filename,
          },
          mcpError,
          context
        );
        return this.formatErrorResponse(mcpError, context);
      }
    }
  • Registers the 'delete_knowledge_file' tool with MCP server, defining title, description from TOOL_DESCRIPTIONS, input schema using secureProjectIdSchema and secureFilenameSchema, and handler that delegates to knowledgeHandler.deleteKnowledgeFileAsync.
      'delete_knowledge_file',
      {
        title: 'Delete Knowledge File',
        description: TOOL_DESCRIPTIONS.delete_knowledge_file,
        inputSchema: {
          project_id: secureProjectIdSchema.describe('The project identifier'),
          filename: secureFilenameSchema.describe('Full filename including .md extension'),
        },
      },
      async ({ project_id, filename }) => {
        const result = await knowledgeHandler.deleteKnowledgeFileAsync({ project_id, filename });
        return {
          content: [
            {
              type: 'text',
              text: result,
            },
          ],
        };
      }
    );
  • Provides the detailed description string for the 'delete_knowledge_file' tool, used in the server registration, explaining usage, features, best practices, and warnings.
      delete_knowledge_file: `Permanently delete a knowledge document - this action cannot be undone.
    
    When to use this tool:
    - Document is obsolete or incorrect
    - Consolidating duplicate documents
    - Removing outdated information
    - Explicit request to delete
    
    Key features:
    - Complete removal of document
    - Removes from search index
    - Permanent deletion
    
    You should:
    1. Verify document exists first
    2. Check if content should be preserved elsewhere
    3. Confirm filename is correct (with .md extension)
    4. Understand deletion is permanent
    5. Consider if update would be better
    
    DO NOT use when:
    - Document might be useful later
    - Should be updated instead
    - Unsure about the impact
    
    Returns: {success: bool, message?: str, error?: str}`,
  • Synchronous version of the delete knowledge file handler, similar logic using sync fs operations (existsSync, unlinkSync, etc.). Not directly called by server but available as fallback.
    deleteKnowledgeFile(params: {
      project_id: z.infer<typeof secureProjectIdSchema>;
      filename: z.infer<typeof secureFilenameSchema>;
    }): string {
      const context = this.createContext('delete_knowledge_file', params);
    
      try {
        const { project_id, filename } = params;
        const projectInfo = getProjectDirectory(this.storagePath, project_id);
    
        // Project doesn't exist - return error without creating ghost entry
        if (!projectInfo) {
          throw new MCPError(MCPErrorCode.PROJECT_NOT_FOUND, `Project ${project_id} not found`, {
            project_id,
            filename,
            traceId: context.traceId,
          });
        }
    
        const [originalId, projectPath] = projectInfo;
        const knowledgePath = join(projectPath, 'knowledge');
        const filePath = join(knowledgePath, filename);
    
        // Check if file exists
        if (!existsSync(filePath)) {
          throw new MCPError(
            MCPErrorCode.DOCUMENT_NOT_FOUND,
            `Knowledge file ${filename} not found in project ${originalId}`,
            { project_id, filename, traceId: context.traceId }
          );
        }
    
        // Delete the file
        unlinkSync(filePath);
    
        // Auto-commit
        autoCommit(this.storagePath, `Delete knowledge file ${filename} from ${originalId}`);
    
        this.logSuccess('delete_knowledge_file', { project_id, filename }, context);
        return this.formatSuccessResponse({
          message: `Knowledge file ${filename} deleted from project ${originalId}`,
        });
      } catch (error) {
        const mcpError =
          error instanceof MCPError
            ? error
            : new MCPError(
                MCPErrorCode.FILE_SYSTEM_ERROR,
                `Failed to delete knowledge file: ${error instanceof Error ? error.message : String(error)}`,
                {
                  project_id: params.project_id,
                  filename: params.filename,
                  traceId: context.traceId,
                }
              );
        this.logError(
          'delete_knowledge_file',
          {
            project_id: params.project_id,
            filename: params.filename,
          },
          mcpError,
          context
        );
        return this.formatErrorResponse(mcpError, context);
      }
    }
Behavior4/5

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

With no annotations provided, the description carries full burden and does well by disclosing key behavioral traits: the action is permanent/cannot be undone, removes from search index, and requires verification steps. It doesn't mention authentication needs, rate limits, or error handling specifics, but covers the critical destructive nature thoroughly.

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

Conciseness4/5

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

The description is well-structured with clear sections (purpose, usage guidelines, features, steps, exclusions, returns) and front-loaded with the most critical information. Some redundancy exists (e.g., '.md extension' appears twice), but overall it's appropriately sized with each section earning its place.

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 destructive tool with no annotations and no output schema, the description provides substantial context: clear purpose, usage guidelines, behavioral transparency about permanence, and return value documentation. It doesn't fully explain error scenarios or authentication requirements, but covers the essential aspects given the tool's complexity.

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?

Schema description coverage is 100%, so the schema already documents both parameters fully. The description adds minimal value beyond the schema - it mentions '.md extension' for filename (already in schema) and suggests verifying document existence, but doesn't provide additional semantic context about parameters like project_id significance.

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 the specific action ('permanently delete') and resource ('knowledge document'), distinguishing it from sibling tools like 'create_knowledge_file' or 'update_chapter'. It goes beyond just restating the name/title by emphasizing the irreversible nature of the action.

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

Usage Guidelines5/5

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

The description provides explicit guidance with 'When to use this tool' (four specific scenarios) and 'DO NOT use when' (three explicit exclusions). It also mentions alternatives like updating instead of deleting, helping the agent choose between this and tools like 'update_chapter' or 'update_project_main'.

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

Related 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/sven-borkert/knowledge-mcp'

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