Gemini Hands
<p align="center">
<img src="docs/icon.svg" width="112" height="112" alt="Gemini Hands icon: a gold hand and spark on navy">
</p>
<h1 align="center">Gemini Hands</h1>
<p align="center">
<a href="./README.md">English</a> · <a href="./README.zh.md">简体中文</a>
</p>
<p align="center">
Local MCP hands for <strong>Gemini on the web</strong> and the Gemini app on this machine.<br>
The server runs on your computer. Gemini reads files, searches code, and runs commands through it.
</p>
<p align="center"><img src="docs/architecture.svg" alt="Gemini on the web reaches this computer over HTTPS. Gemini Hands listens locally and works with files and commands."></p>
- Listens on a local port. Gemini on the web arrives through **Tailscale Funnel**, a **Cloudflare** tunnel, or your own HTTPS reverse proxy
- Tool names and PascalCase arguments follow Antigravity / original agy (`Path`, `CommandLine`, `Confirm`)
- HTTP serves Streamable MCP (`/mcp`) plus OAuth; a local subprocess can use `stdio` with no config
- One HTTP process per machine. Destructive commands are refused until you `Confirm`. Sessions claim write paths
- UI language defaults to **English**; switch to Chinese in the setup screen or with `language=zh`
Private repo: <https://github.com/luckfu/gemini-hands>. The sibling Node project `gemini-space` is read-only reference and is not modified.
## Contents
- [Requirements](#requirements)
- [Install](#install)
- [Five-minute start](#five-minute-start)
- [Connect Gemini on the web](#connect-gemini-on-the-web)
- [Four connection modes](#four-connection-modes)
- [Tailscale and cloudflared](#tailscale-and-cloudflared)
- [Commands](#commands)
- [Configuration](#configuration)
- [Tools](#tools)
- [Behavior](#behavior)
- [Local stdio](#local-stdio)
- [Audit page and icon](#audit-page-and-icon)
- [Process and ports](#process-and-ports)
- [Troubleshooting](#troubleshooting)
- [Environment](#environment)
- [Development](#development)
- [License](#license)
## Requirements
- Python 3.13+
- [uv](https://docs.astral.sh/uv/)
- Gemini on the web: an HTTPS hostname (Tailscale Funnel or Cloudflare is enough)
- Tailscale mode: signed-in Tailscale app, Funnel and HTTPS certificates enabled in the admin console
- Cloudflare mode: `cloudflared` on `PATH` (no Cloudflare account)
## Install
```bash
git clone https://github.com/luckfu/gemini-hands.git
cd gemini-hands
uv sync
```
Then run `uv run gemini-hands …`. After you install the script, `gemini-hands` works on its own.
## Five-minute start
```bash
uv run gemini-hands serve
```
If there is no config yet, the terminal UI opens. Pick how Gemini should reach this machine, set a workspace, **Save and start**.
<p align="center"><img src="docs/setup.svg" alt="Setup screen: language, connection mode, port, workspace, and a live preview of the MCP URL"></p>
Startup prints the MCP URL and the owner password. You can also ask later:
```bash
uv run gemini-hands url # https://…/mcp for Gemini on the web
uv run gemini-hands password # owner password; copied to the clipboard
```
Paste the URL into a custom Gemini connector. Leave Client ID / Secret empty. On the authorize page, paste the owner password.
<p align="center"><img src="docs/home.svg" alt="Home screen after setup: MCP URLs, owner password, Start server and Edit config"></p>
Day to day:
```bash
uv run gemini-hands serve # start
uv run gemini-hands stop # stop
uv run gemini-hands setup # edit config
uv run gemini-hands doctor # check the tunnel
```
Language (English is the default):
```bash
uv run gemini-hands config set language=zh # 中文
uv run gemini-hands config set language=en # English
```
## Connect Gemini on the web
```mermaid
sequenceDiagram
participant You
participant Hands as Gemini Hands
participant Gemini as Gemini on the web
You->>Hands: serve (Funnel or Cloudflare)
Hands-->>You: https://host/mcp + owner password
You->>Gemini: Custom connector URL, empty client id/secret
Gemini->>Hands: OAuth register + authorize
You->>Hands: paste owner password
Hands-->>Gemini: code + tokens
Gemini->>Hands: MCP tools
```
1. The server must be running.
2. Open [gemini.google.com/customize/connectors](https://gemini.google.com/customize/connectors) → **+ Custom**.
3. MCP Server URL is the output of `uv run gemini-hands url`, for example:
```text
https://macbook-air.your-tailnet.ts.net/mcp
https://xxxx.trycloudflare.com/mcp
```
4. Leave **Client ID** and **Client Secret** empty. Dynamic client registration accepts Gemini’s six `oauth-redirect*.googleusercontent.com` callbacks.
5. On the approve page, paste the owner password from the start log or `uv run gemini-hands password`. It lives in `~/.gemini-hands/auth.json` as `ownerToken`. It is not your Google password.
6. After it connects, ordinary chat and Gemini Task can call tools.
Google binds a connector by **hostname**. Do not hang a second test connector on the same host or you will get 401s. Use another hostname for parallel tests (for example `*.ts.net` vs `*.trycloudflare.com`).
A trycloudflare hostname changes every start; update the connector. A Tailscale Funnel hostname usually follows the machine name and can stay.
## Four connection modes
<p align="center"><img src="docs/modes.svg" alt="local, tailscale, cloudflare, and public connection modes"></p>
Gemini Hands always listens on this machine (`public` listens on `0.0.0.0`). Remote modes forward HTTPS to that port. Default port `7676`.
| Mode | `connect` | Gemini on the web | Who opens the tunnel |
|---|---|---|---|
| This machine only | `local` | cannot connect | none. Use `http://127.0.0.1:7676/mcp` or stdio |
| Tailscale Funnel | `tailscale` | `https://machine.ts.net/mcp` | `serve` runs `tailscale funnel --bg --yes <port>` |
| Cloudflare tunnel | `cloudflare` | `https://xxxx.trycloudflare.com/mcp` | `serve` runs `cloudflared` for trycloudflare |
| Existing public HTTPS | `public` | your `https://domain/mcp` | your reverse proxy forwards 443 |
### local
For clients on this computer. No OAuth. Use it for the Gemini app, debugging, or `stdio`.
### tailscale
1. Install and sign in to Tailscale ([downloads](https://tailscale.com/download)).
2. In [admin DNS](https://login.tailscale.com/admin/dns) turn on **HTTPS certificates** and **Funnel**.
3. `gemini-hands config set connect=tailscale` then `serve`. Leave the URL empty; Funnel is enabled on start. If `tailscale` is missing, `serve` prints install notes and exits.
4. The hostname is usually `https://<machine>.<tailnet>.ts.net` and stays stable.
### cloudflare
1. Install `cloudflared` and keep it on `PATH` ([downloads](https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/downloads/)).
2. Choose Cloudflare and **leave the HTTPS URL empty**.
3. On start, `cloudflared` opens a `*.trycloudflare.com` tunnel. No Cloudflare account. If the binary is missing, `serve` prints install notes and exits — it will not install it for you.
4. Gemini on the web must use the hostname printed **this** start.
5. If you already have a named host, put `https://space.your.domain` in config and the server will not open trycloudflare.
### public
Nginx / Caddy / a cloud load balancer already terminates TLS. Gemini Hands listens on `0.0.0.0:<port>`. Config holds the HTTPS origin that already opens in a browser, without `/mcp`.
## Tailscale and cloudflared
Only Gemini on the web needs a tunnel. `stdio` / `connect=local` do not.
### Tailscale
| OS | Typical install |
|---|---|
| macOS | App from the site, or `brew install --cask tailscale` |
| Windows | Installer, or `winget install Tailscale.Tailscale` |
| Linux | Distro package from the site, or `curl -fsSL https://tailscale.com/install.sh \| sh` |
### cloudflared
| OS | Typical install |
|---|---|
| macOS | `brew install cloudflared` |
| Windows | `winget install Cloudflare.cloudflared`, or the `.msi` |
| Debian / Ubuntu | Cloudflare apt repo, or a `.deb` from GitHub Releases |
| Other Linux | Matching binary from GitHub Releases, on `PATH` |
Do not assume every machine has `brew`. `cloudflared --version` and `tailscale status` should work in a terminal.
## Commands
```text
gemini-hands Open the UI. Create config if missing; start or edit if it exists
gemini-hands setup Jump straight to the edit form
gemini-hands config Show current config (same as config show)
gemini-hands config show
gemini-hands config path Print ~/.gemini-hands/config.json
gemini-hands config set … Change fields without rewriting everything
gemini-hands password Print the owner password and copy it
gemini-hands url Print the MCP URL for Gemini on the web
gemini-hands serve Start HTTP. Opens the UI if config is missing
gemini-hands serve --setup Edit config, then start
gemini-hands serve --stdio Same as stdio
gemini-hands stop Stop the running HTTP server
gemini-hands doctor Check mode, URL, and tunnel
gemini-hands status Same as doctor
gemini-hands stdio Local subprocess; no config required
gemini-hands init Write a full config from flags (needs --connect)
```
```bash
gemini-hands setup
gemini-hands config set workspace ~/Documents/gemini-hands
gemini-hands config set connect=cloudflare
gemini-hands config set connect=tailscale
gemini-hands config set port=7676
gemini-hands config set public-url=https://space.example.com
gemini-hands config set workspace=~/project connect=local
gemini-hands config set language=zh
```
Keys for `config set`: `connect`, `port`, `workspace`, `public-url`, `listen-host`, `hold-ms`, `language`. Switching `connect` clears the old public URL so Tailscale / Cloudflare can request a new one.
A running server does not pick up new config by itself:
```bash
gemini-hands stop
gemini-hands serve
```
One-shot write (replaces the whole file, does not merge):
```bash
gemini-hands init --connect cloudflare --port 7676 --workspace ~
gemini-hands init --connect public --public-url https://space.example.com --port 7676
```
## Configuration
Files live in `~/.gemini-hands/` (`GEMINI_HANDS_HOME` overrides). If only `~/.gemini-space` exists, the first start renames it.
| File | Contents |
|---|---|
| `config.json` | Mode, port, workspace, public URL, language |
| `auth.json` | Owner password `ownerToken` |
| `http.json` | Running HTTP process (written on start, removed on exit) |
| `cloudflared.log` | trycloudflare log |
| `tailscale.log` | Funnel log |
| Field | Meaning | Default |
|---|---|---|
| `connect` | `local` / `tailscale` / `cloudflare` / `public` | required |
| `listenPort` | Local port | `7676` |
| `listenHost` | Usually omit. `public` defaults to `0.0.0.0`, others `127.0.0.1` | `null` |
| `publicBaseUrl` | HTTPS origin, no `/mcp`. Tailscale / Cloudflare may be empty | `null` |
| `workspace` | Starting directory for `run_command` | home |
| `holdMs` | How long to wait before returning a task id | `45000` (500–55000) |
| `language` | `zh` or `en` for UI and terminal copy | `en` |
The setup screen (`gemini-hands` / `setup`) can change mode, port, workspace, a fixed HTTPS origin, and **中文 / English**. The home screen shows the owner password. `serve` prints it every start.
## Tools
Arguments are PascalCase. Paths must be absolute. There is no separate “open workspace” step.
| Tool | What it does |
|---|---|
| `read_file` | Read text. At most 800 lines or 46080 bytes per call; over 100MB or binary is not inlined |
| `write_file` | Create or overwrite. Existing files need `Overwrite` or `Append` |
| `edit_file` | Replace every `Target` with `Replacement`; whitespace must match |
| `list_dir` | List a directory |
| `grep_search` | Search file contents; regex and case-insensitive flags |
| `find_by_name` | Glob filenames, e.g. `*.py` |
| `run_command` | Run zsh in the workspace. Non-daemons wait; timeout returns a task id |
| `manage_task` | `list` / `status` / `send_input` / `kill` background commands |
| `execute` | Code Mode: async Python calling `await tools.read_file({"Path": "…"})` |
| `poll_execution` | Wait on a running `execute` |
| `cancel_execution` | Cancel `execute` |
| `server_info` | Current mode and MCP URLs; does not read files |
Common `run_command` fields: `CommandLine`, `toolSummary`, `WaitMsBeforeAsync`, `IsDaemon`, `Confirm`.
No web search, browser, cron, or sub-agent swarm. Those are out of scope.
## Behavior
**Workspace.** `run_command` starts in `workspace` (home by default). File tools still take absolute paths and may point outside that folder.
**Waiting.** Non-daemon commands wait on the server up to `holdMs` (45s default). After that you get a task id; poll with `manage_task` + `Action=status` + `TaskId`.
**Session isolation.** A Gemini session that wrote a path claims it. Another session cannot write that path or a child of it.
**Destructive commands.** `rm -rf` aimed at `/`, `~`, `*`, plus `mkfs` / `shutdown` / `reboot` / `dd` and similar, are refused. After you agree in the chat, retry the same command with `Confirm: true`.
**Code Mode.** Use `execute` to touch many files from one async Python snippet calling `tools.*`. At most 64 tool calls, 6 concurrent.
**OAuth.** `local` and `stdio` do not require OAuth. Remote modes enable dynamic client registration for Gemini’s Google redirect hosts. The owner password is only for the approve page.
## Local stdio
For the Gemini app or an editor as a subprocess. No port, no config required:
```bash
uv run gemini-hands stdio
```
Protocol on stdout, human logs on stderr. If a config exists, `workspace` and `holdMs` are reused.
## Audit page and icon
After a remote start:
- Audit: `https://hostname/web/` (owner password first)
- Icon: `https://hostname/icon.png` (also `/icon.svg`, `/favicon.png`)
MCP `initialize` sends `title` and `icons`. Gemini’s custom-app UI may still show a default glyph; the files are served.
## Process and ports
Only one HTTP listener. A second `serve` prints the live pid and URLs and exits.
If the preferred port is taken by something else, the next 30 ports are tried and the config is updated (`7676 is in use; using 7677 instead`). If the occupant is this same Gemini Hands process, it will not start a second copy.
`stop` sends SIGTERM. A Cloudflare quick tunnel dies with the process. Tailscale Funnel is node config and may still point at the old port until the next `serve`.
## Troubleshooting
| Symptom | What to do |
|---|---|
| Gemini asks for Client ID / Secret | Dynamic registration failed. Check `POST /register` in the server log, that the process is up, and that the tunnel hostname is allowed |
| Authorize page: what to paste? | `gemini-hands password`, or the `Owner password:` line from `serve` |
| 401 after approve | A second connector on the same hostname, or a trycloudflare host that already rotated |
| `url` is only `http://127.0.0.1` | Remote mode has not started, or the tunnel is still coming up |
| Tailscale Funnel failed | Installed and signed in? Funnel / HTTPS certs on? On `PATH`? See `~/.gemini-hands/tailscale.log` |
| tailscale / cloudflared not found | That mode needs the binary. Install it, then `serve` again. Nothing is auto-installed |
| trycloudflare timed out | `~/.gemini-hands/cloudflared.log`; the network must reach Cloudflare |
| Config changed but behavior did not | `gemini-hands stop && gemini-hands serve` |
| Port in use | Use the port printed at start, or `stop` then start |
| Destructive command refused | Confirm in the chat, then retry with `Confirm: true` |
```bash
uv run gemini-hands doctor
curl -sS http://127.0.0.1:7676/healthz
curl -sS "$(uv run gemini-hands url | sed 's|/mcp$||')/healthz"
```
## Environment
| Variable | Meaning |
|---|---|
| `GEMINI_HANDS_HOME` | Config directory, default `~/.gemini-hands` |
| `GEMINI_SPACE_HOME` | Same (old name) |
| `GEMINI_HANDS_LANG` | `zh` or `en`, overrides `language` in config |
## Development
```bash
uv sync
uv run python -m unittest discover -s tests
```
Package `gemini_hands`, entry `gemini-hands`. HTTP uses the MCP Python SDK Streamable HTTP transport. The setup UI is Textual.
## License
[MIT](LICENSE)
TDQS
Scored across 12 tools
File tools are cleanly separated by action (read/write/edit/list/grep/find), and search-based tools explicitly state which shell command they replace. The one fuzzy area is two parallel task-lifecycle sets: run_command+manage_task for shell processes versus execute+poll_execution+cancel_execution for Python snippets, which an agent could mix up despite the descriptions.
Most tools follow a predictable verb_noun pattern (read_file, write_file, list_dir, grep_search, find_by_name, run_command, manage_task, cancel_execution). Two deviations stand out: bare verb 'execute' and noun-only 'server_info', which break the pattern without causing confusion.
12 tools is squarely in the well-scoped range, and each one maps to a distinct capability: file I/O, directory listing, content/name search, shell execution, background task control, and Python batching. Nothing feels redundant or padded.
Core file operations (read, write, edit, list, search) plus command execution and async task control cover the agent's lifecycle well. There is no dedicated delete or move/rename file tool, but run_command provides a workaround, making it a minor gap.