@cnbcool/mcp-server 0.6.1 → 0.6.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/README_zh.md +2 -0
- package/dist/api/interfaces/dto.queryknowledgebasereq.js +15 -0
- package/dist/api/interfaces/dto.queryknowledgebaseres.js +15 -0
- package/dist/api/knowledge-base/get-knowledge-base-info.js +42 -0
- package/dist/api/knowledge-base/query-knowledge-base.js +44 -0
- package/dist/constants/toolDescriptions.js +4 -1
- package/dist/constants/toolNames.js +3 -0
- package/dist/helpers/{getToken.js → getConfig.js} +12 -1
- package/dist/helpers/request/index.js +3 -6
- package/dist/tools/index.js +5 -3
- package/dist/tools/knowledgeBaseTools.js +64 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -43,6 +43,8 @@ CNB(https://cnb.cool) toolkits for LLMs supporting the MCP protocol
|
|
|
43
43
|
| cnb_stopBuild | Stop a build |
|
|
44
44
|
| cnb_list_workspaces | Get a list of the current user's cloud-native development environments on the CNB platform |
|
|
45
45
|
| cnb_delete_workspace | Delete a specified cloud-native development environment on the CNB platform |
|
|
46
|
+
| cnb_getKnowledgeBaseInfo | Get knowledge base information |
|
|
47
|
+
| cnb_queryKnowledgeBase | Query knowledge base |
|
|
46
48
|
|
|
47
49
|
## How to use
|
|
48
50
|
|
package/README_zh.md
CHANGED
|
@@ -43,6 +43,8 @@ CNB(https://cnb.cool) 支持 MCP 协议的 MCP Server
|
|
|
43
43
|
| cnb_stopBuild | 停止一个构建 |
|
|
44
44
|
| cnb_list_workspaces | 获取当前用户在CNB平台的云原生开发环境列表 |
|
|
45
45
|
| cnb_delete_workspace | 在CNB平台删除指定的云原生开发环境 |
|
|
46
|
+
| cnb_getKnowledgeBaseInfo | 获取知识库信息 |
|
|
47
|
+
| cnb_queryKnowledgeBase | 查询知识库 |
|
|
46
48
|
|
|
47
49
|
## 使用方法
|
|
48
50
|
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// @ts-nocheck
|
|
3
|
+
/* tslint:disable */
|
|
4
|
+
/* eslint-disable */
|
|
5
|
+
/*
|
|
6
|
+
* -------------------------------------------------------------------------
|
|
7
|
+
* ## THIS FILE WAS GENERATED VIA CNB-API-GENERATE ##
|
|
8
|
+
* ## ##
|
|
9
|
+
* ## AUTHOR: bapelin ##
|
|
10
|
+
* ## SOURCE: https://cnb.woa.com/cnb/frontend-science/cnb-api-generate ##
|
|
11
|
+
* -------------------------------------------------------------------------
|
|
12
|
+
* @Version 1.5.2
|
|
13
|
+
* @Source dto.QueryKnowledgeBaseReq
|
|
14
|
+
*/
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// @ts-nocheck
|
|
3
|
+
/* tslint:disable */
|
|
4
|
+
/* eslint-disable */
|
|
5
|
+
/*
|
|
6
|
+
* -------------------------------------------------------------------------
|
|
7
|
+
* ## THIS FILE WAS GENERATED VIA CNB-API-GENERATE ##
|
|
8
|
+
* ## ##
|
|
9
|
+
* ## AUTHOR: bapelin ##
|
|
10
|
+
* ## SOURCE: https://cnb.woa.com/cnb/frontend-science/cnb-api-generate ##
|
|
11
|
+
* -------------------------------------------------------------------------
|
|
12
|
+
* @Version 1.5.2
|
|
13
|
+
* @Source dto.QueryKnowledgeBaseRes
|
|
14
|
+
*/
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// @ts-nocheck
|
|
3
|
+
/* tslint:disable */
|
|
4
|
+
/* eslint-disable */
|
|
5
|
+
/*
|
|
6
|
+
* -------------------------------------------------------------------------
|
|
7
|
+
* ## THIS FILE WAS GENERATED VIA CNB-API-GENERATE ##
|
|
8
|
+
* ## ##
|
|
9
|
+
* ## AUTHOR: bapelin ##
|
|
10
|
+
* ## SOURCE: https://cnb.woa.com/cnb/frontend-science/cnb-api-generate ##
|
|
11
|
+
* -------------------------------------------------------------------------
|
|
12
|
+
* @Version 1.5.2
|
|
13
|
+
* @Source /{repo}/-/knowledge/base
|
|
14
|
+
*/
|
|
15
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
16
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
17
|
+
};
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.getKnowledgeBaseInfo = getKnowledgeBaseInfo;
|
|
20
|
+
const request_1 = __importDefault(require("../../helpers/request"));
|
|
21
|
+
/**
|
|
22
|
+
* @description 访问令牌调用此接口需包含以下权限。Required permissions for access token.
|
|
23
|
+
* repo-code:r
|
|
24
|
+
* @tags KnowledgeBase
|
|
25
|
+
* @name getKnowledgeBaseInfo
|
|
26
|
+
* @summary 获取知识库信息
|
|
27
|
+
* @request get:/{repo}/-/knowledge/base
|
|
28
|
+
|
|
29
|
+
----------------------------------
|
|
30
|
+
* @param {string} arg0
|
|
31
|
+
* @param {RequestConfig} arg1 - Other reuqest params
|
|
32
|
+
*/
|
|
33
|
+
async function getKnowledgeBaseInfo(repo, { req, options, ...axiosConfig } = {}) {
|
|
34
|
+
return await request_1.default.request({
|
|
35
|
+
...axiosConfig,
|
|
36
|
+
_next_req: req,
|
|
37
|
+
options: options,
|
|
38
|
+
url: `/${repo}/-/knowledge/base`,
|
|
39
|
+
_apiTag: '/{repo}/-/knowledge/base',
|
|
40
|
+
method: 'get'
|
|
41
|
+
});
|
|
42
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// @ts-nocheck
|
|
3
|
+
/* tslint:disable */
|
|
4
|
+
/* eslint-disable */
|
|
5
|
+
/*
|
|
6
|
+
* -------------------------------------------------------------------------
|
|
7
|
+
* ## THIS FILE WAS GENERATED VIA CNB-API-GENERATE ##
|
|
8
|
+
* ## ##
|
|
9
|
+
* ## AUTHOR: bapelin ##
|
|
10
|
+
* ## SOURCE: https://cnb.woa.com/cnb/frontend-science/cnb-api-generate ##
|
|
11
|
+
* -------------------------------------------------------------------------
|
|
12
|
+
* @Version 1.5.2
|
|
13
|
+
* @Source /{repo}/-/knowledge/base/query
|
|
14
|
+
*/
|
|
15
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
16
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
17
|
+
};
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.queryKnowledgeBase = queryKnowledgeBase;
|
|
20
|
+
const request_1 = __importDefault(require("../../helpers/request"));
|
|
21
|
+
/**
|
|
22
|
+
* @description 访问令牌调用此接口需包含以下权限。Required permissions for access token.
|
|
23
|
+
* repo-code:r
|
|
24
|
+
* @tags KnowledgeBase
|
|
25
|
+
* @name queryKnowledgeBase
|
|
26
|
+
* @summary 查询知识库,使用文档:https://docs.cnb.cool/zh/ai/knowledge-base.html
|
|
27
|
+
* @request post:/{repo}/-/knowledge/base/query
|
|
28
|
+
|
|
29
|
+
----------------------------------
|
|
30
|
+
* @param {string} arg0
|
|
31
|
+
* @param {DtoQueryKnowledgeBaseReq} arg1
|
|
32
|
+
* @param {RequestConfig} arg2 - Other reuqest params
|
|
33
|
+
*/
|
|
34
|
+
async function queryKnowledgeBase(repo, query, { req, options, ...axiosConfig } = {}) {
|
|
35
|
+
return await request_1.default.request({
|
|
36
|
+
...axiosConfig,
|
|
37
|
+
_next_req: req,
|
|
38
|
+
options: options,
|
|
39
|
+
url: `/${repo}/-/knowledge/base/query`,
|
|
40
|
+
_apiTag: '/{repo}/-/knowledge/base/query',
|
|
41
|
+
method: 'post',
|
|
42
|
+
data: query
|
|
43
|
+
});
|
|
44
|
+
}
|
|
@@ -45,5 +45,8 @@ exports.toolDescriptions = {
|
|
|
45
45
|
[toolNames_1.ToolNames.STOP_BUILD]: '停止一个构建',
|
|
46
46
|
// 云原生开发工具
|
|
47
47
|
[toolNames_1.ToolNames.LIST_WORKSPACES]: '获取当前用户在CNB平台的云原生开发环境列表',
|
|
48
|
-
[toolNames_1.ToolNames.DELETE_WORKSPACE]: '在CNB平台删除指定的云原生开发环境'
|
|
48
|
+
[toolNames_1.ToolNames.DELETE_WORKSPACE]: '在CNB平台删除指定的云原生开发环境',
|
|
49
|
+
// 知识库工具
|
|
50
|
+
[toolNames_1.ToolNames.GET_KNOWLEDGE_BASE_INFO]: '获取知识库信息',
|
|
51
|
+
[toolNames_1.ToolNames.QUERY_KNOWLEDGE_BASE]: '查询知识库'
|
|
49
52
|
};
|
|
@@ -46,4 +46,7 @@ var ToolNames;
|
|
|
46
46
|
// 云原生开发工具
|
|
47
47
|
ToolNames["LIST_WORKSPACES"] = "cnb_list_workspaces";
|
|
48
48
|
ToolNames["DELETE_WORKSPACE"] = "cnb_delete_workspace";
|
|
49
|
+
// 知识库工具
|
|
50
|
+
ToolNames["GET_KNOWLEDGE_BASE_INFO"] = "cnb_getKnowledgeBaseInfo";
|
|
51
|
+
ToolNames["QUERY_KNOWLEDGE_BASE"] = "cnb_queryKnowledgeBase";
|
|
49
52
|
})(ToolNames || (exports.ToolNames = ToolNames = {}));
|
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.getBaseUrl = getBaseUrl;
|
|
4
|
+
exports.getToken = getToken;
|
|
5
|
+
/**
|
|
6
|
+
* baseUrl 降级获取
|
|
7
|
+
*
|
|
8
|
+
* 环境变量 API_BASE_URL(mcp 客户端配置)--不存在--> CNB 流水线提供的 CNB_API_ENDPOINT ---不存在--> 'https://api.cnb.cool'
|
|
9
|
+
*/
|
|
10
|
+
function getBaseUrl() {
|
|
11
|
+
var _a, _b;
|
|
12
|
+
const baseUrl = (_b = (_a = process.env.API_BASE_URL) !== null && _a !== void 0 ? _a : process.env.CNB_API_ENDPOINT) !== null && _b !== void 0 ? _b : 'https://api.cnb.cool';
|
|
13
|
+
return baseUrl;
|
|
14
|
+
}
|
|
4
15
|
/**
|
|
5
16
|
* token 降级获取
|
|
6
17
|
*
|
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.createHeaders = createHeaders;
|
|
7
|
-
const
|
|
4
|
+
const getConfig_1 = require("../getConfig");
|
|
8
5
|
const cnb_1 = require("./cnb");
|
|
9
|
-
const baseURL =
|
|
6
|
+
const baseURL = (0, getConfig_1.getBaseUrl)();
|
|
10
7
|
const timeout = 10000; // 客户端10秒超时
|
|
11
8
|
const CnbFetcher = new cnb_1.CnbRequest({
|
|
12
9
|
baseURL,
|
|
@@ -15,7 +12,7 @@ const CnbFetcher = new cnb_1.CnbRequest({
|
|
|
15
12
|
exports.default = CnbFetcher;
|
|
16
13
|
function createHeaders(token) {
|
|
17
14
|
return {
|
|
18
|
-
Authorization: `Bearer ${(0,
|
|
15
|
+
Authorization: `Bearer ${(0, getConfig_1.getToken)(token)}`,
|
|
19
16
|
Accept: 'application/vnd.cnb.api+json'
|
|
20
17
|
};
|
|
21
18
|
}
|
package/dist/tools/index.js
CHANGED
|
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.registerTools = registerTools;
|
|
7
|
-
const
|
|
7
|
+
const getConfig_js_1 = require("../helpers/getConfig.js");
|
|
8
8
|
const client_js_1 = __importDefault(require("../api/client.js"));
|
|
9
9
|
const groupTools_js_1 = __importDefault(require("./groupTools.js"));
|
|
10
10
|
const repoTools_js_1 = __importDefault(require("./repoTools.js"));
|
|
@@ -12,10 +12,11 @@ const issueTools_js_1 = __importDefault(require("./issueTools.js"));
|
|
|
12
12
|
const workspaceTools_js_1 = __importDefault(require("./workspaceTools.js"));
|
|
13
13
|
const pullTools_js_1 = __importDefault(require("./pullTools.js"));
|
|
14
14
|
const buildTools_js_1 = __importDefault(require("./buildTools.js"));
|
|
15
|
+
const knowledgeBaseTools_js_1 = __importDefault(require("./knowledgeBaseTools.js"));
|
|
15
16
|
function registerTools(server, token) {
|
|
16
17
|
const client = new client_js_1.default({
|
|
17
|
-
baseUrl:
|
|
18
|
-
token: (0,
|
|
18
|
+
baseUrl: (0, getConfig_js_1.getBaseUrl)(),
|
|
19
|
+
token: (0, getConfig_js_1.getToken)(token)
|
|
19
20
|
});
|
|
20
21
|
(0, groupTools_js_1.default)(server, client);
|
|
21
22
|
(0, repoTools_js_1.default)(server, client);
|
|
@@ -26,4 +27,5 @@ function registerTools(server, token) {
|
|
|
26
27
|
// 使用 cnb-request
|
|
27
28
|
// ================
|
|
28
29
|
(0, buildTools_js_1.default)(server, token);
|
|
30
|
+
(0, knowledgeBaseTools_js_1.default)(server, token);
|
|
29
31
|
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = registerKnowledgeBaseTools;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const toolNames_js_1 = require("../constants/toolNames.js");
|
|
6
|
+
const toolDescriptions_js_1 = require("../constants/toolDescriptions.js");
|
|
7
|
+
const formatToolResult_js_1 = require("../helpers/formatToolResult.js");
|
|
8
|
+
const index_js_1 = require("../helpers/request/index.js");
|
|
9
|
+
const get_knowledge_base_info_js_1 = require("../api/knowledge-base/get-knowledge-base-info.js");
|
|
10
|
+
const query_knowledge_base_js_1 = require("../api/knowledge-base/query-knowledge-base.js");
|
|
11
|
+
function registerKnowledgeBaseTools(server, token) {
|
|
12
|
+
const headers = (0, index_js_1.createHeaders)(token);
|
|
13
|
+
server.tool(toolNames_js_1.ToolNames.GET_KNOWLEDGE_BASE_INFO, toolDescriptions_js_1.toolDescriptions[toolNames_js_1.ToolNames.GET_KNOWLEDGE_BASE_INFO], {
|
|
14
|
+
repo: zod_1.z.string().describe('仓库路径')
|
|
15
|
+
}, async ({ repo }) => {
|
|
16
|
+
try {
|
|
17
|
+
const { error, result } = await (0, get_knowledge_base_info_js_1.getKnowledgeBaseInfo)(repo, { headers });
|
|
18
|
+
if (error)
|
|
19
|
+
throw new Error(`ERROR ${error.code}: ${error.message}`);
|
|
20
|
+
return (0, formatToolResult_js_1.formatTextToolResult)(JSON.stringify(result, null, 2), toolNames_js_1.ToolNames.GET_KNOWLEDGE_BASE_INFO);
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
return (0, formatToolResult_js_1.formatToolError)(error, toolNames_js_1.ToolNames.GET_KNOWLEDGE_BASE_INFO);
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
server.tool(toolNames_js_1.ToolNames.QUERY_KNOWLEDGE_BASE, toolDescriptions_js_1.toolDescriptions[toolNames_js_1.ToolNames.QUERY_KNOWLEDGE_BASE], {
|
|
27
|
+
repo: zod_1.z.string().describe('仓库路径'),
|
|
28
|
+
query: zod_1.z.string().describe('要查询的关键词或问题'),
|
|
29
|
+
score_threshold: zod_1.z.number().default(0).describe('匹配相关性分数阈值'),
|
|
30
|
+
top_k: zod_1.z.number().default(5).describe('返回结果的最大数量'),
|
|
31
|
+
metadata_filtering_conditions: zod_1.z
|
|
32
|
+
.object({
|
|
33
|
+
conditions: zod_1.z.array(zod_1.z.object({
|
|
34
|
+
comparison_operator: zod_1.z
|
|
35
|
+
.enum([
|
|
36
|
+
'is',
|
|
37
|
+
'is not',
|
|
38
|
+
'contains',
|
|
39
|
+
'not contains',
|
|
40
|
+
'starts with',
|
|
41
|
+
'ends with',
|
|
42
|
+
'is empty',
|
|
43
|
+
'is not empty'
|
|
44
|
+
])
|
|
45
|
+
.describe('运算符'),
|
|
46
|
+
name: zod_1.z.enum(['position', 'path', 'type']).describe('字段名称'),
|
|
47
|
+
value: zod_1.z.string().describe('比较值。运算符 "is empty" 和 "is not empty" 时忽略此字段')
|
|
48
|
+
})),
|
|
49
|
+
logical_operator: zod_1.z.enum(['and', 'or']).default('and').describe('逻辑连接条件')
|
|
50
|
+
})
|
|
51
|
+
.optional()
|
|
52
|
+
.describe('元数据过滤条件')
|
|
53
|
+
}, async ({ repo, query, score_threshold, top_k, metadata_filtering_conditions }) => {
|
|
54
|
+
try {
|
|
55
|
+
const { error, result } = await (0, query_knowledge_base_js_1.queryKnowledgeBase)(repo, { query, score_threshold, top_k, metadata_filtering_conditions }, { headers });
|
|
56
|
+
if (error)
|
|
57
|
+
throw new Error(`ERROR ${error.code}: ${error.message}`);
|
|
58
|
+
return (0, formatToolResult_js_1.formatTextToolResult)(JSON.stringify(result, null, 2), toolNames_js_1.ToolNames.QUERY_KNOWLEDGE_BASE);
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
return (0, formatToolResult_js_1.formatToolError)(error, toolNames_js_1.ToolNames.QUERY_KNOWLEDGE_BASE);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cnbcool/mcp-server",
|
|
3
3
|
"description": "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",
|
|
4
|
-
"version": "0.6.
|
|
4
|
+
"version": "0.6.3",
|
|
5
5
|
"main": "./dist/stdio.js",
|
|
6
6
|
"bin": {
|
|
7
7
|
"cnb-mcp-stdio": "dist/stdio.js",
|