add_directory
Add documents from a specified directory to the knowledge base for indexing and querying. Supports multiple file formats including PDF, DOCX, TXT, and HTML.
Instructions
添加目录中的所有文档到知识库
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| directory_path | Yes | 目录路径 |
Implementation Reference
- src/mcp-server.ts:60-72 (registration)Registration of the 'add_directory' MCP tool, including name, description, and input schema.{ name: 'add_directory', description: '添加目录中的所有文档到知识库', inputSchema: { type: 'object', properties: { directory_path: { type: 'string', description: '目录路径' } }, required: ['directory_path'] }
- src/mcp-server.ts:63-71 (schema)JSON schema defining the input parameters for the add_directory tool (directory_path: string).inputSchema: { type: 'object', properties: { directory_path: { type: 'string', description: '目录路径' } }, required: ['directory_path']
- src/mcp-server.ts:175-186 (handler)MCP server handler for 'add_directory' tool: parses arguments, delegates to KnowledgeBase.addDirectory, returns formatted success message with document count.case 'add_directory': { const { directory_path } = args as { directory_path: string }; const count = await this.knowledgeBase.addDirectory(directory_path); return { content: [ { type: 'text', text: `已从目录 "${directory_path}" 添加了 ${count} 个文档到知识库` } ] }; }
- src/knowledge-base.ts:37-46 (handler)Core handler logic in KnowledgeBase class: processes all documents in directory using DocumentProcessor, stores them in memory map, persists index to disk, returns number of added documents.async addDirectory(dirPath: string): Promise<number> { const documents = await this.processor.processDirectory(dirPath); for (const doc of documents) { this.documents.set(doc.id, doc); } await this.saveIndex(); return documents.length; }