issue-scribe-mcp 1.0.0 → 1.2.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/src/index.ts CHANGED
@@ -11,6 +11,18 @@ import { z } from "zod";
11
11
 
12
12
  const GITHUB_TOKEN = process.env.GITHUB_TOKEN;
13
13
 
14
+ // Reaction type mapping: user-friendly names to GitHub API format
15
+ const REACTION_MAP: Record<string, string> = {
16
+ "thumbs_up": "+1",
17
+ "thumbs_down": "-1",
18
+ "laugh": "laugh",
19
+ "confused": "confused",
20
+ "heart": "heart",
21
+ "hooray": "hooray",
22
+ "rocket": "rocket",
23
+ "eyes": "eyes",
24
+ };
25
+
14
26
  if (!GITHUB_TOKEN) {
15
27
  console.error("Error: GITHUB_TOKEN environment variable is required");
16
28
  process.exit(1);
@@ -61,6 +73,142 @@ const CreatePRSchema = z.object({
61
73
  maintainer_can_modify: z.boolean().optional(),
62
74
  });
63
75
 
76
+ const AddCommentSchema = z.object({
77
+ owner: z.string(),
78
+ repo: z.string(),
79
+ issue_number: z.number(), // works for both issues and PRs
80
+ body: z.string(),
81
+ });
82
+
83
+ const UpdateCommentSchema = z.object({
84
+ owner: z.string(),
85
+ repo: z.string(),
86
+ comment_id: z.number(),
87
+ body: z.string(),
88
+ });
89
+
90
+ const DeleteCommentSchema = z.object({
91
+ owner: z.string(),
92
+ repo: z.string(),
93
+ comment_id: z.number(),
94
+ });
95
+
96
+ const AddReactionSchema = z.object({
97
+ owner: z.string(),
98
+ repo: z.string(),
99
+ comment_id: z.number().optional(),
100
+ issue_number: z.number().optional(),
101
+ reaction: z.enum(["thumbs_up", "thumbs_down", "laugh", "confused", "heart", "hooray", "rocket", "eyes"]),
102
+ }).refine(data => data.comment_id || data.issue_number, {
103
+ message: "Either comment_id or issue_number must be provided",
104
+ });
105
+
106
+ const SearchIssuesSchema = z.object({
107
+ owner: z.string(),
108
+ repo: z.string(),
109
+ query: z.string().optional(),
110
+ state: z.enum(["open", "closed", "all"]).optional(),
111
+ labels: z.array(z.string()).optional(),
112
+ sort: z.enum(["created", "updated", "comments"]).optional(),
113
+ direction: z.enum(["asc", "desc"]).optional(),
114
+ per_page: z.number().max(100).optional(),
115
+ });
116
+
117
+ const SearchPRsSchema = z.object({
118
+ owner: z.string(),
119
+ repo: z.string(),
120
+ query: z.string().optional(),
121
+ state: z.enum(["open", "closed", "all"]).optional(),
122
+ sort: z.enum(["created", "updated", "popularity", "long-running"]).optional(),
123
+ direction: z.enum(["asc", "desc"]).optional(),
124
+ per_page: z.number().max(100).optional(),
125
+ });
126
+
127
+ const ListRecentIssuesSchema = z.object({
128
+ owner: z.string(),
129
+ repo: z.string(),
130
+ state: z.enum(["open", "closed", "all"]).optional(),
131
+ sort: z.enum(["created", "updated"]).optional(),
132
+ per_page: z.number().max(100).optional(),
133
+ });
134
+
135
+ const MergePRSchema = z.object({
136
+ owner: z.string(),
137
+ repo: z.string(),
138
+ pull_number: z.number(),
139
+ merge_method: z.enum(["merge", "squash", "rebase"]).optional(),
140
+ commit_title: z.string().optional(),
141
+ commit_message: z.string().optional(),
142
+ });
143
+
144
+ const GetPRDiffSchema = z.object({
145
+ owner: z.string(),
146
+ repo: z.string(),
147
+ pull_number: z.number(),
148
+ });
149
+
150
+ const GetPRFilesSchema = z.object({
151
+ owner: z.string(),
152
+ repo: z.string(),
153
+ pull_number: z.number(),
154
+ });
155
+
156
+ const CreateLabelSchema = z.object({
157
+ owner: z.string(),
158
+ repo: z.string(),
159
+ name: z.string(),
160
+ color: z.string(), // hex color without '#'
161
+ description: z.string().optional(),
162
+ });
163
+
164
+ const UpdateLabelSchema = z.object({
165
+ owner: z.string(),
166
+ repo: z.string(),
167
+ name: z.string(), // current label name
168
+ new_name: z.string().optional(),
169
+ color: z.string().optional(), // hex color without '#'
170
+ description: z.string().optional(),
171
+ });
172
+
173
+ const DeleteLabelSchema = z.object({
174
+ owner: z.string(),
175
+ repo: z.string(),
176
+ name: z.string(),
177
+ });
178
+
179
+ const ListLabelsSchema = z.object({
180
+ owner: z.string(),
181
+ repo: z.string(),
182
+ per_page: z.number().max(100).optional(),
183
+ });
184
+
185
+ const ListBranchesSchema = z.object({
186
+ owner: z.string(),
187
+ repo: z.string(),
188
+ protected: z.boolean().optional(),
189
+ per_page: z.number().max(100).optional(),
190
+ });
191
+
192
+ const CreateBranchSchema = z.object({
193
+ owner: z.string(),
194
+ repo: z.string(),
195
+ branch: z.string(), // new branch name
196
+ ref: z.string(), // source branch or commit SHA (e.g., "main" or full ref "refs/heads/main")
197
+ });
198
+
199
+ const DeleteBranchSchema = z.object({
200
+ owner: z.string(),
201
+ repo: z.string(),
202
+ branch: z.string(), // branch name to delete
203
+ });
204
+
205
+ const CompareBranchesSchema = z.object({
206
+ owner: z.string(),
207
+ repo: z.string(),
208
+ base: z.string(), // base branch
209
+ head: z.string(), // head branch to compare
210
+ });
211
+
64
212
  const server = new Server(
65
213
  {
66
214
  name: "issue-scribe-mcp",
@@ -154,6 +302,270 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
154
302
  required: ["owner", "repo", "title", "head", "base"],
155
303
  },
156
304
  },
305
+ {
306
+ name: "github_add_comment",
307
+ description: "Add a comment to a GitHub Issue or Pull Request",
308
+ inputSchema: {
309
+ type: "object",
310
+ properties: {
311
+ owner: { type: "string", description: "Repository owner" },
312
+ repo: { type: "string", description: "Repository name" },
313
+ issue_number: { type: "number", description: "Issue or PR number" },
314
+ body: { type: "string", description: "Comment body text" },
315
+ },
316
+ required: ["owner", "repo", "issue_number", "body"],
317
+ },
318
+ },
319
+ {
320
+ name: "github_update_comment",
321
+ description: "Update an existing comment on a GitHub Issue or Pull Request",
322
+ inputSchema: {
323
+ type: "object",
324
+ properties: {
325
+ owner: { type: "string", description: "Repository owner" },
326
+ repo: { type: "string", description: "Repository name" },
327
+ comment_id: { type: "number", description: "Comment ID to update" },
328
+ body: { type: "string", description: "New comment body text" },
329
+ },
330
+ required: ["owner", "repo", "comment_id", "body"],
331
+ },
332
+ },
333
+ {
334
+ name: "github_delete_comment",
335
+ description: "Delete a comment from a GitHub Issue or Pull Request",
336
+ inputSchema: {
337
+ type: "object",
338
+ properties: {
339
+ owner: { type: "string", description: "Repository owner" },
340
+ repo: { type: "string", description: "Repository name" },
341
+ comment_id: { type: "number", description: "Comment ID to delete" },
342
+ },
343
+ required: ["owner", "repo", "comment_id"],
344
+ },
345
+ },
346
+ {
347
+ name: "github_add_reaction",
348
+ description: "Add a reaction (emoji) to a comment or an issue/PR directly. Provide either comment_id OR issue_number.",
349
+ inputSchema: {
350
+ type: "object",
351
+ properties: {
352
+ owner: { type: "string", description: "Repository owner" },
353
+ repo: { type: "string", description: "Repository name" },
354
+ comment_id: { type: "number", description: "Comment ID to react to (optional if issue_number is provided)" },
355
+ issue_number: { type: "number", description: "Issue/PR number to react to (optional if comment_id is provided)" },
356
+ reaction: {
357
+ type: "string",
358
+ enum: ["thumbs_up", "thumbs_down", "laugh", "confused", "heart", "hooray", "rocket", "eyes"],
359
+ description: "Reaction type: thumbs_up 👍, thumbs_down 👎, laugh 😄, confused 😕, heart ❤️, hooray 🎉, rocket 🚀, eyes 👀"
360
+ },
361
+ },
362
+ required: ["owner", "repo", "reaction"],
363
+ },
364
+ },
365
+ {
366
+ name: "github_search_issues",
367
+ description: "Search for issues in a repository with advanced filters",
368
+ inputSchema: {
369
+ type: "object",
370
+ properties: {
371
+ owner: { type: "string", description: "Repository owner" },
372
+ repo: { type: "string", description: "Repository name" },
373
+ query: { type: "string", description: "Search query (optional)" },
374
+ state: { type: "string", enum: ["open", "closed", "all"], description: "Issue state (optional)" },
375
+ labels: { type: "array", items: { type: "string" }, description: "Filter by labels (optional)" },
376
+ sort: { type: "string", enum: ["created", "updated", "comments"], description: "Sort by (optional)" },
377
+ direction: { type: "string", enum: ["asc", "desc"], description: "Sort direction (optional)" },
378
+ per_page: { type: "number", description: "Results per page, max 100 (optional)" },
379
+ },
380
+ required: ["owner", "repo"],
381
+ },
382
+ },
383
+ {
384
+ name: "github_search_prs",
385
+ description: "Search for pull requests in a repository with advanced filters",
386
+ inputSchema: {
387
+ type: "object",
388
+ properties: {
389
+ owner: { type: "string", description: "Repository owner" },
390
+ repo: { type: "string", description: "Repository name" },
391
+ query: { type: "string", description: "Search query (optional)" },
392
+ state: { type: "string", enum: ["open", "closed", "all"], description: "PR state (optional)" },
393
+ sort: { type: "string", enum: ["created", "updated", "popularity", "long-running"], description: "Sort by (optional)" },
394
+ direction: { type: "string", enum: ["asc", "desc"], description: "Sort direction (optional)" },
395
+ per_page: { type: "number", description: "Results per page, max 100 (optional)" },
396
+ },
397
+ required: ["owner", "repo"],
398
+ },
399
+ },
400
+ {
401
+ name: "github_list_recent_issues",
402
+ description: "List recent issues in a repository",
403
+ inputSchema: {
404
+ type: "object",
405
+ properties: {
406
+ owner: { type: "string", description: "Repository owner" },
407
+ repo: { type: "string", description: "Repository name" },
408
+ state: { type: "string", enum: ["open", "closed", "all"], description: "Issue state (optional, default: open)" },
409
+ sort: { type: "string", enum: ["created", "updated"], description: "Sort by (optional, default: created)" },
410
+ per_page: { type: "number", description: "Results per page, max 100 (optional, default: 30)" },
411
+ },
412
+ required: ["owner", "repo"],
413
+ },
414
+ },
415
+ {
416
+ name: "github_merge_pr",
417
+ description: "Merge a pull request",
418
+ inputSchema: {
419
+ type: "object",
420
+ properties: {
421
+ owner: { type: "string", description: "Repository owner" },
422
+ repo: { type: "string", description: "Repository name" },
423
+ pull_number: { type: "number", description: "PR number to merge" },
424
+ merge_method: { type: "string", enum: ["merge", "squash", "rebase"], description: "Merge method (optional, default: merge)" },
425
+ commit_title: { type: "string", description: "Custom commit title (optional)" },
426
+ commit_message: { type: "string", description: "Custom commit message (optional)" },
427
+ },
428
+ required: ["owner", "repo", "pull_number"],
429
+ },
430
+ },
431
+ {
432
+ name: "github_get_pr_diff",
433
+ description: "Get the full diff of a pull request",
434
+ inputSchema: {
435
+ type: "object",
436
+ properties: {
437
+ owner: { type: "string", description: "Repository owner" },
438
+ repo: { type: "string", description: "Repository name" },
439
+ pull_number: { type: "number", description: "PR number" },
440
+ },
441
+ required: ["owner", "repo", "pull_number"],
442
+ },
443
+ },
444
+ {
445
+ name: "github_get_pr_files",
446
+ description: "Get list of files changed in a pull request with details",
447
+ inputSchema: {
448
+ type: "object",
449
+ properties: {
450
+ owner: { type: "string", description: "Repository owner" },
451
+ repo: { type: "string", description: "Repository name" },
452
+ pull_number: { type: "number", description: "PR number" },
453
+ },
454
+ required: ["owner", "repo", "pull_number"],
455
+ },
456
+ },
457
+ {
458
+ name: "github_create_label",
459
+ description: "Create a new label in the repository",
460
+ inputSchema: {
461
+ type: "object",
462
+ properties: {
463
+ owner: { type: "string", description: "Repository owner" },
464
+ repo: { type: "string", description: "Repository name" },
465
+ name: { type: "string", description: "Label name" },
466
+ color: { type: "string", description: "Hex color code without '#' (e.g., 'FF0000' for red)" },
467
+ description: { type: "string", description: "Label description (optional)" },
468
+ },
469
+ required: ["owner", "repo", "name", "color"],
470
+ },
471
+ },
472
+ {
473
+ name: "github_update_label",
474
+ description: "Update an existing label (name, color, or description)",
475
+ inputSchema: {
476
+ type: "object",
477
+ properties: {
478
+ owner: { type: "string", description: "Repository owner" },
479
+ repo: { type: "string", description: "Repository name" },
480
+ name: { type: "string", description: "Current label name to update" },
481
+ new_name: { type: "string", description: "New label name (optional)" },
482
+ color: { type: "string", description: "New hex color code without '#' (optional)" },
483
+ description: { type: "string", description: "New description (optional)" },
484
+ },
485
+ required: ["owner", "repo", "name"],
486
+ },
487
+ },
488
+ {
489
+ name: "github_delete_label",
490
+ description: "Delete a label from the repository",
491
+ inputSchema: {
492
+ type: "object",
493
+ properties: {
494
+ owner: { type: "string", description: "Repository owner" },
495
+ repo: { type: "string", description: "Repository name" },
496
+ name: { type: "string", description: "Label name to delete" },
497
+ },
498
+ required: ["owner", "repo", "name"],
499
+ },
500
+ },
501
+ {
502
+ name: "github_list_labels",
503
+ description: "List all labels in the repository",
504
+ inputSchema: {
505
+ type: "object",
506
+ properties: {
507
+ owner: { type: "string", description: "Repository owner" },
508
+ repo: { type: "string", description: "Repository name" },
509
+ per_page: { type: "number", description: "Results per page, max 100 (optional, default: 30)" },
510
+ },
511
+ required: ["owner", "repo"],
512
+ },
513
+ },
514
+ {
515
+ name: "github_list_branches",
516
+ description: "List all branches in the repository",
517
+ inputSchema: {
518
+ type: "object",
519
+ properties: {
520
+ owner: { type: "string", description: "Repository owner" },
521
+ repo: { type: "string", description: "Repository name" },
522
+ protected: { type: "boolean", description: "Filter by protected status (optional)" },
523
+ per_page: { type: "number", description: "Results per page, max 100 (optional, default: 30)" },
524
+ },
525
+ required: ["owner", "repo"],
526
+ },
527
+ },
528
+ {
529
+ name: "github_create_branch",
530
+ description: "Create a new branch from an existing branch or commit",
531
+ inputSchema: {
532
+ type: "object",
533
+ properties: {
534
+ owner: { type: "string", description: "Repository owner" },
535
+ repo: { type: "string", description: "Repository name" },
536
+ branch: { type: "string", description: "New branch name" },
537
+ ref: { type: "string", description: "Source branch name or commit SHA (e.g., 'main' or 'abc123')" },
538
+ },
539
+ required: ["owner", "repo", "branch", "ref"],
540
+ },
541
+ },
542
+ {
543
+ name: "github_delete_branch",
544
+ description: "Delete a branch from the repository",
545
+ inputSchema: {
546
+ type: "object",
547
+ properties: {
548
+ owner: { type: "string", description: "Repository owner" },
549
+ repo: { type: "string", description: "Repository name" },
550
+ branch: { type: "string", description: "Branch name to delete" },
551
+ },
552
+ required: ["owner", "repo", "branch"],
553
+ },
554
+ },
555
+ {
556
+ name: "github_compare_branches",
557
+ description: "Compare two branches and show the differences",
558
+ inputSchema: {
559
+ type: "object",
560
+ properties: {
561
+ owner: { type: "string", description: "Repository owner" },
562
+ repo: { type: "string", description: "Repository name" },
563
+ base: { type: "string", description: "Base branch name" },
564
+ head: { type: "string", description: "Head branch name to compare" },
565
+ },
566
+ required: ["owner", "repo", "base", "head"],
567
+ },
568
+ },
157
569
  ],
