Skip to main content
Glama
ikungsjl

MCP Knowledge Base Server

by ikungsjl

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
NameRequiredDescriptionDefault
file_pathYes文档文件路径

Implementation Reference

  • 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']
      }
    },
  • 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}" 失败`
          }
        ]
      };
    }
  • 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;
    }

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