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"',
          },
        },
      },
    },

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