@rbm897/github-mcp 0.7.1

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/README.md ADDED
@@ -0,0 +1,657 @@
1
+ # GitHub MCP Server
2
+
3
+ A Model Context Protocol (MCP) server that provides GitHub integration tools for pull requests, reviews, and repository operations.
4
+
5
+ ## Features
6
+
7
+ - **Pull Request Management**
8
+ - List pull requests with filtering
9
+ - Get detailed PR information and file changes
10
+ - Create new pull requests
11
+
12
+ - **Code Review Tools**
13
+ - Add review comments to specific lines
14
+ - Approve pull requests
15
+ - Submit comprehensive reviews (approve/request changes/comment)
16
+ - Request reviews from users and teams
17
+ - List all review comments
18
+
19
+ - **Issue Management**
20
+ - Create, update, and close issues
21
+ - List issues with advanced filtering
22
+ - Add comments to issues
23
+ - Assign users to issues
24
+ - Complete issue lifecycle management
25
+
26
+ - **Repository Operations**
27
+ - Get repository information and statistics
28
+ - Browse commit history and details
29
+ - List and create branches
30
+ - Read and update file contents
31
+ - Direct file manipulation via API
32
+
33
+ - **Labels & Organization**
34
+ - List and create repository labels
35
+ - Manage milestones
36
+ - Organize issues and PRs with metadata
37
+
38
+ - **Collaboration Tools**
39
+ - List repository collaborators
40
+ - Check user permissions
41
+ - Manage issue assignments
42
+ - Team and user management
43
+
44
+ - **Search & Discovery**
45
+ - Search repositories across GitHub
46
+ - Search issues and pull requests
47
+ - Search code within repositories
48
+ - Advanced filtering and sorting
49
+
50
+ - **GitHub Actions Integration**
51
+ - List repository workflows
52
+ - Manually trigger workflows
53
+ - Monitor automation status
54
+
55
+ ## Installation
56
+
57
+ ```bash
58
+ npm install @skhatri/github-mcp
59
+ ```
60
+
61
+ ## Setup
62
+
63
+ ### 1. GitHub Authentication
64
+
65
+ Choose one of the following authentication methods:
66
+
67
+ #### Option A: Personal Access Token (PAT)
68
+ Create a GitHub Personal Access Token with the following permissions:
69
+ - `repo` (Full control of private repositories)
70
+ - `pull_requests:write` (Create and update pull requests)
71
+
72
+ #### Option B: GitHub App Installation Token
73
+ If using a GitHub App, you'll need an installation token with these permissions:
74
+ - `Contents: Read` (to read repository files)
75
+ - `Pull requests: Write` (to create/modify pull requests)
76
+ - `Metadata: Read` (basic repository information)
77
+
78
+ GitHub App tokens are preferable for organizations as they provide:
79
+ - Fine-grained repository access
80
+ - Better security and audit logging
81
+ - Organization-level management
82
+
83
+ ### 2. Environment Variables
84
+
85
+ Set your GitHub token as an environment variable:
86
+
87
+ **For Personal Access Token:**
88
+ ```bash
89
+ export GITHUB_TOKEN=ghp_your_personal_access_token_here
90
+ export OWNER=your_github_username_or_org # Optional: set default owner
91
+ ```
92
+
93
+ **For GitHub App Installation Token:**
94
+ ```bash
95
+ export GITHUB_TOKEN=ghs_your_installation_token_here
96
+ export OWNER=your_github_username_or_org # Optional: set default owner
97
+ ```
98
+
99
+ Or create a `.env` file:
100
+
101
+ ```env
102
+ # Personal Access Token (starts with ghp_)
103
+ GITHUB_TOKEN=ghp_your_personal_access_token_here
104
+
105
+ # OR GitHub App Installation Token (starts with ghs_)
106
+ GITHUB_TOKEN=ghs_your_installation_token_here
107
+
108
+ # Optional: Default owner for repository operations
109
+ OWNER=your_github_username_or_org
110
+ ```
111
+
112
+ **Environment Variables:**
113
+ - `GITHUB_TOKEN` (required): Your GitHub authentication token
114
+ - `OWNER` (optional): Default repository owner/organization name
115
+
116
+ **Note**: The MCP server automatically detects the token type. Both Personal Access Tokens and GitHub App Installation Tokens work seamlessly.
117
+
118
+ ### 3. MCP Configuration
119
+
120
+ Add to your MCP client configuration:
121
+
122
+ ```json
123
+ {
124
+ "mcpServers": {
125
+ "github": {
126
+ "command": "npx",
127
+ "args": ["@skhatri/github-mcp"],
128
+ "env": {
129
+ "GITHUB_TOKEN": "your_github_token_here",
130
+ "OWNER": "your_github_username_or_org"
131
+ }
132
+ }
133
+ }
134
+ }
135
+ ```
136
+
137
+ **Configuration Options:**
138
+ - `GITHUB_TOKEN`: Required GitHub authentication token
139
+ - `OWNER`: Optional default owner/organization name. When set, you can omit the `owner` parameter from tool calls
140
+
141
+ ## Available Tools
142
+
143
+ **Total: 32 tools covering the complete GitHub workflow**
144
+
145
+ ### Owner Parameter Behavior
146
+
147
+ All repository-related tools support flexible owner parameter handling:
148
+
149
+ 1. **Explicit owner**: Provide `owner` parameter in tool calls
150
+ ```javascript
151
+ // Always works regardless of environment configuration
152
+ await mcp.callTool('list_pull_requests', {
153
+ owner: 'facebook',
154
+ repo: 'react'
155
+ });
156
+ ```
157
+
158
+ 2. **Default owner from environment**: Set `OWNER` environment variable and omit owner parameter
159
+ ```javascript
160
+ // Works when OWNER env var is set to 'myorg'
161
+ await mcp.callTool('list_pull_requests', {
162
+ repo: 'myrepo' // owner defaults to OWNER env var
163
+ });
164
+ ```
165
+
166
+ 3. **Fallback behavior**:
167
+ - If `owner` is provided → use provided owner
168
+ - If `owner` is omitted but `OWNER` env var is set → use `OWNER` env var
169
+ - If both are missing → error: "Owner parameter is required"
170
+
171
+ This allows you to configure a default organization/user and avoid repeating the owner parameter for every call, while still supporting explicit owner specification when needed.
172
+
173
+ **Note**: All repository-related tools listed below now have **optional** `owner` parameters. If `OWNER` environment variable is set, the `owner` parameter can be omitted from tool calls.
174
+
175
+ ### Pull Request Management
176
+
177
+ ### `list_pull_requests`
178
+ List pull requests for a repository.
179
+
180
+ **Parameters:**
181
+ - `owner` (optional): Repository owner (required if OWNER env var not set)
182
+ - `repo` (required): Repository name
183
+ - `state` (optional): Filter by state ('open', 'closed', 'all')
184
+ - `per_page` (optional): Number of results (default: 30, max: 100)
185
+
186
+ **Examples:**
187
+ ```json
188
+ // With explicit owner
189
+ {
190
+ "owner": "microsoft",
191
+ "repo": "vscode",
192
+ "state": "open",
193
+ "per_page": 10
194
+ }
195
+
196
+ // Without owner (uses OWNER env var)
197
+ {
198
+ "repo": "myrepo",
199
+ "state": "open"
200
+ }
201
+ ```
202
+
203
+ ### `list_pull_requests_for_review`
204
+ List pull requests that are assigned for review to the authenticated user.
205
+
206
+ **Parameters:**
207
+ - `state` (optional): Filter by state ('open', 'closed', 'all') - default: 'open'
208
+ - `per_page` (optional): Number of results (default: 30, max: 100)
209
+
210
+ **Example:**
211
+ ```json
212
+ {
213
+ "state": "open",
214
+ "per_page": 20
215
+ }
216
+ ```
217
+
218
+ **Note**: This tool uses the authenticated user's token to find PRs where they are requested as a reviewer. No owner/repo parameters needed as it searches across all accessible repositories.
219
+
220
+ ### `get_pull_request`
221
+ Get detailed information about a specific pull request.
222
+
223
+ **Parameters:**
224
+ - `owner` (optional): Repository owner (required if OWNER env var not set)
225
+ - `repo` (required): Repository name
226
+ - `pull_number` (required): Pull request number
227
+
228
+ ### `get_pull_request_files`
229
+ Get the files changed in a pull request.
230
+
231
+ **Parameters:**
232
+ - `owner` (required): Repository owner
233
+ - `repo` (required): Repository name
234
+ - `pull_number` (required): Pull request number
235
+
236
+ ### `create_pull_request`
237
+ Create a new pull request.
238
+
239
+ **Parameters:**
240
+ - `owner` (required): Repository owner
241
+ - `repo` (required): Repository name
242
+ - `title` (required): Pull request title
243
+ - `head` (required): Branch containing changes
244
+ - `base` (required): Target branch
245
+ - `body` (optional): Pull request description
246
+ - `draft` (optional): Create as draft PR
247
+
248
+ ### `add_review_comment`
249
+ Add a review comment to a specific line in a pull request.
250
+
251
+ **Parameters:**
252
+ - `owner` (required): Repository owner
253
+ - `repo` (required): Repository name
254
+ - `pull_number` (required): Pull request number
255
+ - `body` (required): Comment text
256
+ - `commit_id` (required): SHA of the commit
257
+ - `path` (required): File path
258
+ - `line` (required): Line number (1-based)
259
+
260
+ ### `approve_pull_request`
261
+ Approve a pull request.
262
+
263
+ **Parameters:**
264
+ - `owner` (required): Repository owner
265
+ - `repo` (required): Repository name
266
+ - `pull_number` (required): Pull request number
267
+ - `body` (optional): Review message
268
+
269
+ ### `request_review`
270
+ Request reviews for a pull request from users or teams.
271
+
272
+ **Parameters:**
273
+ - `owner` (required): Repository owner
274
+ - `repo` (required): Repository name
275
+ - `pull_number` (required): Pull request number
276
+ - `reviewers` (optional): Array of usernames
277
+ - `team_reviewers` (optional): Array of team names
278
+
279
+ ### `submit_review`
280
+ Submit a comprehensive pull request review.
281
+
282
+ **Parameters:**
283
+ - `owner` (required): Repository owner
284
+ - `repo` (required): Repository name
285
+ - `pull_number` (required): Pull request number
286
+ - `event` (required): 'APPROVE', 'REQUEST_CHANGES', or 'COMMENT'
287
+ - `body` (optional): Review summary comment
288
+
289
+ ### `list_review_comments`
290
+ List all review comments for a pull request.
291
+
292
+ **Parameters:**
293
+ - `owner` (required): Repository owner
294
+ - `repo` (required): Repository name
295
+ - `pull_number` (required): Pull request number
296
+
297
+ ## Issue Management
298
+
299
+ ### `create_issue`
300
+ Create a new issue in a repository.
301
+
302
+ **Parameters:**
303
+ - `owner` (required): Repository owner
304
+ - `repo` (required): Repository name
305
+ - `title` (required): Issue title
306
+ - `body` (optional): Issue description
307
+ - `assignees` (optional): Array of usernames to assign
308
+ - `milestone` (optional): Milestone number
309
+ - `labels` (optional): Array of label names
310
+
311
+ ### `list_issues`
312
+ List issues in a repository with filtering options.
313
+
314
+ **Parameters:**
315
+ - `owner` (required): Repository owner
316
+ - `repo` (required): Repository name
317
+ - `state` (optional): 'open', 'closed', or 'all' (default: 'open')
318
+ - `labels` (optional): Comma-separated label names
319
+ - `assignee` (optional): Username assigned to issues
320
+ - `milestone` (optional): Milestone title or number
321
+ - `per_page` (optional): Results per page (max 100)
322
+
323
+ ### `get_issue`
324
+ Get detailed information about a specific issue.
325
+
326
+ **Parameters:**
327
+ - `owner` (required): Repository owner
328
+ - `repo` (required): Repository name
329
+ - `issue_number` (required): Issue number
330
+
331
+ ### `update_issue`
332
+ Update an existing issue's properties.
333
+
334
+ **Parameters:**
335
+ - `owner` (required): Repository owner
336
+ - `repo` (required): Repository name
337
+ - `issue_number` (required): Issue number
338
+ - `title` (optional): Issue title
339
+ - `body` (optional): Issue description
340
+ - `state` (optional): 'open' or 'closed'
341
+ - `assignees` (optional): Array of usernames to assign
342
+ - `labels` (optional): Array of label names
343
+
344
+ ### `close_issue`
345
+ Close an issue with optional reason.
346
+
347
+ **Parameters:**
348
+ - `owner` (required): Repository owner
349
+ - `repo` (required): Repository name
350
+ - `issue_number` (required): Issue number
351
+ - `reason` (optional): 'completed' or 'not_planned'
352
+
353
+ ### `add_issue_comment`
354
+ Add a comment to an issue.
355
+
356
+ **Parameters:**
357
+ - `owner` (required): Repository owner
358
+ - `repo` (required): Repository name
359
+ - `issue_number` (required): Issue number
360
+ - `body` (required): Comment text
361
+
362
+ ### `assign_issue`
363
+ Assign users to an issue.
364
+
365
+ **Parameters:**
366
+ - `owner` (required): Repository owner
367
+ - `repo` (required): Repository name
368
+ - `issue_number` (required): Issue number
369
+ - `assignees` (required): Array of usernames to assign
370
+
371
+ ## Repository Operations
372
+
373
+ ### `get_repository`
374
+ Get comprehensive repository information and statistics.
375
+
376
+ **Parameters:**
377
+ - `owner` (required): Repository owner
378
+ - `repo` (required): Repository name
379
+
380
+ ### `list_commits`
381
+ List commits in a repository with optional filtering.
382
+
383
+ **Parameters:**
384
+ - `owner` (required): Repository owner
385
+ - `repo` (required): Repository name
386
+ - `sha` (optional): Branch, tag, or commit SHA
387
+ - `path` (optional): File path to filter commits
388
+ - `per_page` (optional): Results per page (max 100)
389
+
390
+ ### `get_commit`
391
+ Get detailed information about a specific commit including file changes.
392
+
393
+ **Parameters:**
394
+ - `owner` (required): Repository owner
395
+ - `repo` (required): Repository name
396
+ - `ref` (required): Commit SHA
397
+
398
+ ### `list_branches`
399
+ List all branches in a repository.
400
+
401
+ **Parameters:**
402
+ - `owner` (required): Repository owner
403
+ - `repo` (required): Repository name
404
+ - `protected` (optional): Filter by protection status
405
+ - `per_page` (optional): Results per page (max 100)
406
+
407
+ ### `create_branch`
408
+ Create a new branch from a specific commit.
409
+
410
+ **Parameters:**
411
+ - `owner` (required): Repository owner
412
+ - `repo` (required): Repository name
413
+ - `ref` (required): New branch name (refs/heads/branch-name)
414
+ - `sha` (required): SHA to create branch from
415
+
416
+ ### `get_file_content`
417
+ Read file contents from repository.
418
+
419
+ **Parameters:**
420
+ - `owner` (required): Repository owner
421
+ - `repo` (required): Repository name
422
+ - `path` (required): File path
423
+ - `ref` (optional): Branch, tag, or commit SHA (default: main)
424
+
425
+ ### `update_file`
426
+ Create or update a file in the repository.
427
+
428
+ **Parameters:**
429
+ - `owner` (required): Repository owner
430
+ - `repo` (required): Repository name
431
+ - `path` (required): File path
432
+ - `message` (required): Commit message
433
+ - `content` (required): File content (base64 encoded)
434
+ - `sha` (optional): SHA of file being replaced (for updates)
435
+ - `branch` (optional): Branch name (default: main)
436
+
437
+ ## Labels & Organization
438
+
439
+ ### `list_labels`
440
+ List all labels in a repository.
441
+
442
+ **Parameters:**
443
+ - `owner` (required): Repository owner
444
+ - `repo` (required): Repository name
445
+ - `per_page` (optional): Results per page (max 100)
446
+
447
+ ### `create_label`
448
+ Create a new label in the repository.
449
+
450
+ **Parameters:**
451
+ - `owner` (required): Repository owner
452
+ - `repo` (required): Repository name
453
+ - `name` (required): Label name
454
+ - `color` (required): Hex color code without #
455
+ - `description` (optional): Label description
456
+
457
+ ### `list_milestones`
458
+ List repository milestones.
459
+
460
+ **Parameters:**
461
+ - `owner` (required): Repository owner
462
+ - `repo` (required): Repository name
463
+ - `state` (optional): 'open', 'closed', or 'all' (default: 'open')
464
+ - `per_page` (optional): Results per page (max 100)
465
+
466
+ ### `create_milestone`
467
+ Create a new milestone.
468
+
469
+ **Parameters:**
470
+ - `owner` (required): Repository owner
471
+ - `repo` (required): Repository name
472
+ - `title` (required): Milestone title
473
+ - `description` (optional): Milestone description
474
+ - `due_on` (optional): Due date (ISO 8601 format)
475
+
476
+ ## Collaboration Tools
477
+
478
+ ### `list_collaborators`
479
+ List repository collaborators with their permissions.
480
+
481
+ **Parameters:**
482
+ - `owner` (required): Repository owner
483
+ - `repo` (required): Repository name
484
+ - `affiliation` (optional): 'outside', 'direct', or 'all' (default: 'all')
485
+ - `per_page` (optional): Results per page (max 100)
486
+
487
+ ### `check_user_permissions`
488
+ Check a user's permission level for a repository.
489
+
490
+ **Parameters:**
491
+ - `owner` (required): Repository owner
492
+ - `repo` (required): Repository name
493
+ - `username` (required): Username to check
494
+
495
+ ## Search & Advanced Features
496
+
497
+ ### `search_repositories`
498
+ Search for repositories across GitHub.
499
+
500
+ **Parameters:**
501
+ - `q` (required): Search query
502
+ - `sort` (optional): 'stars', 'forks', or 'updated'
503
+ - `order` (optional): 'asc' or 'desc' (default: 'desc')
504
+ - `per_page` (optional): Results per page (max 100)
505
+
506
+ ### `search_issues`
507
+ Search for issues and pull requests.
508
+
509
+ **Parameters:**
510
+ - `q` (required): Search query
511
+ - `sort` (optional): 'comments', 'reactions', 'created', or 'updated'
512
+ - `order` (optional): 'asc' or 'desc' (default: 'desc')
513
+ - `per_page` (optional): Results per page (max 100)
514
+
515
+ ### `search_code`
516
+ Search for code within repositories.
517
+
518
+ **Parameters:**
519
+ - `q` (required): Search query
520
+ - `sort` (optional): 'indexed'
521
+ - `order` (optional): 'asc' or 'desc' (default: 'desc')
522
+ - `per_page` (optional): Results per page (max 100)
523
+
524
+ ### `list_workflows`
525
+ List GitHub Actions workflows in a repository.
526
+
527
+ **Parameters:**
528
+ - `owner` (required): Repository owner
529
+ - `repo` (required): Repository name
530
+ - `per_page` (optional): Results per page (max 100)
531
+
532
+ ### `trigger_workflow`
533
+ Manually trigger a GitHub Actions workflow.
534
+
535
+ **Parameters:**
536
+ - `owner` (required): Repository owner
537
+ - `repo` (required): Repository name
538
+ - `workflow_id` (required): Workflow ID or filename
539
+ - `ref` (required): Git reference (branch or tag)
540
+ - `inputs` (optional): Input parameters for workflow
541
+
542
+ ## Usage Examples
543
+
544
+ ### List Open Pull Requests
545
+ ```javascript
546
+ // With explicit owner
547
+ await mcp.callTool('list_pull_requests', {
548
+ owner: 'facebook',
549
+ repo: 'react',
550
+ state: 'open'
551
+ });
552
+
553
+ // Without owner (uses OWNER env var)
554
+ await mcp.callTool('list_pull_requests', {
555
+ repo: 'react',
556
+ state: 'open'
557
+ });
558
+ ```
559
+
560
+ ### List Pull Requests for Review
561
+ ```javascript
562
+ // Get all PRs assigned for review to the authenticated user
563
+ await mcp.callTool('list_pull_requests_for_review', {
564
+ state: 'open'
565
+ });
566
+
567
+ // Get recent review requests across all repositories
568
+ await mcp.callTool('list_pull_requests_for_review', {
569
+ per_page: 10
570
+ });
571
+ ```
572
+
573
+ ### Create a Pull Request
574
+ ```javascript
575
+ // With explicit owner
576
+ await mcp.callTool('create_pull_request', {
577
+ owner: 'myorg',
578
+ repo: 'myrepo',
579
+ title: 'Add new feature',
580
+ head: 'feature-branch',
581
+ base: 'main',
582
+ body: 'This PR adds a new feature...'
583
+ });
584
+
585
+ // Without owner (uses OWNER env var set to 'myorg')
586
+ await mcp.callTool('create_pull_request', {
587
+ repo: 'myrepo',
588
+ title: 'Add new feature',
589
+ head: 'feature-branch',
590
+ base: 'main',
591
+ body: 'This PR adds a new feature...'
592
+ });
593
+ ```
594
+
595
+ ### Add Review Comment
596
+ ```javascript
597
+ // Simplified when OWNER env var is set
598
+ await mcp.callTool('add_review_comment', {
599
+ repo: 'myrepo',
600
+ pull_number: 42,
601
+ body: 'Consider using const instead of let here',
602
+ commit_id: 'abc123def456',
603
+ path: 'src/index.ts',
604
+ line: 15
605
+ });
606
+ ```
607
+
608
+ ### Approve Pull Request
609
+ ```javascript
610
+ // Simplified when OWNER env var is set
611
+ await mcp.callTool('approve_pull_request', {
612
+ repo: 'myrepo',
613
+ pull_number: 42,
614
+ body: 'LGTM! Great work on this feature.'
615
+ });
616
+ ```
617
+
618
+ ## Development
619
+
620
+ ```bash
621
+ # Install dependencies
622
+ npm install
623
+
624
+ # Build
625
+ npm run build
626
+
627
+ # Run in development mode
628
+ npm run dev
629
+
630
+ # Run tests
631
+ npm test
632
+ ```
633
+
634
+ ## Security
635
+
636
+ ### For Personal Access Tokens:
637
+ - Always keep your GitHub token secure
638
+ - Use environment variables, never hardcode tokens
639
+ - Consider using fine-grained personal access tokens for better security
640
+ - Review the permissions granted to your token regularly
641
+
642
+ ### For GitHub App Tokens:
643
+ - GitHub App tokens are more secure than PATs for organizations
644
+ - They provide repository-specific access and better audit logging
645
+ - Installation tokens automatically expire (typically 1 hour)
646
+ - App permissions are managed centrally by organization admins
647
+
648
+ ### Best Practices:
649
+ - Use GitHub App tokens for production/organizational deployments
650
+ - Use Personal Access Tokens for development/personal projects
651
+ - Store tokens in secure environment variable management systems
652
+ - Rotate tokens regularly (especially PATs)
653
+ - Monitor token usage through GitHub's audit logs
654
+
655
+ ## License
656
+
657
+ MIT
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}