GreenCode Auditor MCP server
Commit Nov 1, 2026Measures hardware energy consumption, calculates ISO/IEC 21031 SCI scores, and generates AI-powered refactor proposals to reduce software carbon footprints.
Also known as zeenat28-ui/greencode
- Stars
- 0
- Tools
- โ
- Downloads, 30 days
- โ
- Latest version
- โ
- Last commit
- Nov 1, 2026
- License
- Apache-2.0
What is GreenCode Auditor MCP?
GreenCode Auditor measures hardware energy consumption, calculates ISO/IEC 21031 SCI scores, and generates AI-powered refactor proposals to reduce software carbon footprints.
Summary generated from the project's README
About GreenCode Auditor MCP server
Measuring hardware energy consumption and calculating carbon intelligence scores is what GreenCode Auditor enables for developers and cloud architects. This local-first platform tracks emissions per line of code using the ISO/IEC 21031 SCI standard and provides real-time data on global grid carbon intensity across 150 regions. It works by monitoring hardware counters like Intel/AMD RAPL, NVIDIA NVML, and Apple Silicon IOKit to capture precise CPU, GPU, and memory usage.
Users can integrate the server into their workflows via a command-line interface or a web dashboard. The system supports AI-powered refactor proposals using providers such as Amazon Bedrock, Google Gemini Pro, or HuggingFace to suggest code optimizations. For infrastructure management, it scans Terraform, Kubernetes, and Docker configurations to recommend migrations to AWS Graviton4 ARM64. The platform also includes a specialized browser simulator to test MCP tool calls in an Alexa-style environment.
What you can do with it
- 1Analyze hardware energy usageA developer can measure the actual power consumption of their CPU, GPU, and memory during execution.
- 2Generate carbon-aware code fixesAn engineer can request AI-driven refactoring proposals to reduce the carbon footprint of their software.
- 3Schedule jobs based on grid intensityUsers can compare regional carbon intensity to decide where to run batch jobs.
Written from the project's README. Every use case is checked against a quote from it.
Configuration
AWS_ACCESS_KEY_IDAWS_REGIONAWS_SECRET_ACCESS_KEYGEMINI_API_KEYGITHUB_CLIENT_IDGITHUB_CLIENT_SECRETGITHUB_TOKENGOOGLE_CLIENT_IDGOOGLE_CLIENT_SECRETGREENCODE_ALEXA_SKILL_IDGREENCODE_LLM_PROVIDERJWT_SECRETSECRETS_ENCRYPTION_KEYVITE_API_URL
| Name | Description | |
|---|---|---|
| AWS_ACCESS_KEY_ID | โ | |
| AWS_REGION | โ | |
| AWS_SECRET_ACCESS_KEY | โ | |
| GEMINI_API_KEY | โ | |
| GITHUB_CLIENT_ID | โ | |
| GITHUB_CLIENT_SECRET | โ | |
| GITHUB_TOKEN | โ | |
| GOOGLE_CLIENT_ID | โ | |
| GOOGLE_CLIENT_SECRET | โ | |
| GREENCODE_ALEXA_SKILL_ID | โ | |
| GREENCODE_LLM_PROVIDER | โ | |
| JWT_SECRET | โ | |
| SECRETS_ENCRYPTION_KEY | โ | |
| VITE_API_URL | โ |
README
View on GitHub๐ฑ GreenCode Auditor
Software Carbon Intelligence Platform
Featuring a self-hosted MCP server and Alexa+-style browser simulator
๐งฉ Local MCP Demo โข ๐ Documentation โข ๐ Quick Start โข ๐ Hackathon Submission
๐ฏ What is GreenCode Auditor?
GreenCode Auditor is a software carbon intelligence platform that helps developers and cloud architects:
- ๐ฃ๏ธ Try the Alexa+-style web simulator backed by GreenCode's self-hosted MCP server
- โก Measure real hardware energy consumption (CPU, GPU, memory)
- ๐ค Generate and verify refactor proposals with a configured AI provider (Amazon Bedrock is optional)
- ๐ Track carbon emissions per line of code (ISO/IEC 21031 SCI standard)
- ๐ฐ Save cloud costs with AWS Graviton4 ARM64 migration recommendations
- ๐ Live grid intelligence from 150+ global regions
- ๐ Block carbon-heavy PRs in your CI/CD pipeline
๐ Built for Amazon Developer Hackathon 2026
- Primary Track: Alexa+ Track (Agent Skills & MCP Servers)
๐ธ Screenshots
Screenshots will be added here after recording demo video
See docs/screenshots/README.md for screenshot guide.
โจ Key Features
๐งฉ Alexa+-Style MCP Web Simulator
Try real MCP tool calls in the local Alexa+ style browser simulator:
Open http://localhost:5173/alexa-demo
Choose a preset or enter a supported grid, audit, SCI, or refactor request.
The simulator initializes an MCP session, lists tools, and calls the local GreenCode MCP server; displayed results come from those tool responses. It is not an Amazon-hosted Alexa+ session, Developer Console test, or Echo interaction. See the judge demo instructions.
๐ง Refactor Proposals
When configured, AI refactoring tries providers in this order: Amazon Bedrock,
Google Gemini Pro (gemini-3.1-pro-preview), then HuggingFace. Gemini is pinned to the
Pro model; Flash models are not used. Set GEMINI_API_KEY in the backend
.env file to enable the second provider. The same compile, similarity, and
behavior-probe checks are applied to LLM proposals. Recognized patterns also
have deterministic local suggestions when providers are unavailable; these
are explicitly labeled as not behavior-tested. Unsupported patterns require
manual review.
- Supports Amazon Bedrock models such as
amazon.nova-pro-v1:0when configured
๐ Real Hardware Energy Measurement
- Intel/AMD RAPL counters (CPU package, DRAM, GPU)
- NVIDIA NVML for GPU power
- Apple Silicon M1/M2/M3 via IOKit
- Linux cgroup v2 for per-process attribution
- Scaphandre integration
๐ Live Global Grid Carbon Intensity
- 150+ regions from Electricity Maps, WattTime, ENTSO-E, UK ESO
- Real-time marginal carbon intensity (gCOโ/kWh)
- Regional comparisons for batch job scheduling
๐ผ Enterprise FinOps & IaC Auditing
- Scans Terraform, Kubernetes, Docker for power-hungry configs
- Recommends AWS Graviton4 ARM64 migrations
- Reconciles FinOps FOCUS 1.4 cloud billing CSVs
- Estimates annual COโe reductions and cost savings
๐ Security & Compliance
- OAuth 2.0 authorization-code flow with state validation for GitHub login
- Encrypted GitHub credentials โ GitHub credentials used for repository access are encrypted at rest when
SECRETS_ENCRYPTION_KEYis configured; Alexa pairing retains a separate encrypted copy until unlinked - Secrets encrypted at rest with Fernet (AES-256-CBC)
- Pre-commit hooks block secrets and API keys
๐ Quick Start
Run the real application locally
Prerequisites
- Python 3.11+
- Node.js 20+
- Git
- A GitHub OAuth App with callback URL
http://localhost:5173/login
Installation
# 1. Clone the repository
git clone https://github.com/zeenat28-ui/greencode.git
Set-Location greencode
# 2. Create a Python environment and install backend dependencies
py -m venv .venv
.\.venv\Scripts\Activate.ps1
python -m pip install --upgrade pip
python -m pip install -e ".[mcp]"
# 3. Create local settings if they do not already exist.
# Set GitHub OAuth credentials in .env; never commit .env or share its secrets.
if (-not (Test-Path .env)) {
Copy-Item .env.example .env
}
# Never commit .env or share GITHUB_CLIENT_SECRET.
# 4. Install frontend dependencies
Set-Location frontend
npm install
Start the API and UI in separate terminals from the repository root:
# Terminal 1 - FastAPI backend
.\.venv\Scripts\Activate.ps1
python -m uvicorn app.main:app --host 127.0.0.1 --port 8000 --reload
# Terminal 2 - React/Vite frontend
Set-Location frontend
npm run dev -- --host 127.0.0.1
# Terminal 3 - GreenCode MCP Streamable HTTP server for the browser demo
$env:GREENCODE_MCP_PORT = "8766"
python -m app.mcp_server
Open in browser
- Frontend: http://localhost:5173
- Backend API: http://localhost:8000/docs
- Health check: http://localhost:8000/api/health
- MCP endpoint: http://127.0.0.1:8766/mcp (proxied to the dashboard at
/mcp)
Run the Alexa-style hackathon web demo (no account or payment required)
For the Alexa+ hackathon demonstration, use the browser simulator at
http://localhost:5173/alexa-demo. It needs the MCP server and frontend from
the local setup above, but does not require GitHub login, an Echo, a tunnel,
Alexa Developer Console access, or a paid cloud deployment. The page uses the
same self-hosted MCP tools and reports errors if the local MCP server is
unavailable.
# Terminal 1 - MCP server
$env:GREENCODE_MCP_PORT = "8766"
python -m app.mcp_server
# Terminal 2 - frontend
Set-Location frontend
npm run dev -- --host 127.0.0.1
Open http://localhost:5173/alexa-demo and choose a preset. The page is an
Alexa+-style web simulator, not a connection to Amazon's Alexa service.
Optional: run the ASK custom skill on an Echo
The Alexa cloud service cannot reach localhost. A free ngrok account
provides a stable development hostname without buying a domain. Configure it
once, then use the launcher to start the backend, Alexa-only webhook bridge,
tunnel, and frontend together:
winget install --id Ngrok.Ngrok -e
.\scripts\setup-alexa-tunnel.ps1
.\scripts\start-alexa-local.ps1
Create a free ngrok account and enter its agent token only in the launcher's hidden local prompt. Save the endpoint printed by the launcher in the Alexa Developer Console once; the assigned ngrok hostname stays stable across local restarts. The bridge exposes only the ASK webhook path. See Alexa local setup for details.
In the Developer Console, open your skill's Build โ Endpoint page, select
HTTPS, and paste the launcher's https://.../api/alexa/skill URL into
Default Region. For an ngrok *.ngrok-free.dev hostname, choose My
development endpoint is a sub-domain of a domain that has a wildcard
certificate from a certificate authority, then save the endpoint and build
the interaction model. Use the URL printed by your own launcher; it must be
online whenever you test the skill. In the Test tab, enable Development
and try open green code auditor or help.
To let Alexa read the dashboard selection, sign in to GreenCode, connect GitHub,
select a repository in Scan Repository, and choose Pair Alexa with this
repository. Say โlink my GreenCode account with codeโ followed by the
eight-digit code in the Alexa skill. It expires in ten minutes, works once,
and requires SECRETS_ENCRYPTION_KEY; say โunlink my GreenCode accountโ to
revoke access. This is GreenCode's explicit pairing flow, not Amazon OAuth
account linking. See Alexa pairing details.
Connect Alexa+ to the MCP server
Alexa+ uses the separate alexa/addon.json manifest and the self-hosted
Streamable HTTP endpoint ending in /mcp. It must not be pointed at the ASK
webhook in alexa/skill.json. For a local MCP demo exposed over HTTPS, set a
bearer token and run:
$env:GREENCODE_MCP_PORT = "8766"
$env:GREENCODE_MCP_TOKEN = "<set a local secret in this shell>"
.\scripts\start_mcp_remote.ps1
The script configures the Alexa+ MCP manifest (/mcp) and the separate ASK
Custom Skill webhook (/api/alexa/skill) for its HTTPS tunnel URL. For a
deployed MCP host, run
.\scripts\configure-alexa-addon.ps1 -BaseUrl "https://mcp.example.com" -ConfigureAskSkill
before alexa-ai deploy. Enter the printed /api/alexa/skill URL in the ASK
Developer Console while the tunnel is running. The previous Vercel URL is not
an MCP deployment; the Vercel function omits the MCP SDK and does not expose
/mcp.
See Alexa integration setup
for the distinction between Alexa+ MCP and the ASK Custom Skill.
Use the real GitHub audit workflow
- Set
GITHUB_CLIENT_IDandGITHUB_CLIENT_SECRETin the backend.envfile. - Restart the backend, open
http://localhost:5173/login, and choose Continue with GitHub. Authorize repository access when GitHub prompts you. - GitHub redirects back to the same browser tab. After sign-in, choose an accessible repository in Scan Repository, select its branch, and run the audit.
- Review the returned findings in Issues, generate a refactor for a finding, inspect its code diff, and create a pull request.
The GitHub OAuth flow uses the repo, read:user, and user:email scopes so private repositories can be audited and the app can create a branch and PR. OAuth credentials are exchanged by the backend; no PAT entry is required.
Do I need Docker?
No. The frontend, FastAPI backend, GitHub OAuth/repository workflow, static audits, and browser-based Alexa assistant all run locally without Docker. GreenCode uses Docker only for dynamic analysis, where it executes code from a repository to measure runtime behavior. The container is a security boundary; running untrusted repository code directly on the host is not a safe substitute.
On Windows, Docker Desktop with its WSL 2 backend is the supported local option for that feature. A separately provisioned, disposable VM can be an alternative in principle, but GreenCode's current dynamic-analysis adapter expects Docker; another sandbox needs its own isolated adapter and must not fall back to host execution. Without a sandbox, dynamic analysis is explicitly unavailable while static scans and the rest of the local app remain usable.
๐ฎ Usage Examples
Command-Line Interface
# Audit a local repository
greencode --path ./my-project --threshold 80
# Audit only changed lines in a PR
greencode --path . --diff origin/main...HEAD
# Lint Infrastructure-as-Code
greencode --iac terraform/main.tf
# Export SARIF for GitHub Code Scanning
greencode --path . --sarif greencode.sarif
Web Dashboard
- Scan Code: Paste code or enter a GitHub repo URL
- Review Results: View energy anti-patterns ranked by severity
- Generate Fixes: Click "Generate Fix" for AI-powered optimizations
- Create PR: Auto-create GitHub pull requests with refactored code
Browser Voice Assistant
The separate browser voice assistant is not an Amazon Alexa connection:
- Use the microphone button in the signed-in app. The browser captures speech, sends it to the local FastAPI voice endpoint, and speaks the backend response.
- The in-browser microphone works on
localhostin a supported browser after permission is granted. An Amazon Echo cannot reach a loopback address; device testing needs a public HTTPS endpoint or a secure tunnel to the local server. - See the Alexa integration guide for the distinction between the browser simulator, MCP add-on, and ASK Custom Skill.
Example voice commands:
- "Audit my code"
- "Compare Ireland and Virginia"
- "What's the grid intensity in Sweden?"
- "Measure hardware energy"
๐ Repository Structure
greencode/
โโโ ๐ฑ alexa/ # Alexa+ MCP & ASK configurations
โ โโโ addon.json # Alexa+ Add-On manifest
โ โโโ interactionModels/custom/en-US.json # ASK Custom Skill interaction model
โ โโโ skill.json
โโโ ๐ app/ # Core Python backend
โ โโโ main.py # FastAPI application
โ โโโ mcp_server.py # Model Context Protocol server
โ โโโ bedrock_client.py # Amazon Bedrock integration
โ โโโ energy_sensors.py # Hardware power measurement
โ โโโ parser.py # AST parsers (13+ languages)
โ โโโ call_graph.py # Cross-file analysis
โ โโโ sci.py # ISO/IEC 21031 SCI calculator
โ โโโ finops_focus.py # FinOps FOCUS 1.4 reconciler
โ โโโ iac_linter.py # Terraform/K8s linter
โ โโโ auth/ # Authentication & OAuth
โโโ โ๏ธ frontend/ # React + TypeScript UI
โ โโโ src/
โ โ โโโ pages/Login.tsx
โ โ โโโ GreenCodeAuditorApp.jsx
โ โ โโโ context/AuthContext.tsx
โ โ โโโ hooks/useAlexaVoice.ts
โ โโโ package.json
โโโ ๐งช tests/ # Automated unit and integration tests
โ โโโ test_alexa_pipeline_fix.py
โ โโโ test_bedrock.py
โ โโโ test_sci.py
โ โโโ conftest.py
โโโ ๐ docs/ # Comprehensive documentation
โ โโโ API.md
โ โโโ ARCHITECTURE.md
โ โโโ DEPLOYMENT.md
โ โโโ OPERATIONS.md
โโโ ๐ ๏ธ tools/ # Development tools
โ โโโ verification/ # Test & verification scripts
โ โโโ utilities/ # Helper utilities
โโโ ๐ฆ examples/ # Code samples & benchmarks
โ โโโ code-samples/ # Sample files (9 languages)
โ โโโ benchmark-workloads/ # Performance test workloads
โโโ ๐ง scripts/ # Deployment & utility scripts
โโโ ๐ README.md # This file
โโโ ๐ DEVPOST_SUBMISSION.md # Hackathon submission details
โโโ ๐ requirements.txt # Python dependencies
โโโ ๐ .env.example # Environment template
โโโ ๐ LICENSE # Apache 2.0
โ๏ธ Configuration
Required Environment Variables
Create a .env file in the root directory:
# Core Settings
JWT_SECRET=your-secret-key-here-min-32-chars
SECRETS_ENCRYPTION_KEY=your-fernet-key-here
ENV=development
# GitHub OAuth (for repository scanning)
GITHUB_CLIENT_ID=your_github_oauth_client_id
GITHUB_CLIENT_SECRET=your_github_oauth_secret
GITHUB_TOKEN=ghp_your_personal_access_token
# Google OAuth (optional)
GOOGLE_CLIENT_ID=your_google_oauth_client_id
GOOGLE_CLIENT_SECRET=your_google_oauth_secret
# Amazon Bedrock (for AI refactoring)
AWS_ACCESS_KEY_ID=your_aws_access_key
AWS_SECRET_ACCESS_KEY=your_aws_secret_key
AWS_REGION=us-east-1
GEMINI_API_KEY=
GREENCODE_LLM_PROVIDER=auto
# Alexa+ (optional)
GREENCODE_ALEXA_SKILL_ID=amzn1.ask.skill.your-skill-id
# Frontend
VITE_API_URL=http://localhost:8000
API Keys Guide
See docs/API_KEYS.md for detailed instructions on obtaining:
- GitHub Personal Access Token
- Amazon Bedrock API credentials
- Electricity Maps API key (optional)
- WattTime credentials (optional)
๐งช Testing
# Run all tests (541 tests)
pytest
# Run specific test suite
pytest tests/test_alexa_pipeline_fix.py -v
# Run with coverage
pytest --cov=app --cov-report=html
# Run verification scripts
python tools/verification/verify_fullstack_alexa.py
python tools/verification/verify_alexa_pipeline.py
Test Coverage:
- โ Alexa+ MCP & ASK webhook (23 tests)
- โ Amazon Bedrock AI refactoring (45 tests)
- โ Energy measurement & attribution (67 tests)
- โ SCI calculation & grid data (89 tests)
- โ FinOps FOCUS 1.4 reconciliation (34 tests)
- โ Authentication & OAuth flows (52 tests)
- โ Full-stack integration (231 tests)
๐ Hackathon Highlights
Technical Achievements
- โ Full Alexa+ Integration: Native MCP server + ASK webhook
- โ Amazon Bedrock AI: Multi-model refactoring with verification
- โ Real Hardware Measurement: RAPL, NVML, Apple Silicon
- โ 541 Passing Tests: Comprehensive quality assurance
- โ Local workflow: FastAPI backend and Vite frontend run independently on the developer machine
Environmental Impact
- ๐ 68% energy reduction on algorithmic hotspots (measured)
- ๐ 45% AWS cost savings via Graviton4 recommendations
- ๐ 150+ regions with live grid carbon intensity
Innovation
- ๐ Novel voice-operated approach to carbon auditing
- ๐ Innovative MCP integration with Alexa+
- ๐ Combines real hardware sensors with LLM refactoring
๐ฌ Verification & Benchmarks
Energy Reduction Measurements
Our benchmark workloads (available in examples/benchmark-workloads/) demonstrate measurable energy savings:
| Workload | Before | After | Reduction | Method |
|---|---|---|---|---|
| Nested Loop (Python) | 2.4 Wh | 0.8 Wh | 66.7% | Intel RAPL |
| String Concat (Java) | 1.8 Wh | 0.6 Wh | 66.7% | CPU time ร TDP |
| LLM Inference | 45.2 Wh | 14.1 Wh | 68.8% | NVIDIA NVML |
Benchmarks run on: Intel i7-12700K, 32GB RAM, NVIDIA RTX 3080
Reproduce: Run python examples/benchmark-workloads/benchmark_workload.py
Test Coverage
- 541 total tests across 35 test files
- Backend: 412 tests (pytest)
- Frontend: 89 tests (Vitest)
- Integration: 40 end-to-end tests
Run tests: pytest tests/ -v (backend) or cd frontend && npm test (frontend)
๐ Documentation
| Document | Description |
|---|---|
| AWS_INTEGRATION.md | AWS services architecture & usage |
| API.md | REST API reference |
| ARCHITECTURE.md | System design & data flow |
| DEPLOYMENT.md | Production deployment guide |
| DEVPOST_SUBMISSION.md | Hackathon submission details |
| API_KEYS.md | API key setup instructions |
๐ค Contributing
We welcome contributions! See CONTRIBUTING.md for:
- Code of Conduct
- Development workflow
- Pull request process
- Coding standards
๐ License
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
๐ Acknowledgments
- Amazon Web Services for Bedrock, Alexa+, and cloud infrastructure
- Green Software Foundation for the SCI standard (ISO/IEC 21031)
- Electricity Maps for real-time grid carbon intensity data
- OpenAI & Anthropic for language model research
- The open-source community for foundational libraries
๐ Contact & Support
- GitHub: @zeenat28-ui
- Project: github.com/zeenat28-ui/greencode
- Local UI: http://localhost:5173 (after starting the frontend and backend)
- Hackathon: Amazon Developer Hackathon 2026
Built with ๐ for a sustainable future
Reducing software carbon emissions, one line of code at a time
GreenCode Auditor MCP questions
Which AI models are used for refactoring proposals?
The platform prioritizes Amazon Bedrock, followed by Google Gemini Pro, and then HuggingFace.
Does GreenCode require Docker to run?
No, the core application runs locally without Docker, but Docker is required specifically for dynamic analysis to provide a security boundary for executing repository code.