Skip to main content
Glama

delete_file

Remove ingested files or data from the Local RAG vector database to manage stored content and maintain privacy-focused document search.

Instructions

Delete a previously ingested file or data from the vector database. Use filePath for files ingested via ingest_file, or source for data ingested via ingest_data. Either filePath or source must be provided.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filePathNoAbsolute path to the file (for ingest_file). Example: "/Users/user/documents/manual.pdf"
sourceNoSource identifier used in ingest_data. Examples: "https://example.com/page", "clipboard://2024-12-30"

Implementation Reference

  • The handler function for the 'delete_file' tool. Determines the target file path from either 'filePath' or 'source' parameter, validates if necessary, deletes the corresponding chunks from the vector database, and removes the physical raw-data file if applicable. Returns a success message with the deleted file path.
    async handleDeleteFile(
      args: DeleteFileInput
    ): Promise<{ content: [{ type: 'text'; text: string }] }> {
      try {
        let targetPath: string
        let skipValidation = false
    
        if (args.source) {
          // Generate raw-data path from source (extension is always .md)
          // Internal path generation is secure, skip baseDir validation
          targetPath = generateRawDataPath(this.dbPath, args.source, 'markdown')
          skipValidation = true
        } else if (args.filePath) {
          targetPath = args.filePath
        } else {
          throw new Error('Either filePath or source must be provided')
        }
    
        // Only validate user-provided filePath (not internally generated paths)
        if (!skipValidation) {
          this.parser.validateFilePath(targetPath)
        }
    
        // Delete chunks from vector database
        await this.vectorStore.deleteChunks(targetPath)
    
        // Also delete physical raw-data file if applicable
        if (isRawDataPath(targetPath)) {
          try {
            await unlink(targetPath)
            console.error(`Deleted raw-data file: ${targetPath}`)
          } catch {
            // File may already be deleted, log warning only
            console.warn(`Could not delete raw-data file (may not exist): ${targetPath}`)
          }
        }
    
        // Return success message
        const result = {
          filePath: targetPath,
          deleted: true,
          timestamp: new Date().toISOString(),
        }
    
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(result, null, 2),
            },
          ],
        }
      } catch (error) {
        // Error handling: suppress stack trace in production
        const errorMessage =
          process.env['NODE_ENV'] === 'production'
            ? (error as Error).message
            : (error as Error).stack || (error as Error).message
    
        console.error('Failed to delete file:', errorMessage)
    
        throw new Error(`Failed to delete file: ${errorMessage}`)
      }
    }
  • TypeScript interface defining the input parameters for the 'delete_file' tool: optional 'filePath' or 'source'.
    /**
     * delete_file tool input
     * Either filePath or source must be provided
     */
    export interface DeleteFileInput {
      /** File path (for files ingested via ingest_file) */
      filePath?: string
      /** Source identifier (for data ingested via ingest_data) */
      source?: string
    }
  • Registration of the 'delete_file' tool in the MCP server's tool list, including name, description, and input schema.
    {
      name: 'delete_file',
      description:
        'Delete a previously ingested file or data from the vector database. Use filePath for files ingested via ingest_file, or source for data ingested via ingest_data. Either filePath or source must be provided.',
      inputSchema: {
        type: 'object',
        properties: {
          filePath: {
            type: 'string',
            description:
              'Absolute path to the file (for ingest_file). Example: "/Users/user/documents/manual.pdf"',
          },
          source: {
            type: 'string',
            description:
              'Source identifier used in ingest_data. Examples: "https://example.com/page", "clipboard://2024-12-30"',
          },
        },
      },
    },
Behavior3/5

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

No annotations are provided, so the description carries the full burden. It discloses that the tool performs a deletion operation, which implies destructive behavior, but does not mention potential side effects (e.g., irreversible removal, impact on related data), authentication needs, error handling, or rate limits. The description adds basic context about the deletion target but lacks comprehensive behavioral details.

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 front-loaded with the core purpose in the first sentence, followed by usage guidance in the second. Every sentence earns its place by clarifying parameter usage without redundancy. It is appropriately sized and efficiently structured.

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

Completeness3/5

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

Given the tool's complexity (destructive operation with no annotations and no output schema), the description is partially complete. It adequately covers purpose and parameter usage but lacks details on behavioral aspects like irreversibility, error cases, or response format. For a deletion tool without annotations, more context on safety and outcomes would improve 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?

Schema description coverage is 100%, so the schema already documents both parameters (filePath and source) with examples. The description adds value by explaining when to use each parameter based on the ingestion method, but does not provide additional syntax, format, or constraints beyond what the schema specifies. This meets the baseline for high schema coverage.

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 action ('Delete') and the resource ('a previously ingested file or data from the vector database'), making the purpose specific and unambiguous. It distinguishes this tool from siblings like ingest_data, ingest_file, list_files, query_documents, and status by focusing on removal rather than ingestion, listing, querying, or status checking.

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 explicitly states when to use this tool: 'Use filePath for files ingested via ingest_file, or source for data ingested via ingest_data.' This provides clear guidance on which parameter to use based on the ingestion method, effectively distinguishing it from alternatives and specifying prerequisites.

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/shinpr/mcp-local-rag'

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