2025-06-06 14:51:08 +00:00
|
|
|
# Tutorials
|
|
|
|
|
|
2025-06-18 11:15:49 -07:00
|
|
|
This page contains tutorials for interacting with Gemini CLI.
|
2025-06-06 14:51:08 +00:00
|
|
|
|
2025-06-18 11:15:49 -07:00
|
|
|
## Setting up a Model Context Protocol (MCP) server
|
2025-06-06 14:51:08 +00:00
|
|
|
|
2025-10-09 08:17:37 -04:00
|
|
|
> [!CAUTION] Before using a third-party MCP server, ensure you trust its source
|
|
|
|
|
> and understand the tools it provides. Your use of third-party servers is at
|
|
|
|
|
> your own risk.
|
2025-06-06 14:51:08 +00:00
|
|
|
|
2025-10-09 08:17:37 -04:00
|
|
|
This tutorial demonstrates how to set up a MCP server, using the
|
|
|
|
|
[GitHub MCP server](https://github.com/github/github-mcp-server) as an example.
|
|
|
|
|
The GitHub MCP server provides tools for interacting with GitHub repositories,
|
|
|
|
|
such as creating issues and commenting on pull requests.
|
2025-06-06 14:51:08 +00:00
|
|
|
|
2025-06-18 11:15:49 -07:00
|
|
|
### Prerequisites
|
2025-06-06 14:51:08 +00:00
|
|
|
|
|
|
|
|
Before you begin, ensure you have the following installed and configured:
|
|
|
|
|
|
|
|
|
|
- **Docker:** Install and run [Docker].
|
2025-10-09 08:17:37 -04:00
|
|
|
- **GitHub Personal Access Token (PAT):** Create a new [classic] or
|
|
|
|
|
[fine-grained] PAT with the necessary scopes.
|
2025-06-06 14:51:08 +00:00
|
|
|
|
|
|
|
|
[Docker]: https://www.docker.com/
|
|
|
|
|
[classic]: https://github.com/settings/tokens/new
|
|
|
|
|
[fine-grained]: https://github.com/settings/personal-access-tokens/new
|
|
|
|
|
|
2025-06-18 11:15:49 -07:00
|
|
|
### Guide
|
2025-06-06 14:51:08 +00:00
|
|
|
|
2025-06-18 11:15:49 -07:00
|
|
|
#### Configure the MCP server in `settings.json`
|
2025-06-06 14:51:08 +00:00
|
|
|
|
2025-10-09 08:17:37 -04:00
|
|
|
In your project's root directory, create or open the
|
|
|
|
|
[`.gemini/settings.json` file](../get-started/configuration.md). Within the
|
|
|
|
|
file, add the `mcpServers` configuration block, which provides instructions for
|
|
|
|
|
how to launch the GitHub MCP server.
|
2025-06-06 14:51:08 +00:00
|
|
|
|
|
|
|
|
```json
|
|
|
|
|
{
|
|
|
|
|
"mcpServers": {
|
|
|
|
|
"github": {
|
|
|
|
|
"command": "docker",
|
|
|
|
|
"args": [
|
|
|
|
|
"run",
|
|
|
|
|
"-i",
|
|
|
|
|
"--rm",
|
|
|
|
|
"-e",
|
|
|
|
|
"GITHUB_PERSONAL_ACCESS_TOKEN",
|
|
|
|
|
"ghcr.io/github/github-mcp-server"
|
|
|
|
|
],
|
|
|
|
|
"env": {
|
|
|
|
|
"GITHUB_PERSONAL_ACCESS_TOKEN": "${GITHUB_PERSONAL_ACCESS_TOKEN}"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
2025-06-18 11:15:49 -07:00
|
|
|
#### Set your GitHub token
|
2025-06-06 14:51:08 +00:00
|
|
|
|
2025-10-09 08:17:37 -04:00
|
|
|
> [!CAUTION] Using a broadly scoped personal access token that has access to
|
|
|
|
|
> personal and private repositories can lead to information from the private
|
|
|
|
|
> repository being leaked into the public repository. We recommend using a
|
|
|
|
|
> fine-grained access token that doesn't share access to both public and private
|
|
|
|
|
> repositories.
|
2025-06-12 15:23:45 -07:00
|
|
|
|
2025-06-18 11:15:49 -07:00
|
|
|
Use an environment variable to store your GitHub PAT:
|
2025-06-06 14:51:08 +00:00
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
GITHUB_PERSONAL_ACCESS_TOKEN="pat_YourActualGitHubTokenHere"
|
|
|
|
|
```
|
|
|
|
|
|
2025-10-09 08:17:37 -04:00
|
|
|
Gemini CLI uses this value in the `mcpServers` configuration that you defined in
|
|
|
|
|
the `settings.json` file.
|
2025-06-06 14:51:08 +00:00
|
|
|
|
2025-06-18 11:15:49 -07:00
|
|
|
#### Launch Gemini CLI and verify the connection
|
2025-06-06 14:51:08 +00:00
|
|
|
|
2025-10-09 08:17:37 -04:00
|
|
|
When you launch Gemini CLI, it automatically reads your configuration and
|
|
|
|
|
launches the GitHub MCP server in the background. You can then use natural
|
|
|
|
|
language prompts to ask Gemini CLI to perform GitHub actions. For example:
|
2025-06-06 14:51:08 +00:00
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
"get all open issues assigned to me in the 'foo/bar' repo and prioritize them"
|
|
|
|
|
```
|