feat: check org membership#2473
Closed
cbartz wants to merge 5 commits into
Closed
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a new organization membership lookup tool for the GitHub MCP Server, while also introducing broader HTTP authentication and PR mutation guardrail changes.
Changes:
- Added
check_org_membershiptool, schema snapshot, registration, and tests. - Added PR author allowlist enforcement across many mutating PR-related tools.
- Added HTTP server-side default token fallback behavior and documentation.
Reviewed changes
Copilot reviewed 26 out of 26 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| README.md | Documents the new org membership tool plus PR allowlist/default-token behavior. |
| pkg/utils/token.go | Extracts token-type parsing into reusable ParseToken. |
| pkg/http/server.go | Adds HTTP token fallback and PR author allowlist config plumbing. |
| pkg/http/middleware/token.go | Uses a default token when Authorization is missing. |
| pkg/http/middleware/token_test.go | Adds token fallback middleware tests. |
| pkg/http/handler.go | Passes HTTP default token into auth middleware. |
| pkg/github/tools.go | Registers the new org membership tool. |
| pkg/github/server.go | Adds PR author allowlist to MCP server config. |
| pkg/github/server_test.go | Updates test dependency stub for new interface method. |
| pkg/github/pullrequests.go | Enforces PR author allowlist in existing PR mutation handlers. |
| pkg/github/pullrequests_granular.go | Enforces PR author allowlist in granular PR mutation handlers. |
| pkg/github/pr_author_allowlist.go | Adds shared PR author allowlist helpers/enforcement. |
| pkg/github/pr_author_allowlist_test.go | Tests allowlist helper and merge-denial behavior. |
| pkg/github/orgs.go | Implements check_org_membership. |
| pkg/github/orgs_test.go | Tests org membership tool behavior and schema. |
| pkg/github/issues.go | Applies PR author allowlist to comments on PR-backed issues. |
| pkg/github/issues_test.go | Tests PR comment denial via issue comment tool. |
| pkg/github/helper_test.go | Adds org endpoint constants for tests. |
| pkg/github/dependencies.go | Adds allowlist state and API to dependency implementations. |
| pkg/github/copilot.go | Enforces PR author allowlist before requesting Copilot review. |
| pkg/github/copilot_test.go | Tests Copilot review denial for disallowed PR author. |
| pkg/github/toolsnaps/check_org_membership.snap | Adds tool schema snapshot. |
| internal/ghmcp/server.go | Wires allowlist config into stdio server dependencies. |
| docs/streamable-http.md | Documents HTTP server-side default token fallback. |
| docs/server-configuration.md | Documents org lookup and PR author allowlist configuration. |
| cmd/github-mcp-server/main.go | Adds allowlist flag/config parsing and HTTP token fallback config. |
Comments suppressed due to low confidence (1)
pkg/github/orgs.go:126
- This
Organizations.Getresponse is also not closed on the success path. Please closeres.Bodywhen it is non-nil, matching the response-handling pattern used elsewhere in the package (for example,pkg/github/search.go:103).
_, res, err := client.Organizations.Get(ctx, org)
if err == nil {
return nil
| httpConfig := ghhttp.ServerConfig{ | ||
| Version: version, | ||
| Host: viper.GetString("host"), | ||
| Token: viper.GetString("personal_access_token"), |
Comment on lines
107
to
+108
| Metrics(ctx context.Context) metrics.Metrics | ||
|
|
| rootCmd.PersistentFlags().String("gh-host", "", "Specify the GitHub hostname (for GitHub Enterprise etc.)") | ||
| rootCmd.PersistentFlags().Int("content-window-size", 5000, "Specify the content window size") | ||
| rootCmd.PersistentFlags().Bool("lockdown-mode", false, "Enable lockdown mode") | ||
| rootCmd.PersistentFlags().StringSlice("allowed-pr-authors", nil, "Comma-separated list of pull request author logins allowed for mutating pull request tools") |
Comment on lines
+72
to
+88
| isMember, res, err := client.Organizations.IsMember(ctx, args.Org, args.Username) | ||
| if err != nil { | ||
| return ghErrors.NewGitHubAPIErrorResponse(ctx, | ||
| "failed to check organization membership", | ||
| res, | ||
| err, | ||
| ), CheckOrgMembershipOutput{}, nil | ||
| } | ||
|
|
||
| isPublicMember, res, err := client.Organizations.IsPublicMember(ctx, args.Org, args.Username) | ||
| if err != nil { | ||
| return ghErrors.NewGitHubAPIErrorResponse(ctx, | ||
| "failed to check public organization membership", | ||
| res, | ||
| err, | ||
| ), CheckOrgMembershipOutput{}, nil | ||
| } |
| GITHUB_ALLOWED_PR_AUTHORS='renovate[bot],github-actions[bot]' ./github-mcp-server stdio --toolsets=pull_requests,actions | ||
| ``` | ||
|
|
||
| When set, tools such as `merge_pull_request`, `update_pull_request`, review-write tools, and PR branch updates fetch the target PR and reject the call unless `pr.User.Login` is in the allowlist. Read-only PR tools and `create_pull_request` are not restricted. `actions_run_trigger` is not gated by this setting because it targets a ref rather than a PR number. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Changes