tpu-manager

tpu-manager

Enables AI assistants to manage Google Cloud TPU VMs, including queueing, monitoring, bootstrapping, and SSH/tmux integration.

Category
访问服务器

README

tpu-manager

Queue, monitor and bootstrap Google Cloud TPU VMs from a terminal UI — or drive the same operations from an AI assistant over MCP.

Built for TRC / preemptible TPU workflows, where capacity appears and vanishes without warning and you want to grab it the moment it shows up.

┌ TPU Manager ─────────────────────────────────────────────────────────────┐
│ ⭐  Name                 Zone            Latency  Accel    Mode  State    │
│ ⭐  spot-v6e64-ew4a-1    europe-west4-a  ~140ms   v6e-64   spot  ACTIVE   │
│     spot-v6e32-ew4a-1    europe-west4-a  ~140ms   v6e-32   spot  WAITING… │
│     ondemand-v4-8-uc2-1  us-central2-b   ~240ms   v4-8     ond.  NOT_QUEUED│
├──────────────────────────────────────────────────────────────────────────┤
│ 14:22:31 spot-v6e64-ew4a-1: PROVISIONING → ACTIVE                        │
│ 14:22:33 tmux sync: opened 1 new TPU window                              │
└──────────────────────────────────────────────────────────────────────────┘

What it does

  • Fixed slot table. Each row is one reservable quota slot with its own node name, so several TPUs can be held at once. Rows are never added or removed — you queue and cancel them.
  • Bucket race. Star several slots, hit B, and it queues them all in parallel; the first to reach PROVISIONING wins and the rest are cancelled automatically. This is how you actually catch scarce spot capacity.
  • tmux SSH mirror. Every ACTIVE TPU gets a live SSH window in a per-zone tmux session. Windows are never closed behind your back.
  • One-key VM bootstrap. Copies and runs the setup scripts over SSH with agent forwarding, then optionally joins the node to your Tailscale tailnet.
  • MCP server. The same 12 operations exposed as tools, so an assistant can check state, queue capacity and open shells for you.
  • Push notifications via ntfy.sh when a TPU goes live.

Requirements

Python 3.11+ (uses tomllib)
gcloud authenticated, with TPU API access to your project
tmux optional — only for the SSH mirror
xclip / wl-copy optional — clipboard fallback for s
mcp>=1.2 optional — only for the MCP server (SDK 1.x and 2.x both work)

An SSH agent holding your GitHub key is needed if you want the non-interactive VM bootstrap to clone private repos:

eval "$(ssh-agent -s)" && ssh-add ~/.ssh/github

Start the app from that same shell so it inherits SSH_AUTH_SOCK.

Install

git clone https://github.com/<you>/tpu-manager.git
cd tpu-manager
pip install -e .            # TUI only
pip install -e '.[mcp]'     # plus the MCP server

Configure

Nothing about your GCP setup is hardcoded. Write a starter config and edit it:

python -m tpu_manager.config --init     # ~/.config/tpu-manager/config.toml
python -m tpu_manager.config --show     # print what actually resolved
project  = "my-gcp-project"
network  = "tpu-network"
ntfy_topic = ""            # empty disables notifications

poll_interval = 30
poll_concurrency = 8       # max concurrent gcloud calls
auto_setup = false         # run VM bootstrap automatically on ACTIVE
tmux_sync  = true

[subnets]
"europe-west4-a" = "tpu-subnet-europe-west4"

[zone_codes]
"europe-west4-a" = "ew4a"

[[slots]]
name = "ondemand-v4-8-uc2-1"
zone = "us-central2-b"
accelerator = "v4-8"
mode = "on-demand"

# Generated spot rows: one row per machine that fits your v6e quota.
v6e_zones  = [["europe-west4-a", "ew4a"]]
v6e_counts = [["v6e-64", 1], ["v6e-8", 8]]

Any key can be overridden by an environment variable: TPU_MANAGER_POLL_INTERVAL=10, TPU_MANAGER_AUTO_SETUP=1, and so on.

