Skip to main content

gemini-mcp

MCP gateway for massive-payload Gemini analysis on the AI Studio free tier. Runs on a small VPS; a local Freebuff Desktop agent sends huge bodies to it and gets back a compact consolidated result — the agent's own context stays clean.

  • Cascading Flash chain (newest first, deprecated aliases excluded) via gemini-router (per key×model RPD/RPM/TPM ledger shared with tldr-digest).
  • Over-limit bodies: split into overlapping chunks, each marked [CHUNK N/M], analyzed separately, then consolidated (recursively if needed).
  • thinking_level default medium, per-request override; opt-in overflow (flash-lite → gemma) when the daily quota is gone; hard stop otherwise; per-request wait policy for minute-limit resets (default: wait, countdown reported in progress).
  • Deep progress to the caller (MCP progress + logging notifications + embedded trace), rotating disk logs, gemini-mcp quota|logs|calls|doctor in the terminal.
  • Transports: SSH-stdio (primary) and streamable HTTP daemon (127.0.0.1, bearer).
  • Dual backend: router (fleet: shared SQLite ledger on the VPS) or direct (plain Google AI Studio: same engine, a local persistent ledger, no server at all). backend: auto picks router only when persistent state exists; env GEMINI_MCP_BACKEND overrides. See docs/08-dual-mode.md.

Quick start

If you're human

pnpm dlx @vernikr/gemini-mcp setup     # or: uvx --from gemini-mcp-gateway gemini-mcp setup

Answer the questions: 1 Simple (direct to Google AI Studio, keys via hidden paste/file/skip) or 2 Fleet (your VPS — the wizard clones the repos, provisions the server, pushes keys, health-checks, all you answer is host + projects folder). It finishes with a numbered checklist: paste one JSON block into your MCP client (Freebuff/Claude Desktop/Cursor — or add --write-client freebuff|claude|cursor and it merges the block in for you, with a .bak backup), restart the client, send the agent the printed verify prompt. gemini-mcp doctor re-checks keys/chain/limits; gemini-mcp uninstall --yes removes everything the wizard wrote. Full client matrix + fleet JSON forms: docs/06-consumer.md.

If you're an AI agent

One shot, no TTY, machine-readable. Exit 0 + "ok": true = done; otherwise every failure carries error/deploy_error/clients_failed[].fix naming the exact remedy — apply it, re-run the same command (idempotent). Relay to the human only the two manual actions: restart the MCP client, then send the agent the prompt from verify_prompt (tool quota_status, MCP server gemini).

# direct (no server); keys from a file — never from shell history
npx -y @vernikr/gemini-mcp setup --backend direct \
  --keys-file /abs/path/keys.txt --write-client freebuff --json

# fleet (shared-quota server); clones/provisions/health-checks by itself
npx -y @vernikr/gemini-mcp setup --backend router --vps-host <ip> \
  [--vps-user root] [--projects-dir ~/projects] [--keys-file /abs/path/keys.txt] \
  --write-client freebuff --json

