add_directory
Add all documents from a specified directory to the MCP Knowledge Base Server for indexing and question-based content retrieval.
Instructions
添加目录中的所有文档到知识库
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| directory_path | Yes | 目录路径 |
Input Schema (JSON Schema)
{
"properties": {
"directory_path": {
"description": "目录路径",
"type": "string"
}
},
"required": [
"directory_path"
],
"type": "object"
}
Implementation Reference
- src/knowledge-base.ts:37-46 (handler)Core implementation of the add_directory tool: processes all documents in the given directory using DocumentProcessor, adds them to the internal documents Map, saves the index, and returns the count 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; }
- src/mcp-server.ts:175-186 (handler)MCP server dispatch handler for 'add_directory' tool call: extracts directory_path from arguments, delegates to KnowledgeBase.addDirectory, and returns formatted success message with 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/mcp-server.ts:60-72 (registration)Registration of the 'add_directory' tool in ListTools response, including name, description, and input schema definition.{ name: 'add_directory', description: '添加目录中的所有文档到知识库', inputSchema: { type: 'object', properties: { directory_path: { type: 'string', description: '目录路径' } }, required: ['directory_path'] }
- src/mcp-server.ts:60-72 (schema)Input schema for add_directory tool: requires 'directory_path' string.{ name: 'add_directory', description: '添加目录中的所有文档到知识库', inputSchema: { type: 'object', properties: { directory_path: { type: 'string', description: '目录路径' } }, required: ['directory_path'] }