Skip to main content
Glama

query_knowledge_base

Search and retrieve relevant information from indexed documents in the MCP Knowledge Base Server by submitting queries and specifying result limits or similarity thresholds.

Instructions

查询知识库

Input Schema

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

Input Schema (JSON Schema)

{ "properties": { "max_results": { "default": 5, "description": "最大返回结果数", "type": "number" }, "question": { "description": "查询问题", "type": "string" }, "threshold": { "default": 0.1, "description": "相似度阈值", "type": "number" } }, "required": [ "question" ], "type": "object" }

Implementation Reference

  • The MCP CallToolRequestHandler case for 'query_knowledge_base'. Extracts args, calls KnowledgeBase.query, formats response with question, answer, confidence score, and source documents/snippets into a single text block.
    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 } ] }; }
  • JSON Schema for the input parameters of the 'query_knowledge_base' tool, defining question (required), max_results, and threshold.
    inputSchema: { type: 'object', properties: { question: { type: 'string', description: '查询问题' }, max_results: { type: 'number', description: '最大返回结果数', default: 5 }, threshold: { type: 'number', description: '相似度阈值', default: 0.1 } }, required: ['question'] }
  • Tool registration entry in ListToolsRequestHandler response, specifying name, description, and input schema for 'query_knowledge_base'.
    { 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'] } },
  • KnowledgeBase.query method: orchestrates document search using searchDocuments, generates a simple answer from top result, computes confidence; core logic delegated by the MCP handler.
    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) }; }
  • TypeScript type definition for QueryRequest interface used in KnowledgeBase.query, matching the tool's input schema.
    export interface QueryRequest { question: string; maxResults?: number; threshold?: number; }

Other Tools

Related 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