issue-scribe-mcp 1.1.0 → 1.3.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.
package/dist/index.js CHANGED
@@ -1,137 +1,12 @@
1
1
  #!/usr/bin/env node
2
2
  import { Server } from "@modelcontextprotocol/sdk/server/index.js";
3
3
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
4
- import { CallToolRequestSchema, ListToolsRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
5
- import { Octokit } from "@octokit/rest";
6
- import { z } from "zod";
7
- const GITHUB_TOKEN = process.env.GITHUB_TOKEN;
8
- // Reaction type mapping: user-friendly names to GitHub API format
9
- const REACTION_MAP = {
10
- "thumbs_up": "+1",
11
- "thumbs_down": "-1",
12
- "laugh": "laugh",
13
- "confused": "confused",
14
- "heart": "heart",
15
- "hooray": "hooray",
16
- "rocket": "rocket",
17
- "eyes": "eyes",
18
- };
19
- if (!GITHUB_TOKEN) {
20
- console.error("Error: GITHUB_TOKEN environment variable is required");
21
- process.exit(1);
22
- }
23
- const octokit = new Octokit({ auth: GITHUB_TOKEN });
24
- const GetIssueSchema = z.object({
25
- owner: z.string(),
26
- repo: z.string(),
27
- issue_number: z.number(),
28
- });
29
- const GetPRSchema = z.object({
30
- owner: z.string(),
31
- repo: z.string(),
32
- pull_number: z.number(),
33
- });
34
- const CreateIssueSchema = z.object({
35
- owner: z.string(),
36
- repo: z.string(),
37
- title: z.string(),
38
- body: z.string().optional(),
39
- labels: z.array(z.string()).optional(),
40
- assignees: z.array(z.string()).optional(),
41
- });
42
- const UpdateIssueSchema = z.object({
43
- owner: z.string(),
44
- repo: z.string(),
45
- issue_number: z.number(),
46
- title: z.string().optional(),
47
- body: z.string().optional(),
48
- state: z.enum(["open", "closed"]).optional(),
49
- labels: z.array(z.string()).optional(),
50
- assignees: z.array(z.string()).optional(),
51
- });
52
- const CreatePRSchema = z.object({
53
- owner: z.string(),
54
- repo: z.string(),
55
- title: z.string(),
56
- body: z.string().optional(),
57
- head: z.string(), // branch to merge FROM (e.g., "feature-branch")
58
- base: z.string(), // branch to merge INTO (e.g., "main")
59
- draft: z.boolean().optional(),
60
- maintainer_can_modify: z.boolean().optional(),
61
- });
62
- const AddCommentSchema = z.object({
63
- owner: z.string(),
64
- repo: z.string(),
65
- issue_number: z.number(), // works for both issues and PRs
66
- body: z.string(),
67
- });
68
- const UpdateCommentSchema = z.object({
69
- owner: z.string(),
70
- repo: z.string(),
71
- comment_id: z.number(),
72
- body: z.string(),
73
- });
74
- const DeleteCommentSchema = z.object({
75
- owner: z.string(),
76
- repo: z.string(),
77
- comment_id: z.number(),
78
- });
79
- const AddReactionSchema = z.object({
80
- owner: z.string(),
81
- repo: z.string(),
82
- comment_id: z.number().optional(),
83
- issue_number: z.number().optional(),
84
- reaction: z.enum(["thumbs_up", "thumbs_down", "laugh", "confused", "heart", "hooray", "rocket", "eyes"]),
85
- }).refine(data => data.comment_id || data.issue_number, {
86
- message: "Either comment_id or issue_number must be provided",
87
- });
88
- const SearchIssuesSchema = z.object({
89
- owner: z.string(),
90
- repo: z.string(),
91
- query: z.string().optional(),
92
- state: z.enum(["open", "closed", "all"]).optional(),
93
- labels: z.array(z.string()).optional(),
94
- sort: z.enum(["created", "updated", "comments"]).optional(),
95
- direction: z.enum(["asc", "desc"]).optional(),
96
- per_page: z.number().max(100).optional(),
97
- });
98
- const SearchPRsSchema = z.object({
99
- owner: z.string(),
100
- repo: z.string(),
101
- query: z.string().optional(),
102
- state: z.enum(["open", "closed", "all"]).optional(),
103
- sort: z.enum(["created", "updated", "popularity", "long-running"]).optional(),
104
- direction: z.enum(["asc", "desc"]).optional(),
105
- per_page: z.number().max(100).optional(),
106
- });
107
- const ListRecentIssuesSchema = z.object({
108
- owner: z.string(),
109
- repo: z.string(),
110
- state: z.enum(["open", "closed", "all"]).optional(),
111
- sort: z.enum(["created", "updated"]).optional(),
112
- per_page: z.number().max(100).optional(),
113
- });
114
- const MergePRSchema = z.object({
115
- owner: z.string(),
116
- repo: z.string(),
117
- pull_number: z.number(),
118
- merge_method: z.enum(["merge", "squash", "rebase"]).optional(),
119
- commit_title: z.string().optional(),
120
- commit_message: z.string().optional(),
121
- });
122
- const GetPRDiffSchema = z.object({
123
- owner: z.string(),
124
- repo: z.string(),
125
- pull_number: z.number(),
126
- });
127
- const GetPRFilesSchema = z.object({
128
- owner: z.string(),
129
- repo: z.string(),
130
- pull_number: z.number(),
131
- });
4
+ import { CallToolRequestSchema, ListToolsRequestSchema } from "@modelcontextprotocol/sdk/types.js";
5
+ import { dispatchTool, toolDefinitions } from "./tools/index.js";
6
+ import { SERVER_VERSION } from "./lib/version.js";
132
7
  const server = new Server({
133
8
  name: "issue-scribe-mcp",
134
- version: "1.0.0",
9
+ version: SERVER_VERSION,
135
10
  }, {
136
11
  capabilities: {
137
12
  tools: {},
@@ -139,1019 +14,17 @@ const server = new Server({
139
14
  });
140
15
  server.setRequestHandler(ListToolsRequestSchema, async () => {
141
16
  return {
142
- tools: [
143
- {
144
- name: "github_get_issue_context",
145
- description: "Get GitHub Issue context including title, body, comments, and metadata",
146
- inputSchema: {
147
- type: "object",
148
- properties: {
149
- owner: { type: "string", description: "Repository owner" },
150
- repo: { type: "string", description: "Repository name" },
151
- issue_number: { type: "number", description: "Issue number" },
152
- },
153
- required: ["owner", "repo", "issue_number"],
154
- },
155
- },
156
- {
157
- name: "github_get_pr_context",
158
- description: "Get GitHub Pull Request context including title, body, comments, commits, and metadata",
159
- inputSchema: {
160
- type: "object",
161
- properties: {
162
- owner: { type: "string", description: "Repository owner" },
163
- repo: { type: "string", description: "Repository name" },
164
- pull_number: { type: "number", description: "Pull request number" },
165
- },
166
- required: ["owner", "repo", "pull_number"],
167
- },
168
- },
169
- {
170
- name: "github_create_issue",
171
- description: "Create a new GitHub Issue",
172
- inputSchema: {
173
- type: "object",
174
- properties: {
175
- owner: { type: "string", description: "Repository owner" },
176
- repo: { type: "string", description: "Repository name" },
177
- title: { type: "string", description: "Issue title" },
178
- body: { type: "string", description: "Issue body (optional)" },
179
- labels: { type: "array", items: { type: "string" }, description: "Labels to add (optional)" },
180
- assignees: { type: "array", items: { type: "string" }, description: "Assignees (optional)" },
181
- },
182
- required: ["owner", "repo", "title"],
183
- },
184
- },
185
- {
186
- name: "github_update_issue",
187
- description: "Update an existing GitHub Issue",
188
- inputSchema: {
189
- type: "object",
190
- properties: {
191
- owner: { type: "string", description: "Repository owner" },
192
- repo: { type: "string", description: "Repository name" },
193
- issue_number: { type: "number", description: "Issue number" },
194
- title: { type: "string", description: "New title (optional)" },
195
- body: { type: "string", description: "New body (optional)" },
196
- state: { type: "string", enum: ["open", "closed"], description: "Issue state (optional)" },
197
- labels: { type: "array", items: { type: "string" }, description: "New labels (optional)" },
198
- assignees: { type: "array", items: { type: "string" }, description: "New assignees (optional)" },
199
- },
200
- required: ["owner", "repo", "issue_number"],
201
- },
202
- },
203
- {
204
- name: "github_create_pr",
205
- description: "Create a new GitHub Pull Request",
206
- inputSchema: {
207
- type: "object",
208
- properties: {
209
- owner: { type: "string", description: "Repository owner" },
210
- repo: { type: "string", description: "Repository name" },
211
- title: { type: "string", description: "PR title" },
212
- body: { type: "string", description: "PR body/description (optional)" },
213
- head: { type: "string", description: "Branch to merge FROM (e.g., 'feature-branch')" },
214
- base: { type: "string", description: "Branch to merge INTO (e.g., 'main')" },
215
- draft: { type: "boolean", description: "Create as draft PR (optional)" },
216
- maintainer_can_modify: { type: "boolean", description: "Allow maintainer edits (optional)" },
217
- },
218
- required: ["owner", "repo", "title", "head", "base"],
219
- },
220
- },
221
- {
222
- name: "github_add_comment",
223
- description: "Add a comment to a GitHub Issue or Pull Request",
224
- inputSchema: {
225
- type: "object",
226
- properties: {
227
- owner: { type: "string", description: "Repository owner" },
228
- repo: { type: "string", description: "Repository name" },
229
- issue_number: { type: "number", description: "Issue or PR number" },
230
- body: { type: "string", description: "Comment body text" },
231
- },
232
- required: ["owner", "repo", "issue_number", "body"],
233
- },
234
- },
235
- {
236
- name: "github_update_comment",
237
- description: "Update an existing comment on a GitHub Issue or Pull Request",
238
- inputSchema: {
239
- type: "object",
240
- properties: {
241
- owner: { type: "string", description: "Repository owner" },
242
- repo: { type: "string", description: "Repository name" },
243
- comment_id: { type: "number", description: "Comment ID to update" },
244
- body: { type: "string", description: "New comment body text" },
245
- },
246
- required: ["owner", "repo", "comment_id", "body"],
247
- },
248
- },
249
- {
250
- name: "github_delete_comment",
251
- description: "Delete a comment from a GitHub Issue or Pull Request",
252
- inputSchema: {
253
- type: "object",
254
- properties: {
255
- owner: { type: "string", description: "Repository owner" },
256
- repo: { type: "string", description: "Repository name" },
257
- comment_id: { type: "number", description: "Comment ID to delete" },
258
- },
259
- required: ["owner", "repo", "comment_id"],
260
- },
261
- },
262
- {
263
- name: "github_add_reaction",
264
- description: "Add a reaction (emoji) to a comment or an issue/PR directly. Provide either comment_id OR issue_number.",
265
- inputSchema: {
266
- type: "object",
267
- properties: {
268
- owner: { type: "string", description: "Repository owner" },
269
- repo: { type: "string", description: "Repository name" },
270
- comment_id: { type: "number", description: "Comment ID to react to (optional if issue_number is provided)" },
271
- issue_number: { type: "number", description: "Issue/PR number to react to (optional if comment_id is provided)" },
272
- reaction: {
273
- type: "string",
274
- enum: ["thumbs_up", "thumbs_down", "laugh", "confused", "heart", "hooray", "rocket", "eyes"],
275
- description: "Reaction type: thumbs_up 👍, thumbs_down 👎, laugh 😄, confused 😕, heart ❤️, hooray 🎉, rocket 🚀, eyes 👀"
276
- },
277
- },
278
- required: ["owner", "repo", "reaction"],
279
- },
280
- },
281
- {
282
- name: "github_search_issues",
283
- description: "Search for issues in a repository with advanced filters",
284
- inputSchema: {
285
- type: "object",
286
- properties: {
287
- owner: { type: "string", description: "Repository owner" },
288
- repo: { type: "string", description: "Repository name" },
289
- query: { type: "string", description: "Search query (optional)" },
290
- state: { type: "string", enum: ["open", "closed", "all"], description: "Issue state (optional)" },
291
- labels: { type: "array", items: { type: "string" }, description: "Filter by labels (optional)" },
292
- sort: { type: "string", enum: ["created", "updated", "comments"], description: "Sort by (optional)" },
293
- direction: { type: "string", enum: ["asc", "desc"], description: "Sort direction (optional)" },
294
- per_page: { type: "number", description: "Results per page, max 100 (optional)" },
295
- },
296
- required: ["owner", "repo"],
297
- },
298
- },
299
- {
300
- name: "github_search_prs",
301
- description: "Search for pull requests in a repository with advanced filters",
302
- inputSchema: {
303
- type: "object",
304
- properties: {
305
- owner: { type: "string", description: "Repository owner" },
306
- repo: { type: "string", description: "Repository name" },
307
- query: { type: "string", description: "Search query (optional)" },
308
- state: { type: "string", enum: ["open", "closed", "all"], description: "PR state (optional)" },
309
- sort: { type: "string", enum: ["created", "updated", "popularity", "long-running"], description: "Sort by (optional)" },
310
- direction: { type: "string", enum: ["asc", "desc"], description: "Sort direction (optional)" },
311
- per_page: { type: "number", description: "Results per page, max 100 (optional)" },
312
- },
313
- required: ["owner", "repo"],
314
- },
315
- },
316
- {
317
- name: "github_list_recent_issues",
318
- description: "List recent issues in a repository",
319
- inputSchema: {
320
- type: "object",
321
- properties: {
322
- owner: { type: "string", description: "Repository owner" },
323
- repo: { type: "string", description: "Repository name" },
324
- state: { type: "string", enum: ["open", "closed", "all"], description: "Issue state (optional, default: open)" },
325
- sort: { type: "string", enum: ["created", "updated"], description: "Sort by (optional, default: created)" },
326
- per_page: { type: "number", description: "Results per page, max 100 (optional, default: 30)" },
327
- },
328
- required: ["owner", "repo"],
329
- },
330
- },
331
- {
332
- name: "github_merge_pr",
333
- description: "Merge a pull request",
334
- inputSchema: {
335
- type: "object",
336
- properties: {
337
- owner: { type: "string", description: "Repository owner" },
338
- repo: { type: "string", description: "Repository name" },
339
- pull_number: { type: "number", description: "PR number to merge" },
340
- merge_method: { type: "string", enum: ["merge", "squash", "rebase"], description: "Merge method (optional, default: merge)" },
341
- commit_title: { type: "string", description: "Custom commit title (optional)" },
342
- commit_message: { type: "string", description: "Custom commit message (optional)" },
343
- },
344
- required: ["owner", "repo", "pull_number"],
345
- },
346
- },
347
- {
348
- name: "github_get_pr_diff",
349
- description: "Get the full diff of a pull request",
350
- inputSchema: {
351
- type: "object",
352
- properties: {
353
- owner: { type: "string", description: "Repository owner" },
354
- repo: { type: "string", description: "Repository name" },
355
- pull_number: { type: "number", description: "PR number" },
356
- },
357
- required: ["owner", "repo", "pull_number"],
358
- },
359
- },
360
- {
361
- name: "github_get_pr_files",
362
- description: "Get list of files changed in a pull request with details",
363
- inputSchema: {
364
- type: "object",
365
- properties: {
366
- owner: { type: "string", description: "Repository owner" },
367
- repo: { type: "string", description: "Repository name" },
368
- pull_number: { type: "number", description: "PR number" },
369
- },
370
- required: ["owner", "repo", "pull_number"],
371
- },
372
- },
373
- ],
17
+ tools: toolDefinitions,
374
18
  };
375
19
  });
376
20
  server.setRequestHandler(CallToolRequestSchema, async (request) => {
377
21
  const { name, arguments: args } = request.params;
378
- if (name === "github_get_issue_context") {
379
- try {
380
- const { owner, repo, issue_number } = GetIssueSchema.parse(args);
381
- const [issue, comments] = await Promise.all([
382
- octokit.rest.issues.get({ owner, repo, issue_number }),
383
- octokit.rest.issues.listComments({ owner, repo, issue_number }),
384
- ]);
385
- return {
386
- content: [
387
- {
388
- type: "text",
389
- text: JSON.stringify({
390
- issue: {
391
- number: issue.data.number,
392
- title: issue.data.title,
393
- body: issue.data.body,
394
- state: issue.data.state,
395
- user: issue.data.user?.login,
396
- created_at: issue.data.created_at,
397
- updated_at: issue.data.updated_at,
398
- labels: issue.data.labels.map((l) => typeof l === "string" ? l : l.name),
399
- },
400
- comments: comments.data.map((c) => ({
401
- id: c.id,
402
- user: c.user?.login,
403
- body: c.body,
404
- created_at: c.created_at,
405
- html_url: c.html_url,
406
- })),
407
- }, null, 2),
408
- },
409
- ],
410
- };
411
- }
412
- catch (error) {
413
- const issueNum = args && typeof args === 'object' && 'issue_number' in args ? args.issue_number : 'unknown';
414
- const owner = args && typeof args === 'object' && 'owner' in args ? args.owner : 'unknown';
415
- const repo = args && typeof args === 'object' && 'repo' in args ? args.repo : 'unknown';
416
- return {
417
- content: [
418
- {
419
- type: "text",
420
- text: JSON.stringify({
421
- error: error.message,
422
- status: error.status,
423
- detail: `Failed to fetch issue #${issueNum} from ${owner}/${repo}`,
424
- }, null, 2),
425
- },
426
- ],
427
- isError: true,
428
- };
429
- }
430
- }
431
- if (name === "github_get_pr_context") {
432
- try {
433
- const { owner, repo, pull_number } = GetPRSchema.parse(args);
434
- const [pr, comments, commits] = await Promise.all([
435
- octokit.rest.pulls.get({ owner, repo, pull_number }),
436
- octokit.rest.issues.listComments({ owner, repo, issue_number: pull_number }),
437
- octokit.rest.pulls.listCommits({ owner, repo, pull_number }),
438
- ]);
439
- return {
440
- content: [
441
- {
442
- type: "text",
443
- text: JSON.stringify({
444
- pull_request: {
445
- number: pr.data.number,
446
- title: pr.data.title,
447
- body: pr.data.body,
448
- state: pr.data.state,
449
- user: pr.data.user?.login,
450
- created_at: pr.data.created_at,
451
- updated_at: pr.data.updated_at,
452
- merged_at: pr.data.merged_at,
453
- base: pr.data.base.ref,
454
- head: pr.data.head.ref,
455
- labels: pr.data.labels.map((l) => typeof l === "string" ? l : l.name),
456
- },
457
- comments: comments.data.map((c) => ({
458
- id: c.id,
459
- user: c.user?.login,
460
- body: c.body,
461
- created_at: c.created_at,
462
- html_url: c.html_url,
463
- })),
464
- commits: commits.data.map((c) => ({
465
- sha: c.sha,
466
- message: c.commit.message,
467
- author: c.commit.author?.name,
468
- date: c.commit.author?.date,
469
- })),
470
- }, null, 2),
471
- },
472
- ],
473
- };
474
- }
475
- catch (error) {
476
- const pullNum = args && typeof args === 'object' && 'pull_number' in args ? args.pull_number : 'unknown';
477
- const owner = args && typeof args === 'object' && 'owner' in args ? args.owner : 'unknown';
478
- const repo = args && typeof args === 'object' && 'repo' in args ? args.repo : 'unknown';
479
- return {
480
- content: [
481
- {
482
- type: "text",
483
- text: JSON.stringify({
484
- error: error.message,
485
- status: error.status,
486
- detail: `Failed to fetch PR #${pullNum} from ${owner}/${repo}`,
487
- }, null, 2),
488
- },
489
- ],
490
- isError: true,
491
- };
492
- }
493
- }
494
- if (name === "github_create_issue") {
495
- try {
496
- const { owner, repo, title, body, labels, assignees } = CreateIssueSchema.parse(args);
497
- const issue = await octokit.rest.issues.create({
498
- owner,
499
- repo,
500
- title,
501
- body,
502
- labels,
503
- assignees,
504
- });
505
- return {
506
- content: [
507
- {
508
- type: "text",
509
- text: JSON.stringify({
510
- success: true,
511
- issue: {
512
- number: issue.data.number,
513
- title: issue.data.title,
514
- state: issue.data.state,
515
- html_url: issue.data.html_url,
516
- created_at: issue.data.created_at,
517
- },
518
- message: `Issue #${issue.data.number} created successfully`,
519
- }, null, 2),
520
- },
521
- ],
522
- };
523
- }
524
- catch (error) {
525
- const owner = args && typeof args === 'object' && 'owner' in args ? args.owner : 'unknown';
526
- const repo = args && typeof args === 'object' && 'repo' in args ? args.repo : 'unknown';
527
- const title = args && typeof args === 'object' && 'title' in args ? args.title : 'unknown';
528
- return {
529
- content: [
530
- {
531
- type: "text",
532
- text: JSON.stringify({
533
- error: error.message,
534
- status: error.status,
535
- detail: `Failed to create issue "${title}" in ${owner}/${repo}`,
536
- }, null, 2),
537
- },
538
- ],
539
- isError: true,
540
- };
541
- }
542
- }
543
- if (name === "github_update_issue") {
544
- try {
545
- const { owner, repo, issue_number, title, body, state, labels, assignees } = UpdateIssueSchema.parse(args);
546
- const issue = await octokit.rest.issues.update({
547
- owner,
548
- repo,
549
- issue_number,
550
- title,
551
- body,
552
- state,
553
- labels,
554
- assignees,
555
- });
556
- return {
557
- content: [
558
- {
559
- type: "text",
560
- text: JSON.stringify({
561
- success: true,
562
- issue: {
563
- number: issue.data.number,
564
- title: issue.data.title,
565
- state: issue.data.state,
566
- html_url: issue.data.html_url,
567
- updated_at: issue.data.updated_at,
568
- },
569
- message: `Issue #${issue.data.number} updated successfully`,
570
- }, null, 2),
571
- },
572
- ],
573
- };
574
- }
575
- catch (error) {
576
- const issueNum = args && typeof args === 'object' && 'issue_number' in args ? args.issue_number : 'unknown';
577
- const owner = args && typeof args === 'object' && 'owner' in args ? args.owner : 'unknown';
578
- const repo = args && typeof args === 'object' && 'repo' in args ? args.repo : 'unknown';
579
- return {
580
- content: [
581
- {
582
- type: "text",
583
- text: JSON.stringify({
584
- error: error.message,
585
- status: error.status,
586
- detail: `Failed to update issue #${issueNum} in ${owner}/${repo}`,
587
- }, null, 2),
588
- },
589
- ],
590
- isError: true,
591
- };
592
- }
593
- }
594
- if (name === "github_create_pr") {
595
- try {
596
- const { owner, repo, title, body, head, base, draft, maintainer_can_modify } = CreatePRSchema.parse(args);
597
- const pr = await octokit.rest.pulls.create({
598
- owner,
599
- repo,
600
- title,
601
- body,
602
- head,
603
- base,
604
- draft,
605
- maintainer_can_modify,
606
- });
607
- return {
608
- content: [
609
- {
610
- type: "text",
611
- text: JSON.stringify({
612
- success: true,
613
- pull_request: {
614
- number: pr.data.number,
615
- title: pr.data.title,
616
- state: pr.data.state,
617
- html_url: pr.data.html_url,
618
- draft: pr.data.draft,
619
- head: pr.data.head.ref,
620
- base: pr.data.base.ref,
621
- created_at: pr.data.created_at,
622
- },
623
- message: `PR #${pr.data.number} created successfully`,
624
- }, null, 2),
625
- },
626
- ],
627
- };
628
- }
629
- catch (error) {
630
- const owner = args && typeof args === 'object' && 'owner' in args ? args.owner : 'unknown';
631
- const repo = args && typeof args === 'object' && 'repo' in args ? args.repo : 'unknown';
632
- const title = args && typeof args === 'object' && 'title' in args ? args.title : 'unknown';
633
- return {
634
- content: [
635
- {
636
- type: "text",
637
- text: JSON.stringify({
638
- error: error.message,
639
- status: error.status,
640
- detail: `Failed to create PR "${title}" in ${owner}/${repo}`,
641
- }, null, 2),
642
- },
643
- ],
644
- isError: true,
645
- };
646
- }
647
- }
648
- if (name === "github_add_comment") {
649
- try {
650
- const { owner, repo, issue_number, body } = AddCommentSchema.parse(args);
651
- const comment = await octokit.rest.issues.createComment({
652
- owner,
653
- repo,
654
- issue_number,
655
- body,
656
- });
657
- return {
658
- content: [
659
- {
660
- type: "text",
661
- text: JSON.stringify({
662
- success: true,
663
- comment: {
664
- id: comment.data.id,
665
- body: comment.data.body,
666
- user: comment.data.user?.login,
667
- html_url: comment.data.html_url,
668
- created_at: comment.data.created_at,
669
- },
670
- message: `Comment added successfully to issue/PR #${issue_number}`,
671
- }, null, 2),
672
- },
673
- ],
674
- };
675
- }
676
- catch (error) {
677
- const issueNum = args && typeof args === 'object' && 'issue_number' in args ? args.issue_number : 'unknown';
678
- const owner = args && typeof args === 'object' && 'owner' in args ? args.owner : 'unknown';
679
- const repo = args && typeof args === 'object' && 'repo' in args ? args.repo : 'unknown';
680
- return {
681
- content: [
682
- {
683
- type: "text",
684
- text: JSON.stringify({
685
- error: error.message,
686
- status: error.status,
687
- detail: `Failed to add comment to issue/PR #${issueNum} in ${owner}/${repo}`,
688
- }, null, 2),
689
- },
690
- ],
691
- isError: true,
692
- };
693
- }
694
- }
695
- if (name === "github_update_comment") {
696
- try {
697
- const { owner, repo, comment_id, body } = UpdateCommentSchema.parse(args);
698
- const comment = await octokit.rest.issues.updateComment({
699
- owner,
700
- repo,
701
- comment_id,
702
- body,
703
- });
704
- return {
705
- content: [
706
- {
707
- type: "text",
708
- text: JSON.stringify({
709
- success: true,
710
- comment: {
711
- id: comment.data.id,
712
- body: comment.data.body,
713
- user: comment.data.user?.login,
714
- html_url: comment.data.html_url,
715
- updated_at: comment.data.updated_at,
716
- },
717
- message: `Comment #${comment_id} updated successfully`,
718
- }, null, 2),
719
- },
720
- ],
721
- };
722
- }
723
- catch (error) {
724
- const commentId = args && typeof args === 'object' && 'comment_id' in args ? args.comment_id : 'unknown';
725
- const owner = args && typeof args === 'object' && 'owner' in args ? args.owner : 'unknown';
726
- const repo = args && typeof args === 'object' && 'repo' in args ? args.repo : 'unknown';
727
- return {
728
- content: [
729
- {
730
- type: "text",
731
- text: JSON.stringify({
732
- error: error.message,
733
- status: error.status,
734
- detail: `Failed to update comment #${commentId} in ${owner}/${repo}`,
735
- }, null, 2),
736
- },
737
- ],
738
- isError: true,
739
- };
740
- }
741
- }
742
- if (name === "github_delete_comment") {
743
- try {
744
- const { owner, repo, comment_id } = DeleteCommentSchema.parse(args);
745
- await octokit.rest.issues.deleteComment({
746
- owner,
747
- repo,
748
- comment_id,
749
- });
750
- return {
751
- content: [
752
- {
753
- type: "text",
754
- text: JSON.stringify({
755
- success: true,
756
- message: `Comment #${comment_id} deleted successfully`,
757
- }, null, 2),
758
- },
759
- ],
760
- };
761
- }
762
- catch (error) {
763
- const commentId = args && typeof args === 'object' && 'comment_id' in args ? args.comment_id : 'unknown';
764
- const owner = args && typeof args === 'object' && 'owner' in args ? args.owner : 'unknown';
765
- const repo = args && typeof args === 'object' && 'repo' in args ? args.repo : 'unknown';
766
- return {
767
- content: [
768
- {
769
- type: "text",
770
- text: JSON.stringify({
771
- error: error.message,
772
- status: error.status,
773
- detail: `Failed to delete comment #${commentId} in ${owner}/${repo}`,
774
- }, null, 2),
775
- },
776
- ],
777
- isError: true,
778
- };
779
- }
780
- }
781
- if (name === "github_add_reaction") {
782
- try {
783
- const { owner, repo, comment_id, issue_number, reaction } = AddReactionSchema.parse(args);
784
- let reactionResponse;
785
- let target = "";
786
- const githubReaction = REACTION_MAP[reaction] || reaction;
787
- if (comment_id) {
788
- // Add reaction to a comment
789
- reactionResponse = await octokit.rest.reactions.createForIssueComment({
790
- owner,
791
- repo,
792
- comment_id,
793
- content: githubReaction,
794
- });
795
- target = `comment #${comment_id}`;
796
- }
797
- else if (issue_number) {
798
- // Add reaction to an issue/PR
799
- reactionResponse = await octokit.rest.reactions.createForIssue({
800
- owner,
801
- repo,
802
- issue_number,
803
- content: githubReaction,
804
- });
805
- target = `issue/PR #${issue_number}`;
806
- }
807
- return {
808
- content: [
809
- {
810
- type: "text",
811
- text: JSON.stringify({
812
- success: true,
813
- reaction: {
814
- id: reactionResponse.data.id,
815
- content: reactionResponse.data.content,
816
- user: reactionResponse.data.user?.login,
817
- created_at: reactionResponse.data.created_at,
818
- },
819
- message: `Reaction "${reaction}" added successfully to ${target}`,
820
- }, null, 2),
821
- },
822
- ],
823
- };
824
- }
825
- catch (error) {
826
- const commentId = args && typeof args === 'object' && 'comment_id' in args ? args.comment_id : undefined;
827
- const issueNum = args && typeof args === 'object' && 'issue_number' in args ? args.issue_number : undefined;
828
- const owner = args && typeof args === 'object' && 'owner' in args ? args.owner : 'unknown';
829
- const repo = args && typeof args === 'object' && 'repo' in args ? args.repo : 'unknown';
830
- const reaction = args && typeof args === 'object' && 'reaction' in args ? args.reaction : 'unknown';
831
- const target = commentId ? `comment #${commentId}` : issueNum ? `issue/PR #${issueNum}` : 'unknown';
832
- return {
833
- content: [
834
- {
835
- type: "text",
836
- text: JSON.stringify({
837
- error: error.message,
838
- status: error.status,
839
- detail: `Failed to add reaction "${reaction}" to ${target} in ${owner}/${repo}`,
840
- }, null, 2),
841
- },
842
- ],
843
- isError: true,
844
- };
845
- }
846
- }
847
- if (name === "github_search_issues") {
848
- try {
849
- const { owner, repo, query, state, labels, sort, direction, per_page } = SearchIssuesSchema.parse(args);
850
- const issues = await octokit.rest.issues.listForRepo({
851
- owner,
852
- repo,
853
- state: state || "open",
854
- labels: labels?.join(","),
855
- sort: sort,
856
- direction: direction,
857
- per_page: per_page || 30,
858
- });
859
- // Filter out pull requests first
860
- const issuesOnly = issues.data.filter(issue => !issue.pull_request);
861
- const filteredIssues = query
862
- ? issues.data.filter(issue => !issue.pull_request).filter(issue => issue.title.toLowerCase().includes(query.toLowerCase()) ||
863
- issue.body?.toLowerCase().includes(query.toLowerCase()))
864
- : issues.data.filter(issue => !issue.pull_request);
865
- return {
866
- content: [
867
- {
868
- type: "text",
869
- text: JSON.stringify({
870
- total_count: filteredIssues.length,
871
- issues: filteredIssues.map(issue => ({
872
- number: issue.number,
873
- title: issue.title,
874
- state: issue.state,
875
- user: issue.user?.login,
876
- labels: issue.labels.map((l) => typeof l === "string" ? l : l.name),
877
- created_at: issue.created_at,
878
- updated_at: issue.updated_at,
879
- comments: issue.comments,
880
- html_url: issue.html_url,
881
- })),
882
- }, null, 2),
883
- },
884
- ],
885
- };
886
- }
887
- catch (error) {
888
- const owner = args && typeof args === 'object' && 'owner' in args ? args.owner : 'unknown';
889
- const repo = args && typeof args === 'object' && 'repo' in args ? args.repo : 'unknown';
890
- return {
891
- content: [
892
- {
893
- type: "text",
894
- text: JSON.stringify({
895
- error: error.message,
896
- status: error.status,
897
- detail: `Failed to search issues in ${owner}/${repo}`,
898
- }, null, 2),
899
- },
900
- ],
901
- isError: true,
902
- };
903
- }
904
- }
905
- if (name === "github_search_prs") {
906
- try {
907
- const { owner, repo, query, state, sort, direction, per_page } = SearchPRsSchema.parse(args);
908
- const prs = await octokit.rest.pulls.list({
909
- owner,
910
- repo,
911
- state: state || "open",
912
- sort: sort,
913
- direction: direction,
914
- per_page: per_page || 30,
915
- });
916
- const filteredPRs = query
917
- ? prs.data.filter(pr => pr.title.toLowerCase().includes(query.toLowerCase()) ||
918
- pr.body?.toLowerCase().includes(query.toLowerCase()))
919
- : prs.data;
920
- return {
921
- content: [
922
- {
923
- type: "text",
924
- text: JSON.stringify({
925
- total_count: filteredPRs.length,
926
- pull_requests: filteredPRs.map(pr => ({
927
- number: pr.number,
928
- title: pr.title,
929
- state: pr.state,
930
- user: pr.user?.login,
931
- head: pr.head.ref,
932
- base: pr.base.ref,
933
- created_at: pr.created_at,
934
- updated_at: pr.updated_at,
935
- draft: pr.draft,
936
- html_url: pr.html_url,
937
- })),
938
- }, null, 2),
939
- },
940
- ],
941
- };
942
- }
943
- catch (error) {
944
- const owner = args && typeof args === 'object' && 'owner' in args ? args.owner : 'unknown';
945
- const repo = args && typeof args === 'object' && 'repo' in args ? args.repo : 'unknown';
946
- return {
947
- content: [
948
- {
949
- type: "text",
950
- text: JSON.stringify({
951
- error: error.message,
952
- status: error.status,
953
- detail: `Failed to search PRs in ${owner}/${repo}`,
954
- }, null, 2),
955
- },
956
- ],
957
- isError: true,
958
- };
959
- }
960
- }
961
- if (name === "github_list_recent_issues") {
962
- try {
963
- const { owner, repo, state, sort, per_page } = ListRecentIssuesSchema.parse(args);
964
- const issues = await octokit.rest.issues.listForRepo({
965
- owner,
966
- repo,
967
- state: state || "open",
968
- sort: sort || "created",
969
- direction: "desc",
970
- per_page: per_page || 30,
971
- });
972
- // Filter out pull requests (GitHub API returns both issues and PRs)
973
- const actualIssues = issues.data.filter(issue => !issue.pull_request);
974
- return {
975
- content: [
976
- {
977
- type: "text",
978
- text: JSON.stringify({
979
- count: actualIssues.length,
980
- issues: actualIssues.map(issue => ({
981
- number: issue.number,
982
- title: issue.title,
983
- state: issue.state,
984
- user: issue.user?.login,
985
- labels: issue.labels.map((l) => typeof l === "string" ? l : l.name),
986
- created_at: issue.created_at,
987
- updated_at: issue.updated_at,
988
- comments: issue.comments,
989
- html_url: issue.html_url,
990
- })),
991
- }, null, 2),
992
- },
993
- ],
994
- };
995
- }
996
- catch (error) {
997
- const owner = args && typeof args === 'object' && 'owner' in args ? args.owner : 'unknown';
998
- const repo = args && typeof args === 'object' && 'repo' in args ? args.repo : 'unknown';
999
- return {
1000
- content: [
1001
- {
1002
- type: "text",
1003
- text: JSON.stringify({
1004
- error: error.message,
1005
- status: error.status,
1006
- detail: `Failed to list recent issues in ${owner}/${repo}`,
1007
- }, null, 2),
1008
- },
1009
- ],
1010
- isError: true,
1011
- };
1012
- }
1013
- }
1014
- if (name === "github_merge_pr") {
1015
- try {
1016
- const { owner, repo, pull_number, merge_method, commit_title, commit_message } = MergePRSchema.parse(args);
1017
- const result = await octokit.rest.pulls.merge({
1018
- owner,
1019
- repo,
1020
- pull_number,
1021
- merge_method: merge_method,
1022
- commit_title,
1023
- commit_message,
1024
- });
1025
- return {
1026
- content: [
1027
- {
1028
- type: "text",
1029
- text: JSON.stringify({
1030
- success: true,
1031
- merged: result.data.merged,
1032
- sha: result.data.sha,
1033
- message: result.data.message,
1034
- }, null, 2),
1035
- },
1036
- ],
1037
- };
1038
- }
1039
- catch (error) {
1040
- const pullNum = args && typeof args === 'object' && 'pull_number' in args ? args.pull_number : 'unknown';
1041
- const owner = args && typeof args === 'object' && 'owner' in args ? args.owner : 'unknown';
1042
- const repo = args && typeof args === 'object' && 'repo' in args ? args.repo : 'unknown';
1043
- return {
1044
- content: [
1045
- {
1046
- type: "text",
1047
- text: JSON.stringify({
1048
- error: error.message,
1049
- status: error.status,
1050
- detail: `Failed to merge PR #${pullNum} in ${owner}/${repo}`,
1051
- }, null, 2),
1052
- },
1053
- ],
1054
- isError: true,
1055
- };
1056
- }
1057
- }
1058
- if (name === "github_get_pr_diff") {
1059
- try {
1060
- const { owner, repo, pull_number } = GetPRDiffSchema.parse(args);
1061
- const diff = await octokit.rest.pulls.get({
1062
- owner,
1063
- repo,
1064
- pull_number,
1065
- mediaType: {
1066
- format: "diff",
1067
- },
1068
- });
1069
- return {
1070
- content: [
1071
- {
1072
- type: "text",
1073
- text: JSON.stringify({
1074
- pull_number,
1075
- diff: diff.data,
1076
- }, null, 2),
1077
- },
1078
- ],
1079
- };
1080
- }
1081
- catch (error) {
1082
- const pullNum = args && typeof args === 'object' && 'pull_number' in args ? args.pull_number : 'unknown';
1083
- const owner = args && typeof args === 'object' && 'owner' in args ? args.owner : 'unknown';
1084
- const repo = args && typeof args === 'object' && 'repo' in args ? args.repo : 'unknown';
1085
- return {
1086
- content: [
1087
- {
1088
- type: "text",
1089
- text: JSON.stringify({
1090
- error: error.message,
1091
- status: error.status,
1092
- detail: `Failed to get diff for PR #${pullNum} in ${owner}/${repo}`,
1093
- }, null, 2),
1094
- },
1095
- ],
1096
- isError: true,
1097
- };
1098
- }
1099
- }
1100
- if (name === "github_get_pr_files") {
1101
- try {
1102
- const { owner, repo, pull_number } = GetPRFilesSchema.parse(args);
1103
- const files = await octokit.rest.pulls.listFiles({
1104
- owner,
1105
- repo,
1106
- pull_number,
1107
- });
1108
- return {
1109
- content: [
1110
- {
1111
- type: "text",
1112
- text: JSON.stringify({
1113
- pull_number,
1114
- total_files: files.data.length,
1115
- files: files.data.map(file => ({
1116
- filename: file.filename,
1117
- status: file.status,
1118
- additions: file.additions,
1119
- deletions: file.deletions,
1120
- changes: file.changes,
1121
- blob_url: file.blob_url,
1122
- raw_url: file.raw_url,
1123
- patch: file.patch,
1124
- })),
1125
- }, null, 2),
1126
- },
1127
- ],
1128
- };
1129
- }
1130
- catch (error) {
1131
- const pullNum = args && typeof args === 'object' && 'pull_number' in args ? args.pull_number : 'unknown';
1132
- const owner = args && typeof args === 'object' && 'owner' in args ? args.owner : 'unknown';
1133
- const repo = args && typeof args === 'object' && 'repo' in args ? args.repo : 'unknown';
1134
- return {
1135
- content: [
1136
- {
1137
- type: "text",
1138
- text: JSON.stringify({
1139
- error: error.message,
1140
- status: error.status,
1141
- detail: `Failed to get files for PR #${pullNum} in ${owner}/${repo}`,
1142
- }, null, 2),
1143
- },
1144
- ],
1145
- isError: true,
1146
- };
1147
- }
1148
- }
1149
- throw new Error(`Unknown tool: ${name}`);
22
+ return dispatchTool(name, args);
1150
23
  });
1151
24
  async function main() {
1152
25
  const transport = new StdioServerTransport();
1153
26
  await server.connect(transport);
1154
- console.error("issue-scribe-mcp server running on stdio");
27
+ console.error(`issue-scribe-mcp server running on stdio (v${SERVER_VERSION})`);
1155
28
  }
1156
29
  main().catch((error) => {
1157
30
  console.error("Fatal error:", error);