MCP · GitHub · Updated

Secure the GitHub MCP server for Claude Code and Codex

The GitHub MCP server lets Claude Code and Codex read issues, open pull requests and push code with your token. With a Stashbase profile, the agent holds a placeholder instead of the token, sees only the tools you allow, and can only call write tools with the arguments you approve, like issues in one repository.

What the GitHub MCP server can do

GitHub’s official MCP server exposes dozens of tools across toolsets for issues, pull requests, repository contents, Actions and more. Connected with a personal access token, an agent can read code and issues, but also create and merge pull requests, push files, delete files and trigger workflows. Whatever the token can do, the agent can do.

GitHub gives you two coarse controls: a read-only mode (the /readonly URL or --read-only flag) and toolsets to switch whole groups of tools on or off. That’s a good start, but it’s all or nothing. You can’t say “create issues, but only in this repository” or “comment, but never merge”.

The risks

  • The token is in the agent’s environment. Anything the agent can read can end up in its context, logs or the code it writes.
  • Write tools are all-or-nothing. An agent that can open a pull request can usually merge one, and one that can update a file can push to any branch the token reaches.
  • Prompt injection comes through GitHub itself. Issues, comments and READMEs are text written by other people. An agent that reads a malicious issue can be told to call any tool it has.

A Stashbase profile for the GitHub MCP server

This profile lets the agent read issues, pull requests and code anywhere the token can, create issues and comments only in acme/widget, and nothing else:

# .stashbase/agents/github.toml
egress_hosts = ["api.anthropic.com", "api.githubcopilot.com"]

[secrets]
project = "my-app"
environment = "agents"

[secrets.GITHUB_TOKEN]

[[secrets.GITHUB_TOKEN.rules]]
effect = "allow"
hosts = ["api.githubcopilot.com"]
methods = ["GET", "POST"]
paths = ["/mcp/*"]

[mcp_servers.github]
url = "https://api.githubcopilot.com/mcp/"
binding = "GITHUB_TOKEN"
allow_tools = [
  "issue_read", "list_issues", "search_issues",
  "pull_request_read", "list_pull_requests",
  "get_file_contents",
]

# Create issues only in acme/widget, with only a title, body and labels.
[[mcp_servers.github.tool_rules]]
effect = "allow"
tools = ["issue_write"]
arguments = { owner = ["acme"], repo = ["widget"], method = ["create"] }
allow_fields = ["title", "body", "labels"]

# Comment only in acme/widget.
[[mcp_servers.github.tool_rules]]
effect = "allow"
tools = ["add_issue_comment"]
arguments = { owner = ["acme"], repo = ["widget"] }

Then connect it and run the agent:

claude mcp add github -- stashbase agent mcp connect github
stashbase agent run --profile github -- claude

Whose GitHub account does the agent use?

Agent’s own identityYour identity
Profile section[secrets.GITHUB_TOKEN][personal_credentials.GITHUB_TOKEN]
GitHub accountA bot or machine accountYour own account
Owned byThe workspace, in a Stashbase environmentYour Stashbase account, private to you
Issues and comments show up asThe botYou
ProxyLocal or remoteRemote
Use it whenThe agent works for the teamThe agent works on your behalf

Give the agent its own identity. The profile above uses a Stashbase secret: a token for a bot or machine account, kept in a Stashbase environment. Everyone on the team who runs the profile gets the same access, and issues and comments show up as the bot. It’s the right choice when the agent works for the team.

Let the agent act as you. When the agent should use your own GitHub account and your own repository access, use a personal credential instead. It’s private to your Stashbase account, the CLI never fetches, prints or logs it, and the remote Agent Proxy adds it only to requests your rules allow. Swap the secret binding for a personal one:

[personal_credentials.GITHUB_TOKEN]
env = "GITHUB_TOKEN"

[[personal_credentials.GITHUB_TOKEN.rules]]
effect = "allow"
hosts = ["api.githubcopilot.com"]
methods = ["GET", "POST"]
paths = ["/mcp/*"]

The [mcp_servers.github] section stays the same, with binding = "GITHUB_TOKEN". Personal credentials need the remote proxy, so start the agent with --remote:

stashbase agent run --remote --profile github -- claude

Teammates can share the same profile file: each of them runs it with their own GitHub token, and nobody’s token is shared.

What the agent can and can’t do

ActionResult
Read issues, pull requests and filesAllowed
Create an issue in acme/widget with a title and bodyAllowed
Create an issue in another repositoryBlocked
Set assignees or a milestone on a new issueBlocked, field not allowed
Edit an existing issueBlocked, only create is allowed
Merge a pull request, push or delete filesNot visible to the agent
Read the GitHub tokenNever: it only holds a placeholder, for its own token or yours

Blocked calls return an error that names the argument, like arguments.repo, and show up in the audit log, so you can see what the agent tried and allow it with one rule if it was legitimate.

Check your profile

Tool names change as GitHub updates the server. List what the server exposes and test a call before you rely on a rule:

stashbase agent mcp tools --profile github --server github
stashbase agent mcp check --profile github --server github --tool merge_pull_request

The same approach works for any MCP server. See the MCP docs for argument conditions such as numeric ranges and absent fields, and Claude Code’s sandbox vs Stashbase for how this differs from Claude Code’s own MCP permissions.

Let your agents do more, starting today.

Sandboxing, the local proxy and unlimited agent profiles are free forever.