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

122 lines (121 loc) 6.58 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = registerPullTools; const zod_1 = require("zod"); const pull_js_1 = require("../api/pull.js"); const formatToolResult_js_1 = require("../helpers/formatToolResult.js"); function registerPullTools(server) { server.tool('list-pulls', '查询仓库的Pull Requests', { repo: zod_1.z.string().describe('仓库路径,格式为 {group}/{repo}'), state: zod_1.z .preprocess((val) => (val === null ? undefined : val), zod_1.z.enum(['open', 'closed', 'all']).optional()) .describe('Pull Request状态'), sort: zod_1.z .preprocess((val) => (val === null ? undefined : val), zod_1.z.enum(['created', 'updated']).optional()) .describe('排序字段'), direction: zod_1.z .preprocess((val) => (val === null ? undefined : val), zod_1.z.enum(['asc', 'desc']).optional()) .describe('排序方向'), page: zod_1.z.number().default(1).describe('页码'), per_page: zod_1.z.number().default(30).describe('每页数量') }, async ({ repo, ...params }) => { try { const pulls = await (0, pull_js_1.listPulls)(repo, params); return (0, formatToolResult_js_1.formatTextToolResult)(JSON.stringify(pulls, null, 2), 'list-pulls'); } catch (error) { return (0, formatToolResult_js_1.formatToolError)(error, 'list-pulls'); } }); server.tool('get-pull', '获取单个Pull Request详情', { repo: zod_1.z.string().describe('仓库路径,格式为 {group}/{repo}'), number: zod_1.z.number().describe('Pull Request编号') }, async ({ repo, number }) => { try { const pull = await (0, pull_js_1.getPull)(repo, number); return (0, formatToolResult_js_1.formatTextToolResult)(JSON.stringify(pull, null, 2), 'get-pull'); } catch (error) { return (0, formatToolResult_js_1.formatToolError)(error, 'get-pull'); } }); server.tool('create-pull', '创建Pull Request', { repo: zod_1.z.string().describe('目标仓库路径,格式为 {group}/{repo}'), base: zod_1.z.string().describe('目标仓库目标分支'), head_repo: zod_1.z.string().optional().describe('来源仓库路径,格式为 {group}/{repo},不填则为目标仓库'), head: zod_1.z.string().describe('来源仓库分支'), title: zod_1.z.string().describe('标题'), body: zod_1.z.preprocess((val) => (val === null ? undefined : val), zod_1.z.string().optional()).describe('描述') }, async ({ repo, ...params }) => { try { const pull = await (0, pull_js_1.createPull)(repo, params); return (0, formatToolResult_js_1.formatTextToolResult)(JSON.stringify(pull, null, 2), 'create-pull'); } catch (error) { return (0, formatToolResult_js_1.formatToolError)(error, 'create-pull'); } }); server.tool('update-pull', '更新Pull Request', { repo: zod_1.z.string().describe('仓库路径,格式为 {group}/{repo}'), number: zod_1.z.number().describe('Pull Request编号'), title: zod_1.z.preprocess((val) => (val === null ? undefined : val), zod_1.z.string().optional()).describe('标题'), body: zod_1.z.preprocess((val) => (val === null ? undefined : val), zod_1.z.string().optional()).describe('描述'), state: zod_1.z .preprocess((val) => (val === null ? undefined : val), zod_1.z.enum(['open', 'closed']).optional()) .describe('状态') }, async ({ repo, number, ...params }) => { try { const pull = await (0, pull_js_1.updatePull)(repo, number, params); return (0, formatToolResult_js_1.formatTextToolResult)(JSON.stringify(pull, null, 2), 'update-pull'); } catch (error) { return (0, formatToolResult_js_1.formatToolError)(error, 'update-pull'); } }); server.tool('merge-pull', '合并Pull Request', { repo: zod_1.z.string().describe('仓库路径,格式为 {group}/{repo}'), number: zod_1.z.number().describe('Pull Request编号'), merge_style: zod_1.z .preprocess((val) => (val === null ? undefined : val), zod_1.z.enum(['merge', 'squash', 'rebase']).optional()) .describe('合并方式'), commit_title: zod_1.z.preprocess((val) => (val === null ? undefined : val), zod_1.z.string()).describe('合并提交标题'), commit_message: zod_1.z .preprocess((val) => (val === null ? undefined : val), zod_1.z.string().optional()) .describe('合并提交信息') }, async ({ repo, number, ...params }) => { try { const result = await (0, pull_js_1.mergePull)(repo, number, params); return (0, formatToolResult_js_1.formatTextToolResult)(JSON.stringify(result, null, 2), 'merge-pull'); } catch (error) { return (0, formatToolResult_js_1.formatToolError)(error, 'merge-pull'); } }); server.tool('list-pull-comments', '列出Pull Request的评论', { repo: zod_1.z.string().describe('仓库路径,格式为 {group}/{repo}'), number: zod_1.z.number().describe('Pull Request编号'), page: zod_1.z.number().default(1).describe('页码'), per_page: zod_1.z.number().default(30).describe('每页数量') }, async ({ repo, number, ...params }) => { try { const comments = await (0, pull_js_1.listPullComments)(repo, number, params); return (0, formatToolResult_js_1.formatTextToolResult)(JSON.stringify(comments, null, 2), 'list-pull-comments'); } catch (error) { return (0, formatToolResult_js_1.formatToolError)(error, 'list-pull-comments'); } }); server.tool('create-pull-comment', '创建Pull Request评论', { repo: zod_1.z.string().describe('仓库路径,格式为 {group}/{repo}'), number: zod_1.z.number().describe('Pull Request编号'), body: zod_1.z.string().describe('评论内容') }, async ({ repo, number, body }) => { try { await (0, pull_js_1.createPullComment)(repo, number, { body }); return (0, formatToolResult_js_1.formatTextToolResult)('Comment created', 'create-pull-comment'); } catch (error) { return (0, formatToolResult_js_1.formatToolError)(error, 'create-pull-comment'); } }); }