Skip to main content
Glama

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

TableJSON Schema
NameRequiredDescriptionDefault
filePathYesPath to the file to add to the RAG system

Implementation Reference

  • 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),
          },
        ],
      };
    }
  • 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'],
      },
    },
  • 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}`
        };
      }
    }

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

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