Fleet prerequisites (each failure message tells you how to check): GitHub auth for the private repos (git ls-remote https://github.com/vernikr/gemini-mcp), passwordless ssh <user>@<ip>, bash+rsync, macOS/Linux. No env vars needed afterwards: the gateway auto-discovers ~/.config/gemini-mcp/.

Analyzing a FILE (agent): never read it yourself and never inline its contents into a prompt. Call file_upload_ticket(filename, size_bytes) → HTTP PUT the raw bytes to upload_url → analyze_file(upload_id, task). Text documents are extracted and chunked server-side; PDFs, images and audio are sent to the provider once and answered in one measured request (never split). Quota is accounted either way; quota_status returns this recipe in its file_flow field, and raw RTF/PDF/DOCX payloads in text tools fail fast with a raw_document_inlined fix.

Direct mode needs nothing but API keys. Usage is tracked in a LOCAL persistent ledger (~/.config/gemini-mcp/state.db): quota counters survive restarts and are shared by all gateway processes on the machine — but not across machines (that's fleet mode: VPS daemon + backend: router). Every response says backend=direct in its report line; gemini-mcp uninstall --yes removes keys, config and ledger together. The npm shim @vernikr/gemini-mcp (pnpm-first install) ships the same core at the same version.

Development

uv sync --extra dev    # dev pin: gemini-router from a git tag (tool.uv.sources);
                       # published metadata uses the PyPI range — no auth needed
uv run pytest -q       # chunker, pipeline, tools/server, logging, backends, wizard —
                       # all faked, no network
uv run ruff check src tests
GEMINI_API_KEYS=... uv run gemini-mcp setup|quota|calls|logs|prune|doctor|smoke
Stage Artifact
Functional/business requirements docs/02-requirements.md
Architecture & stack docs/03-architecture.md
Consumer guide (client JSON, direct mode) docs/06-consumer.md
Dual-mode backend design docs/08-dual-mode.md
CI/CD and release mechanics docs/09-ci.md
Risks docs/blockers/
Superseded stage docs and ops logs docs/worklog/archive/

Planned usage (Freebuff, ~/.agents/mcp.json)

{ "mcpServers": {
    "gemini": {                       // A) SSH-stdio — primary, encrypted, no open ports
      "command": "ssh",
      "args": ["root@38.244.152.2", "~/.local/bin/gemini-mcp", "stdio"] },
    "gemini-http": {                  // B) HTTP via `ssh -L 8790:127.0.0.1:8790 root@38.244.152.2`
      "type": "http", "url": "http://127.0.0.1:8790/mcp",
      "headers": { "Authorization": "Bearer $GEMINI_MCP_TOKEN" } } } }

Tools: analyze_large (chunking pipeline), gemini_generate (single shot), file_upload_ticket + analyze_file (file flow: upload → text extraction or the provider's Files API for PDFs/images/audio → analysis), analyze_result (async poll), quota_status, router_logs. Raw document bytes (RTF/PDF/DOCX markers) pasted into gemini_generate/analyze_large are rejected with raw_document_inlined + the exact fix — always use the file flow.

Deployment (M4)

From the workstation (sibling checkout of gemini-router required next to this repo):

bash scripts/run_remote.sh setup    # rsync both repos → venv, .env, systemd unit, doctor
bash scripts/run_remote.sh smoke    # first real-key run on the VPS (spends ≤1 RPD)
bash scripts/run_remote.sh status|logs

Freebuff Desktop wiring (SSH-stdio and HTTP-via-tunnel snippets, verification steps): docs/freebuff-wiring.md. The daemon never leaves 127.0.0.1:8790; no firewall changes are made (server-spec compliant).

Ops (after M4)

ssh root@38.244.152.2
sudo systemctl status gemini-mcp          # daemon (HTTP)
~/.local/bin/gemini-mcp quota    # what's left, per key×model (on the VPS, as its user)
~/.local/bin/gemini-mcp logs -f  # live app log
~/.local/bin/gemini-mcp keys    # the key pool: fingerprints, where it lives
gemini-mcp keys add <key>       # add a key: validated, probed free, service restarted

gemini-mcp keys edits the env file the daemon actually reads (the unit's EnvironmentFile) and restarts the service — the same command works on a workstation, where it writes the wizard's .env instead.

Conventions: English in files, Conventional Commits, SemVer, docs updated with every functional change (see AGENTS.md).

Metadata

Release files for gemini-mcp-gateway 0.25.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gemini-mcp-gateway 0.25.1
File Size Uploaded Provenance Actions
gemini_mcp_gateway-0.25.1.tar.gz 295.2 kB With provenance Details for gemini_mcp_gateway-0.25.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for gemini-mcp-gateway 0.25.1
File Interpreter ABI Platform Actions
gemini_mcp_gateway-0.25.1-py3-none-any.whl Python 3 none any Details for gemini_mcp_gateway-0.25.1-py3-none-any.whl

Total release size: 376.7 kB

Release files / gemini_mcp_gateway-0.25.1.tar.gz

Download URL gemini_mcp_gateway-0.25.1.tar.gz
Size 295.2 kB
Tags Source
SHA-256 checksum
How to use checksums
23a9fe6d72b8f24f5f934e84af9af9f1fd8c05e6e04aa4e1dee39e053f2d66f1
BLAKE2b-256 checksum
How to use checksums
9f6d5ae398f2242456d3740f777faae8c5c475758899cddf5f5d1a3984ed8250
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 13, 2026.

Transparency log

Release files / gemini_mcp_gateway-0.25.1-py3-none-any.whl

Download URL gemini_mcp_gateway-0.25.1-py3-none-any.whl
Size 81.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
157239858f7abb06435169896f24fa7f362af79ef9a87dd442565319dbb2066f
BLAKE2b-256 checksum
How to use checksums
6ad25f8910e26eeb6bb7a285f8c1dfc96555982411cc3a556b0acc130f8bae68
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 13, 2026.

Transparency log

Security for gemini-mcp-gateway 0.25.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for gemini_mcp_gateway-0.25.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 13, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.25.1 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page