@cnbcool/mcp-server 0.3.1 → 0.3.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/CHANGELOG.md +24 -0
- package/dist/api/client.js +8 -1
- package/dist/api/group.js +46 -0
- package/dist/api/repository.js +17 -0
- package/dist/api/user.js +5 -0
- package/dist/tools/groupTools.js +121 -0
- package/dist/tools/index.js +4 -2
- package/dist/tools/repoTools.js +39 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,27 @@
|
|
|
1
|
+
## 0.3.3 (May 7, 2025)
|
|
2
|
+
|
|
3
|
+
### Bug Fixes
|
|
4
|
+
|
|
5
|
+
- Format repository creation response
|
|
6
|
+
- Format group creation response
|
|
7
|
+
|
|
8
|
+
## 0.3.2 (May 6, 2025)
|
|
9
|
+
|
|
10
|
+
### New Features
|
|
11
|
+
|
|
12
|
+
- Supports list groups with various filters
|
|
13
|
+
- Supports list sub-groups with various filters
|
|
14
|
+
- Supports get group details
|
|
15
|
+
- Supports create group
|
|
16
|
+
- Supports create repository
|
|
17
|
+
|
|
18
|
+
## 0.3.1 (April 23, 2025)
|
|
19
|
+
|
|
20
|
+
### New Features
|
|
21
|
+
|
|
22
|
+
- Bump to @modelcontextprotocol/sdk 1.10.2
|
|
23
|
+
- Add zod preprocess, convert null to undefined
|
|
24
|
+
|
|
1
25
|
## 0.3.0 (April 23, 2025)
|
|
2
26
|
|
|
3
27
|
### New Features
|
package/dist/api/client.js
CHANGED
|
@@ -20,7 +20,8 @@ export default class CnbApiClient {
|
|
|
20
20
|
}
|
|
21
21
|
return CnbApiClient.instance;
|
|
22
22
|
}
|
|
23
|
-
async request(method, path, body, config
|
|
23
|
+
async request(method, path, body, config, responseType = 'json' // 'json' | 'text' | 'raw'
|
|
24
|
+
) {
|
|
24
25
|
const url = `${this._baseUrl}${path}`;
|
|
25
26
|
const headers = {
|
|
26
27
|
Authorization: `Bearer ${this._token}`,
|
|
@@ -37,6 +38,12 @@ export default class CnbApiClient {
|
|
|
37
38
|
const errorText = await response.text();
|
|
38
39
|
throw new Error(`API request failed: ${response.status} ${errorText}`);
|
|
39
40
|
}
|
|
41
|
+
if (responseType === 'raw') {
|
|
42
|
+
return response;
|
|
43
|
+
}
|
|
44
|
+
if (responseType === 'text') {
|
|
45
|
+
return response.text();
|
|
46
|
+
}
|
|
40
47
|
return response.json();
|
|
41
48
|
}
|
|
42
49
|
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import CnbApiClient from './client.js';
|
|
2
|
+
export async function listGroups(params) {
|
|
3
|
+
const cnbInst = CnbApiClient.getInstance();
|
|
4
|
+
const url = new URL('/user/groups', cnbInst.baseUrl);
|
|
5
|
+
if (params) {
|
|
6
|
+
for (const [key, value] of Object.entries(params)) {
|
|
7
|
+
if (value === undefined)
|
|
8
|
+
continue;
|
|
9
|
+
url.searchParams.set(key, value.toString());
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
return cnbInst.request('GET', `${url.pathname}${url.search}`);
|
|
13
|
+
}
|
|
14
|
+
export async function listSubGroups(group, params) {
|
|
15
|
+
const cnbInst = CnbApiClient.getInstance();
|
|
16
|
+
const url = new URL(`/user/groups/${group}`, cnbInst.baseUrl);
|
|
17
|
+
if (params) {
|
|
18
|
+
for (const [key, value] of Object.entries(params)) {
|
|
19
|
+
if (value === undefined)
|
|
20
|
+
continue;
|
|
21
|
+
url.searchParams.set(key, value.toString());
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return cnbInst.request('GET', `${url.pathname}${url.search}`);
|
|
25
|
+
}
|
|
26
|
+
export async function getGroup(group) {
|
|
27
|
+
const cnbInst = CnbApiClient.getInstance();
|
|
28
|
+
return cnbInst.request('GET', `/${group}`);
|
|
29
|
+
}
|
|
30
|
+
export async function createGroup(params) {
|
|
31
|
+
const body = Object.entries(params).reduce((acc, [key, value]) => {
|
|
32
|
+
if (value === undefined)
|
|
33
|
+
return acc;
|
|
34
|
+
Object.assign(acc, { [key]: value });
|
|
35
|
+
return acc;
|
|
36
|
+
}, {});
|
|
37
|
+
const response = await CnbApiClient.getInstance().request('POST', '/groups', body, {
|
|
38
|
+
header: { 'Content-Type': 'application/json' }
|
|
39
|
+
}, 'raw');
|
|
40
|
+
if (response.status === 201) {
|
|
41
|
+
return { message: 'Created' };
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
return { status: response.status, message: response.statusText };
|
|
45
|
+
}
|
|
46
|
+
}
|
package/dist/api/repository.js
CHANGED
|
@@ -26,3 +26,20 @@ export async function listGroupRepositories(group, params) {
|
|
|
26
26
|
export async function getRepository(repo) {
|
|
27
27
|
return CnbApiClient.getInstance().request('GET', `/${repo}`);
|
|
28
28
|
}
|
|
29
|
+
export async function createRepository(group, params) {
|
|
30
|
+
const body = Object.entries(params).reduce((acc, [key, value]) => {
|
|
31
|
+
if (value === undefined)
|
|
32
|
+
return acc;
|
|
33
|
+
Object.assign(acc, { [key]: value });
|
|
34
|
+
return acc;
|
|
35
|
+
}, {});
|
|
36
|
+
const response = await CnbApiClient.getInstance().request('POST', `/${group}/-/repos`, body, {
|
|
37
|
+
header: { 'Content-Type': 'application/json' }
|
|
38
|
+
}, 'raw');
|
|
39
|
+
if (response.status === 201) {
|
|
40
|
+
return { message: 'Created' };
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
return { status: response.status, message: response.statusText };
|
|
44
|
+
}
|
|
45
|
+
}
|
package/dist/api/user.js
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { createGroup, getGroup, listGroups, listSubGroups } from '../api/group.js';
|
|
3
|
+
export default function registerGroupTools(server) {
|
|
4
|
+
server.tool('list-groups', '获取当前用户拥有权限的顶层组织列表', {
|
|
5
|
+
page: z.number().default(1).describe('第几页,从1开始'),
|
|
6
|
+
page_size: z.number().default(10).describe('每页多少条数据'),
|
|
7
|
+
search: z.preprocess((val) => (val === null ? undefined : val), z.string().optional()).describe('仓库关键字'),
|
|
8
|
+
role: z
|
|
9
|
+
.preprocess((val) => (val === null ? undefined : val), z.enum(['Guest', 'Reporter', 'Developer', 'Master', 'Owner']).optional())
|
|
10
|
+
.describe('最小仓库权限')
|
|
11
|
+
}, async ({ page, page_size, search, role }) => {
|
|
12
|
+
try {
|
|
13
|
+
const repos = await listGroups({ page, page_size, search, role });
|
|
14
|
+
return {
|
|
15
|
+
content: [
|
|
16
|
+
{
|
|
17
|
+
type: 'text',
|
|
18
|
+
text: JSON.stringify(repos, null, 2)
|
|
19
|
+
}
|
|
20
|
+
]
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
return {
|
|
25
|
+
content: [
|
|
26
|
+
{
|
|
27
|
+
type: 'text',
|
|
28
|
+
text: `Error listing repositories: ${error instanceof Error ? error.message : String(error)}`
|
|
29
|
+
}
|
|
30
|
+
],
|
|
31
|
+
isError: true
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
server.tool('list-sub-groups', '查询当前用户在指定组织下拥有指定权限的子组织列表', {
|
|
36
|
+
group: z.string().describe('组织名称'),
|
|
37
|
+
page: z.number().default(1).describe('第几页,从1开始'),
|
|
38
|
+
page_size: z.number().default(10).describe('每页多少条数据'),
|
|
39
|
+
access: z.preprocess((val) => (val === null ? undefined : val), z.number().optional()).describe('权限等级')
|
|
40
|
+
}, async ({ group, page, page_size, access }) => {
|
|
41
|
+
try {
|
|
42
|
+
const subGroups = await listSubGroups(group, { page, page_size, access });
|
|
43
|
+
return {
|
|
44
|
+
content: [
|
|
45
|
+
{
|
|
46
|
+
type: 'text',
|
|
47
|
+
text: JSON.stringify(subGroups, null, 2)
|
|
48
|
+
}
|
|
49
|
+
]
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
return {
|
|
54
|
+
content: [
|
|
55
|
+
{
|
|
56
|
+
type: 'text',
|
|
57
|
+
text: `Error listing repositories: ${error instanceof Error ? error.message : String(error)}`
|
|
58
|
+
}
|
|
59
|
+
],
|
|
60
|
+
isError: true
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
server.tool('get-group', '获取指定组织信息', {
|
|
65
|
+
group: z.string().describe('组织路径')
|
|
66
|
+
}, async ({ group }) => {
|
|
67
|
+
try {
|
|
68
|
+
const data = await getGroup(group);
|
|
69
|
+
return {
|
|
70
|
+
content: [
|
|
71
|
+
{
|
|
72
|
+
type: 'text',
|
|
73
|
+
text: JSON.stringify(data, null, 2)
|
|
74
|
+
}
|
|
75
|
+
]
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
return {
|
|
80
|
+
content: [
|
|
81
|
+
{
|
|
82
|
+
type: 'text',
|
|
83
|
+
text: `Error getting repository: ${error instanceof Error ? error.message : String(error)}`
|
|
84
|
+
}
|
|
85
|
+
],
|
|
86
|
+
isError: true
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
server.tool('create-group', '创建新组织', {
|
|
91
|
+
path: z.string().describe('组织路径'),
|
|
92
|
+
description: z.preprocess((val) => (val === null ? undefined : val), z.string().optional()).describe('组织描述'),
|
|
93
|
+
remark: z.preprocess((val) => (val === null ? undefined : val), z.string().optional()).describe('仓库备注'),
|
|
94
|
+
bind_domain: z
|
|
95
|
+
.preprocess((val) => (val === null ? undefined : val), z.string().optional())
|
|
96
|
+
.describe('根组织绑定的域名')
|
|
97
|
+
}, async ({ path, description, remark, bind_domain }) => {
|
|
98
|
+
try {
|
|
99
|
+
const data = await createGroup({ path, description, remark, bind_domain });
|
|
100
|
+
return {
|
|
101
|
+
content: [
|
|
102
|
+
{
|
|
103
|
+
type: 'text',
|
|
104
|
+
text: JSON.stringify(data, null, 2)
|
|
105
|
+
}
|
|
106
|
+
]
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
return {
|
|
111
|
+
content: [
|
|
112
|
+
{
|
|
113
|
+
type: 'text',
|
|
114
|
+
text: `Error creating repository: ${error instanceof Error ? error.message : String(error)}`
|
|
115
|
+
}
|
|
116
|
+
],
|
|
117
|
+
isError: true
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
}
|
package/dist/tools/index.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import CnbApiClient from '../api/client.js';
|
|
2
|
+
import registerGroupTools from './groupTools.js';
|
|
2
3
|
import registerRepoTools from './repoTools.js';
|
|
3
4
|
import registerIssueTools from './issueTools.js';
|
|
4
5
|
import registerWorkspaceTools from './workspaceTools.js';
|
|
5
|
-
export function registerTools(server
|
|
6
|
+
export function registerTools(server) {
|
|
6
7
|
CnbApiClient.initialize({
|
|
7
8
|
baseUrl: process.env.API_BASE_URL || 'https://api.cnb.cool',
|
|
8
|
-
token: process.env.API_TOKEN ||
|
|
9
|
+
token: process.env.API_TOKEN || ''
|
|
9
10
|
});
|
|
11
|
+
registerGroupTools(server);
|
|
10
12
|
registerRepoTools(server);
|
|
11
13
|
registerIssueTools(server);
|
|
12
14
|
registerWorkspaceTools(server);
|
package/dist/tools/repoTools.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import { getRepository, listGroupRepositories, listRepositories } from '../api/repository.js';
|
|
2
|
+
import { createRepository, getRepository, listGroupRepositories, listRepositories } from '../api/repository.js';
|
|
3
|
+
import { getUser } from '../api/user.js';
|
|
3
4
|
export default function registerRepoTools(server) {
|
|
4
5
|
server.tool('list-repositories', '获取当前用户拥有指定权限及其以上权限的仓库', {
|
|
5
6
|
page: z.number().default(1).describe('第几页,从1开始'),
|
|
@@ -112,4 +113,41 @@ export default function registerRepoTools(server) {
|
|
|
112
113
|
};
|
|
113
114
|
}
|
|
114
115
|
});
|
|
116
|
+
server.tool('create-repository', '创建仓库', {
|
|
117
|
+
group: z.preprocess((val) => (val === null ? undefined : val), z.string().optional()).describe('仓库所属分组'),
|
|
118
|
+
name: z.string().describe('仓库名称'),
|
|
119
|
+
description: z.preprocess((val) => (val === null ? undefined : val), z.string().optional()).describe('仓库描述'),
|
|
120
|
+
license: z.preprocess((val) => (val === null ? undefined : val), z.string().optional()).describe('仓库许可'),
|
|
121
|
+
visibility: z
|
|
122
|
+
.preprocess((val) => (val === null ? undefined : val), z.enum(['public', 'private', 'secret']).default('public'))
|
|
123
|
+
.describe('仓库可见性')
|
|
124
|
+
}, async ({ group, name, description, license, visibility }) => {
|
|
125
|
+
let repoGroup = group;
|
|
126
|
+
if (!repoGroup) {
|
|
127
|
+
const { username = '' } = await getUser();
|
|
128
|
+
repoGroup = username;
|
|
129
|
+
}
|
|
130
|
+
try {
|
|
131
|
+
const data = await createRepository(repoGroup, { name, description, license, visibility });
|
|
132
|
+
return {
|
|
133
|
+
content: [
|
|
134
|
+
{
|
|
135
|
+
type: 'text',
|
|
136
|
+
text: JSON.stringify(data, null, 2)
|
|
137
|
+
}
|
|
138
|
+
]
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
catch (error) {
|
|
142
|
+
return {
|
|
143
|
+
content: [
|
|
144
|
+
{
|
|
145
|
+
type: 'text',
|
|
146
|
+
text: `Error creating repository: ${error instanceof Error ? error.message : String(error)}`
|
|
147
|
+
}
|
|
148
|
+
],
|
|
149
|
+
isError: true
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
});
|
|
115
153
|
}
|
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.3.
|
|
4
|
+
"version": "0.3.3",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"bin": {
|
|
7
7
|
"cnb-mcp-server": "dist/index.js"
|