@cnbcool/mcp-server 0.4.2 → 0.4.4
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 +35 -2
- package/README_zh.md +35 -0
- package/dist/api/client.js +6 -5
- package/dist/api/group.js +18 -9
- package/dist/api/issue.js +42 -25
- package/dist/api/pull.js +27 -15
- package/dist/api/repository.js +18 -9
- package/dist/api/user.js +9 -3
- package/dist/api/workspace.js +12 -5
- package/dist/constants/index.js +9 -0
- package/dist/constants/toolDescriptions.js +41 -0
- package/dist/constants/toolNames.js +41 -0
- package/dist/helpers/checkRepoVisibility.js +19 -0
- package/dist/helpers/createMcpServer.js +12 -9
- package/dist/helpers/formatRepoUrl.js +20 -0
- package/dist/helpers/formatToolResult.js +6 -2
- package/dist/helpers/sendResponse.js +4 -1
- package/dist/stdio.js +11 -6
- package/dist/streamable.js +28 -22
- package/dist/tools/groupTools.js +40 -35
- package/dist/tools/index.js +19 -13
- package/dist/tools/issueTools.js +126 -121
- package/dist/tools/pullTools.js +74 -69
- package/dist/tools/repoTools.js +72 -74
- package/dist/tools/workspaceTools.js +32 -27
- package/package.json +14 -15
package/README.md
CHANGED
|
@@ -2,6 +2,41 @@
|
|
|
2
2
|
|
|
3
3
|
CNB(https://cnb.cool) toolkits for LLMs supporting the MCP protocol
|
|
4
4
|
|
|
5
|
+
## Tool List
|
|
6
|
+
|
|
7
|
+
| Tool Name | Tool Description |
|
|
8
|
+
| :----- | :------- |
|
|
9
|
+
| cnb_list_groups | Gets a list of top-level organizations for which the current user has permissions on the CNB platform. |
|
|
10
|
+
| cnb_list_sub_groups | Gets a list of sub-organizations for which the current user has permissions on the CNB platform under a specified organization. |
|
|
11
|
+
| cnb_get_group | Gets information about a specified organization on the CNB platform. |
|
|
12
|
+
| cnb_create_group | Creates a new organization on the CNB platform. |
|
|
13
|
+
| cnb_list_repositories | Gets a list of repositories for which the current user has permissions on the CNB platform. |
|
|
14
|
+
| cnb_list_group_repositories | Gets a list of repositories for which the current user has permissions on the CNB platform under a specified organization. |
|
|
15
|
+
| cnb_get_current_repository | Gets information about the CNB platform repository corresponding to the current workspace. |
|
|
16
|
+
| cnb_get_repository | Gets information about a specified repository on the CNB platform. |
|
|
17
|
+
| cnb_create_repository | Create a new repository on the CNB platform. |
|
|
18
|
+
| cnb_list_issues | Get a list of issues in a specified repository on the CNB platform. |
|
|
19
|
+
| cnb_get_issue | Get information about a specified issue on the CNB platform. |
|
|
20
|
+
| cnb_create_issue | Create a new issue in a specified repository on the CNB platform. To add labels, use the cnb_add_issue_labels tool. |
|
|
21
|
+
| cnb_update_issue | Update information about a specified issue on the CNB platform. To update labels, call the cnb_set_issue_labels tool separately. |
|
|
22
|
+
| cnb_list_issue_comments | Get a list of comments for a specified issue on the CNB platform. |
|
|
23
|
+
| cnb_create_issue_comment | Create a new comment on a specified issue on the CNB platform. |
|
|
24
|
+
| cnb_update_issue_comment | Update the content of a comment on a specified issue on the CNB platform. |
|
|
25
|
+
| cnb_list_issue_labels | Get a list of labels for a specified issue on the CNB platform. |
|
|
26
|
+
| cnb_add_issue_labels | Add one or more labels to a specified issue on the CNB platform. |
|
|
27
|
+
| cnb_set_issue_labels | Change the labels for a specified issue on the CNB platform. |
|
|
28
|
+
| cnb_clear_issue_labels | Clear the labels for a specified issue on the CNB platform. |
|
|
29
|
+
| cnb_remove_issue_label | Remove a specified label from a specified issue on the CNB platform. |
|
|
30
|
+
| cnb_list_pulls | Get a list of merge requests for a specified repository on the CNB platform. |
|
|
31
|
+
| cnb_get_pull | Get information about a merge request specified on the CNB platform |
|
|
32
|
+
| cnb_create_pull | Create a new merge request in a repository specified on the CNB platform |
|
|
33
|
+
| cnb_update_pull | Update information about a merge request specified on the CNB platform |
|
|
34
|
+
| cnb_merge_pull | Merge a merge request specified on the CNB platform |
|
|
35
|
+
| cnb_list_pull_comments | Get a list of comments for a merge request specified on the CNB platform |
|
|
36
|
+
| cnb_create_pull_comment | Create a new comment on a merge request specified on the CNB platform |
|
|
37
|
+
| cnb_list_workspaces | Get a list of the current user's cloud-native development environments on the CNB platform |
|
|
38
|
+
| cnb_delete_workspace | Delete a specified cloud-native development environment on the CNB platform |
|
|
39
|
+
|
|
5
40
|
## How to use
|
|
6
41
|
|
|
7
42
|
### STDIO
|
|
@@ -57,5 +92,3 @@ CNB(https://cnb.cool) toolkits for LLMs supporting the MCP protocol
|
|
|
57
92
|
}
|
|
58
93
|
}
|
|
59
94
|
```
|
|
60
|
-
|
|
61
|
-
|
package/README_zh.md
CHANGED
|
@@ -2,6 +2,41 @@
|
|
|
2
2
|
|
|
3
3
|
CNB(https://cnb.cool) 支持 MCP 协议的 MCP Server
|
|
4
4
|
|
|
5
|
+
## 工具列表
|
|
6
|
+
|
|
7
|
+
| 工具名 | 工具描述 |
|
|
8
|
+
| :----- | :------- |
|
|
9
|
+
| cnb_list_groups | 获取当前用户在CNB平台里拥有权限的顶层组织列表 |
|
|
10
|
+
| cnb_list_sub_groups | 获取当前用户在CNB平台里指定组织下拥有权限的子组织列表 |
|
|
11
|
+
| cnb_get_group | 获取CNB平台指定组织的信息 |
|
|
12
|
+
| cnb_create_group | 在CNB平台创建一个新组织 |
|
|
13
|
+
| cnb_list_repositories | 获取当前用户在CNB平台里拥有权限的仓库列表 |
|
|
14
|
+
| cnb_list_group_repositories | 获取当前用户在CNB平台里指定组织下拥有权限的仓库列表 |
|
|
15
|
+
| cnb_get_current_repository | 获取当前工作区对应的CNB平台仓库信息 |
|
|
16
|
+
| cnb_get_repository | 获取CNB平台指定仓库的信息 |
|
|
17
|
+
| cnb_create_repository | 在CNB平台创建一个新仓库 |
|
|
18
|
+
| cnb_list_issues | 获取CNB平台指定仓库的ISSUE列表 |
|
|
19
|
+
| cnb_get_issue | 获取CNB平台指定ISSUE的信息 |
|
|
20
|
+
| cnb_create_issue | 在CNB平台指定的仓库创建一条新ISSUE。如需添加标签,另外调用cnb_add_issue_labels工具 |
|
|
21
|
+
| cnb_update_issue | 更新CNB平台指定ISSUE的信息。如需更新标签,另外调用cnb_set_issue_labels工具 |
|
|
22
|
+
| cnb_list_issue_comments | 获取CNB平台指定ISSUE的评论列表 |
|
|
23
|
+
| cnb_create_issue_comment | 在CNB平台指定的ISSUE创建一条新评论 |
|
|
24
|
+
| cnb_update_issue_comment | 更新CNB平台指定ISSUE评论的内容 |
|
|
25
|
+
| cnb_list_issue_labels | 获取CNB平台指定ISSUE的标签列表 |
|
|
26
|
+
| cnb_add_issue_labels | 为CNB平台指定的ISSUE添加一个或多个标签 |
|
|
27
|
+
| cnb_set_issue_labels | 变更CNB平台指定ISSUE的标签 |
|
|
28
|
+
| cnb_clear_issue_labels | 清除CNB平台指定ISSUE的标签 |
|
|
29
|
+
| cnb_remove_issue_label | 移除CNB平台指定ISSUE的指定标签 |
|
|
30
|
+
| cnb_list_pulls | 获取CNB平台指定仓库的合并请求列表 |
|
|
31
|
+
| cnb_get_pull | 获取CNB平台指定合并请求的信息 |
|
|
32
|
+
| cnb_create_pull | 在CNB平台指定的仓库创建一个新合并请求 |
|
|
33
|
+
| cnb_update_pull | 更新CNB平台指定合并请求的信息 |
|
|
34
|
+
| cnb_merge_pull | 合并CNB平台指定的合并请求 |
|
|
35
|
+
| cnb_list_pull_comments | 获取CNB平台指定合并请求的评论列表 |
|
|
36
|
+
| cnb_create_pull_comment | 在CNB平台指定的合并请求创建一条新评论 |
|
|
37
|
+
| cnb_list_workspaces | 获取当前用户在CNB平台的云原生开发环境列表 |
|
|
38
|
+
| cnb_delete_workspace | 在CNB平台删除指定的云原生开发环境 |
|
|
39
|
+
|
|
5
40
|
## 使用方法
|
|
6
41
|
|
|
7
42
|
### STDIO
|
package/dist/api/client.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
_token;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class CnbApiClient {
|
|
5
4
|
constructor(options) {
|
|
6
5
|
this._baseUrl = options.baseUrl;
|
|
7
6
|
this._token = options.token;
|
|
@@ -26,7 +25,7 @@ export default class CnbApiClient {
|
|
|
26
25
|
const headers = {
|
|
27
26
|
Authorization: `Bearer ${this._token}`,
|
|
28
27
|
Accept: 'application/vnd.cnb.api+json',
|
|
29
|
-
...(config
|
|
28
|
+
...((config === null || config === void 0 ? void 0 : config.header) || {})
|
|
30
29
|
};
|
|
31
30
|
const options = {
|
|
32
31
|
method,
|
|
@@ -47,3 +46,5 @@ export default class CnbApiClient {
|
|
|
47
46
|
return response.json();
|
|
48
47
|
}
|
|
49
48
|
}
|
|
49
|
+
CnbApiClient.instance = null;
|
|
50
|
+
exports.default = CnbApiClient;
|
package/dist/api/group.js
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.listGroups = listGroups;
|
|
7
|
+
exports.listSubGroups = listSubGroups;
|
|
8
|
+
exports.getGroup = getGroup;
|
|
9
|
+
exports.createGroup = createGroup;
|
|
10
|
+
const client_js_1 = __importDefault(require("./client.js"));
|
|
11
|
+
async function listGroups(params) {
|
|
12
|
+
const cnbInst = client_js_1.default.getInstance();
|
|
4
13
|
const url = new URL('/user/groups', cnbInst.baseUrl);
|
|
5
14
|
if (params) {
|
|
6
15
|
for (const [key, value] of Object.entries(params)) {
|
|
@@ -11,8 +20,8 @@ export async function listGroups(params) {
|
|
|
11
20
|
}
|
|
12
21
|
return cnbInst.request('GET', `${url.pathname}${url.search}`);
|
|
13
22
|
}
|
|
14
|
-
|
|
15
|
-
const cnbInst =
|
|
23
|
+
async function listSubGroups(group, params) {
|
|
24
|
+
const cnbInst = client_js_1.default.getInstance();
|
|
16
25
|
const url = new URL(`/user/groups/${group}`, cnbInst.baseUrl);
|
|
17
26
|
if (params) {
|
|
18
27
|
for (const [key, value] of Object.entries(params)) {
|
|
@@ -23,18 +32,18 @@ export async function listSubGroups(group, params) {
|
|
|
23
32
|
}
|
|
24
33
|
return cnbInst.request('GET', `${url.pathname}${url.search}`);
|
|
25
34
|
}
|
|
26
|
-
|
|
27
|
-
const cnbInst =
|
|
35
|
+
async function getGroup(group) {
|
|
36
|
+
const cnbInst = client_js_1.default.getInstance();
|
|
28
37
|
return cnbInst.request('GET', `/${group}`);
|
|
29
38
|
}
|
|
30
|
-
|
|
39
|
+
async function createGroup(params) {
|
|
31
40
|
const body = Object.entries(params).reduce((acc, [key, value]) => {
|
|
32
41
|
if (value === undefined)
|
|
33
42
|
return acc;
|
|
34
43
|
Object.assign(acc, { [key]: value });
|
|
35
44
|
return acc;
|
|
36
45
|
}, {});
|
|
37
|
-
const response = await
|
|
46
|
+
const response = await client_js_1.default.getInstance().request('POST', '/groups', body, {
|
|
38
47
|
header: { 'Content-Type': 'application/json' }
|
|
39
48
|
}, 'raw');
|
|
40
49
|
if (response.status === 201) {
|
package/dist/api/issue.js
CHANGED
|
@@ -1,6 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.listIssues = listIssues;
|
|
7
|
+
exports.getIssue = getIssue;
|
|
8
|
+
exports.createIssue = createIssue;
|
|
9
|
+
exports.updateIssue = updateIssue;
|
|
10
|
+
exports.listIssueComments = listIssueComments;
|
|
11
|
+
exports.createIssueComment = createIssueComment;
|
|
12
|
+
exports.updateIssueComment = updateIssueComment;
|
|
13
|
+
exports.listIssueLabels = listIssueLabels;
|
|
14
|
+
exports.addIssueLabels = addIssueLabels;
|
|
15
|
+
exports.setIssueLabels = setIssueLabels;
|
|
16
|
+
exports.deleteIssueLabels = deleteIssueLabels;
|
|
17
|
+
exports.deleteIssueLabel = deleteIssueLabel;
|
|
18
|
+
const client_js_1 = __importDefault(require("./client.js"));
|
|
19
|
+
async function listIssues(repo, params) {
|
|
20
|
+
const cnbInst = client_js_1.default.getInstance();
|
|
4
21
|
const url = new URL(`/${repo}/-/issues`, cnbInst.baseUrl);
|
|
5
22
|
if (params) {
|
|
6
23
|
for (const [key, value] of Object.entries(params)) {
|
|
@@ -11,27 +28,27 @@ export async function listIssues(repo, params) {
|
|
|
11
28
|
}
|
|
12
29
|
return cnbInst.request('GET', `${url.pathname}${url.search}`);
|
|
13
30
|
}
|
|
14
|
-
|
|
15
|
-
return
|
|
31
|
+
async function getIssue(repo, issueId) {
|
|
32
|
+
return client_js_1.default.getInstance().request('GET', `/${repo}/-/issues/${issueId}`);
|
|
16
33
|
}
|
|
17
|
-
|
|
34
|
+
async function createIssue(repo, params) {
|
|
18
35
|
const newParams = Object.entries(params).reduce((acc, [key, value]) => {
|
|
19
36
|
if (value === undefined)
|
|
20
37
|
return acc;
|
|
21
38
|
Object.assign(acc, { [key]: value });
|
|
22
39
|
return acc;
|
|
23
40
|
}, {});
|
|
24
|
-
return
|
|
41
|
+
return client_js_1.default.getInstance().request('POST', `/${repo}/-/issues`, newParams, {
|
|
25
42
|
header: { 'Content-Type': 'application/json' }
|
|
26
43
|
});
|
|
27
44
|
}
|
|
28
|
-
|
|
29
|
-
return
|
|
45
|
+
async function updateIssue(repo, issueId, params) {
|
|
46
|
+
return client_js_1.default.getInstance().request('PATCH', `/${repo}/-/issues/${issueId}`, params, {
|
|
30
47
|
header: { 'Content-Type': 'application/json' }
|
|
31
48
|
});
|
|
32
49
|
}
|
|
33
|
-
|
|
34
|
-
const cnbInst =
|
|
50
|
+
async function listIssueComments(repo, issueId, params) {
|
|
51
|
+
const cnbInst = client_js_1.default.getInstance();
|
|
35
52
|
const url = new URL(`/${repo}/-/issues/${issueId}/comments`, cnbInst.baseUrl);
|
|
36
53
|
if (params) {
|
|
37
54
|
for (const [key, value] of Object.entries(params)) {
|
|
@@ -42,32 +59,32 @@ export async function listIssueComments(repo, issueId, params) {
|
|
|
42
59
|
}
|
|
43
60
|
return cnbInst.request('GET', `${url.pathname}${url.search}`);
|
|
44
61
|
}
|
|
45
|
-
|
|
46
|
-
return
|
|
62
|
+
async function createIssueComment(repo, issueId, params) {
|
|
63
|
+
return client_js_1.default.getInstance().request('POST', `/${repo}/-/issues/${issueId}/comments`, params, {
|
|
47
64
|
header: { 'Content-Type': 'application/json' }
|
|
48
65
|
});
|
|
49
66
|
}
|
|
50
|
-
|
|
51
|
-
return
|
|
67
|
+
async function updateIssueComment(repo, issueId, commentId, params) {
|
|
68
|
+
return client_js_1.default.getInstance().request('PATCH', `/${repo}/-/issues/${issueId}/comments/${commentId}`, params, {
|
|
52
69
|
header: { 'Content-Type': 'application/json' }
|
|
53
70
|
});
|
|
54
71
|
}
|
|
55
|
-
|
|
56
|
-
return
|
|
72
|
+
async function listIssueLabels(repo, issueId) {
|
|
73
|
+
return client_js_1.default.getInstance().request('GET', `/${repo}/-/issues/${issueId}/labels`);
|
|
57
74
|
}
|
|
58
|
-
|
|
59
|
-
return
|
|
75
|
+
async function addIssueLabels(repo, issueId, labels) {
|
|
76
|
+
return client_js_1.default.getInstance().request('POST', `/${repo}/-/issues/${issueId}/labels`, { labels }, {
|
|
60
77
|
header: { 'Content-Type': 'application/json' }
|
|
61
78
|
});
|
|
62
79
|
}
|
|
63
|
-
|
|
64
|
-
return
|
|
80
|
+
async function setIssueLabels(repo, issueId, labels) {
|
|
81
|
+
return client_js_1.default.getInstance().request('PUT', `/${repo}/-/issues/${issueId}/labels`, { labels }, {
|
|
65
82
|
header: { 'Content-Type': 'application/json' }
|
|
66
83
|
});
|
|
67
84
|
}
|
|
68
|
-
|
|
69
|
-
await
|
|
85
|
+
async function deleteIssueLabels(repo, issueId) {
|
|
86
|
+
await client_js_1.default.getInstance().request('DELETE', `/${repo}/-/issues/${issueId}/labels`);
|
|
70
87
|
}
|
|
71
|
-
|
|
72
|
-
await
|
|
88
|
+
async function deleteIssueLabel(repo, issueId, labelName) {
|
|
89
|
+
await client_js_1.default.getInstance().request('DELETE', `/${repo}/-/issues/${issueId}/labels/${encodeURIComponent(labelName)}`);
|
|
73
90
|
}
|
package/dist/api/pull.js
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.listPulls = listPulls;
|
|
7
|
+
exports.getPull = getPull;
|
|
8
|
+
exports.createPull = createPull;
|
|
9
|
+
exports.updatePull = updatePull;
|
|
10
|
+
exports.mergePull = mergePull;
|
|
11
|
+
exports.listPullComments = listPullComments;
|
|
12
|
+
exports.createPullComment = createPullComment;
|
|
13
|
+
const client_js_1 = __importDefault(require("./client.js"));
|
|
14
|
+
async function listPulls(repo, params) {
|
|
15
|
+
const cnbInst = client_js_1.default.getInstance();
|
|
4
16
|
const url = new URL(`/${repo}/-/pulls`, cnbInst.baseUrl);
|
|
5
17
|
if (params) {
|
|
6
18
|
for (const [key, value] of Object.entries(params)) {
|
|
@@ -11,26 +23,26 @@ export async function listPulls(repo, params) {
|
|
|
11
23
|
}
|
|
12
24
|
return cnbInst.request('GET', `${url.pathname}${url.search}`);
|
|
13
25
|
}
|
|
14
|
-
|
|
15
|
-
return
|
|
26
|
+
async function getPull(repo, number) {
|
|
27
|
+
return client_js_1.default.getInstance().request('GET', `/${repo}/-/pulls/${number}`);
|
|
16
28
|
}
|
|
17
|
-
|
|
18
|
-
return
|
|
29
|
+
async function createPull(repo, params) {
|
|
30
|
+
return client_js_1.default.getInstance().request('POST', `/${repo}/-/pulls`, params, {
|
|
19
31
|
header: { 'Content-Type': 'application/json' }
|
|
20
32
|
});
|
|
21
33
|
}
|
|
22
|
-
|
|
23
|
-
return
|
|
34
|
+
async function updatePull(repo, number, params) {
|
|
35
|
+
return client_js_1.default.getInstance().request('PATCH', `/${repo}/-/pulls/${number}`, params, {
|
|
24
36
|
header: { 'Content-Type': 'application/json' }
|
|
25
37
|
});
|
|
26
38
|
}
|
|
27
|
-
|
|
28
|
-
return
|
|
39
|
+
async function mergePull(repo, number, params) {
|
|
40
|
+
return client_js_1.default.getInstance().request('PUT', `/${repo}/-/pulls/${number}/merge`, params, {
|
|
29
41
|
header: { 'Content-Type': 'application/json' }
|
|
30
42
|
});
|
|
31
43
|
}
|
|
32
|
-
|
|
33
|
-
const cnbInst =
|
|
44
|
+
async function listPullComments(repo, number, params) {
|
|
45
|
+
const cnbInst = client_js_1.default.getInstance();
|
|
34
46
|
const url = new URL(`/${repo}/-/pulls/${number}/comments`, cnbInst.baseUrl);
|
|
35
47
|
if (params) {
|
|
36
48
|
for (const [key, value] of Object.entries(params)) {
|
|
@@ -41,8 +53,8 @@ export async function listPullComments(repo, number, params) {
|
|
|
41
53
|
}
|
|
42
54
|
return cnbInst.request('GET', `${url.pathname}${url.search}`);
|
|
43
55
|
}
|
|
44
|
-
|
|
45
|
-
const response = await
|
|
56
|
+
async function createPullComment(repo, number, params) {
|
|
57
|
+
const response = await client_js_1.default.getInstance().request('POST', `/${repo}/-/pulls/${number}/comments`, params, {
|
|
46
58
|
header: { 'Content-Type': 'application/json' }
|
|
47
59
|
}, 'raw');
|
|
48
60
|
if (response.status === 201) {
|
package/dist/api/repository.js
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.listRepositories = listRepositories;
|
|
7
|
+
exports.listGroupRepositories = listGroupRepositories;
|
|
8
|
+
exports.getRepository = getRepository;
|
|
9
|
+
exports.createRepository = createRepository;
|
|
10
|
+
const client_js_1 = __importDefault(require("./client.js"));
|
|
11
|
+
async function listRepositories(params) {
|
|
12
|
+
const cnbInst = client_js_1.default.getInstance();
|
|
4
13
|
const url = new URL('/user/repos', cnbInst.baseUrl);
|
|
5
14
|
if (params) {
|
|
6
15
|
for (const [key, value] of Object.entries(params)) {
|
|
@@ -11,8 +20,8 @@ export async function listRepositories(params) {
|
|
|
11
20
|
}
|
|
12
21
|
return cnbInst.request('GET', `${url.pathname}${url.search}`);
|
|
13
22
|
}
|
|
14
|
-
|
|
15
|
-
const cnbInst =
|
|
23
|
+
async function listGroupRepositories(group, params) {
|
|
24
|
+
const cnbInst = client_js_1.default.getInstance();
|
|
16
25
|
const url = new URL(`/${group}/-/repos`, cnbInst.baseUrl);
|
|
17
26
|
if (params) {
|
|
18
27
|
for (const [key, value] of Object.entries(params)) {
|
|
@@ -23,17 +32,17 @@ export async function listGroupRepositories(group, params) {
|
|
|
23
32
|
}
|
|
24
33
|
return cnbInst.request('GET', `${url.pathname}${url.search}`);
|
|
25
34
|
}
|
|
26
|
-
|
|
27
|
-
return
|
|
35
|
+
async function getRepository(repo) {
|
|
36
|
+
return client_js_1.default.getInstance().request('GET', `/${repo}`);
|
|
28
37
|
}
|
|
29
|
-
|
|
38
|
+
async function createRepository(group, params) {
|
|
30
39
|
const body = Object.entries(params).reduce((acc, [key, value]) => {
|
|
31
40
|
if (value === undefined)
|
|
32
41
|
return acc;
|
|
33
42
|
Object.assign(acc, { [key]: value });
|
|
34
43
|
return acc;
|
|
35
44
|
}, {});
|
|
36
|
-
const response = await
|
|
45
|
+
const response = await client_js_1.default.getInstance().request('POST', `/${group}/-/repos`, body, {
|
|
37
46
|
header: { 'Content-Type': 'application/json' }
|
|
38
47
|
}, 'raw');
|
|
39
48
|
if (response.status === 201) {
|
package/dist/api/user.js
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getUser = getUser;
|
|
7
|
+
const client_js_1 = __importDefault(require("./client.js"));
|
|
8
|
+
async function getUser() {
|
|
9
|
+
const cnbInst = client_js_1.default.getInstance();
|
|
4
10
|
return cnbInst.request('GET', '/user');
|
|
5
11
|
}
|
package/dist/api/workspace.js
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.listWorkspace = listWorkspace;
|
|
7
|
+
exports.deleteWorkspace = deleteWorkspace;
|
|
8
|
+
const client_js_1 = __importDefault(require("./client.js"));
|
|
9
|
+
async function listWorkspace(params) {
|
|
10
|
+
const cnbInst = client_js_1.default.getInstance();
|
|
4
11
|
const url = new URL('/workspace/list', cnbInst.baseUrl);
|
|
5
12
|
if (params) {
|
|
6
13
|
for (const [key, value] of Object.entries(params)) {
|
|
@@ -11,8 +18,8 @@ export async function listWorkspace(params) {
|
|
|
11
18
|
}
|
|
12
19
|
return cnbInst.request('GET', `${url.pathname}${url.search}`);
|
|
13
20
|
}
|
|
14
|
-
|
|
15
|
-
const cnbInst =
|
|
21
|
+
async function deleteWorkspace(params) {
|
|
22
|
+
const cnbInst = client_js_1.default.getInstance();
|
|
16
23
|
const url = new URL('/workspace/delete', cnbInst.baseUrl);
|
|
17
24
|
return cnbInst.request('POST', `${url.pathname}`, params, {
|
|
18
25
|
header: { 'Content-Type': 'application/json' }
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RepoVisibility = void 0;
|
|
4
|
+
var RepoVisibility;
|
|
5
|
+
(function (RepoVisibility) {
|
|
6
|
+
RepoVisibility["private"] = "Private";
|
|
7
|
+
RepoVisibility["public"] = "Public";
|
|
8
|
+
RepoVisibility["secret"] = "Secret";
|
|
9
|
+
})(RepoVisibility || (exports.RepoVisibility = RepoVisibility = {}));
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toolDescriptions = void 0;
|
|
4
|
+
const toolNames_1 = require("./toolNames");
|
|
5
|
+
exports.toolDescriptions = {
|
|
6
|
+
// 组织工具
|
|
7
|
+
[toolNames_1.ToolNames.LIST_GROUPS]: '获取当前用户在CNB平台里拥有权限的顶层组织列表',
|
|
8
|
+
[toolNames_1.ToolNames.LIST_SUB_GROUPS]: '获取当前用户在CNB平台里指定组织下拥有权限的子组织列表',
|
|
9
|
+
[toolNames_1.ToolNames.GET_GROUP]: '获取CNB平台指定组织的信息',
|
|
10
|
+
[toolNames_1.ToolNames.CREATE_GROUP]: '在CNB平台创建一个新组织',
|
|
11
|
+
// 仓库工具
|
|
12
|
+
[toolNames_1.ToolNames.LIST_REPOSITORIES]: '获取当前用户在CNB平台里拥有权限的仓库列表',
|
|
13
|
+
[toolNames_1.ToolNames.LIST_GROUP_REPOSITORIES]: '获取当前用户在CNB平台里指定组织下拥有权限的仓库列表',
|
|
14
|
+
[toolNames_1.ToolNames.GET_CURRENT_REPOSITORY]: '获取当前工作区对应的CNB平台仓库信息',
|
|
15
|
+
[toolNames_1.ToolNames.GET_REPOSITORY]: '获取CNB平台指定仓库的信息',
|
|
16
|
+
[toolNames_1.ToolNames.CREATE_REPOSITORY]: '在CNB平台创建一个新仓库',
|
|
17
|
+
// ISSUE 工具
|
|
18
|
+
[toolNames_1.ToolNames.LIST_ISSUES]: '获取CNB平台指定仓库的ISSUE列表',
|
|
19
|
+
[toolNames_1.ToolNames.GET_ISSUE]: '获取CNB平台指定ISSUE的信息',
|
|
20
|
+
[toolNames_1.ToolNames.CREATE_ISSUE]: `在CNB平台指定的仓库创建一条新ISSUE。如需添加标签,另外调用${toolNames_1.ToolNames.ADD_ISSUE_LABELS}工具`,
|
|
21
|
+
[toolNames_1.ToolNames.UPDATE_ISSUE]: `更新CNB平台指定ISSUE的信息。如需更新标签,另外调用${toolNames_1.ToolNames.SET_ISSUE_LABELS}工具`,
|
|
22
|
+
[toolNames_1.ToolNames.LIST_ISSUE_COMMENTS]: '获取CNB平台指定ISSUE的评论列表',
|
|
23
|
+
[toolNames_1.ToolNames.CREATE_ISSUE_COMMENT]: '在CNB平台指定的ISSUE创建一条新评论',
|
|
24
|
+
[toolNames_1.ToolNames.UPDATE_ISSUE_COMMENT]: '更新CNB平台指定ISSUE评论的内容',
|
|
25
|
+
[toolNames_1.ToolNames.LIST_ISSUE_LABELS]: '获取CNB平台指定ISSUE的标签列表',
|
|
26
|
+
[toolNames_1.ToolNames.ADD_ISSUE_LABELS]: '为CNB平台指定的ISSUE添加一个或多个标签',
|
|
27
|
+
[toolNames_1.ToolNames.SET_ISSUE_LABELS]: '变更CNB平台指定ISSUE的标签',
|
|
28
|
+
[toolNames_1.ToolNames.CLEAR_ISSUE_LABELS]: '清除CNB平台指定ISSUE的标签',
|
|
29
|
+
[toolNames_1.ToolNames.REMOVE_ISSUE_LABEL]: '移除CNB平台指定ISSUE的指定标签',
|
|
30
|
+
// 合并请求工具
|
|
31
|
+
[toolNames_1.ToolNames.LIST_PULLS]: '获取CNB平台指定仓库的合并请求列表',
|
|
32
|
+
[toolNames_1.ToolNames.GET_PULL]: '获取CNB平台指定合并请求的信息',
|
|
33
|
+
[toolNames_1.ToolNames.CREATE_PULL]: '在CNB平台指定的仓库创建一个新合并请求',
|
|
34
|
+
[toolNames_1.ToolNames.UPDATE_PULL]: '更新CNB平台指定合并请求的信息',
|
|
35
|
+
[toolNames_1.ToolNames.MERGE_PULL]: '合并CNB平台指定的合并请求',
|
|
36
|
+
[toolNames_1.ToolNames.LIST_PULL_COMMENTS]: '获取CNB平台指定合并请求的评论列表',
|
|
37
|
+
[toolNames_1.ToolNames.CREATE_PULL_COMMENT]: '在CNB平台指定的合并请求创建一条新评论',
|
|
38
|
+
// 云原生开发工具
|
|
39
|
+
[toolNames_1.ToolNames.LIST_WORKSPACES]: '获取当前用户在CNB平台的云原生开发环境列表',
|
|
40
|
+
[toolNames_1.ToolNames.DELETE_WORKSPACE]: '在CNB平台删除指定的云原生开发环境'
|
|
41
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ToolNames = void 0;
|
|
4
|
+
var ToolNames;
|
|
5
|
+
(function (ToolNames) {
|
|
6
|
+
// 组织工具
|
|
7
|
+
ToolNames["LIST_GROUPS"] = "cnb_list_groups";
|
|
8
|
+
ToolNames["LIST_SUB_GROUPS"] = "cnb_list_sub_groups";
|
|
9
|
+
ToolNames["GET_GROUP"] = "cnb_get_group";
|
|
10
|
+
ToolNames["CREATE_GROUP"] = "cnb_create_group";
|
|
11
|
+
// 仓库工具
|
|
12
|
+
ToolNames["LIST_REPOSITORIES"] = "cnb_list_repositories";
|
|
13
|
+
ToolNames["LIST_GROUP_REPOSITORIES"] = "cnb_list_group_repositories";
|
|
14
|
+
ToolNames["GET_CURRENT_REPOSITORY"] = "cnb_get_current_repository";
|
|
15
|
+
ToolNames["GET_REPOSITORY"] = "cnb_get_repository";
|
|
16
|
+
ToolNames["CREATE_REPOSITORY"] = "cnb_create_repository";
|
|
17
|
+
// ISSUE 工具
|
|
18
|
+
ToolNames["LIST_ISSUES"] = "cnb_list_issues";
|
|
19
|
+
ToolNames["GET_ISSUE"] = "cnb_get_issue";
|
|
20
|
+
ToolNames["CREATE_ISSUE"] = "cnb_create_issue";
|
|
21
|
+
ToolNames["UPDATE_ISSUE"] = "cnb_update_issue";
|
|
22
|
+
ToolNames["LIST_ISSUE_COMMENTS"] = "cnb_list_issue_comments";
|
|
23
|
+
ToolNames["CREATE_ISSUE_COMMENT"] = "cnb_create_issue_comment";
|
|
24
|
+
ToolNames["UPDATE_ISSUE_COMMENT"] = "cnb_update_issue_comment";
|
|
25
|
+
ToolNames["LIST_ISSUE_LABELS"] = "cnb_list_issue_labels";
|
|
26
|
+
ToolNames["ADD_ISSUE_LABELS"] = "cnb_add_issue_labels";
|
|
27
|
+
ToolNames["SET_ISSUE_LABELS"] = "cnb_set_issue_labels";
|
|
28
|
+
ToolNames["CLEAR_ISSUE_LABELS"] = "cnb_clear_issue_labels";
|
|
29
|
+
ToolNames["REMOVE_ISSUE_LABEL"] = "cnb_remove_issue_label";
|
|
30
|
+
// 合并请求工具
|
|
31
|
+
ToolNames["LIST_PULLS"] = "cnb_list_pulls";
|
|
32
|
+
ToolNames["GET_PULL"] = "cnb_get_pull";
|
|
33
|
+
ToolNames["CREATE_PULL"] = "cnb_create_pull";
|
|
34
|
+
ToolNames["UPDATE_PULL"] = "cnb_update_pull";
|
|
35
|
+
ToolNames["MERGE_PULL"] = "cnb_merge_pull";
|
|
36
|
+
ToolNames["LIST_PULL_COMMENTS"] = "cnb_list_pull_comments";
|
|
37
|
+
ToolNames["CREATE_PULL_COMMENT"] = "cnb_create_pull_comment";
|
|
38
|
+
// 云原生开发工具
|
|
39
|
+
ToolNames["LIST_WORKSPACES"] = "cnb_list_workspaces";
|
|
40
|
+
ToolNames["DELETE_WORKSPACE"] = "cnb_delete_workspace";
|
|
41
|
+
})(ToolNames || (exports.ToolNames = ToolNames = {}));
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isRepoPublic = isRepoPublic;
|
|
4
|
+
const index_js_1 = require("../constants/index.js");
|
|
5
|
+
const repository_js_1 = require("../api/repository.js");
|
|
6
|
+
const formatRepoUrl_js_1 = require("./formatRepoUrl.js");
|
|
7
|
+
async function isRepoPublic(url) {
|
|
8
|
+
const repoPath = (0, formatRepoUrl_js_1.getRepoPath)(url);
|
|
9
|
+
if (!repoPath)
|
|
10
|
+
return true;
|
|
11
|
+
try {
|
|
12
|
+
const { visibility_level } = await (0, repository_js_1.getRepository)(repoPath);
|
|
13
|
+
// @ts-expect-error 字段类型转换过,但 swagger 无法感知
|
|
14
|
+
return visibility_level === index_js_1.RepoVisibility.public;
|
|
15
|
+
}
|
|
16
|
+
catch (_a) {
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createMcpServer = createMcpServer;
|
|
4
|
+
const mcp_js_1 = require("@modelcontextprotocol/sdk/server/mcp.js");
|
|
5
|
+
const index_js_1 = require("../tools/index.js");
|
|
6
|
+
const package_json_1 = require("../../package.json");
|
|
7
|
+
function createMcpServer(req) {
|
|
8
|
+
var _a;
|
|
9
|
+
const mcpServer = new mcp_js_1.McpServer({
|
|
7
10
|
name: 'cnb-mcp-server',
|
|
8
|
-
version:
|
|
11
|
+
version: package_json_1.version
|
|
9
12
|
});
|
|
10
|
-
const token = req
|
|
11
|
-
registerTools(mcpServer, token);
|
|
13
|
+
const token = (_a = req === null || req === void 0 ? void 0 : req.headers['authorization']) === null || _a === void 0 ? void 0 : _a.split(' ')[1];
|
|
14
|
+
(0, index_js_1.registerTools)(mcpServer, token);
|
|
12
15
|
return mcpServer;
|
|
13
16
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getRepoPath = getRepoPath;
|
|
4
|
+
function getRepoPath(url) {
|
|
5
|
+
let repoPath = '';
|
|
6
|
+
if (!url)
|
|
7
|
+
return repoPath;
|
|
8
|
+
try {
|
|
9
|
+
const urlObj = new URL(url);
|
|
10
|
+
// Remove leading /
|
|
11
|
+
repoPath = urlObj.pathname.substring(1);
|
|
12
|
+
}
|
|
13
|
+
catch (_a) {
|
|
14
|
+
// ssh format address
|
|
15
|
+
repoPath = url.split(':')[1];
|
|
16
|
+
}
|
|
17
|
+
// Remove tailing .git
|
|
18
|
+
repoPath = repoPath.replace(/\.git$/, '');
|
|
19
|
+
return repoPath;
|
|
20
|
+
}
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formatTextToolResult = formatTextToolResult;
|
|
4
|
+
exports.formatToolError = formatToolError;
|
|
5
|
+
function formatTextToolResult(text, toolName) {
|
|
2
6
|
return {
|
|
3
7
|
content: [
|
|
4
8
|
{
|
|
@@ -8,7 +12,7 @@ export function formatTextToolResult(text, toolName) {
|
|
|
8
12
|
]
|
|
9
13
|
};
|
|
10
14
|
}
|
|
11
|
-
|
|
15
|
+
function formatToolError(error, toolName) {
|
|
12
16
|
return {
|
|
13
17
|
content: [
|
|
14
18
|
{
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.stopWithWrongTransport = stopWithWrongTransport;
|
|
4
|
+
function stopWithWrongTransport(res) {
|
|
2
5
|
res.status(400).json({
|
|
3
6
|
jsonrpc: '2.0',
|
|
4
7
|
error: {
|