@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
61 lines (60 loc) • 3.05 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = registerWorkspaceTools;
const zod_1 = require("zod");
const workspace_js_1 = require("../api/workspace.js");
const formatToolResult_js_1 = require("../helpers/formatToolResult.js");
function registerWorkspaceTools(server) {
server.tool('list-workspace', '获取我的云原生开发环境列表', {
branch: zod_1.z
.preprocess((val) => (val === null ? undefined : val), zod_1.z.string().optional())
.describe('分支名,例如:main'),
start: zod_1.z
.preprocess((val) => (val === null ? undefined : val), zod_1.z.string().optional())
.describe('查询结束时间,格式:YYYY-MM-DD HH:mm:ssZZ,例如:2024-12-01 00:00:00+0800'),
end: zod_1.z
.preprocess((val) => (val === null ? undefined : val), zod_1.z.string().optional())
.describe('查询开始时间,格式:YYYY-MM-DD HH:mm:ssZZ,例如:2024-12-01 00:00:00+0800'),
page: zod_1.z
.preprocess((val) => (val === null ? undefined : val), zod_1.z.number().optional())
.describe('分页页码,从 1 开始,默认为 1'),
page_size: zod_1.z
.preprocess((val) => (val === null ? undefined : val), zod_1.z.number().optional())
.describe('每页条数,默认为 20,最高 100'),
slug: zod_1.z
.preprocess((val) => (val === null ? undefined : val), zod_1.z.string().optional())
.describe('仓库路径,例如:groupname/reponame'),
status: zod_1.z
.preprocess((val) => (val === null ? undefined : val), zod_1.z.enum(['running', 'closed']).optional())
.describe('开发环境状态,running: 开发环境已启动,closed:开发环境已关闭,默认为所有状态')
}, async ({ branch, page, page_size, start, end, slug, status }) => {
try {
const workspaces = await (0, workspace_js_1.listWorkspace)({
branch,
page,
pageSize: page_size,
start,
end,
slug,
status
});
return (0, formatToolResult_js_1.formatTextToolResult)(JSON.stringify(workspaces, null, 2), 'list-workspace');
}
catch (error) {
return (0, formatToolResult_js_1.formatToolError)(error, 'list-workspace');
}
});
server.tool('delete-workspace', '删除我的云原生开发环境', {
pipelineId: zod_1.z.string().describe('开发环境 ID')
}, async ({ pipelineId }) => {
try {
const result = await (0, workspace_js_1.deleteWorkspace)({
pipelineId
});
return (0, formatToolResult_js_1.formatTextToolResult)(JSON.stringify(result, null, 2), 'delete-workspace');
}
catch (error) {
return (0, formatToolResult_js_1.formatToolError)(error, 'delete-workspace');
}
});
}