feat: demo-infra MCP server (simulated infrastructure + 8 tools) - #4
feat: demo-infra MCP server (simulated infrastructure + 8 tools)#4ADITYA-tp01 wants to merge 7 commits into
Conversation
PR Summary by QodoAdd simulated infrastructure MCP server and dashboard API
AI Description
Diagram
High-Level Assessment
Files changed (6)
|
|
Failed to generate code suggestions for PR |
Code Review by Qodo
1.
|
- remove inject_chaos from MCP surface (human-only via dashboard REST) - bind REST sidecar to loopback by default, restrict CORS allowlist - reject rollbacks referencing another service's deploy - reset_demo restores seeded versions and regenerates baseline logs - cascade recovery now restores all degraded dependencies - validate limit params -> HTTP 400 instead of handler crash - add regression tests (13 passing)
|
/review |
|
Preparing review... |
|
Code review by qodo was updated up to the latest commit 1394e9c |
|
/review |
|
Preparing review... |
|
Code review by qodo was updated up to the latest commit 017cb73 |
|
Ruling on Qodo findings — all addressed Finding 1 (High) — inject_chaos exposed as MCP tool: |
…-16 sources to UTF-8
🤖 CodeAnt AI — Review Status
|
Fix for finding "Invalid chaos clears incident" (commit
|
| def _body(handler: BaseHTTPRequestHandler) -> dict: | ||
| length = int(handler.headers.get("Content-Length", 0) or 0) | ||
| if length == 0: | ||
| return {} | ||
| raw = handler.rfile.read(length) | ||
| try: | ||
| parsed = json.loads(raw.decode("utf-8")) |
There was a problem hiding this comment.
Suggestion: Content-Length is converted with int() outside error handling and the declared number of bytes is read without any upper bound. A malformed header causes an uncaught ValueError in the request handler, while an excessively large declared length can tie up a thread waiting for bytes or consume substantial memory. Parse and cap the length before reading, and return a 400 response for invalid request bodies. [resource leak]
Severity Level: Major ⚠️
- ❌ Malformed requests can terminate individual request handling.<br/>- ❌ Slow large-body requests can exhaust sidecar threads.<br/>- ⚠️ REST dashboard operations may become unavailable.Prompt for AI Agent 🤖
This is a comment left during a code review.
**Path:** mcp-servers/demo-infra/http_api.py
**Line:** 52:58
**Comment:**
*Resource Leak: `Content-Length` is converted with `int()` outside error handling and the declared number of bytes is read without any upper bound. A malformed header causes an uncaught `ValueError` in the request handler, while an excessively large declared length can tie up a thread waiting for bytes or consume substantial memory. Parse and cap the length before reading, and return a 400 response for invalid request bodies.
Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix| if path == "/api/sessions": | ||
| self._send(200, {"sessions": dict(state.agent_sessions)}) | ||
| return |
There was a problem hiding this comment.
Suggestion: The sessions endpoint copies state.agent_sessions without acquiring state.lock, while POST requests update that dictionary under the lock. Concurrent mutation during dict() iteration can raise RuntimeError: dictionary changed size during iteration, causing the request to fail, and the response can also be inconsistent with the other state fields. Add a locked snapshot accessor in InfraState and use it here. [race condition]
Severity Level: Major ⚠️
- ⚠️ Concurrent session dashboard requests can fail intermittently.<br/>- ⚠️ Session listings may not represent one consistent snapshot.Prompt for AI Agent 🤖
This is a comment left during a code review.
**Path:** mcp-servers/demo-infra/http_api.py
**Line:** 179:181
**Comment:**
*Race Condition: The sessions endpoint copies `state.agent_sessions` without acquiring `state.lock`, while POST requests update that dictionary under the lock. Concurrent mutation during `dict()` iteration can raise `RuntimeError: dictionary changed size during iteration`, causing the request to fail, and the response can also be inconsistent with the other state fields. Add a locked snapshot accessor in `InfraState` and use it here.
Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix| if path == "/api/remediate": | ||
| # Intentional human bypass for demo scope: the dashboard's | ||
| # hold-to-confirm control plays the "human operator" role here. | ||
| # Approval semantics are enforced on the agent path (TrueForge | ||
| # approval gates on the MCP tools), not on this endpoint. | ||
| action = body.get("action") | ||
| service = body.get("service", "") | ||
| if action == "rollback": | ||
| result = state.rollback_deploy(service, body.get("deploy_id", "")) | ||
| elif action == "restart": | ||
| result = state.restart_service(service) |
There was a problem hiding this comment.
Suggestion: Destructive remediation is exposed without authentication, authorization, or an approval token. Because docker-compose.yml publishes port 8001 and binds the sidecar to 0.0.0.0, any network-reachable caller can POST a rollback or restart request and mutate infrastructure state, despite the documented requirement for human approval. Require an authenticated, explicitly approved request or keep this endpoint bound to a trusted dashboard-only channel. [security]
Severity Level: Major ⚠️
- ❌ Network callers can trigger dashboard remediation actions.<br/>- ❌ Simulated service state can be altered without approval.<br/>- ⚠️ Impact is limited to fabricated demo infrastructure.Prompt for AI Agent 🤖
This is a comment left during a code review.
**Path:** mcp-servers/demo-infra/http_api.py
**Line:** 197:207
**Comment:**
*Security: Destructive remediation is exposed without authentication, authorization, or an approval token. Because `docker-compose.yml` publishes port 8001 and binds the sidecar to `0.0.0.0`, any network-reachable caller can POST a rollback or restart request and mutate infrastructure state, despite the documented requirement for human approval. Require an authenticated, explicitly approved request or keep this endpoint bound to a trusted dashboard-only channel.
Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix| state = get_state() | ||
| result = state.rollback_deploy(service, deploy_id) | ||
| return json.dumps(result, indent=2) |
There was a problem hiding this comment.
Suggestion: The MCP tools claim to require human approval, but these handlers perform the mutation immediately and do not inspect any approval state or request context. A direct MCP client can therefore invoke either tool without the approval workflow described in the tool instructions and incident-response contract. Enforce approval before calling the state mutation, or expose only an approval-aware execution path. [security]
Severity Level: Major ⚠️
- ❌ Direct MCP clients can bypass documented approval gates.<br/>- ❌ Rollback and restart mutate shared demo state immediately.<br/>- ⚠️ Consequences remain limited to simulated infrastructure.Prompt for AI Agent 🤖
This is a comment left during a code review.
**Path:** mcp-servers/demo-infra/server.py
**Line:** 139:141
**Comment:**
*Security: The MCP tools claim to require human approval, but these handlers perform the mutation immediately and do not inspect any approval state or request context. A direct MCP client can therefore invoke either tool without the approval workflow described in the tool instructions and incident-response contract. Enforce approval before calling the state mutation, or expose only an approval-aware execution path.
Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
CodeAnt Nitpicks2 code suggestions1. Unknown services are reported as successful metrics responses instead of missing resources.Api mismatch · 2. Nonpositive limits produce incorrect collection sizes through Python slicing.Logic error · |
Fix for finding "REST bypasses remediation approval" (commit
|
Requesting dismissal of PR #4 Finding #6 "REST bypasses remediation approval"This finding was created against the original PR review. The CORS wildcard and loopback issues it describes were already fixed in earlier commits (CORS allowlist for localhost:3000/3001, loopback default). The remaining concern — unauthenticated state-mutating endpoints — was addressed in commit Fix applied (http_api.py): all Default token The finding's evidence primarily cites Please dismiss with this reasoning. |
Thanks for using CodeAnt! 🎉We're free for open-source projects. if you're enjoying it, help us grow by sharing. Share on X · |
User description
What
Core simulation layer for MissionControl: a custom MCP server modeling fake production infrastructure that the agent investigates and remediates.
Components
Design notes
ollback_deploy,
estart_service) are the ones gated by TrueForge approval checkpoints; \inject_chaos\ is human-only per agent safety rules
CodeAnt-AI Description
Add a secure simulated infrastructure server for incident investigation and recovery
What Changed
Impact
✅ Safer incident remediation✅ Complete recovery after cascading failures✅ Fewer accidental infrastructure state changes💡 Usage Guide
Checking Your Pull Request
Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.
Talking to CodeAnt AI
Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:
This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.
Example
Preserve Org Learnings with CodeAnt
You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:
This helps CodeAnt AI learn and adapt to your team's coding style and standards.
Example
Retrigger review
Ask CodeAnt AI to review the PR again, by typing:
Check Your Repository Health
To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.