rag_add_document
Add documents to a RAG corpus for AI-powered search and retrieval, enabling intelligent querying of local files, notes, and web content.
Instructions
Добавить документ в RAG корпус
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| content | Yes | Содержимое документа | |
| title | Yes | Заголовок документа | |
| uri | Yes | URI документа |
Implementation Reference
- src/rag/rag-service.ts:39-73 (handler)Core handler function that implements the rag_add_document tool logic: checks if document exists, adds new or updates existing in the RAG SQLite database.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}`); } }
- src/server.ts:62-83 (registration)Registers the rag_add_document tool in the MCP ListTools handler with name, description, and input schema.{ 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 (handler)MCP CallTool handler dispatch: calls RAGService.addDocument with parsed arguments and returns success message.case 'rag_add_document': await this.ragService.addDocument(args.uri as string, args.content as string, args.title as string); return { content: 'Документ добавлен' };
- src/server.ts:65-82 (schema)Input schema definition for rag_add_document tool parameters (uri, content, title).inputSchema: { type: 'object', properties: { uri: { type: 'string', description: 'URI документа', }, content: { type: 'string', description: 'Содержимое документа', }, title: { type: 'string', description: 'Заголовок документа', }, }, required: ['uri', 'content', 'title'], },
- src/transports/http-transport.ts:228-231 (handler)HTTP transport handler dispatch for rag_add_document: calls RAGService.addDocument.case 'rag_add_document': await this.ragService.addDocument(args.uri, args.content, args.title); result = { message: 'Документ добавлен' }; break;