add_file
Add files to a RAG system for document retrieval, supporting PDF, DOCX, TXT, MD, CSV, and JSON formats to enable semantic search and information access.
Instructions
Add a file to the RAG system for document retrieval
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| filePath | Yes | Path to the file to add to the RAG system |
Input Schema (JSON Schema)
{
"properties": {
"filePath": {
"description": "Path to the file to add to the RAG system",
"type": "string"
}
},
"required": [
"filePath"
],
"type": "object"
}
Implementation Reference
- src/index.ts:330-340 (handler)MCP tool handler for 'add_file' that calls ragService.addFile and formats the MCP response.private async handleAddFile(args: { filePath: string }) { const result = await this.ragService.addFile(args.filePath); return { content: [ { type: 'text', text: JSON.stringify(result, null, 2), }, ], }; }
- src/index.ts:37-46 (schema)Input schema definition for the 'add_file' tool.inputSchema: { type: 'object', properties: { filePath: { type: 'string', description: 'Path to the file to add to the RAG system', }, }, required: ['filePath'], },
- src/index.ts:34-47 (registration)Registration of the 'add_file' tool in the ListToolsRequestSchema handler.{ name: 'add_file', description: 'Add a file to the RAG system for document retrieval', inputSchema: { type: 'object', properties: { filePath: { type: 'string', description: 'Path to the file to add to the RAG system', }, }, required: ['filePath'], }, },
- src/services/ragService.ts:30-68 (helper)Core implementation of file addition: processes file into chunks and stores in vector database.async addFile(filePath: string): Promise<{ success: boolean; chunks: number; message: string; }> { try { logger.info(`Adding file to RAG: ${filePath}`); // Check if file exists and is supported if (!await this.fileProcessor.isSupportedFile(filePath.split('/').pop() || '')) { throw new Error('Unsupported file type'); } // Process file into chunks const chunks = await this.fileProcessor.processFile(filePath); if (chunks.length === 0) { throw new Error('No content could be extracted from the file'); } // Add chunks to vector database await this.vectorDatabase.addDocuments(chunks); logger.info(`Successfully added file: ${filePath} (${chunks.length} chunks)`); return { success: true, chunks: chunks.length, message: `File added successfully with ${chunks.length} chunks` }; } catch (error) { logger.error(`Error adding file: ${error}`); return { success: false, chunks: 0, message: `Failed to add file: ${error}` }; } }