@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
68 lines (67 loc) • 4.28 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = registerGroupTools;
const zod_1 = require("zod");
const toolNames_js_1 = require("../constants/toolNames.js");
const toolDescriptions_js_1 = require("../constants/toolDescriptions.js");
const group_js_1 = require("../api/group.js");
const formatToolResult_js_1 = require("../helpers/formatToolResult.js");
function registerGroupTools(server, client) {
server.tool(toolNames_js_1.ToolNames.LIST_GROUPS, toolDescriptions_js_1.toolDescriptions[toolNames_js_1.ToolNames.LIST_GROUPS], {
page: zod_1.z.number().default(1).describe('第几页,从1开始'),
page_size: zod_1.z.number().default(10).describe('每页多少条数据'),
search: zod_1.z.preprocess((val) => (val === null ? undefined : val), zod_1.z.string().optional()).describe('仓库关键字'),
role: zod_1.z
.preprocess((val) => (val === null ? undefined : val), zod_1.z.enum(['Guest', 'Reporter', 'Developer', 'Master', 'Owner']).optional())
.describe('最小仓库权限')
}, async ({ page, page_size, search, role }) => {
try {
const groups = await (0, group_js_1.listGroups)(client, { page, page_size, search, role });
return (0, formatToolResult_js_1.formatTextToolResult)(JSON.stringify(groups, null, 2), toolNames_js_1.ToolNames.LIST_GROUPS);
}
catch (error) {
return (0, formatToolResult_js_1.formatToolError)(error, toolNames_js_1.ToolNames.LIST_GROUPS);
}
});
server.tool(toolNames_js_1.ToolNames.LIST_SUB_GROUPS, toolDescriptions_js_1.toolDescriptions[toolNames_js_1.ToolNames.LIST_SUB_GROUPS], {
group: zod_1.z.string().describe('组织名称'),
page: zod_1.z.number().default(1).describe('第几页,从1开始'),
page_size: zod_1.z.number().default(10).describe('每页多少条数据'),
access: zod_1.z.preprocess((val) => (val === null ? undefined : val), zod_1.z.number().optional()).describe('权限等级')
}, async ({ group, page, page_size, access }) => {
try {
const subGroups = await (0, group_js_1.listSubGroups)(client, group, { page, page_size, access });
return (0, formatToolResult_js_1.formatTextToolResult)(JSON.stringify(subGroups, null, 2), toolNames_js_1.ToolNames.LIST_SUB_GROUPS);
}
catch (error) {
return (0, formatToolResult_js_1.formatToolError)(error, toolNames_js_1.ToolNames.LIST_SUB_GROUPS);
}
});
server.tool(toolNames_js_1.ToolNames.GET_GROUP, toolDescriptions_js_1.toolDescriptions[toolNames_js_1.ToolNames.GET_GROUP], {
group: zod_1.z.string().describe('组织路径')
}, async ({ group }) => {
try {
const groupInfo = await (0, group_js_1.getGroup)(client, group);
return (0, formatToolResult_js_1.formatTextToolResult)(JSON.stringify(groupInfo, null, 2), toolNames_js_1.ToolNames.GET_GROUP);
}
catch (error) {
return (0, formatToolResult_js_1.formatToolError)(error, toolNames_js_1.ToolNames.GET_GROUP);
}
});
server.tool(toolNames_js_1.ToolNames.CREATE_GROUP, toolDescriptions_js_1.toolDescriptions[toolNames_js_1.ToolNames.CREATE_GROUP], {
path: zod_1.z.string().describe('组织路径'),
description: zod_1.z.preprocess((val) => (val === null ? undefined : val), zod_1.z.string().optional()).describe('组织描述'),
remark: zod_1.z.preprocess((val) => (val === null ? undefined : val), zod_1.z.string().optional()).describe('仓库备注'),
bind_domain: zod_1.z
.preprocess((val) => (val === null ? undefined : val), zod_1.z.string().optional())
.describe('根组织绑定的域名')
}, async ({ path, description, remark, bind_domain }) => {
try {
const data = await (0, group_js_1.createGroup)(client, { path, description, remark, bind_domain });
return (0, formatToolResult_js_1.formatTextToolResult)(JSON.stringify(data, null, 2), toolNames_js_1.ToolNames.CREATE_GROUP);
}
catch (error) {
return (0, formatToolResult_js_1.formatToolError)(error, toolNames_js_1.ToolNames.CREATE_GROUP);
}
});
}