mcp-server-bugzilla4 0.0.0-stage → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,159 @@
1
+ import { assertBugId, assertFieldName } from '../lib/search.js';
2
+ import { assertWritable, bugUrl } from './common.js';
3
+
4
+ const ADD_REMOVE = {
5
+ type: 'object',
6
+ properties: {
7
+ add: { type: 'array', items: { type: ['string', 'integer'] } },
8
+ remove: { type: 'array', items: { type: ['string', 'integer'] } },
9
+ },
10
+ additionalProperties: false,
11
+ };
12
+ const ADD_REMOVE_SET = {
13
+ type: 'object',
14
+ properties: {
15
+ add: { type: 'array', items: { type: ['string', 'integer'] } },
16
+ remove: { type: 'array', items: { type: ['string', 'integer'] } },
17
+ set: { type: 'array', items: { type: ['string', 'integer'] } },
18
+ },
19
+ additionalProperties: false,
20
+ };
21
+
22
+ /** Bug.update(4.0 新增)支持的普通字段 */
23
+ const UPDATABLE_FIELDS = [
24
+ 'status', 'resolution', 'dupe_of', 'assigned_to', 'qa_contact', 'priority', 'severity', 'version',
25
+ 'target_milestone', 'component', 'product', 'summary', 'whiteboard', 'op_sys', 'platform', 'url', 'alias', 'deadline',
26
+ ];
27
+
28
+ function addCustomFields(input, custom) {
29
+ for (const [k, v] of Object.entries(custom || {})) {
30
+ assertFieldName(k, 'custom_fields');
31
+ if (!k.startsWith('cf_')) throw new Error(`custom_fields 的键必须以 cf_ 开头:${k}`);
32
+ input[k] = v;
33
+ }
34
+ }
35
+
36
+ export const addComment = {
37
+ name: 'add_comment',
38
+ description: '给 Bug 添加评论(Bug.add_comment)。建议先 dry_run 预览。受 BUGZILLA_READ_ONLY 约束。',
39
+ inputSchema: {
40
+ type: 'object',
41
+ properties: {
42
+ id: { type: ['string', 'integer'] },
43
+ comment: { type: 'string', minLength: 1, maxLength: 65535 },
44
+ is_private: { type: 'boolean', default: false },
45
+ dry_run: { type: 'boolean', default: false },
46
+ },
47
+ required: ['id', 'comment'],
48
+ additionalProperties: false,
49
+ },
50
+ async handler(args, { client, config }) {
51
+ const id = assertBugId(args.id);
52
+ const request = { id, comment: args.comment, is_private: Boolean(args.is_private) };
53
+ if (args.dry_run) return { dry_run: true, request };
54
+ assertWritable(config);
55
+ const r = await client.addComment(id, args.comment, Boolean(args.is_private));
56
+ return { added: true, id, comment_id: r?.id, url: bugUrl(config, id) };
57
+ },
58
+ };
59
+
60
+ export const updateBug = {
61
+ name: 'update_bug',
62
+ description:
63
+ '更新一个或多个 Bug(Bug.update):状态 / 解决结果、处理人、优先级、严重程度、版本、里程碑、关键字、CC、依赖关系,可附带评论。' +
64
+ '自定义字段 cf_* 在部分 4.0 站点不被 Bug.update 支持,服务器会忽略或报错。建议先 dry_run。受 BUGZILLA_READ_ONLY 约束。',
65
+ inputSchema: {
66
+ type: 'object',
67
+ properties: {
68
+ ids: { type: 'array', items: { type: ['string', 'integer'] }, minItems: 1, maxItems: 100 },
69
+ status: { type: 'string' },
70
+ resolution: { type: 'string' },
71
+ dupe_of: { type: 'integer' },
72
+ assigned_to: { type: 'string' },
73
+ qa_contact: { type: 'string' },
74
+ priority: { type: 'string' },
75
+ severity: { type: 'string' },
76
+ version: { type: 'string' },
77
+ target_milestone: { type: 'string' },
78
+ component: { type: 'string' },
79
+ product: { type: 'string' },
80
+ summary: { type: 'string', maxLength: 255 },
81
+ whiteboard: { type: 'string' },
82
+ op_sys: { type: 'string' },
83
+ platform: { type: 'string' },
84
+ url: { type: 'string' },
85
+ alias: { type: 'string' },
86
+ deadline: { type: 'string' },
87
+ keywords: ADD_REMOVE_SET,
88
+ cc: ADD_REMOVE,
89
+ blocks: ADD_REMOVE_SET,
90
+ depends_on: ADD_REMOVE_SET,
91
+ custom_fields: { type: 'object', description: '自定义字段,键必须以 cf_ 开头' },
92
+ comment: { type: 'string', maxLength: 65535, description: '随更新附带的评论' },
93
+ comment_is_private: { type: 'boolean', default: false },
94
+ dry_run: { type: 'boolean', default: false },
95
+ },
96
+ required: ['ids'],
97
+ additionalProperties: false,
98
+ },
99
+ async handler(args, { client, config }) {
100
+ const ids = args.ids.map(assertBugId).map((v) => (/^\d+$/.test(v) ? Number(v) : v));
101
+ const input = { ids };
102
+ for (const f of UPDATABLE_FIELDS) if (args[f] !== undefined) input[f] = args[f];
103
+ for (const f of ['keywords', 'cc', 'blocks', 'depends_on']) if (args[f]) input[f] = args[f];
104
+ addCustomFields(input, args.custom_fields);
105
+ if (args.comment) input.comment = { body: args.comment, is_private: Boolean(args.comment_is_private) };
106
+ if (Object.keys(input).length === 1) throw new Error('没有任何要修改的字段');
107
+ const warning =
108
+ /^RESOLVED$/i.test(args.status || '') && !args.resolution && !args.dupe_of
109
+ ? '状态改为 RESOLVED 时通常需要 resolution(如 FIXED),否则 Bugzilla 会拒绝'
110
+ : undefined;
111
+
112
+ if (args.dry_run) return { dry_run: true, request: input, warning };
113
+ assertWritable(config);
114
+ const r = await client.update(input);
115
+ return {
116
+ updated: true,
117
+ warning,
118
+ bugs: (r?.bugs || []).map((b) => ({ id: b.id, last_change_time: b.last_change_time, changes: b.changes, url: bugUrl(config, b.id) })),
119
+ };
120
+ },
121
+ };
122
+
123
+ export const createBug = {
124
+ name: 'create_bug',
125
+ description: '创建新 Bug(Bug.create)。product / component / summary / version 为必填,description 为首条描述。建议先 dry_run。受 BUGZILLA_READ_ONLY 约束。',
126
+ inputSchema: {
127
+ type: 'object',
128
+ properties: {
129
+ product: { type: 'string' },
130
+ component: { type: 'string' },
131
+ summary: { type: 'string', maxLength: 255 },
132
+ version: { type: 'string' },
133
+ description: { type: 'string', maxLength: 65535 },
134
+ priority: { type: 'string' },
135
+ severity: { type: 'string' },
136
+ op_sys: { type: 'string' },
137
+ platform: { type: 'string' },
138
+ assigned_to: { type: 'string' },
139
+ qa_contact: { type: 'string' },
140
+ cc: { type: 'array', items: { type: 'string' } },
141
+ target_milestone: { type: 'string' },
142
+ status: { type: 'string', description: '初始状态,默认由站点决定' },
143
+ alias: { type: 'string' },
144
+ custom_fields: { type: 'object', description: '自定义字段,键必须以 cf_ 开头' },
145
+ dry_run: { type: 'boolean', default: false },
146
+ },
147
+ required: ['product', 'component', 'summary', 'version'],
148
+ additionalProperties: false,
149
+ },
150
+ async handler(args, { client, config }) {
151
+ const { dry_run: dryRun, custom_fields: custom, ...rest } = args;
152
+ const input = { ...rest };
153
+ addCustomFields(input, custom);
154
+ if (dryRun) return { dry_run: true, request: input };
155
+ assertWritable(config);
156
+ const r = await client.create(input);
157
+ return { created: true, id: r?.id, url: r?.id ? bugUrl(config, r.id) : undefined };
158
+ },
159
+ };