UNPKG

@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

63 lines (62 loc) 3.44 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = registerWorkspaceTools; const zod_1 = require("zod"); const toolNames_js_1 = require("../constants/toolNames.js"); const toolDescriptions_js_1 = require("../constants/toolDescriptions.js"); const workspace_js_1 = require("../api/workspace.js"); const formatToolResult_js_1 = require("../helpers/formatToolResult.js"); function registerWorkspaceTools(server, client) { server.tool(toolNames_js_1.ToolNames.LIST_WORKSPACES, toolDescriptions_js_1.toolDescriptions[toolNames_js_1.ToolNames.LIST_WORKSPACES], { 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)(client, { branch, page, pageSize: page_size, start, end, slug, status }); return (0, formatToolResult_js_1.formatTextToolResult)(JSON.stringify(workspaces, null, 2), toolNames_js_1.ToolNames.LIST_WORKSPACES); } catch (error) { return (0, formatToolResult_js_1.formatToolError)(error, toolNames_js_1.ToolNames.LIST_WORKSPACES); } }); server.tool(toolNames_js_1.ToolNames.DELETE_WORKSPACE, toolDescriptions_js_1.toolDescriptions[toolNames_js_1.ToolNames.DELETE_WORKSPACE], { pipelineId: zod_1.z.string().describe('开发环境 ID') }, async ({ pipelineId }) => { try { const result = await (0, workspace_js_1.deleteWorkspace)(client, { pipelineId }); return (0, formatToolResult_js_1.formatTextToolResult)(JSON.stringify(result, null, 2), toolNames_js_1.ToolNames.DELETE_WORKSPACE); } catch (error) { return (0, formatToolResult_js_1.formatToolError)(error, toolNames_js_1.ToolNames.DELETE_WORKSPACE); } }); }