158
570
  };
159
571
  });
@@ -189,9 +601,11 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
189
601
  ),
190
602
  },
191
603
  comments: comments.data.map((c) => ({
604
+ id: c.id,
192
605
  user: c.user?.login,
193
606
  body: c.body,
194
607
  created_at: c.created_at,
608
+ html_url: c.html_url,
195
609
  })),
196
610
  },
197
611
  null,
@@ -252,9 +666,11 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
252
666
  ),
253
667
  },
254
668
  comments: comments.data.map((c) => ({
669
+ id: c.id,
255
670
  user: c.user?.login,
256
671
  body: c.body,
257
672
  created_at: c.created_at,
673
+ html_url: c.html_url,
258
674
  })),
259
675
  commits: commits.data.map((c) => ({
260
676
  sha: c.sha,
@@ -461,6 +877,1018 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
461
877
  }
462
878
  }
463
879
 
880
+ if (name === "github_add_comment") {
881
+ try {
882
+ const { owner, repo, issue_number, body } = AddCommentSchema.parse(args);
883
+
884
+ const comment = await octokit.rest.issues.createComment({
885
+ owner,
886
+ repo,
887
+ issue_number,
888
+ body,
889
+ });
890
+
891
+ return {
892
+ content: [
893
+ {
894
+ type: "text",
895
+ text: JSON.stringify(
896
+ {
897
+ success: true,
898
+ comment: {
899
+ id: comment.data.id,
900
+ body: comment.data.body,
901
+ user: comment.data.user?.login,
902
+ html_url: comment.data.html_url,
903
+ created_at: comment.data.created_at,
904
+ },
905
+ message: `Comment added successfully to issue/PR #${issue_number}`,
906
+ },
907
+ null,
908
+ 2
909
+ ),
910
+ },
911
+ ],
912
+ };
913
+ } catch (error: any) {
914
+ const issueNum = args && typeof args === 'object' && 'issue_number' in args ? args.issue_number : 'unknown';
915
+ const owner = args && typeof args === 'object' && 'owner' in args ? args.owner : 'unknown';
916
+ const repo = args && typeof args === 'object' && 'repo' in args ? args.repo : 'unknown';
917
+ return {
918
+ content: [
919
+ {
920
+ type: "text",
921
+ text: JSON.stringify({
922
+ error: error.message,
923
+ status: error.status,
924
+ detail: `Failed to add comment to issue/PR #${issueNum} in ${owner}/${repo}`,
925
+ }, null, 2),
926
+ },
927
+ ],
928
+ isError: true,
929
+ };
930
+ }
931
+ }
932
+
933
+ if (name === "github_update_comment") {
934
+ try {
935
+ const { owner, repo, comment_id, body } = UpdateCommentSchema.parse(args);
936
+
937
+ const comment = await octokit.rest.issues.updateComment({
938
+ owner,
939
+ repo,
940
+ comment_id,
941
+ body,
942
+ });
943
+
944
+ return {
945
+ content: [
946
+ {
947
+ type: "text",
948
+ text: JSON.stringify(
949
+ {
950
+ success: true,
951
+ comment: {
952
+ id: comment.data.id,
953
+ body: comment.data.body,
954
+ user: comment.data.user?.login,
955
+ html_url: comment.data.html_url,
956
+ updated_at: comment.data.updated_at,
957
+ },
958
+ message: `Comment #${comment_id} updated successfully`,
959
+ },
960
+ null,
961
+ 2
962
+ ),
963
+ },
964
+ ],
965
+ };
966
+ } catch (error: any) {
967
+ const commentId = args && typeof args === 'object' && 'comment_id' in args ? args.comment_id : 'unknown';
968
+ const owner = args && typeof args === 'object' && 'owner' in args ? args.owner : 'unknown';
969
+ const repo = args && typeof args === 'object' && 'repo' in args ? args.repo : 'unknown';
970
+ return {
971
+ content: [
972
+ {
973
+ type: "text",
974
+ text: JSON.stringify({
975
+ error: error.message,
976
+ status: error.status,
977
+ detail: `Failed to update comment #${commentId} in ${owner}/${repo}`,
978
+ }, null, 2),
979
+ },
980
+ ],
981
+ isError: true,
982
+ };
983
+ }
984
+ }
985
+
986
+ if (name === "github_delete_comment") {
987
+ try {
988
+ const { owner, repo, comment_id } = DeleteCommentSchema.parse(args);
989
+
990
+ await octokit.rest.issues.deleteComment({
991
+ owner,
992
+ repo,
993
+ comment_id,
994
+ });
995
+
996
+ return {
997
+ content: [
998
+ {
999
+ type: "text",
1000
+ text: JSON.stringify(
1001
+ {
1002
+ success: true,
1003
+ message: `Comment #${comment_id} deleted successfully`,
1004
+ },
1005
+ null,
1006
+ 2
1007
+ ),
1008
+ },
1009
+ ],
1010
+ };
1011
+ } catch (error: any) {
1012
+ const commentId = args && typeof args === 'object' && 'comment_id' in args ? args.comment_id : 'unknown';
1013
+ const owner = args && typeof args === 'object' && 'owner' in args ? args.owner : 'unknown';
1014
+ const repo = args && typeof args === 'object' && 'repo' in args ? args.repo : 'unknown';
1015
+ return {
1016
+ content: [
1017
+ {
1018
+ type: "text",
1019
+ text: JSON.stringify({
1020
+ error: error.message,
1021
+ status: error.status,
1022
+ detail: `Failed to delete comment #${commentId} in ${owner}/${repo}`,
1023
+ }, null, 2),
1024
+ },
1025
+ ],
1026
+ isError: true,
1027
+ };
1028
+ }
1029
+ }
1030
+
1031
+ if (name === "github_add_reaction") {
1032
+ try {
1033
+ const { owner, repo, comment_id, issue_number, reaction } = AddReactionSchema.parse(args);
1034
+
1035
+ let reactionResponse;
1036
+ let target = "";
1037
+
1038
+ const githubReaction = REACTION_MAP[reaction] || reaction;
1039
+
1040
+ if (comment_id) {
1041
+ // Add reaction to a comment
1042
+ reactionResponse = await octokit.rest.reactions.createForIssueComment({
1043
+ owner,
1044
+ repo,
1045
+ comment_id,
1046
+ content: githubReaction as any,
1047
+ });
1048
+ target = `comment #${comment_id}`;
1049
+ } else if (issue_number) {
1050
+ // Add reaction to an issue/PR
1051
+ reactionResponse = await octokit.rest.reactions.createForIssue({
1052
+ owner,
1053
+ repo,
1054
+ issue_number,
1055
+ content: githubReaction as any,
1056
+ });
1057
+ target = `issue/PR #${issue_number}`;
1058
+ }
1059
+
1060
+ return {
1061
+ content: [
1062
+ {
1063
+ type: "text",
1064
+ text: JSON.stringify(
1065
+ {
1066
+ success: true,
1067
+ reaction: {
1068
+ id: reactionResponse!.data.id,
1069
+ content: reactionResponse!.data.content,
1070
+ user: reactionResponse!.data.user?.login,
1071
+ created_at: reactionResponse!.data.created_at,
1072
+ },
1073
+ message: `Reaction "${reaction}" added successfully to ${target}`,
1074
+ },
1075
+ null,
1076
+ 2
1077
+ ),
1078
+ },
1079
+ ],
1080
+ };
1081
+ } catch (error: any) {
1082
+ const commentId = args && typeof args === 'object' && 'comment_id' in args ? args.comment_id : undefined;
1083
+ const issueNum = args && typeof args === 'object' && 'issue_number' in args ? args.issue_number : undefined;
1084
+ const owner = args && typeof args === 'object' && 'owner' in args ? args.owner : 'unknown';
1085
+ const repo = args && typeof args === 'object' && 'repo' in args ? args.repo : 'unknown';
1086
+ const reaction = args && typeof args === 'object' && 'reaction' in args ? args.reaction : 'unknown';
1087
+ const target = commentId ? `comment #${commentId}` : issueNum ? `issue/PR #${issueNum}` : 'unknown';
1088
+ return {
1089
+ content: [
1090
+ {
1091
+ type: "text",
1092
+ text: JSON.stringify({
1093
+ error: error.message,
1094
+ status: error.status,
1095
+ detail: `Failed to add reaction "${reaction}" to ${target} in ${owner}/${repo}`,
1096
+ }, null, 2),
1097
+ },
1098
+ ],
1099
+ isError: true,
1100
+ };
1101
+ }
1102
+ }
1103
+
1104
+ if (name === "github_search_issues") {
1105
+ try {
1106
+ const { owner, repo, query, state, labels, sort, direction, per_page } = SearchIssuesSchema.parse(args);
1107
+
1108
+ const issues = await octokit.rest.issues.listForRepo({
1109
+ owner,
1110
+ repo,
1111
+ state: state || "open",
1112
+ labels: labels?.join(","),
1113
+ sort: sort as any,
1114
+ direction: direction as any,
1115
+ per_page: per_page || 30,
1116
+ });
1117
+
1118
+ // Filter out pull requests first
1119
+ const issuesOnly = issues.data.filter(issue => !issue.pull_request);
1120
+ const filteredIssues = query
1121
+ ? issues.data.filter(issue => !issue.pull_request).filter(issue =>
1122
+ issue.title.toLowerCase().includes(query.toLowerCase()) ||
1123
+ issue.body?.toLowerCase().includes(query.toLowerCase())
1124
+ )
1125
+ : issues.data.filter(issue => !issue.pull_request);
1126
+
1127
+ return {
1128
+ content: [
1129
+ {
1130
+ type: "text",
1131
+ text: JSON.stringify(
1132
+ {
1133
+ total_count: filteredIssues.length,
1134
+ issues: filteredIssues.map(issue => ({
1135
+ number: issue.number,
1136
+ title: issue.title,
1137
+ state: issue.state,
1138
+ user: issue.user?.login,
1139
+ labels: issue.labels.map((l: any) => typeof l === "string" ? l : l.name),
1140
+ created_at: issue.created_at,
1141
+ updated_at: issue.updated_at,
1142
+ comments: issue.comments,
1143
+ html_url: issue.html_url,
1144
+ })),
1145
+ },
1146
+ null,
1147
+ 2
1148
+ ),
1149
+ },
1150
+ ],
1151
+ };
1152
+ } catch (error: any) {
1153
+ const owner = args && typeof args === 'object' && 'owner' in args ? args.owner : 'unknown';
1154
+ const repo = args && typeof args === 'object' && 'repo' in args ? args.repo : 'unknown';
1155
+ return {
1156
+ content: [
1157
+ {
1158
+ type: "text",
1159
+ text: JSON.stringify({
1160
+ error: error.message,
1161
+ status: error.status,
1162
+ detail: `Failed to search issues in ${owner}/${repo}`,
1163
+ }, null, 2),
1164
+ },
1165
+ ],
1166
+ isError: true,
1167
+ };
1168
+ }
1169
+ }
1170
+
1171
+ if (name === "github_search_prs") {
1172
+ try {
1173
+ const { owner, repo, query, state, sort, direction, per_page } = SearchPRsSchema.parse(args);
1174
+
1175
+ const prs = await octokit.rest.pulls.list({
1176
+ owner,
1177
+ repo,
1178
+ state: state || "open",
1179
+ sort: sort as any,
1180
+ direction: direction as any,
1181
+ per_page: per_page || 30,
1182
+ });
1183
+
1184
+ const filteredPRs = query
1185
+ ? prs.data.filter(pr =>
1186
+ pr.title.toLowerCase().includes(query.toLowerCase()) ||
1187
+ pr.body?.toLowerCase().includes(query.toLowerCase())
1188
+ )
1189
+ : prs.data;
1190
+
1191
+ return {
1192
+ content: [
1193
+ {
1194
+ type: "text",
1195
+ text: JSON.stringify(
1196
+ {
1197
+ total_count: filteredPRs.length,
1198
+ pull_requests: filteredPRs.map(pr => ({
1199
+ number: pr.number,
1200
+ title: pr.title,
1201
+ state: pr.state,
1202
+ user: pr.user?.login,
1203
+ head: pr.head.ref,
1204
+ base: pr.base.ref,
1205
+ created_at: pr.created_at,
1206
+ updated_at: pr.updated_at,
1207
+ draft: pr.draft,
1208
+ html_url: pr.html_url,
1209
+ })),
1210
+ },
1211
+ null,
1212
+ 2
1213
+ ),
1214
+ },
1215
+ ],
1216
+ };
1217
+ } catch (error: any) {
1218
+ const owner = args && typeof args === 'object' && 'owner' in args ? args.owner : 'unknown';
1219
+ const repo = args && typeof args === 'object' && 'repo' in args ? args.repo : 'unknown';
1220
+ return {
1221
+ content: [
1222
+ {
1223
+ type: "text",
1224
+ text: JSON.stringify({
1225
+ error: error.message,
1226
+ status: error.status,
1227
+ detail: `Failed to search PRs in ${owner}/${repo}`,
1228
+ }, null, 2),
1229
+ },
1230
+ ],
1231
+ isError: true,
1232
+ };
1233
+ }
1234
+ }
1235
+
1236
+ if (name === "github_list_recent_issues") {
1237
+ try {
1238
+ const { owner, repo, state, sort, per_page } = ListRecentIssuesSchema.parse(args);
1239
+
1240
+ const issues = await octokit.rest.issues.listForRepo({
1241
+ owner,
1242
+ repo,
1243
+ state: state || "open",
1244
+ sort: sort || "created",
1245
+ direction: "desc",
1246
+ per_page: per_page || 30,
1247
+ });
1248
+
1249
+ // Filter out pull requests (GitHub API returns both issues and PRs)
1250
+ const actualIssues = issues.data.filter(issue => !issue.pull_request);
1251
+
1252
+ return {
1253
+ content: [
1254
+ {
1255
+ type: "text",
1256
+ text: JSON.stringify(
1257
+ {
1258
+ count: actualIssues.length,
1259
+ issues: actualIssues.map(issue => ({
1260
+ number: issue.number,
1261
+ title: issue.title,
1262
+ state: issue.state,
1263
+ user: issue.user?.login,
1264
+ labels: issue.labels.map((l: any) => typeof l === "string" ? l : l.name),
1265
+ created_at: issue.created_at,
1266
+ updated_at: issue.updated_at,
1267
+ comments: issue.comments,
1268
+ html_url: issue.html_url,
1269
+ })),
1270
+ },
1271
+ null,
1272
+ 2
1273
+ ),
1274
+ },
1275
+ ],
1276
+ };
1277
+ } catch (error: any) {
1278
+ const owner = args && typeof args === 'object' && 'owner' in args ? args.owner : 'unknown';
1279
+ const repo = args && typeof args === 'object' && 'repo' in args ? args.repo : 'unknown';
1280
+ return {
1281
+ content: [
1282
+ {
1283
+ type: "text",
1284
+ text: JSON.stringify({
1285
+ error: error.message,
1286
+ status: error.status,
1287
+ detail: `Failed to list recent issues in ${owner}/${repo}`,
1288
+ }, null, 2),
1289
+ },
1290
+ ],
1291
+ isError: true,
1292
+ };
1293
+ }
1294
+ }
1295
+
1296
+ if (name === "github_merge_pr") {
1297
+ try {
1298
+ const { owner, repo, pull_number, merge_method, commit_title, commit_message } = MergePRSchema.parse(args);
1299
+
1300
+ const result = await octokit.rest.pulls.merge({
1301
+ owner,
1302
+ repo,
1303
+ pull_number,
1304
+ merge_method: merge_method as any,
1305
+ commit_title,
1306
+ commit_message,
1307
+ });
1308
+
1309
+ return {
1310
+ content: [
1311
+ {
1312
+ type: "text",
1313
+ text: JSON.stringify(
1314
+ {
1315
+ success: true,
1316
+ merged: result.data.merged,
1317
+ sha: result.data.sha,
1318
+ message: result.data.message,
1319
+ },
1320
+ null,
1321
+ 2
1322
+ ),
1323
+ },
1324
+ ],
1325
+ };
1326
+ } catch (error: any) {
1327
+ const pullNum = args && typeof args === 'object' && 'pull_number' in args ? args.pull_number : 'unknown';
1328
+ const owner = args && typeof args === 'object' && 'owner' in args ? args.owner : 'unknown';
1329
+ const repo = args && typeof args === 'object' && 'repo' in args ? args.repo : 'unknown';
1330
+ return {
1331
+ content: [
1332
+ {
1333
+ type: "text",
1334
+ text: JSON.stringify({
1335
+ error: error.message,
1336
+ status: error.status,
1337
+ detail: `Failed to merge PR #${pullNum} in ${owner}/${repo}`,
1338
+ }, null, 2),
1339
+ },
1340
+ ],
1341
+ isError: true,
1342
+ };
1343
+ }
1344
+ }
1345
+
1346
+ if (name === "github_get_pr_diff") {
1347
+ try {
1348
+ const { owner, repo, pull_number } = GetPRDiffSchema.parse(args);
1349
+
1350
+ const diff = await octokit.rest.pulls.get({
1351
+ owner,
1352
+ repo,
1353
+ pull_number,
1354
+ mediaType: {
1355
+ format: "diff",
1356
+ },
1357
+ });
1358
+
1359
+ return {
1360
+ content: [
1361
+ {
1362
+ type: "text",
1363
+ text: JSON.stringify(
1364
+ {
1365
+ pull_number,
1366
+ diff: diff.data as any,
1367
+ },
1368
+ null,
1369
+ 2
1370
+ ),
1371
+ },
1372
+ ],
1373
+ };
1374
+ } catch (error: any) {
1375
+ const pullNum = args && typeof args === 'object' && 'pull_number' in args ? args.pull_number : 'unknown';
1376
+ const owner = args && typeof args === 'object' && 'owner' in args ? args.owner : 'unknown';
1377
+ const repo = args && typeof args === 'object' && 'repo' in args ? args.repo : 'unknown';
1378
+ return {
1379
+ content: [
1380
+ {
1381
+ type: "text",
1382
+ text: JSON.stringify({
1383
+ error: error.message,
1384
+ status: error.status,
1385
+ detail: `Failed to get diff for PR #${pullNum} in ${owner}/${repo}`,
1386
+ }, null, 2),
1387
+ },
1388
+ ],
1389
+ isError: true,
1390
+ };
1391
+ }
1392
+ }
1393
+
1394
+ if (name === "github_get_pr_files") {
1395
+ try {
1396
+ const { owner, repo, pull_number } = GetPRFilesSchema.parse(args);
1397
+
1398
+ const files = await octokit.rest.pulls.listFiles({
1399
+ owner,
1400
+ repo,
1401
+ pull_number,
1402
+ });
1403
+
1404
+ return {
1405
+ content: [
1406
+ {
1407
+ type: "text",
1408
+ text: JSON.stringify(
1409
+ {
1410
+ pull_number,
1411
+ total_files: files.data.length,
1412
+ files: files.data.map(file => ({
1413
+ filename: file.filename,
1414
+ status: file.status,
1415
+ additions: file.additions,
1416
+ deletions: file.deletions,
1417
+ changes: file.changes,
1418
+ blob_url: file.blob_url,
1419
+ raw_url: file.raw_url,
1420
+ patch: file.patch,
1421
+ })),
1422
+ },
1423
+ null,
1424
+ 2
1425
+ ),
1426
+ },
1427
+ ],
1428
+ };
1429
+ } catch (error: any) {
1430
+ const pullNum = args && typeof args === 'object' && 'pull_number' in args ? args.pull_number : 'unknown';
1431
+ const owner = args && typeof args === 'object' && 'owner' in args ? args.owner : 'unknown';
1432
+ const repo = args && typeof args === 'object' && 'repo' in args ? args.repo : 'unknown';
1433
+ return {
1434
+ content: [
1435
+ {
1436
+ type: "text",
1437
+ text: JSON.stringify({
1438
+ error: error.message,
1439
+ status: error.status,
1440
+ detail: `Failed to get files for PR #${pullNum} in ${owner}/${repo}`,
1441
+ }, null, 2),
1442
+ },
1443
+ ],
1444
+ isError: true,
1445
+ };
1446
+ }
1447
+ }
1448
+
1449
+ if (name === "github_create_label") {
1450
+ try {
1451
+ const { owner, repo, name: labelName, color, description } = CreateLabelSchema.parse(args);
1452
+
1453
+ const label = await octokit.rest.issues.createLabel({
1454
+ owner,
1455
+ repo,
1456
+ name: labelName,
1457
+ color,
1458
+ description,
1459
+ });
1460
+
1461
+ return {
1462
+ content: [
1463
+ {
1464
+ type: "text",
1465
+ text: JSON.stringify(
1466
+ {
1467
+ success: true,
1468
+ label: {
1469
+ name: label.data.name,
1470
+ color: label.data.color,
1471
+ description: label.data.description,
1472
+ url: label.data.url,
1473
+ },
1474
+ message: `Label "${labelName}" created successfully`,
1475
+ },
1476
+ null,
1477
+ 2
1478
+ ),
1479
+ },
1480
+ ],
1481
+ };
1482
+ } catch (error: any) {
1483
+ const labelName = args && typeof args === 'object' && 'name' in args ? args.name : 'unknown';
1484
+ const owner = args && typeof args === 'object' && 'owner' in args ? args.owner : 'unknown';
1485
+ const repo = args && typeof args === 'object' && 'repo' in args ? args.repo : 'unknown';
1486
+ return {
1487
+ content: [
1488
+ {
1489
+ type: "text",
1490
+ text: JSON.stringify({
1491
+ error: error.message,
1492
+ status: error.status,
1493
+ detail: `Failed to create label "${labelName}" in ${owner}/${repo}`,
1494
+ }, null, 2),
1495
+ },
1496
+ ],
1497
+ isError: true,
1498
+ };
1499
+ }
1500
+ }
1501
+
1502
+ if (name === "github_update_label") {
1503
+ try {
1504
+ const { owner, repo, name: currentName, new_name, color, description } = UpdateLabelSchema.parse(args);
1505
+
1506
+ const label = await octokit.rest.issues.updateLabel({
1507
+ owner,
1508
+ repo,
1509
+ name: currentName,
1510
+ new_name,
1511
+ color,
1512
+ description,
1513
+ });
1514
+
1515
+ return {
1516
+ content: [
1517
+ {
1518
+ type: "text",
1519
+ text: JSON.stringify(
1520
+ {
1521
+ success: true,
1522
+ label: {
1523
+ name: label.data.name,
1524
+ color: label.data.color,
1525
+ description: label.data.description,
1526
+ url: label.data.url,
1527
+ },
1528
+ message: `Label "${currentName}" updated successfully`,
1529
+ },
1530
+ null,
1531
+ 2
1532
+ ),
1533
+ },
1534
+ ],
1535
+ };
1536
+ } catch (error: any) {
1537
+ const labelName = args && typeof args === 'object' && 'name' in args ? args.name : 'unknown';
1538
+ const owner = args && typeof args === 'object' && 'owner' in args ? args.owner : 'unknown';
1539
+ const repo = args && typeof args === 'object' && 'repo' in args ? args.repo : 'unknown';
1540
+ return {
1541
+ content: [
1542
+ {
1543
+ type: "text",
1544
+ text: JSON.stringify({
1545
+ error: error.message,
1546
+ status: error.status,
1547
+ detail: `Failed to update label "${labelName}" in ${owner}/${repo}`,
1548
+ }, null, 2),
1549
+ },
1550
+ ],
1551
+ isError: true,
1552
+ };
1553
+ }
1554
+ }
1555
+
1556
+ if (name === "github_delete_label") {
1557
+ try {
1558
+ const { owner, repo, name: labelName } = DeleteLabelSchema.parse(args);
1559
+
1560
+ await octokit.rest.issues.deleteLabel({
1561
+ owner,
1562
+ repo,
1563
+ name: labelName,
1564
+ });
1565
+
1566
+ return {
1567
+ content: [
1568
+ {
1569
+ type: "text",
1570
+ text: JSON.stringify(
1571
+ {
1572
+ success: true,
1573
+ message: `Label "${labelName}" deleted successfully from ${owner}/${repo}`,
1574
+ },
1575
+ null,
1576
+ 2
1577
+ ),
1578
+ },
1579
+ ],
1580
+ };
1581
+ } catch (error: any) {
1582
+ const labelName = args && typeof args === 'object' && 'name' in args ? args.name : 'unknown';
1583
+ const owner = args && typeof args === 'object' && 'owner' in args ? args.owner : 'unknown';
1584
+ const repo = args && typeof args === 'object' && 'repo' in args ? args.repo : 'unknown';
1585
+ return {
1586
+ content: [
1587
+ {
1588
+ type: "text",
1589
+ text: JSON.stringify({
1590
+ error: error.message,
1591
+ status: error.status,
1592
+ detail: `Failed to delete label "${labelName}" from ${owner}/${repo}`,
1593
+ }, null, 2),
1594
+ },
1595
+ ],
1596
+ isError: true,
1597
+ };
1598
+ }
1599
+ }
1600
+
1601
+ if (name === "github_list_labels") {
1602
+ try {
1603
+ const { owner, repo, per_page } = ListLabelsSchema.parse(args);
1604
+
1605
+ const labels = await octokit.rest.issues.listLabelsForRepo({
1606
+ owner,
1607
+ repo,
1608
+ per_page,
1609
+ });
1610
+
1611
+ return {
1612
+ content: [
1613
+ {
1614
+ type: "text",
1615
+ text: JSON.stringify(
1616
+ {
1617
+ success: true,
1618
+ count: labels.data.length,
1619
+ labels: labels.data.map((label) => ({
1620
+ name: label.name,
1621
+ color: label.color,
1622
+ description: label.description,
1623
+ url: label.url,
1624
+ })),
1625
+ },
1626
+ null,
1627
+ 2
1628
+ ),
1629
+ },
1630
+ ],
1631
+ };
1632
+ } catch (error: any) {
1633
+ const owner = args && typeof args === 'object' && 'owner' in args ? args.owner : 'unknown';
1634
+ const repo = args && typeof args === 'object' && 'repo' in args ? args.repo : 'unknown';
1635
+ return {
1636
+ content: [
1637
+ {
1638
+ type: "text",
1639
+ text: JSON.stringify({
1640
+ error: error.message,
1641
+ status: error.status,
1642
+ detail: `Failed to list labels for ${owner}/${repo}`,
1643
+ }, null, 2),
1644
+ },
1645
+ ],
1646
+ isError: true,
1647
+ };
1648
+ }
1649
+ }
1650
+
1651
+ if (name === "github_list_branches") {
1652
+ try {
1653
+ const { owner, repo, protected: isProtected, per_page } = ListBranchesSchema.parse(args);
1654
+
1655
+ const branches = await octokit.rest.repos.listBranches({
1656
+ owner,
1657
+ repo,
1658
+ protected: isProtected,
1659
+ per_page,
1660
+ });
1661
+
1662
+ return {
1663
+ content: [
1664
+ {
1665
+ type: "text",
1666
+ text: JSON.stringify(
1667
+ {
1668
+ success: true,
1669
+ count: branches.data.length,
1670
+ branches: branches.data.map((branch) => ({
1671
+ name: branch.name,
1672
+ commit: {
1673
+ sha: branch.commit.sha,
1674
+ url: branch.commit.url,
1675
+ },
1676
+ protected: branch.protected,
1677
+ })),
1678
+ },
1679
+ null,
1680
+ 2
1681
+ ),
1682
+ },
1683
+ ],
1684
+ };
1685
+ } catch (error: any) {
1686
+ const owner = args && typeof args === 'object' && 'owner' in args ? args.owner : 'unknown';
1687
+ const repo = args && typeof args === 'object' && 'repo' in args ? args.repo : 'unknown';
1688
+ return {
1689
+ content: [
1690
+ {
1691
+ type: "text",
1692
+ text: JSON.stringify({
1693
+ error: error.message,
1694
+ status: error.status,
1695
+ detail: `Failed to list branches for ${owner}/${repo}`,
1696
+ }, null, 2),
1697
+ },
1698
+ ],
1699
+ isError: true,
1700
+ };
1701
+ }
1702
+ }
1703
+
1704
+ if (name === "github_create_branch") {
1705
+ try {
1706
+ const { owner, repo, branch, ref } = CreateBranchSchema.parse(args);
1707
+
1708
+ // Get the SHA of the source ref
1709
+ let sha: string;
1710
+ try {
1711
+ // Try to get ref as a branch first
1712
+ const refData = await octokit.rest.git.getRef({
1713
+ owner,
1714
+ repo,
1715
+ ref: `heads/${ref}`,
1716
+ });
1717
+ sha = refData.data.object.sha;
1718
+ } catch {
1719
+ // If not a branch, try as a commit SHA
1720
+ const commit = await octokit.rest.git.getCommit({
1721
+ owner,
1722
+ repo,
1723
+ commit_sha: ref,
1724
+ });
1725
+ sha = commit.data.sha;
1726
+ }
1727
+
1728
+ // Create the new branch
1729
+ const newBranch = await octokit.rest.git.createRef({
1730
+ owner,
1731
+ repo,
1732
+ ref: `refs/heads/${branch}`,
1733
+ sha,
1734
+ });
1735
+
1736
+ return {
1737
+ content: [
1738
+ {
1739
+ type: "text",
1740
+ text: JSON.stringify(
1741
+ {
1742
+ success: true,
1743
+ branch: {
1744
+ name: branch,
1745
+ ref: newBranch.data.ref,
1746
+ sha: newBranch.data.object.sha,
1747
+ url: newBranch.data.url,
1748
+ },
1749
+ message: `Branch "${branch}" created successfully from "${ref}"`,
1750
+ },
1751
+ null,
1752
+ 2
1753
+ ),
1754
+ },
1755
+ ],
1756
+ };
1757
+ } catch (error: any) {
1758
+ const branchName = args && typeof args === 'object' && 'branch' in args ? args.branch : 'unknown';
1759
+ const owner = args && typeof args === 'object' && 'owner' in args ? args.owner : 'unknown';
1760
+ const repo = args && typeof args === 'object' && 'repo' in args ? args.repo : 'unknown';
1761
+ return {
1762
+ content: [
1763
+ {
1764
+ type: "text",
1765
+ text: JSON.stringify({
1766
+ error: error.message,
1767
+ status: error.status,
1768
+ detail: `Failed to create branch "${branchName}" in ${owner}/${repo}`,
1769
+ }, null, 2),
1770
+ },
1771
+ ],
1772
+ isError: true,
1773
+ };
1774
+ }
1775
+ }
1776
+
1777
+ if (name === "github_delete_branch") {
1778
+ try {
1779
+ const { owner, repo, branch } = DeleteBranchSchema.parse(args);
1780
+
1781
+ await octokit.rest.git.deleteRef({
1782
+ owner,
1783
+ repo,
1784
+ ref: `heads/${branch}`,
1785
+ });
1786
+
1787
+ return {
1788
+ content: [
1789
+ {
1790
+ type: "text",
1791
+ text: JSON.stringify(
1792
+ {
1793
+ success: true,
1794
+ message: `Branch "${branch}" deleted successfully from ${owner}/${repo}`,
1795
+ },
1796
+ null,
1797
+ 2
1798
+ ),
1799
+ },
1800
+ ],
1801
+ };
1802
+ } catch (error: any) {
1803
+ const branchName = args && typeof args === 'object' && 'branch' in args ? args.branch : 'unknown';
1804
+ const owner = args && typeof args === 'object' && 'owner' in args ? args.owner : 'unknown';
1805
+ const repo = args && typeof args === 'object' && 'repo' in args ? args.repo : 'unknown';
1806
+ return {
1807
+ content: [
1808
+ {
1809
+ type: "text",
1810
+ text: JSON.stringify({
1811
+ error: error.message,
1812
+ status: error.status,
1813
+ detail: `Failed to delete branch "${branchName}" from ${owner}/${repo}`,
1814
+ }, null, 2),
1815
+ },
1816
+ ],
1817
+ isError: true,
1818
+ };
1819
+ }
1820
+ }
1821
+
1822
+ if (name === "github_compare_branches") {
1823
+ try {
1824
+ const { owner, repo, base, head } = CompareBranchesSchema.parse(args);
1825
+
1826
+ const comparison = await octokit.rest.repos.compareCommits({
1827
+ owner,
1828
+ repo,
1829
+ base,
1830
+ head,
1831
+ });
1832
+
1833
+ return {
1834
+ content: [
1835
+ {
1836
+ type: "text",
1837
+ text: JSON.stringify(
1838
+ {
1839
+ success: true,
1840
+ comparison: {
1841
+ status: comparison.data.status,
1842
+ ahead_by: comparison.data.ahead_by,
1843
+ behind_by: comparison.data.behind_by,
1844
+ total_commits: comparison.data.total_commits,
1845
+ base_commit: {
1846
+ sha: comparison.data.base_commit.sha,
1847
+ message: comparison.data.base_commit.commit.message,
1848
+ },
1849
+ commits: comparison.data.commits.map((commit) => ({
1850
+ sha: commit.sha,
1851
+ message: commit.commit.message,
1852
+ author: commit.commit.author?.name,
1853
+ date: commit.commit.author?.date,
1854
+ })),
1855
+ files: comparison.data.files?.map((file) => ({
1856
+ filename: file.filename,
1857
+ status: file.status,
1858
+ additions: file.additions,
1859
+ deletions: file.deletions,
1860
+ changes: file.changes,
1861
+ })),
1862
+ },
1863
+ message: `Comparing ${base}...${head}: ${comparison.data.ahead_by} commits ahead, ${comparison.data.behind_by} commits behind`,
1864
+ },
1865
+ null,
1866
+ 2
1867
+ ),
1868
+ },
1869
+ ],
1870
+ };
1871
+ } catch (error: any) {
1872
+ const base = args && typeof args === 'object' && 'base' in args ? args.base : 'unknown';
1873
+ const head = args && typeof args === 'object' && 'head' in args ? args.head : 'unknown';
1874
+ const owner = args && typeof args === 'object' && 'owner' in args ? args.owner : 'unknown';
1875
+ const repo = args && typeof args === 'object' && 'repo' in args ? args.repo : 'unknown';
1876
+ return {
1877
+ content: [
1878
+ {
1879
+ type: "text",
1880
+ text: JSON.stringify({
1881
+ error: error.message,
1882
+ status: error.status,
1883
+ detail: `Failed to compare branches ${base}...${head} in ${owner}/${repo}`,
1884
+ }, null, 2),
1885
+ },
1886
+ ],
1887
+ isError: true,
1888
+ };
1889
+ }
1890
+ }
1891
+
464
1892
  throw new Error(`Unknown tool: ${name}`);
465
1893
  });
466
1894