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

118 lines (117 loc) 4.45 kB
import { z } from 'zod'; import { createIssue, getIssue, listIssues } from '../api/issue.js'; export default function registerIssueTools(server) { server.tool('list-issues', '查询仓库的 Issues', { repo: z.string().describe('仓库路径'), page: z.number().optional().describe('第几页,从1开始'), page_size: z.number().optional().describe('每页多少条数据'), state: z.enum(['open', 'closed']).optional().describe('Issue 状态'), keyword: z.string().optional().describe('Issue 关键字'), priority: z.string().optional().describe('Issue 优先级'), labels: z.string().optional().describe('Issue 标签'), authors: z.string().optional().describe('Issue 作者的名字'), assignees: z.string().optional().describe('Issue 处理人'), updated_time_begin: z.string().optional().describe('Issue 更新时间的范围,开始时间点'), updated_time_end: z.string().optional().describe('Issue 更新时间的范围,结束时间点'), order_by: z.string().optional().describe('Issue 排序顺序') }, async ({ repo, page, page_size, state, keyword, priority, labels, authors, assignees, updated_time_begin, updated_time_end, order_by }) => { try { const issues = await listIssues(repo, { page, page_size, state, keyword, priority, labels, authors, assignees, updated_time_begin, updated_time_end, order_by }); return { content: [ { type: 'text', text: JSON.stringify(issues, null, 2) } ] }; } catch (error) { return { content: [ { type: 'text', text: `Error listing issues: ${error instanceof Error ? error.message : String(error)}` } ], isError: true }; } }); server.tool('get-issue', '获取指定 Issue 信息', { repo: z.string().describe('仓库路径'), issueId: z.number().describe('Issue ID') }, async ({ repo, issueId }) => { try { const issues = await getIssue(repo, issueId); return { content: [ { type: 'text', text: JSON.stringify(issues, null, 2) } ] }; } catch (error) { return { content: [ { type: 'text', text: `Error listing issues: ${error instanceof Error ? error.message : String(error)}` } ], isError: true }; } }); server.tool('create-issue', '创建一个 Issue', { repo: z.string().describe('仓库路径'), title: z.string().describe('Issue 标题'), body: z.string().optional().describe('Issue 描述'), assignees: z.array(z.string()).optional().describe('一个或多个 Issue 处理人的用户名'), labels: z.array(z.string()).optional().describe('一个或多个 Issue 标签'), priority: z.string().optional().describe('Issue 优先级') }, async ({ repo, title, body, assignees, labels, priority }) => { try { const issue = await createIssue(repo, { title, body, assignees, labels, priority }); return { content: [ { type: 'text', text: `Issue created successfully:\n${JSON.stringify(issue, null, 2)}` } ] }; } catch (error) { return { content: [ { type: 'text', text: `Error creating issue: ${error instanceof Error ? error.message : String(error)}` } ], isError: true }; } }); }