ntfy topics are public to anyone who guesses the name. Leave ntfy_topic empty unless you pick something unguessable.

Run the TUI

tpu-manager          # or: python -m tpu_manager
Key Action
c / a queue selected slot / every NOT_QUEUED slot
b / B toggle slot in the bucket / run the bucket race
d cancel queue or delete VM — press twice
x close the slot's tmux window — press twice
o open a tmux SSH window
s copy the SSH command to the clipboard
S copy and run the VM bootstrap script
t / T save a Tailscale auth key / push Tailscale to the VM
i show IPs and create time
r / q force refresh / quit

Run the MCP server

tpu-mcp                        # or: python -m tpu_manager --mcp

Register it with Claude Code:

claude mcp add tpu-manager -- tpu-mcp

Or in an MCP client config:

{
  "mcpServers": {
    "tpu-manager": { "command": "tpu-mcp" }
  }
}
Tool Kind Purpose
list_slots read-only all slots and their states
slot_info read-only IPs, create time, SSH command
ssh_command read-only the SSH command, without connecting
tmux_status read-only managed windows, orphans flagged
queue_slot / queue_slots mutating request capacity
setup_vm mutating run the bootstrap over SSH
tailscale_setup mutating join the node to your tailnet
tmux_sync / tmux_open mutating open SSH windows
cancel_slot destructive delete the TPU — needs confirm=true
tmux_close destructive kill a tmux window — needs confirm=true

Destructive tools carry destructive_hint=true annotations, so a client can prompt before running them.

tmux lifetime

The rule, stated once and enforced everywhere:

  • Each ACTIVE TPU gets one tmux window named after the slot, in session tpu-<zone-code>.
  • Reconciliation only creates. It never kills a window — not when the TPU leaves ACTIVE, not when a duplicate exists, not when the app exits.
  • A window whose slot is no longer ACTIVE is reported as orphaned and left running.
  • Windows are set remain-on-exit on, so a dropped SSH leaves a readable pane instead of the window vanishing.
  • The only way to close one is explicit and confirmed: x twice in the TUI, or tmux_close(name, confirm=true) over MCP.
  • Deleting a TPU leaves its window alone and warns you; pass close_tmux=true to do both at once.

What gets remembered

~/.local/state/tpu-manager/state.json keeps, between runs:

  • the resolved OS Login username (the gcloud lookup is slow — caching it is what keeps startup snappy),
  • your bucket selection,
  • the cursor position,
  • which slots finished setup, and which were already announced.

Delete the file to reset; a corrupt file degrades to "first run" rather than breaking anything.

Responsiveness

Earlier versions froze whenever a gcloud call was in flight. The current design keeps the UI live:

  • Every key handler returns immediately and dispatches to a Textual worker. An async def action_* is awaited by the message pump, so a slow refresh — or the bucket race, which loops until a winner appears — used to lock the whole UI.
  • Long jobs run in an exclusive worker group, so a second keypress cannot start a duplicate.
  • Polling is bounded by a semaphore (poll_concurrency). Unbounded, ~40 slots forked ~40 gcloud processes per tick.
  • Blocking calls — the ntfy HTTP post, clipboard helpers, the OS Login lookup — run in threads, never on the event loop.
  • The table repaints on a timer, so a burst of state transitions is one redraw.

Layout

src/tpu_manager/
  config.py       config resolution, slot table, zones, naming
  state.py        the small JSON store described above
  core.py         TPUManager — every gcloud/tmux side effect, no UI
  tui.py          Textual app
  mcp_server.py   MCP stdio server
scripts/          bootstrap scripts scp'd to each VM
tests/            no gcloud, no tmux, no network required

Develop

pip install -e '.[dev,mcp]'
pytest
ruff check .

See docs/vm-setup.md for what the bootstrap scripts do and how to debug a failed setup.

License

MIT — see LICENSE.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选