Skip to main content
Glama

rag_add_document

Add documents to a RAG corpus for AI-powered search and retrieval within the AI Ops Hub, enabling secure access to local files, web pages, and notes for developer operational tasks.

Instructions

Добавить документ в RAG корпус

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
uriYesURI документа
contentYesСодержимое документа
titleYesЗаголовок документа

Implementation Reference

  • Core implementation of the rag_add_document tool handler. Manages adding or updating documents in the RAG corpus by interacting with SQLiteClient for storage and embedding.
    async addDocument(uri: string, content: string, title: string): Promise<void> {
      try {
        console.log(`📄 Добавление документа: ${title} (${uri})`);
        
        // Получаем SQLiteClient из пула соединений
        const sqliteClient = await this.connectionPool.getSQLiteClient();
        
        // Проверяем, существует ли уже документ
        const existingDocResult = await sqliteClient.getDocument(uri);
        if (existingDocResult.isErr()) {
          throw new Error(`Ошибка проверки документа: ${existingDocResult.error.message}`);
        }
        
        const existingDoc = existingDocResult.value;
        if (existingDoc) {
          // Обновляем существующий документ
          const updateResult = await sqliteClient.updateDocument(uri, title, content);
          if (updateResult.isErr()) {
            throw new Error(`Ошибка обновления документа: ${updateResult.error.message}`);
          }
          console.log(`✅ Документ "${title}" обновлен в корпусе`);
        } else {
          // Добавляем новый документ
          const addResult = await sqliteClient.addDocument(uri, title, content);
          if (addResult.isErr()) {
            throw new Error(`Ошибка добавления документа: ${addResult.error.message}`);
          }
          const docId = addResult.value;
          console.log(`✅ Документ "${title}" добавлен в корпус (ID: ${docId})`);
        }
      } catch (error) {
        console.error('Ошибка добавления документа:', error);
        throw new Error(`Ошибка добавления документа: ${error}`);
      }
    }
  • Input schema and metadata for the rag_add_document tool, defined in the MCP server's list of tools.
    {
      name: 'rag_add_document',
      description: 'Добавить документ в RAG корпус',
      inputSchema: {
        type: 'object',
        properties: {
          uri: {
            type: 'string',
            description: 'URI документа',
          },
          content: {
            type: 'string',
            description: 'Содержимое документа',
          },
          title: {
            type: 'string',
            description: 'Заголовок документа',
          },
        },
        required: ['uri', 'content', 'title'],
      },
    },
  • src/server.ts:192-194 (registration)
    Registration and dispatch logic in the MCP CallToolRequest handler that routes rag_add_document calls to RAGService.addDocument.
    case 'rag_add_document':
      await this.ragService.addDocument(args.uri as string, args.content as string, args.title as string);
      return { content: 'Документ добавлен' };
  • Duplicate input schema for rag_add_document in the HTTP transport's tool list.
      name: 'rag_add_document',
      description: 'Добавить документ в RAG корпус',
      inputSchema: {
        type: 'object',
        properties: {
          uri: { type: 'string', description: 'URI документа' },
          content: { type: 'string', description: 'Содержимое документа' },
          title: { type: 'string', description: 'Заголовок документа' }
        },
        required: ['uri', 'content', 'title']
      }
    },
  • Dispatch logic for rag_add_document in the HTTP transport's call tool handler.
    case 'rag_add_document':
      await this.ragService.addDocument(args.uri, args.content, args.title);
      result = { message: 'Документ добавлен' };

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/Galiusbro/MCP'

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