Skip to main content
Glama
ikungsjl

MCP Knowledge Base Server

by ikungsjl

query_knowledge_base

Search indexed documents to find answers to questions using semantic similarity matching with configurable result limits and relevance thresholds.

Instructions

查询知识库

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
questionYes查询问题
max_resultsNo最大返回结果数
thresholdNo相似度阈值

Implementation Reference

  • MCP tool handler for 'query_knowledge_base' that extracts query parameters, invokes KnowledgeBase.query method, formats the response including question, answer, confidence score, and source snippets.
    case 'query_knowledge_base': {
      const { question, max_results, threshold } = args as {
        question: string;
        max_results?: number;
        threshold?: number;
      };
      
      const response = await this.knowledgeBase.query({
        question,
        maxResults: max_results,
        threshold
      });
    
      let resultText = `问题: ${question}\n\n答案: ${response.answer}\n\n置信度: ${(response.confidence * 100).toFixed(1)}%\n\n来源:\n`;
      
      response.sources.forEach((source, index) => {
        resultText += `${index + 1}. ${source.document.title} (相似度: ${(source.score * 100).toFixed(1)}%)\n`;
        resultText += `   片段: ${source.snippet}\n\n`;
      });
    
      return {
        content: [
          {
            type: 'text',
            text: resultText
          }
        ]
      };
    }
  • Input schema definition for the 'query_knowledge_base' tool, specifying parameters for question, max_results, and threshold.
    {
      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']
      }
    },
  • Core implementation of the knowledge base query logic, handling search, answer generation, and confidence calculation using private helper methods.
    async query(request: QueryRequest): Promise<QueryResponse> {
      const { question, maxResults = this.config.maxSearchResults, threshold = this.config.similarityThreshold } = request;
      
      // 简单的关键词搜索实现
      const results = this.searchDocuments(question, maxResults, threshold);
      
      // 生成答案
      const answer = this.generateAnswer(question, results);
      
      return {
        answer,
        sources: results,
        confidence: this.calculateConfidence(results)
      };
    }

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