gemini-workspace-mcp
by SaromChars
README.md
# gemini-workspace-mcp
English | [简体中文](README.zh-CN.md)
[](#platform-support--requirements)
[](pyproject.toml)
[](pyproject.toml)
[](LICENSE)
**Make full use of Gemini Mac App's Task Mode — equip Gemini with a real, controllable local engineering scaffold!**
The native **Gemini Mac App** already packs strong Task Mode reasoning and execution capabilities, yet putting it to work on real repositories out of the box hits familiar friction: manual prompt handoffs, coarse directory permissions, disruptive confirmation popups, and no structured lifecycle or audit trail.
`gemini-workspace-mcp` solves this by pairing Gemini Mac App with a **task-scoped local workspace MCP service and resident daemon**. With dual-socket isolation, short-lived per-task capabilities, zero-popup staged file writes, concurrent task queuing, and objective MCP call telemetry, developers and external orchestrator agents can reliably delegate real **coding, planning, and code review** work to Gemini.
---
## Key Features
- **Dual-Channel Isolation** — Separates the trusted **Host Control Plane** (`serve-host`) from the **Worker Workspace Plane** (`serve`) over dedicated `0600` Unix domain sockets (`h.sock` and `w.sock`) backed by a single SQLite store.
- **Task-Scoped Bearer Capabilities** — Every worker tool call requires a per-task `task_id` and short-lived `capability` secret. Grants are bounded to explicit roots (`read_only` or `read_write`), time-limited via TTL, and revocable immediately upon acceptance or cancellation.
- **Zero-Popup Staged File Writes** — Workers stage proposed edits in task-private SQLite storage via `task_stage_file`; the host validates policy rules and commits each staged file via `host_task_apply` with SHA-256 preflight checks and per-file atomic rename, avoiding native UI confirmation popups (not a cross-file transaction or cross-process lock against external editors).
- **Multi-Session Concurrency & Async FIFO Queue** — Supports configurable concurrent slots (`max_concurrent_tasks`), non-blocking `async_dispatch=True` queuing with a resident background dispatcher, and a frontmost-only idle guard (`idle_guard_seconds`) so UI automation avoids interrupting active user input.
- **Objective Per-Task MCP Telemetry (`mcp_metrics`)** — Tracks completed authorized worker handler calls, error counts, per-tool breakdowns, and canonical non-capability request / redacted `structuredContent` UTF-8 bytes (excluding cancelled calls and pre-handler SDK validation errors). Because the native Gemini Mac App does not expose server-side token usage, `official_model_tokens` is explicitly reported as `null` rather than estimated.
---
## Architecture
A single resident daemon arbitrates between the trusted host orchestrator (`serve-host`), the native Swift Accessibility helper (`gemini-task`), and the worker MCP endpoint (`serve`) inside Gemini Mac App:
```mermaid
flowchart LR
HostAgent["Host / Orchestrator Agent"] <-->|stdio| HostProxy["serve-host (stdio proxy)"]
HostProxy <-->|"h.sock (0600 UDS)"| Daemon["Resident Daemon\n(SQLite + FIFO Dispatcher)"]
Daemon <-->|"stdin/stdout JSON"| SwiftHelper["gemini-task (Swift AX Helper)"]
SwiftHelper <-->|"macOS AppKit / AX"| GeminiApp["Native Gemini Mac App"]
GeminiApp <-->|"stdio"| WorkerProxy["serve (stdio proxy)"]
WorkerProxy <-->|"w.sock (0600 UDS)"| Daemon
```
**Typical task lifecycle:** `host_task_create` (mint bounded grant) → `host_task_submit` (dispatch or queue into Gemini Mac App) → worker inspects/stages changes via `serve` & reports completion via `task_report` → `host_task_apply` & `host_task_accept` (atomically commit staged files and revoke capability).
---
## Platform Support & Requirements
> **macOS Only** for full Gemini Mac App delegation.
| Component | Requirement | Notes |
| --- | --- | --- |
| **OS** | macOS (Apple Silicon / Intel) | Native helper ([GeminiTask.swift](tools/gemini-app/GeminiTask.swift)) uses AppKit & macOS Accessibility (`AXUIElement`), and daemon supervision uses `launchd`. Core POSIX file descriptor tools (`store.py`, `workspace.py`, `persistent.py`) use standard POSIX APIs with `O_NOFOLLOW_ANY` on macOS. |
| **Native Client** | Gemini Mac App | Tested on `1.150.3.1601`. |
| **Permissions** | Accessibility (TCC) | Required for the context driving `gemini-task` UI preparation/submission. |
| **Python** | `>=3.11, <3.15` | Tested with Python `3.13.15` and `mcp==1.26.0`. |
| **Toolchain** | `uv`, Swift compiler (`swiftc`) | `uv` for dependency management/wheel builds; `swiftc` if rebuilding `gemini-task`. |
---
## Quick Start
### 1. Clone & Build
```sh
git clone https://github.com/SaromChars/gemini-workspace-mcp.git
cd gemini-workspace-mcp
uv sync --locked
uv build --wheel --out-dir dist .
```
Create an isolated runtime environment, install the wheel with its dependencies, and compile the native Swift Accessibility helper:
```sh
BASE="$HOME/.local/share/gemini-workspace-mcp"
HOST_PRIVATE="$HOME/.local/state/gemini-workspace-mcp-host"
mkdir -p -m 0700 "$BASE" "$BASE/runtime" "$BASE/control" "$BASE/run" \
"$HOST_PRIVATE" "$HOST_PRIVATE/bin" "$HOST_PRIVATE/run" "$HOST_PRIVATE/logs"
uv venv "$BASE/runtime/env" --python 3.13
uv pip install --python "$BASE/runtime/env/bin/python" dist/gemini_workspace_mcp-0.8.1-py3-none-any.whl
swiftc -O -framework Cocoa -framework ApplicationServices \
tools/gemini-app/GeminiTask.swift -o "$HOST_PRIVATE/bin/gemini-task"
chmod 0700 "$HOST_PRIVATE/bin/gemini-task"
shasum -a 256 "$HOST_PRIVATE/bin/gemini-task"
```
### 2. Configure `policy.json` & `daemon.json`
`$HOST_PRIVATE/policy.json` (`0600`) — set `helper_sha256` to the `shasum -a 256` output above and replace `$HOME` with your absolute home directory path:
```json
{
"version": 1,
"origin_host": "local",
"private_dir": "$HOME/.local/state/gemini-workspace-mcp-host",
"helper_path": "$HOME/.local/state/gemini-workspace-mcp-host/bin/gemini-task",
"helper_sha256": "<64-hex-sha256-of-gemini-task>",
"helper_timeout_seconds": 20,
"max_ttl_seconds": 3600,
"max_queue": 8,
"requests_per_minute": 30,
"model": "Neon",
"allowed_roots": {
"work": {
"path": "$HOME/workspace",
"mode": "read_write"
}
},
"max_concurrent_tasks": 3,
"idle_guard_seconds": 5.0,
"auto_activate_app": true,
"restore_previous_app": true,
"enable_background_dispatcher": true
}
```
> Replace `$HOME` in JSON files with your actual absolute home directory path (JSON does not expand environment variables).
`$BASE/control/daemon.json` (`0600`):
```json
{
"version": 1,
"worker_socket": "$HOME/.local/share/gemini-workspace-mcp/run/w.sock",
"host_socket": "$HOME/.local/state/gemini-workspace-mcp-host/run/h.sock",
"policy_file": "$HOME/.local/state/gemini-workspace-mcp-host/policy.json"
}
```
### 3. Start the Resident Daemon (`launchd`)
```sh
"$BASE/runtime/env/bin/python" -I -m gemini_workspace_mcp --state-dir "$BASE/control" daemon launchagent \
--label local.gemini-workspace-mcp \
--python "$BASE/runtime/env/bin/python" \
--output "$HOST_PRIVATE/local.gemini-workspace-mcp.plist" \
--log-dir "$HOST_PRIVATE/logs"
install -m 0600 "$HOST_PRIVATE/local.gemini-workspace-mcp.plist" "$HOME/Library/LaunchAgents/local.gemini-workspace-mcp.plist"
launchctl bootstrap "gui/$(id -u)" "$HOME/Library/LaunchAgents/local.gemini-workspace-mcp.plist"
"$BASE/runtime/env/bin/python" -I -m gemini_workspace_mcp --state-dir "$BASE/control" daemon status
```
### 4. Connect MCP Clients
- **Host Client** (orchestrator):
```sh
$HOME/.local/share/gemini-workspace-mcp/runtime/env/bin/python -I -m gemini_workspace_mcp \
--state-dir $HOME/.local/share/gemini-workspace-mcp/control \
serve-host --policy $HOME/.local/state/gemini-workspace-mcp-host/policy.json
```
- **Worker Client** (Gemini Mac App Local MCP):
```sh
$HOME/.local/share/gemini-workspace-mcp/runtime/env/bin/python -I -m gemini_workspace_mcp \
--state-dir $HOME/.local/share/gemini-workspace-mcp/control \
serve
```
---
## MCP Tools Reference
### Host Control Tools (`serve-host`)
| Tool | Purpose |
| --- | --- |
| `host_task_create` | Register a bounded task, roots (`read_only` / `read_write`), TTL, and private prompt/capability artifacts. |
| `host_task_submit` | Dispatch the task to Gemini Mac App immediately or enqueue via `async_dispatch=True`. |
| `host_task_advance` | Poll events and handle bounded native approval cards when `native_write_rules` are configured. |
| `host_task_status` | Return current task state, slot/queue status, `reporting` summary, and `mcp_metrics`. |
| `host_task_wait` | Long-poll for durable worker events up to 30 seconds. |
| `host_task_result` | Fetch durable events and task status/metrics without mutating state. |
| `host_task_read` | Read a file inside an authorized task root from the trusted host side. |
| `host_task_apply` | Validate policy & SHA-256 preconditions and commit staged files from `task_stage_file`. |
| `host_task_accept` | Persist host acknowledgment receipt for an event cursor and optionally revoke the task (`revoke=True`). |
| `host_task_cancel` | Request cancellation, revoke capability, and clean up active slot state. |
| `host_task_reconcile` | Reconcile native app state when submission/stop status is uncertain. |
| `host_task_run` | Composite deterministic helper: create → submit → wait/advance → optional apply & accept. |
### Worker Workspace Tools (`serve`)
All worker tools require `task_id` and `capability`.
| Tool | Purpose |
| --- | --- |
| `task_info` | Inspect task roots, mode, and limits (never returns the bearer capability). |
| `workspace_list` | List regular files inside one authorized named root. |
| `workspace_search` | Bounded literal UTF-8 content search inside an authorized root. |
| `workspace_read` | Read a bounded UTF-8 file slice with full-file SHA-256 digest. |
| `task_stage_file` | Stage a create/update file write in task-private storage for `host_task_apply`. |
| `workspace_write` | Direct hash-checked create/update inside a `read_write` grant. |
| `task_report` | Persist an idempotent `blocked`, `completed`, or `failed` event with `dedup_key`. |
| `task_events` | Read durable events for the active grant. |
| `task_wait` | Cancellable poll for new events while rechecking capability validity. |
---
## Security Model & Non-Goals
- **Path & Link Safety**: Rejects directory traversal (`..`), absolute paths, symlinks (`O_NOFOLLOW_ANY` / fd-walk), multi-hardlink files, special files, and `.git` components.
- **No Shell or Network Tools**: Worker tools have no command execution, HTTP server, or host-wake capabilities.
- **Secret Hygiene**: Capabilities are excluded from logs, metrics byte counts, and `PrivateOutput` redacts any accidental secret echo.
- **Non-Goals**: This service is **not** an OS-level sandbox and cannot restrict Gemini Mac App's own built-in tools or same-UID local processes. It does **not** estimate or fabricate official Gemini model token counts.
---
## Development & Testing
```sh
PYTHONDONTWRITEBYTECODE=1 .venv/bin/python -m pytest -q
```
### Documentation
- [Native Swift Helper Reference](tools/gemini-app/README.md)
---
## License
[MIT](LICENSE)
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues