add_document
Add a document file to the knowledge base for indexing and content-based querying, supporting formats like PDF, DOCX, TXT, and HTML.
Instructions
添加单个文档到知识库
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| file_path | Yes | 文档文件路径 |
Implementation Reference
- src/mcp-server.ts:46-59 (registration)Registration of the 'add_document' tool, including name, description, and input schema definition.{ name: 'add_document', description: '添加单个文档到知识库', inputSchema: { type: 'object', properties: { file_path: { type: 'string', description: '文档文件路径' } }, required: ['file_path'] } },
- src/mcp-server.ts:160-173 (handler)MCP server handler for the 'add_document' tool call, which delegates to KnowledgeBase.addDocument and formats the response.case 'add_document': { const { file_path } = args as { file_path: string }; const success = await this.knowledgeBase.addDocument(file_path); return { content: [ { type: 'text', text: success ? `文档 "${file_path}" 已成功添加到知识库` : `添加文档 "${file_path}" 失败` } ] }; }
- src/knowledge-base.ts:25-35 (handler)Core implementation of adding a document: processes the file, stores the document in the map, and saves the index.async addDocument(filePath: string): Promise<boolean> { const result = await this.processor.processDocument(filePath); if (result.success && result.document) { this.documents.set(result.document.id, result.document); await this.saveIndex(); return true; } return false; }