@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
79 lines (78 loc) • 2.9 kB
JavaScript
import { z } from 'zod';
import { deleteWorkspace, listWorkspace } from '../api/workspace.js';
export default function registerWorkspaceTools(server) {
server.tool('list-workspace', '获取我的云原生开发环境列表', {
branch: z.string().optional().describe('分支名,例如:main'),
start: z
.string()
.optional()
.describe('查询结束时间,格式:YYYY-MM-DD HH:mm:ssZZ,例如:2024-12-01 00:00:00+0800'),
end: z.string().optional().describe('查询开始时间,格式:YYYY-MM-DD HH:mm:ssZZ,例如:2024-12-01 00:00:00+0800'),
page: z.number().optional().describe('分页页码,从 1 开始,默认为 1'),
page_size: z.number().optional().describe('每页条数,默认为 20,最高 100'),
slug: z.string().optional().describe('仓库路径,例如:groupname/reponame'),
status: z
.enum(['running', 'closed'])
.optional()
.describe('开发环境状态,running: 开发环境已启动,closed:开发环境已关闭,默认为所有状态')
}, async ({ branch, page, page_size, start, end, slug, status }) => {
try {
const workspaces = await listWorkspace({
branch,
page,
pageSize: page_size,
start,
end,
slug,
status
});
return {
content: [
{
type: 'text',
text: JSON.stringify(workspaces, null, 2)
}
]
};
}
catch (error) {
return {
content: [
{
type: 'text',
text: `Error listing workspace: ${error instanceof Error ? error.message : String(error)}`
}
],
isError: true
};
}
});
server.tool('delete-workspace', '删除我的云原生开发环境', {
pipelineId: z.string().describe('开发环境 ID')
}, async ({ pipelineId }) => {
try {
const result = await deleteWorkspace({
pipelineId
});
return {
content: [
{
type: 'text',
text: JSON.stringify(result, null, 2)
}
]
};
}
catch (error) {
return {
content: [
{
type: 'text',
text: `error delete workspace: ${error instanceof Error ? error.message : String(error)}`
}
],
isError: true
};
}
});
}