---
title: How to connect GitHub MCP to Gemini CLI
description: Install GitHub’s Gemini CLI extension or add https://api.githubcopilot.com/mcp/ with a token header. Read-only mode, policy rules, headless runs and fixes.
canonical: https://mcp1.com/blog/github-mcp-gemini-cli
last-updated: 2026-11-28
---

# How to connect GitHub MCP to Gemini CLI

Install GitHub’s Gemini CLI extension or add https://api.githubcopilot.com/mcp/ with a token header. Read-only mode, policy rules, headless runs and fixes.

![](https://avatars.githubusercontent.com/u/1297371?s=96&v=4)Eldad FuxFounder and CEO, Appwrite

 Terminal

$ gemini mcp add --transport http github https://api.githubcopilot.com/mcp/

\-H 'Authorization: Bearer $GITHUB\_MCP\_PAT'

githubConnected

 Terminal

$ gemini mcp add --transport http github https://api.githubcopilot.com/mcp/

\-H 'Authorization: Bearer $GITHUB\_MCP\_PAT'

githubConnected

To connect GitHub to Gemini CLI, create a fine-grained personal access token, save it as `GITHUB_MCP_PAT`, and either install GitHub’s Gemini CLI extension or add `https://api.githubcopilot.com/mcp/` to `~/.gemini/settings.json` with the token in an `Authorization` header. Gemini can then read code, issues, pull requests and Actions logs in the repositories the token reaches. Add `X-MCP-Readonly` to stop it from writing.

## What is the fastest way to add GitHub MCP to Gemini CLI?

GitHub’s own extension. It is the method GitHub’s install guide recommends, and it adds the hosted server with nothing to run locally.

1. 1Create a fine-grained token at `github.com/settings/personal-access-tokens`. Choose the repositories it may reach and grant read access to Contents, Issues, Pull requests and Metadata, plus Actions for build logs. Grant write only where you want Gemini to write.
2. 2Put it in `~/.gemini/.env`, which Gemini CLI loads on start:  
\~/.gemini/.env  
```  
GITHUB_MCP_PAT=github_pat_...  
```
3. 3Install the extension:  
Terminal  
```  
gemini extensions install https://github.com/github/github-mcp-server  
```
4. 4Start `gemini` and run `/mcp list`. github should show as connected with its tools.

Then ask for something that changes nothing:

Prompt

```
List open pull requests in owner/repo that are waiting on my review,
with their failing checks. Don't change anything.
```

## How do I add GitHub MCP to Gemini CLI without the extension?

Use `gemini mcp add`, or edit `settings.json` yourself. The command defaults to project scope (`.gemini/settings.json` in the current folder), so pass `--scope user` to have GitHub in every project. Single quotes keep the shell from expanding the variable, so the file stores the name and not the token:

Terminal

```
gemini mcp add --scope user --transport http github https://api.githubcopilot.com/mcp/ \
  --header 'Authorization: Bearer $GITHUB_MCP_PAT'
```

The same server written by hand, which is what GitHub’s guide shows as its second method:

\~/.gemini/settings.json

```
{
  "mcpServers": {
    "github": {
      "httpUrl": "https://api.githubcopilot.com/mcp/",
      "headers": {
        "Authorization": "Bearer $GITHUB_MCP_PAT"
      }
    }
  }
}
```

Gemini fills `$GITHUB_MCP_PAT` (or `${GITHUB_MCP_PAT}`) from the environment and `.env` files when it loads settings. An undefined variable becomes an empty string, which shows up as a 401 rather than a clear error.

Why a token and not /mcp auth

Gemini CLI supports OAuth for MCP servers through `/mcp auth`, but GitHub’s hosted server only accepts OAuth from clients that register their own GitHub app. GitHub’s compatibility table lists Gemini CLI as token only. For a browser sign-in, run GitHub’s Docker image locally, which GitHub’s guide covers as its third method.

## Which GitHub tools does Gemini CLI get?

The base URL loads five toolsets: `context`, `repos`, `issues`, `pull_requests` and `users`. Run `/mcp desc` to see every tool with its description. The ones you’ll use most:

ToolWhat it does

`get_file_contents`

Reads a file or directory in any repository the token reaches. Read.

`search_code`

Searches code with qualifiers like repo: and org:. Read.

`issue_read`

Fetches an issue and its comments. Read.

`pull_request_read`

Fetches a pull request’s diff, files, reviews or checks. Read.

`get_job_logs`

Returns logs for a failed Actions job. In the actions toolset, which is off by default. Read.

`issue_write`

Creates or updates an issue. Write.

`create_pull_request`

Opens a pull request from a branch. Write.

`merge_pull_request`

Merges a pull request. Write.

## How do I make GitHub MCP read-only in Gemini CLI?

Point `httpUrl` at `https://api.githubcopilot.com/mcp/readonly`, or send headers. `X-MCP-Readonly` drops every write tool, and `X-MCP-Toolsets` picks which toolsets load, here with `actions` added for build logs:

\~/.gemini/settings.json

```
{
  "mcpServers": {
    "github": {
      "httpUrl": "https://api.githubcopilot.com/mcp/",
      "headers": {
        "Authorization": "Bearer $GITHUB_MCP_PAT",
        "X-MCP-Toolsets": "repos,issues,pull_requests,actions",
        "X-MCP-Readonly": "true"
      }
    }
  }
}
```

Gemini’s own `includeTools` and `excludeTools` fields filter tools on the client side, and `excludeTools` wins when both name a tool. All of these live in a file the user can edit. A token with read permissions only is the limit GitHub enforces. More in [how to make an MCP server read-only](https://mcp1.com/blog/read-only-mcp-server).

## How do I stop Gemini CLI from merging or writing?

With a policy file. Gemini CLI asks before each MCP tool call by default, and rules in `~/.gemini/policies/*.toml` change that per server and tool. A `deny` rule hides the tool from the model entirely; an `allow` rule skips the prompt:

\~/.gemini/policies/github.toml

```
# ~/.gemini/policies/github.toml

# Run GitHub tools that declare themselves read-only without asking
[[rule]]
mcpName = "github"
toolAnnotations = { readOnlyHint = true }
decision = "allow"
priority = 200

# Never let the model merge
[[rule]]
mcpName = "github"
toolName = "merge_pull_request"
decision = "deny"
priority = 500
denyMessage = "Merging is done by a person."
```

`toolName` is the plain tool name, not a prefixed one. Avoid underscores in the server name, since the policy parser splits on them. Two settings undo all of this: `"trust": true` on the server skips every confirmation for it, and `--approval-mode=yolo` skips them for everything. See [stopping destructive MCP tools](https://mcp1.com/blog/stop-destructive-mcp-tools) for the same idea in other clients.

## Can I use GitHub MCP in headless Gemini CLI runs?

Yes. `gemini -p` runs one prompt without the interactive UI, which suits scripts and CI. In that mode a tool that would ask is denied instead, so the policy above matters: read tools run, writes don’t, unless you allow them.

Terminal

```
gemini -p "Summarize the failing checks on PR 128 in owner/repo" \
  --allowed-mcp-server-names github --output-format json
```

`--allowed-mcp-server-names` limits the run to the servers you name. In CI, pass the token from the runner’s secrets as `GITHUB_MCP_PAT` and use a token scoped to the one repository. [MCP in CI and headless agents](https://mcp1.com/blog/mcp-in-ci-and-headless-agents) covers the rest.

## What if GitHub MCP doesn’t connect in Gemini CLI?

Run `gemini --debug` to see why a server failed to load, then match the error:

SymptomFix

github isn’t listed

It was added in project scope from another folder. Run gemini mcp list there, or re-add it with --scope user.

401 Unauthorized

GITHUB\_MCP\_PAT was empty or the token expired. Check \~/.gemini/.env and that the header uses the same variable name.

Organization repositories come back empty

The organization must approve fine-grained tokens, or the token needs SSO authorization. Check the token’s page in GitHub settings.

A tool you expect is missing

Its toolset isn’t loaded, read-only mode removed it, or a deny rule or excludeTools hides it.

The server fails after editing headers

A name in X-MCP-Tools is misspelled, which stops GitHub’s server from starting. Fix or remove it.

## GitHub for the whole team, without a token on every laptop

The setup above puts a GitHub token in every developer’s `.env` and leaves read-only mode and policies in files each person controls. MCP1 is a gateway that does it once. An admin installs [GitHub](https://mcp1.com/servers/github) in the workspace with a fine-grained token, and can add a second, read-only token that people on read-only access call with, so GitHub itself refuses their writes. In Gemini CLI, people add the gateway and run `/mcp auth mcp1` to sign in with OAuth:

Terminal

```
gemini mcp add --scope user --transport http mcp1 https://mcp1.com/mcp/<workspace>/<gateway>
```

GitHub’s tools arrive as `github__<tool>` next to Linear, Sentry and the rest, rules like `github__merge_*` hold risky tools to admins, and every call goes in the audit log with the person who made it. For CI, an API key scoped to the gateway replaces the personal token. The Cursor version of this guide is [here](https://mcp1.com/blog/github-mcp-cursor), the [docs](https://mcp1.com/docs) cover gateways and groups, and you can [start free](https://mcp1.com/signup).

## Common questions

### Does Gemini CLI support OAuth for GitHub’s MCP server?

Not with GitHub’s hosted server, which only accepts OAuth from clients with their own GitHub app. Use a personal access token, or run GitHub’s Docker image locally for a browser sign-in.

### Where does Gemini CLI store MCP servers?

In settings.json under mcpServers: \~/.gemini/settings.json for user scope and .gemini/settings.json in a project. gemini mcp add writes to the project file unless you pass --scope user.

### Do I need GitHub Copilot to use GitHub MCP in Gemini CLI?

No. GitHub’s MCP server works on every GitHub plan even though it is hosted at api.githubcopilot.com. Only tools for paid features need a Copilot license.

### Why do MCP tools get denied when I run gemini -p?

In non-interactive mode a tool that would ask for confirmation is denied. Add an allow rule in a policy file for the tools the script needs.

Give your team one URL

Create a workspace, install your servers and share a gateway with a group. Free for individuals.

[Start with MCP1](https://mcp1.com/signup)[Read the docs](https://mcp1.com/docs)

## More from the blog

[ ProductLinearRead onlyProductboardRead onlyFigmaRead onlyPostHogRead onlyMCP servers for product teams: what to connect firstConnect Linear, a feedback tool (Productboard, Dovetail), analytics (PostHog, Amplitude) and Figma, read-only. Their tools, setup and which writes to hold back.![](https://avatars.githubusercontent.com/u/1297371?s=96&v=4)Eldad FuxFounder and CEO, Appwrite](https://mcp1.com/blog/mcp-servers-for-product-teams)[ DataClickHouse CloudSELECT onlyMotherDuckSELECT onlyMetabaseSELECT onlyPostHogSELECT onlyMCP servers for data teams: what to connect firstConnect a warehouse (BigQuery, Snowflake, ClickHouse, MotherDuck), BI (Metabase, Hex) and PostHog, read-only. Their tools, setup and which SQL to hold back.![](https://avatars.githubusercontent.com/u/1297371?s=96&v=4)Eldad FuxFounder and CEO, Appwrite](https://mcp1.com/blog/mcp-servers-for-data-teams)

---

This is the markdown copy of https://mcp1.com/blog/github-mcp-gemini-cli. Site index for agents: https://mcp1.com/llms.txt
