diff --git a/README.md b/README.md index 8cff2e138..e42c1570d 100644 --- a/README.md +++ b/README.md @@ -1001,6 +1001,38 @@ export GITHUB_MCP_TOOL_ADD_ISSUE_COMMENT_DESCRIPTION="an alternative description The exported Go API of this module should currently be considered unstable, and subject to breaking changes. In the future, we may offer stability; please file an issue if there is a use case where this would be valuable. +## Using Pull Request Resources + +The GitHub MCP Server supports fetching files in a pull request as resources using the following URI pattern: + +- Pull request content (PR head commit): + - `repo://{owner}/{repo}/refs/pull/{prNumber}/head/contents{/path*}` + +Other resource templates also available for repository content: + +- Repository content: + - `repo://{owner}/{repo}/contents{/path*}` +- Branch content: + - `repo://{owner}/{repo}/refs/heads/{branch}/contents{/path*}` +- Commit content: + - `repo://{owner}/{repo}/sha/{sha}/contents{/path*}` +- Tag content: + - `repo://{owner}/{repo}/refs/tags/{tag}/contents{/path*}` + +**Example**: + +```json +{ + "resources": [ + { + "id": "prReadme", + "type": "repo", + "path": "repo://octocat/hello-world/refs/pull/42/head/contents/README.md" + } + ] +} +``` + ## License This project is licensed under the terms of the MIT open source license. Please refer to [MIT](./LICENSE) for the full terms. diff --git a/pkg/github/repository_resource_test.go b/pkg/github/repository_resource_test.go index 0e9f018e7..06c6d0e33 100644 --- a/pkg/github/repository_resource_test.go +++ b/pkg/github/repository_resource_test.go @@ -278,3 +278,12 @@ func Test_GetRepositoryResourceTagContent(t *testing.T) { tmpl, _ := GetRepositoryResourceTagContent(nil, stubGetRawClientFn(mockRawClient), translations.NullTranslationHelper) require.Equal(t, "repo://{owner}/{repo}/refs/tags/{tag}/contents{/path*}", tmpl.URITemplate.Raw()) } + +func Test_GetRepositoryResourcePrContent(t *testing.T) { + mockRawClient := raw.NewClient(github.NewClient(nil), &url.URL{}) + tmpl, _ := GetRepositoryResourcePrContent(nil, stubGetRawClientFn(mockRawClient), translations.NullTranslationHelper) + require.Equal(t, + "repo://{owner}/{repo}/refs/pull/{prNumber}/head/contents{/path*}", + tmpl.URITemplate.Raw(), + ) +}