remove_document
Delete documents from the knowledge base by specifying their document ID to manage content and maintain accurate information.
Instructions
从知识库中移除文档
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| document_id | Yes | 文档ID |
Implementation Reference
- src/mcp-server.ts:266-280 (handler)MCP tool handler for 'remove_document': extracts document_id from args, calls KnowledgeBase.removeDocument, and returns success or failure message.case 'remove_document': { const { document_id } = args as { document_id: string }; const success = await this.knowledgeBase.removeDocument(document_id); return { content: [ { type: 'text', text: success ? `文档 "${document_id}" 已从知识库中移除` : `移除文档 "${document_id}" 失败,可能不存在` } ] }; }
- src/knowledge-base.ts:170-176 (helper)Core implementation: deletes the document by ID from the internal Map and saves the updated index to disk.async removeDocument(id: string): Promise<boolean> { const deleted = this.documents.delete(id); if (deleted) { await this.saveIndex(); } return deleted; }
- src/mcp-server.ts:121-133 (schema)Input schema definition for the 'remove_document' tool, specifying required 'document_id' string parameter.name: 'remove_document', description: '从知识库中移除文档', inputSchema: { type: 'object', properties: { document_id: { type: 'string', description: '文档ID' } }, required: ['document_id'] } },
- src/mcp-server.ts:45-151 (registration)The 'remove_document' tool is registered in the list of tools returned by ListToolsRequestSchema handler.tools: [ { name: 'add_document', description: '添加单个文档到知识库', inputSchema: { type: 'object', properties: { file_path: { type: 'string', description: '文档文件路径' } }, required: ['file_path'] } }, { name: 'add_directory', description: '添加目录中的所有文档到知识库', inputSchema: { type: 'object', properties: { directory_path: { type: 'string', description: '目录路径' } }, required: ['directory_path'] } }, { name: 'query_knowledge_base', description: '查询知识库', inputSchema: { type: 'object', properties: { question: { type: 'string', description: '查询问题' }, max_results: { type: 'number', description: '最大返回结果数', default: 5 }, threshold: { type: 'number', description: '相似度阈值', default: 0.1 } }, required: ['question'] } }, { name: 'list_documents', description: '列出知识库中的所有文档', inputSchema: { type: 'object', properties: {} } }, { name: 'get_document', description: '获取特定文档信息', inputSchema: { type: 'object', properties: { document_id: { type: 'string', description: '文档ID' } }, required: ['document_id'] } }, { name: 'remove_document', description: '从知识库中移除文档', inputSchema: { type: 'object', properties: { document_id: { type: 'string', description: '文档ID' } }, required: ['document_id'] } }, { name: 'clear_knowledge_base', description: '清空知识库', inputSchema: { type: 'object', properties: {} } }, { name: 'get_stats', description: '获取知识库统计信息', inputSchema: { type: 'object', properties: {} } } ] as Tool[] };