green-mcp
The green-mcp server is a local agent that measures and compares the CPU energy consumption and LLM token usage of programs, helping you refactor for efficiency while verifying behavioral equivalence. Its capabilities include:
Measure energy of a shell command (CPU package energy in joules), with repeated runs and statistical reporting (mean, standard deviation, coefficient of variation) for reliability.
Compare energy consumption of two shell commands to determine which is more efficient and by what margin.
Check energy backend availability on the host (e.g., AMD uProf, Linux RAPL, macOS powermetrics) before attempting measurements.
Verify equivalence of two commands by comparing their stdout and exit codes, optionally with a battery of stdin inputs to ensure functional parity.
Measure LLM token usage (input, output, cache, reasoning, and total tokens) of a program via a transparent counting proxy, without requiring special hardware.
Compare LLM token usage between two programs to find the more token-efficient one.
Allows measuring CPU energy consumption using AMD uProf on Windows systems with AMD processors.
Allows measuring CPU and DRAM energy consumption via the Linux RAPL interface (requires root on some distros).
Allows measuring energy consumption using the built-in powermetrics tool (requires passwordless sudo).
Allows measuring token usage of programs that call OpenAI's API.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@green-mcp measure energy of 'python script.py'"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
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
pipx install green-mcp # provides the `green-mcp` command (stdlib + mcp only)Mount it in your IDE (configs in deploy/):
IDE | File |
Claude Code |
|
Cursor |
|
OpenAI Codex |
|
Google Antigravity |
|
Then ask your agent to measure or compare energy/tokens of a command. See
deploy/README.md for the full mount + harness guide.
Related MCP server: ledgermind
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 server | Python 3.10+, |
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, butenergy_ujis 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: falseand 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
usagepath and rate-limit behavior are still only exercised against a local fake upstream. These gaps are tracked, not hidden.
Development
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.
Available Tools
6 toolscompare_energyA
Measure two commands and report which consumes less energy and by what margin.
Only meaningful if both commands are functionally equivalent (same outputs for the same inputs) — verify that separately before drawing conclusions.
Inputs: command_a (required), command_b (required), repeats, idle_seconds.
compare_tokensA
Measure two programs' token use and report which uses fewer, by how much. Only meaningful if both produce acceptable equivalent results — verify that separately (fewer tokens with worse answers is not a win).
Inputs: command_a (required), command_b (required), upstream, base_url_env.
energy_backend_infoA
Report whether energy measurement is available on this host and which backend would be used. Call this before measure_energy to know if the energy axis works here — on a machine with no reachable CPU power sensor it returns energy_available: false, and you should rely on the token axis (or say energy can't be measured) rather than estimate.
Inputs: no named parameters.
measure_energyA
Measure the electrical energy (joules) a shell command consumes while running.
Methodology: samples CPU package power at 100 ms during the run, subtracts a separately measured idle baseline, repeats the run (default 3x) and reports mean/stdev/CV. Use absolute paths; wrap any path containing spaces in double quotes. Expect ~(idle_seconds + repeats x runtime) of wall time.
Inputs: command (required), repeats, idle_seconds.
measure_tokensA
Measure how many LLM tokens a program consumes when it runs (works on any machine — no
special hardware). The program must read base_url_env for its LLM endpoint (most SDKs do);
we point that at a non-blocking counting proxy forwarding to upstream, run the program, and
report real provider usage (input/output/total tokens, call count). For a non-Anthropic
target, pass its provider's base-url env var and upstream (e.g. OPENAI_BASE_URL,
https://api.openai.com). If llm_calls is 0, the target didn't route through base_url_env.
Inputs: command (required), upstream, base_url_env.
verify_equivalenceA
Run two commands and compare stdout + exit code. The gate before any energy/token comparison.
With no stdin_inputs it's a single-input smoke test. Pass stdin_inputs (a list of strings fed to each program's stdin) to run an input BATTERY — all inputs must match. Stronger evidence still comes from running the project's own test suite.
Inputs: command_a (required), command_b (required), stdin_inputs.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 6 tools
Each tool has a clearly distinct purpose: measuring vs comparing energy vs tokens, verifying equivalence, and checking backend availability. No two tools overlap in function.
Most tools follow a consistent verb_noun pattern (compare_energy, compare_tokens, measure_energy, measure_tokens, verify_equivalence). However, energy_backend_info breaks the pattern with a noun_noun structure, causing a minor inconsistency.
With 6 tools, the server is well-scoped. It covers all core operations (measure, compare, verify, and check backend) without being overly numerous or too sparse.
The tool set is complete for its domain: it provides the necessary steps to measure energy/tokens, compare two commands, verify equivalence, and check measurement availability. No obvious gaps.
Maintenance
Related MCP Connectors
LLM cost optimization gateway, repo token-waste auditor & model arbitrage MCP server.
Exact Claude API cost calc with real cache economics, plus a tiktoken-misuse scanner.
Token guard and rate limiter preventing runaway API cost spikes for OpenAI and Anthropic.
Track API spend, credit balances and runway across OpenAI, Anthropic, OpenRouter and 25 more.
Related MCP Servers
- AlicenseBqualityDmaintenanceTrack LLM token costs across Claude, GPT and Gemini. MCP server + CLI with optimization hints and $ savings estimates.813 npm1MIT
- FlicenseNot gradedqualityDmaintenanceLocal LLM cost & token forensics proxy with anomaly detection, enabling security teams to scan for cost anomalies and abuse patterns, and expose results via MCP for autonomous agents.-
- FlicenseAqualityDmaintenanceEstimates the environmental footprint of your AI use — energy (kWh), miles driven, water used for cooling, and CO₂ — plus a prompt-efficiency score, working with any AI client by measuring token usage.9-
- AlicenseNot gradedqualityBmaintenanceEnables token counting, usage tracking, and cost calculation for LLM APIs, with a proxy server mode to automatically intercept and monitor API requests from clients like Cursor and Windsurf.15 npm1MIT