Skip to main content
Glama
ikungsjl

MCP Knowledge Base Server

by ikungsjl

remove_document

Delete documents from the knowledge base by specifying their document ID to manage content and maintain accurate information.

Instructions

从知识库中移除文档

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
document_idYes文档ID

Implementation Reference

  • MCP tool handler for 'remove_document': extracts document_id from args, calls KnowledgeBase.removeDocument, and returns success or failure message.
    case 'remove_document': {
      const { document_id } = args as { document_id: string };
      const success = await this.knowledgeBase.removeDocument(document_id);
      
      return {
        content: [
          {
            type: 'text',
            text: success 
              ? `文档 "${document_id}" 已从知识库中移除`
              : `移除文档 "${document_id}" 失败,可能不存在`
          }
        ]
      };
    }
  • Core implementation: deletes the document by ID from the internal Map and saves the updated index to disk.
    async removeDocument(id: string): Promise<boolean> {
      const deleted = this.documents.delete(id);
      if (deleted) {
        await this.saveIndex();
      }
      return deleted;
    }
  • Input schema definition for the 'remove_document' tool, specifying required 'document_id' string parameter.
      name: 'remove_document',
      description: '从知识库中移除文档',
      inputSchema: {
        type: 'object',
        properties: {
          document_id: {
            type: 'string',
            description: '文档ID'
          }
        },
        required: ['document_id']
      }
    },
  • The 'remove_document' tool is registered in the list of tools returned by ListToolsRequestSchema handler.
      tools: [
        {
          name: 'add_document',
          description: '添加单个文档到知识库',
          inputSchema: {
            type: 'object',
            properties: {
              file_path: {
                type: 'string',
                description: '文档文件路径'
              }
            },
            required: ['file_path']
          }
        },
        {
          name: 'add_directory',
          description: '添加目录中的所有文档到知识库',
          inputSchema: {
            type: 'object',
            properties: {
              directory_path: {
                type: 'string',
                description: '目录路径'
              }
            },
            required: ['directory_path']
          }
        },
        {
          name: 'query_knowledge_base',
          description: '查询知识库',
          inputSchema: {
            type: 'object',
            properties: {
              question: {
                type: 'string',
                description: '查询问题'
              },
              max_results: {
                type: 'number',
                description: '最大返回结果数',
                default: 5
              },
              threshold: {
                type: 'number',
                description: '相似度阈值',
                default: 0.1
              }
            },
            required: ['question']
          }
        },
        {
          name: 'list_documents',
          description: '列出知识库中的所有文档',
          inputSchema: {
            type: 'object',
            properties: {}
          }
        },
        {
          name: 'get_document',
          description: '获取特定文档信息',
          inputSchema: {
            type: 'object',
            properties: {
              document_id: {
                type: 'string',
                description: '文档ID'
              }
            },
            required: ['document_id']
          }
        },
        {
          name: 'remove_document',
          description: '从知识库中移除文档',
          inputSchema: {
            type: 'object',
            properties: {
              document_id: {
                type: 'string',
                description: '文档ID'
              }
            },
            required: ['document_id']
          }
        },
        {
          name: 'clear_knowledge_base',
          description: '清空知识库',
          inputSchema: {
            type: 'object',
            properties: {}
          }
        },
        {
          name: 'get_stats',
          description: '获取知识库统计信息',
          inputSchema: {
            type: 'object',
            properties: {}
          }
        }
      ] as Tool[]
    };
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It states the action ('移除/remove') which implies a destructive mutation, but doesn't clarify if removal is permanent, reversible, requires specific permissions, or has side effects (e.g., affecting related data). The description lacks critical context for a mutation tool, leaving behavioral traits unclear.

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

Conciseness5/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 purpose without unnecessary words. It is front-loaded and wastes no space, making it highly concise and well-structured for its simplicity.

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?

Given this is a destructive mutation tool with no annotations and no output schema, the description is incomplete. It doesn't address key contextual aspects like error conditions, return values, or safety warnings (e.g., irreversible deletion). For a tool that removes documents, more information is needed to ensure proper usage.

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%, with the single parameter 'document_id' documented in the schema as '文档ID'. The description adds no additional meaning about the parameter beyond what the schema provides, such as format examples or sourcing instructions. Baseline 3 is appropriate since the schema handles parameter documentation adequately.

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 (移除/remove) and target resource (文档/document from knowledge base), which is specific and unambiguous. It doesn't explicitly differentiate from sibling tools like 'clear_knowledge_base' or 'add_document', but the verb+resource combination makes the purpose evident.

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., needing a valid document_id), exclusions (e.g., not for bulk removal), or comparisons to siblings like 'clear_knowledge_base' for mass deletion. Usage is implied by the action but not explicitly defined.

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