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;
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden but offers minimal behavioral insight. It implies a write operation ('添加' meaning 'add') but doesn't disclose permissions needed, whether it overwrites existing documents, error handling, or response format. This leaves significant gaps for a mutation tool.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence in Chinese that directly states the tool's function without unnecessary words. It's appropriately sized for a simple tool, though it could be more structured with context or examples.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a mutation tool with no annotations and no output schema, the description is incomplete. It lacks details on behavioral traits (e.g., idempotency, side effects), usage context, or what happens post-addition, making it inadequate for safe and effective use by an AI agent.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the input schema already documents the 'file_path' parameter adequately. The description adds no additional meaning beyond what the schema provides, such as file format constraints or path examples, but this is acceptable given the high schema coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('添加' meaning 'add') and resource ('文档到知识库' meaning 'document to knowledge base'), making the purpose understandable. However, it doesn't explicitly differentiate from sibling tools like 'add_directory' or 'remove_document', which would require more specificity about scope or constraints.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., file must exist), exclusions (e.g., not for directories), or comparisons to siblings like 'add_directory' for bulk operations or 'remove_document' for deletions.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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