Green Mcp

io.github.rlawogh1005由 GitHub 帳號 rlawogh1005 發布v0.1.2更新於 Oct 27, 2026

Measure a program's CPU energy and LLM tokens, then refactor it cheaper. Measure, never estimate.

概覽

AI 產生的概覽

本機 MCP 伺服器,量測程式的 CPU 能耗與 LLM token 用量,對多次執行做統計比較,並協助重構以降低成本。

可以做什麼
  • 透過硬體遙測(AMD uProf、Linux RAPL、macOS powermetrics)量測指令的 CPU 能耗
  • 以統計檢定比較兩次執行的能耗
  • 透過計數代理量測程式的 LLM token 用量
  • 比較不同執行的 token 用量
  • 驗證重構後的程式行為是否維持一致
  • 回報主機上可用的能耗後端
適用情境
適合讓助理量化某個指令或腳本的能耗或 token 成本、判斷重構是否真的更省,以及確認最佳化後行為沒有改變。最適用於能存取功耗感測器的本機開發環境。
執行需求
由 IDE 以本機 stdio 子程序啟動;需要 Python 3.10+ 與 green-mcp 套件(以 pipx 或 pip 安裝)。能耗量測需要功耗感測器後端:Windows+AMD 需另裝 AMD uProf,Linux 讀取 /sys/class/powercap,macOS 使用 powermetrics 且需 root 或免密碼 sudo。token 量測要求被測程式從環境變數(如 ANTHROPIC_BASE_URL、OPENAI_BASE_URL)讀取 LLM 端點,並需能連線至服務商。選用的內建代理需要 Anthropic 憑證。
安裝前請注意
被測指令會在本機以任意指令執行,只應在可信任環境使用。token 量測會把目標的真實 LLM 呼叫轉送至真實服務商,目標的 API key 照常計費。macOS 能耗量測需要 root 或免密碼 sudo。能耗工具在 Docker 或 CI 中通常無法使用,沒有感測器時會拒絕估算。不同後端的數據不可互相比較,且只有 AMD/uProf 後端在真實硬體上驗證過可重複性。

安裝

在 SourceWeft 中

  1. 開啟 儀表板中的 Green Mcp,將其新增到工作區。
  2. 為需要使用其工具的對話啟用該服務。

Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。

其他 MCP 客戶端

參照 儲存庫 中的啟動說明。

README

Green Agent

A pluggable MCP server that measures two efficiency axes of a program and refactors it to be cheaper while preserving behavior:

  • CPU energy — joules the code actually consumes, from real hardware telemetry (AMD uProf / Linux RAPL / macOS powermetrics), chosen automatically for the host.
  • LLM tokens — the token usage of a program that calls LLMs (input/output/cache/reasoning), measured provider-neutrally and non-blockingly.

Defining principle: measure, never estimate. Every claim is a measurement with the command, the number, and its run-to-run uncertainty — or it's labeled an estimate. The comparison verdict is a real statistical test (Welch's t with the idle-baseline uncertainty folded in), not a heuristic.

Quick start

sh
pipx install green-mcp        # provides the `green-mcp` command (stdlib + mcp only)

Mount it in your IDE (configs in deploy/):

IDEFile
Claude Code.mcp.json
Cursor.cursor/mcp.json
OpenAI Codex~/.codex/config.toml (codex mcp add green -- green-mcp)
Google Antigravity~/.gemini/config/mcp_config.json

Then ask your agent to measure or compare energy/tokens of a command. See deploy/README.md for the full mount + harness guide.

Tools

measure_energy · compare_energy · measure_tokens · compare_tokens · verify_equivalence · energy_backend_info

Requirements (what each part needs to actually work)

No server to host. green-mcp is not a web service — your IDE launches it as a local stdio subprocess. There's no cloud, no account, and no LLM key needed for the measurement server itself.

To run the serverPython 3.10+, pip install green-mcp. That's it — tools mount immediately.

Energy axis — needs a power-sensor backend on the host (the largest prerequisite):

  • Windows + AMD → install AMD uProf separately (driver-based; admin to install). Not bundled.
  • Linux → reads /sys/class/powercap (RAPL); no extra install, but energy_uj is root-only on some distros.
  • macOS → uses the built-in powermetrics, which requires root / passwordless sudo.
  • No reachable sensor (a VM, a container, a locked-down machine) → energy tools report energy_available: false and refuse to estimate. Energy generally does NOT work in Docker/CI — containers and VMs have no power-sensor passthrough. Use the token axis there.
  • The measured command runs locally (arbitrary commands → use in a trusted environment only).

Token axis — no special hardware, works anywhere, but:

  • The target program must read its LLM endpoint from an env var (ANTHROPIC_BASE_URL, OPENAI_BASE_URL, …) so we can route it through the counting proxy. A hardcoded endpoint won't be measured (reports 0 calls).
  • Measuring runs the target's real LLM calls — the proxy forwards to the real provider, so the target's API key is billed as usual, and network access to the provider is required.

Bundled agent (optional) — pip install green-mcp[agent] adds the Claude Agent SDK and needs Anthropic credentials. The MCP server alone needs none.

Honest scope

  • Energy is CPU package energy (+DRAM on RAPL) — not carbon, not whole-system.
  • Numbers from different backends are not comparable.
  • Only the AMD/uProf backend is validated for repeatability on real hardware; Linux/macOS are written and unit-tested but unverified on metal, and no backend is yet cross-validated against a wall power meter. The token measurer is validated against a live provider (NVIDIA NIM, OpenAI-compatible: 5 real calls, streaming and non-streaming, matching the provider's own usage records exactly) — but the Anthropic-shaped usage path and rate-limit behavior are still only exercised against a local fake upstream. These gaps are tracked, not hidden.

Development

sh
python -m venv .venv && .venv/Scripts/pip install -e ".[dev]".venv/Scripts/python -m pytest -q          # unit tests.venv/Scripts/python -m pytest -m integration   # real-hardware (needs AMD uProf)

Architecture and decisions live in North Star.md, Green.md, and docs/. Licensed under MIT.

來源:README.md,提交 7049f98

工具

0
SourceWeft 尚未在沙箱中啟動過該軟體包,因此其工具未知。

版本歷史

1
  1. v0.1.2最新Sep 16, 2026

評分

已滿足適用檢查項的 50%

該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。

  • 近 30 天內可連通25 分

    請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。

  • 已宣告認證方式10 分

    請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。

  • 已列出工具15 分

    請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。

  • 描述必需15 分
  • 圖示10 分
  • 文件15 分
  • 授權條款10 分