MCP (Model Context Protocol)¶
Solar AI Optimizer exposes an optional MCP server so AI agents (Cursor, SDK automations) can read optimizer state, troubleshoot decisions, and apply the same safe overrides as the dashboard.
MCP is a sidecar control plane — it does not replace the real-time control loop. All writes go through the existing Executor, shadow mode, and Override safety model.
When to use MCP vs the dashboard¶
| Use MCP when | Use the dashboard when |
|---|---|
| Debugging engine logic with an AI agent | Day-to-day operator control |
| Correlating decisions with history from Cursor | Visual charts and settings UI |
| Scripting overrides with bearer auth | HA ingress viewer/admin roles |
Security checklist¶
- Bearer token = full admin.
API_TOKENandMCP_TOKENgrant the same mutating access as a local admin. - Prefer a dedicated
MCP_TOKENso you can revoke agent access without breaking CI scripts. - HTTP MCP (
/mcp) accepts Bearer only — no ingress cookies. - Kill switch requires
confirm_kill_switch=true(MCP) orconfirm=true(REST). - Treat tool outputs as untrusted (entity names can contain prompt-injection text).
Configure from Settings (standalone / Proxmox / Docker)¶
- Open Settings → System → Agent access.
- Enable HTTP MCP, set or Generate a token, click Save MCP (writes
data/mcp.envon the data volume). - Click Restart service in the sticky bar next to Save changes (Docker socket + self-update required).
- Confirm health shows MCP mounted, then point Cursor at
http://<host>:8000/mcpwith the Bearer token.
On Home Assistant apps, use Apps options (mcp_enabled / mcp_token) and restart the app — Settings remains status-only for that path.
Recreate container (Software updates) is for host solar.env edits. A plain restart does not re-read host env files; mcp.env on the data volume is enough for Settings-driven MCP.
Cursor setup (stdio)¶
- Start the optimizer:
docker compose up -d solar - Set a token:
export SOLAR_MCP_TOKEN=your-secret(must matchAPI_TOKENorMCP_TOKENon the container) - Copy
.cursor/mcp.json.exampleto your user or project MCP config and adjust paths. - Restart Cursor → Settings → MCP → verify
solar-ai-optimizeris connected.
The stdio server uses the mcp compose profile and talks to the running API at http://host.docker.internal:8000.
Remote HTTP (Streamable)¶
environment:
MCP_ENABLED: "true"
MCP_TOKEN: "change-me"
# MCP_HTTP_PATH: /mcp # optional, default /mcp
Or use Settings → Agent access (standalone). Mount is refused if no token is configured. Terminate TLS at your reverse proxy or HA ingress.
Persistence notes¶
| Source | When |
|---|---|
data/mcp.env |
Settings UI on standalone; loaded by run.sh when not an HA add-on |
HA options.json |
Add-on options → env at start |
Host solar.env / Compose env |
Bootstrap; recreate container after edits |
Tool catalog¶
Tier 1 — start here¶
| Tool | Purpose |
|---|---|
solar_get_status |
Live telemetry, decision, shadow mode |
solar_explain_decision |
Full forensics trace (inputs → decision/causality → execution) |
solar_simulate_decision |
Dry-run decision without writes |
solar_get_engine_config |
Redacted effective config |
solar_apply_override |
Apply Override fields |
solar_clear_override |
Clear overrides |
Tier 2 — drill-down¶
solar_get_forecast, solar_get_plan, solar_get_grid_stats, history tools, solar_get_shed_snapshots.
Tier 3 — mutating¶
solar_trigger_cycle, solar_refresh_forecast, solar_update_config.
Troubleshooting playbook¶
Expected vs actual (reserve % / grid-charge amps)¶
- On the dashboard Overview, compare Intended vs Applied for reserve and grid charge.
- If that disagrees with expected behavior, call
solar_explain_decisionwith sections includingcausalityandexecution(legacy aliasreasoningmaps to decision+causality). - Check
causality.explanation.reserve.source(rules|mpc|operator) andgrid_charge.binding_factor. - Join history by
cycle_idon decision / execution / shed history tools when correlating writes.
General¶
solar_explain_decision— find the layer: forecast degraded? override active? MPC fallback? skipped write? writes paused?solar_get_engine_config— check reserve buffers,priority_order, subsystem enables.solar_get_decision_history+solar_get_telemetry_window— input-driven vs logic bug.solar_simulate_decision— test a config hypothesis without live writes.- Note:
paused_optimizationdoes not stop planning; onlypaused_grid_charge/paused_sheddingblock actuator writes. - If rationale keys point to a rule bug, fix code in
backend/app/engine/.
Unauthenticated POST /mcp should return 401 Bearer required (not 405). If you see 405, the static UI may be swallowing /mcp — upgrade to a build that mounts MCP before the static catch-all.
REST debug endpoints¶
Admin-only (same data as MCP forensics tools). Trace is live latest cycle (not historical time-travel):
GET /api/debug/trace?sections=causality,decision,execution,enginePOST /api/debug/simulate(rate-limited)
Environment variables¶
| Variable | Default | Purpose |
|---|---|---|
MCP_ENABLED |
false |
Mount Streamable HTTP at /mcp |
MCP_HTTP_PATH |
/mcp |
HTTP path |
MCP_TOKEN |
"" |
Agent bearer token; falls back to API_TOKEN |
SOLAR_API_URL |
http://127.0.0.1:8000 |
stdio client API base URL |
See also Configuration.