UNPKG

@cnbcool/mcp-server

Version:

CNB MCP Server. A comprehensive MCP server that provides seamless integration to the CNB's API(https://cnb.cool), offering a wide range of tools for repository management, pipelines operations and collaboration features

65 lines (64 loc) 3.62 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = registerKnowledgeBaseTools; const zod_1 = require("zod"); const toolNames_js_1 = require("../constants/toolNames.js"); const toolDescriptions_js_1 = require("../constants/toolDescriptions.js"); const formatToolResult_js_1 = require("../helpers/formatToolResult.js"); const index_js_1 = require("../helpers/request/index.js"); const get_knowledge_base_info_js_1 = require("../api/knowledge-base/get-knowledge-base-info.js"); const query_knowledge_base_js_1 = require("../api/knowledge-base/query-knowledge-base.js"); function registerKnowledgeBaseTools(server, token) { const headers = (0, index_js_1.createHeaders)(token); server.tool(toolNames_js_1.ToolNames.GET_KNOWLEDGE_BASE_INFO, toolDescriptions_js_1.toolDescriptions[toolNames_js_1.ToolNames.GET_KNOWLEDGE_BASE_INFO], { repo: zod_1.z.string().describe('仓库路径') }, async ({ repo }) => { try { const { error, result } = await (0, get_knowledge_base_info_js_1.getKnowledgeBaseInfo)(repo, { headers }); if (error) throw new Error(`ERROR ${error.code}: ${error.message}`); return (0, formatToolResult_js_1.formatTextToolResult)(JSON.stringify(result, null, 2), toolNames_js_1.ToolNames.GET_KNOWLEDGE_BASE_INFO); } catch (error) { return (0, formatToolResult_js_1.formatToolError)(error, toolNames_js_1.ToolNames.GET_KNOWLEDGE_BASE_INFO); } }); server.tool(toolNames_js_1.ToolNames.QUERY_KNOWLEDGE_BASE, toolDescriptions_js_1.toolDescriptions[toolNames_js_1.ToolNames.QUERY_KNOWLEDGE_BASE], { repo: zod_1.z.string().describe('仓库路径'), query: zod_1.z.string().describe('要查询的关键词或问题'), score_threshold: zod_1.z.number().default(0).describe('匹配相关性分数阈值'), top_k: zod_1.z.number().default(5).describe('返回结果的最大数量'), metadata_filtering_conditions: zod_1.z .object({ conditions: zod_1.z.array(zod_1.z.object({ comparison_operator: zod_1.z .enum([ 'is', 'is not', 'contains', 'not contains', 'starts with', 'ends with', 'is empty', 'is not empty' ]) .describe('运算符'), name: zod_1.z.enum(['position', 'path', 'type']).describe('字段名称'), value: zod_1.z.string().describe('比较值。运算符 "is empty" 和 "is not empty" 时忽略此字段') })), logical_operator: zod_1.z.enum(['and', 'or']).default('and').describe('逻辑连接条件') }) .optional() .describe('元数据过滤条件') }, async ({ repo, query, score_threshold, top_k, metadata_filtering_conditions }) => { try { const { error, result } = await (0, query_knowledge_base_js_1.queryKnowledgeBase)(repo, { query, score_threshold, top_k, metadata_filtering_conditions }, { headers }); if (error) throw new Error(`ERROR ${error.code}: ${error.message}`); return (0, formatToolResult_js_1.formatTextToolResult)(JSON.stringify(result, null, 2), toolNames_js_1.ToolNames.QUERY_KNOWLEDGE_BASE); } catch (error) { return (0, formatToolResult_js_1.formatToolError)(error, toolNames_js_1.ToolNames.QUERY_KNOWLEDGE_BASE); } }); }