- Notifications
You must be signed in to change notification settings - Fork1.4k
Add comprehensive documentation and examples for Pull Request resources#677
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Draft
Copilot wants to merge2 commits intomainChoose a base branch fromcopilot/fix-70f37556-44a9-4a71-b571-f0bc8def7445
base:main
Could not load branches
Branch not found:{{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline, and old review comments may become outdated.
+291 −0
Draft
Changes fromall commits
Commits
Show all changes
2 commits Select commitHold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
# Pull Request Resources | ||
The GitHub MCP Server supports accessing files and content from Pull Requests (PRs) as MCP resources. This allows AI tools to read and analyze code changes in pull requests for various purposes like code review, documentation, and analysis. | ||
## Resource URI Template | ||
Pull Request resources use the following URI template: | ||
``` | ||
repo://{owner}/{repo}/refs/pull/{prNumber}/head/contents{/path*} | ||
``` | ||
## Parameters | ||
- **`owner`** (required): The GitHub username or organization that owns the repository | ||
- **`repo`** (required): The name of the repository | ||
- **`prNumber`** (required): The pull request number (not the pull request ID) | ||
- **`path`** (optional): The path to a specific file or directory within the pull request | ||
## How It Works | ||
When you request a PR resource, the server: | ||
1. Fetches the pull request information from GitHub's API to get the latest commit SHA from the PR's head branch | ||
2. Uses that commit SHA to retrieve the file content at that specific point in time | ||
3. Returns the content as either text or binary (base64-encoded) depending on the file type | ||
## Examples | ||
### Basic Usage | ||
Access the README file from PR #123: | ||
``` | ||
repo://microsoft/vscode/refs/pull/123/head/contents/README.md | ||
``` | ||
Access a specific file in a subdirectory: | ||
``` | ||
repo://facebook/react/refs/pull/456/head/contents/packages/react/src/React.js | ||
``` | ||
### Valid Path Values | ||
The `path` parameter supports: | ||
- **Single files**: `README.md`, `package.json`, `src/index.js` | ||
- **Nested files**: `src/components/Button/Button.tsx`, `docs/api/authentication.md` | ||
- **Files with special characters**: `docs/how-to-use-@scoped-packages.md` | ||
- **Files in any directory depth**: `very/deep/nested/directory/structure/file.txt` | ||
### Supported File Types | ||
The server automatically detects file types and returns appropriate content: | ||
- **Text files** (`.md`, `.js`, `.py`, `.go`, etc.): Returned as text with proper MIME type | ||
- **Binary files** (`.png`, `.jpg`, `.pdf`, etc.): Returned as base64-encoded blobs | ||
- **Configuration files** (`.json`, `.yaml`, `.toml`, etc.): Returned as text with appropriate MIME type | ||
## Use Cases | ||
### Code Review | ||
``` | ||
repo://owner/repo/refs/pull/789/head/contents/src/new-feature.js | ||
``` | ||
Access the implementation of a new feature to provide code review feedback. | ||
### Documentation Analysis | ||
``` | ||
repo://owner/repo/refs/pull/234/head/contents/docs/api-changes.md | ||
``` | ||
Review documentation changes in a pull request. | ||
### Test Coverage | ||
``` | ||
repo://owner/repo/refs/pull/567/head/contents/tests/new-feature.test.js | ||
``` | ||
Examine test files to understand test coverage for new features. | ||
### Configuration Changes | ||
``` | ||
repo://owner/repo/refs/pull/890/head/contents/.github/workflows/ci.yml | ||
``` | ||
Review changes to CI/CD workflows or other configuration files. | ||
## Error Handling | ||
The server will return appropriate errors for common scenarios: | ||
- **Pull request not found**: If the PR number doesn't exist | ||
- **File not found**: If the specified path doesn't exist in the PR | ||
- **Invalid PR number**: If the PR number is not a valid integer | ||
- **Access denied**: If the GitHub token doesn't have permission to access the PR or repository | ||
## Limitations | ||
- **Directories are not supported**: You can only access individual files, not directory listings | ||
- **Private repositories**: Require appropriate GitHub token permissions | ||
- **Large files**: Very large files may hit GitHub API limits | ||
- **Binary files**: Returned as base64-encoded content which may be large | ||
## Related Resources | ||
- [Repository Resources](../README.md#tools) - For accessing files from the main branch | ||
- [Branch Resources](../README.md#tools) - For accessing files from specific branches | ||
- [Tag Resources](../README.md#tools) - For accessing files from specific tags | ||
- [Commit Resources](../README.md#tools) - For accessing files from specific commits | ||
## Tips | ||
1. **Use specific paths**: Always specify the full path to the file you want to access | ||
2. **Check PR status**: Ensure the PR is still open and accessible before attempting to access resources | ||
3. **Handle errors gracefully**: Always implement proper error handling for resource access | ||
4. **Consider file size**: Be mindful of large files that may impact performance |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.