Skip to main content
Glama
ikungsjl

MCP Knowledge Base Server

by ikungsjl

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
NameRequiredDescriptionDefault
directory_pathYes目录路径

Implementation Reference

  • 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']
      }
  • 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']
  • 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} 个文档到知识库`
          }
        ]
      };
    }
  • 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;
    }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/ikungsjl/mcp-knowledge-base'

If you have feedback or need assistance with the MCP directory API, please join our Discord server