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 分