sitl-mcp-guard
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
sitl-mcp-guard
An MCP server that lets an AI agent fly a simulated ArduPilot copter, with a deterministic safety gate between the agent and the vehicle.
The agent never sends a flight command. It sends a proposal. A small, pure Python function checks the proposal against explicit limits and the current telemetry, and only an approved, rebuilt command reaches the vehicle adapter. Every proposal and verdict is written to an audit log.
Scope: ArduPilot Copter SITL (the simulator) and an offline fake vehicle. Nothing here has flown on physical hardware, and it is not a substitute for the autopilot's own failsafes and fence. It is a prototype.
How it works
agent (MCP client)
| propose_goto_ned(north_m=200, ...)
v
server.py six MCP tools, strict JSON number types, no flight logic
v
guard.py 1. read telemetry 2. ask the gate 3. write the audit record
| 4. execute only decision.sanitized_cmd 5. write the outcome
| one call at a time (a lock covers all five steps)
v
safety_gate.py evaluate(cmd, telemetry, policy) -> GateDecision (pure, 182 lines)
v
adapters/ fake_vehicle.py (offline, deterministic) | sitl_mavlink.py (pymavlink, loopback SITL only)The gate is the file to read first: src/sitl_mcp_guard/safety_gate.py.
Related MCP server: ardupilot-mavlink-mcp
What the gate enforces
Positions are metres from home: north_m, east_m, and alt_m as height above home. Defaults are in SafetyPolicy.
Rule name | Denies when | Default |
| a target is farther from home than the limit (a circle, like ArduPilot's | 50 m |
| commanded height is outside the band | 2 m to 30 m |
| speed is below | 0.1 to 5 m/s |
| one leg, measured from the previous point, is too long | 40 m |
| goto, grid or the per-leg check while the vehicle is not in | |
| takeoff while armed, or goto / grid while disarmed | |
| battery is below the floor, or reported above 100 % | 25 % |
|
| |
| GPS fix type is below 3D, or above 8 (the highest MAVLink value) | 3 |
| telemetry is absent, or a field is missing, non-finite or the wrong type | |
| the oldest telemetry reading is too old | 2 s |
| a command number is | |
| waypoint list is empty, not a list, or too long | 20 |
| the command or a waypoint is not an object, or the type is unknown | |
| the policy itself is not usable: a limit is non-finite, a bool, zero or negative where it must be positive, or the limits contradict each other | |
| the gate itself raised an exception (a bug must never become an allow) | |
| the MCP layer refused the arguments before a tool ran (audited as a DENY) |
Design points:
Fail closed.
evaluate()has one line that builds an allow. Every other path, including an unexpected exception and a bad policy, returns a denial.Pure. No I/O, no clock, no state. Same inputs, same decision. That is what makes it testable at every boundary.
Sanitized output. The gate returns a rebuilt command that holds only known keys and finite floats. The adapter executes that, never the agent's original dict.
Whole mission first, then every leg again.
propose_inspection_gridvalidates every waypoint before the first one is flown. Then, just before each leg, the guard reads fresh telemetry and gates that leg from the vehicle's measured position. An arrival that stops 0.5 m short cannot stretch a limit-length next leg pastmax_step_m, and a change of health or flight mode stops the mission.An abort does not fight a failsafe. When a mission is stopped, the guard commands RTL only if the vehicle is armed and still in
GUIDED, or if its state is unknown. A vehicle that is disarmed, or that a failsafe or a pilot already moved toLAND,RTL,BRAKE,LOITERor another mode, is left in that mode. The telemetry that triggered the abort is stored in the audit record.RTL is always allowed.
trigger_rtlpasses the gate with any telemetry, including none, and with any policy.
MCP tools
Tool | Gated | What it does |
| read-only | position, battery, EKF, GPS, armed, mode |
| read-only | the limits in force |
| yes | switch to |
| yes | fly to one position (needs |
| yes | fly a list of |
| always allowed | switch to RTL mode |
A gated tool answers {"verdict": "ALLOW" | "DENY", "rule": ..., "reason": ...} and, when allowed, an outcome (a grid also reports legs_flown).
Top-level numeric arguments (
alt_m,north_m,east_m,speed_mps) must be JSON numbers.true,falseand strings such as"12"are refused by the tool schema: the call returns an MCP error, no tool runs, and the audit log records a DENY with rulerejected_before_gate. The objects insidewaypointsare not typed by the schema. A bad value there reaches the gate and is denied asnon_finite, with a normal DENY answer.trigger_rtlanswers"outcome": "rtl_mode_confirmed"as soon as the vehicle reports RTL mode. It does not wait for the landing. On SITL, pollget_telemetryuntilarmedisfalse. The fake backend does not move by itself: polling changes nothing there, and a test finishes the return by callingFakeVehicle.complete_rtl()directly in Python.Calls run one at a time. The lock is held for a whole call, and a
propose_inspection_gridcall covers every leg of the grid. Atrigger_rtlthat arrives in the middle of a grid waits until that grid has finished or aborted, not just until the current leg ends. A move in flight cannot be preempted through this server. One goto waits at most 120 s.
Audit log
audit.jsonl is append-only, one JSON object per line. A proposal record holds the proposal as received, the verdict, the rule, the sanitized command and the telemetry snapshot the gate saw. A leg record holds the same for each grid leg. An outcome record holds the result, the telemetry afterwards and, for an abort, abort_trigger_telemetry.
Each line stores the SHA-256 of the previous line, so an edited, removed or reordered line is found by the verifier:
python -m sitl_mcp_guard.audit verify evidence/sitl-smoke-2026-12-04/audit.jsonlIt prints the record count and the head hash, and exits non-zero on a broken chain, a line that is not a JSON object, a seq that is not an integer, a non-standard number such as NaN, or a file that does not end with a newline. The chain makes tampering evident. It does not prevent it. Someone who can rewrite the whole file can rebuild the chain. The final record has no successor, so a change to it, or the removal of complete records from the end, leaves a log that still verifies. Catching either needs a head hash that was saved outside the log: keep the printed value somewhere else and compare.
Quick start
python -m venv .venv
.venv\Scripts\activate (Linux and macOS: source .venv/bin/activate)
pip install -e ".[dev]"
python -m pytest
python scripts/mutation_check.py
python -m sitl_mcp_guard.server --backend fakeThe server speaks MCP over stdio. To use the simulator, start ArduPilot Copter SITL with MAVLink going to a loopback port, and run:
python -m sitl_mcp_guard.server --backend sitl --connect udpin:127.0.0.1:14550 --audit audit.jsonl--connect accepts only tcp:, tcpin:, udp:, udpin: or udpout: on 127.0.0.1 or localhost. Serial ports and other hosts are refused at startup and again in the adapter.
--policy limits.json replaces SafetyPolicy defaults. The file is checked strictly: unknown keys, NaN, Infinity, bools, strings and inconsistent limits stop the server with an error.
Verification
Check | Result | How to run it |
Unit tests for the gate | 383 passed |
|
End-to-end MCP tests on the fake vehicle | 139 passed |
|
SITL adapter tests on a fake MAVLink link | 63 passed |
|
All tests | 585 passed |
|
Mutation check | 80 of 80 mutants caught |
|
Real ArduPilot SITL smoke test | PASS, 14 of 14 checks on this version's code (recorded runs below) |
|
The mutation check weakens or removes one safety check at a time in a temporary copy of the gate (limit off, limit loosened, type check off, policy check skipped, catch-all turned into an allow, and so on) and requires the gate's unit tests to fail for each one.
The SITL smoke test starts arducopter in a private network namespace and drives it through the MCP server over stdio: takeoff, a 2-point inspection, a 200 m goto that the geofence denies, a grid with a bad second waypoint that is denied as a whole, then RTL and landing. ARDUPILOT_DIR points at an ArduPilot checkout with a built SITL binary and PYTHON at an interpreter with this package's dependencies.
Recorded runs, all on 2026-12-04 against ArduPilot 4.7.2 (fb773567) Copter SITL:
Transcript | Code under test | Result |
first version | FAIL, 11 of 12 checks: 5.54 m/s measured on a leg commanded at 3 m/s | |
first version with the speed fix | PASS, 12 of 12 checks: 3.08 m/s measured | |
the version after the first round of review fixes | PASS, 14 of 14 checks: 3.1 m/s measured, both grid legs gated and flown, RTL confirmed in flight | |
this version's code (commit | PASS, 14 of 14 checks: 3.1 m/s measured, both grid legs gated and flown, RTL confirmed in flight |
The first run found a real adapter bug. Copter's guided mode resets its speed limit when the first position target arrives after a takeoff, so a speed sent before the target was discarded. The adapter now sends the speed after the target. The gate was right in both runs, and only the simulator could show the bug. The first two transcripts were recorded before the review fixes: their RTL outcome reads completed, and they have no leg records.
The last run was made after the second review round, on the code of commit 45c1055. It runs the adapter changes from that round on the real simulator along their normal path: the last gate check before a goto is transmitted, the fence check after arming, the disarm and mode monitoring inside the takeoff and goto wait loops, and the deadline guards. Their failure paths (a failsafe or a disarm during a move, a vehicle outside the fence after arming, a link that never goes quiet) did not occur in that flight and are covered by the offline adapter tests. No code changed after that run. The commit that added its transcript changed only this README and evidence/.
Limits
Simulator and fake vehicle only. No hardware flight.
The loopback-only check looks at the connection string. It cannot know what is behind the port: local port forwarding or a serial-to-UDP bridge could still put a real vehicle on loopback. Do not do that.
The gate checks commanded targets, not the path between them, and it knows nothing about obstacles or terrain.
The fence is a cylinder around home. The local frame uses a flat-earth conversion, which is fine at tens of metres and not at long range.
The gate's speed limits apply to the commanded speed. The adapter sets it with
MAV_CMD_DO_CHANGE_SPEED; the autopilot is what holds it.Telemetry age is measured from when each message was received here, not from a vehicle timestamp. It shows that the link is alive. It cannot show a delay inside the vehicle or the simulator.
Execution is serialized and a call in progress cannot be preempted, not even by
trigger_rtl. The longest wait is one whole grid: up to 20 legs of at most 120 s each.A slow leg that cannot finish inside the 120 s ceiling is aborted, although the gate allowed it (40 m at 0.1 m/s, for example).
Battery, EKF, GPS and telemetry freshness are re-checked between legs, not during a leg. During a move the adapter only watches the heartbeat for a disarm or a mode change.
One vehicle, one client, no authentication. The stdio transport trusts whoever started the process.
Layout
src/sitl_mcp_guard/safety_gate.py the gate (read this first)
src/sitl_mcp_guard/guard.py gate -> audit -> execute, per-leg checks, abort
src/sitl_mcp_guard/audit.py hash-chained JSONL log and its verifier
src/sitl_mcp_guard/server.py MCP tools, policy loading, the command line
src/sitl_mcp_guard/adapters/ fake_vehicle.py, sitl_mavlink.py, loopback check
tests/ gate unit tests, MCP end-to-end tests, adapter tests
scripts/mutation_check.py mutation check
scripts/sitl_smoke_test.py smoke test on a running SITL
scripts/run_sitl_smoke.sh starts SITL in a private namespace, then the smoke test
evidence/ audit transcripts of real SITL runsLicense
MIT. See LICENSE.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
This server cannot be deployed
Maintenance
Related MCP Connectors
Governed autonomous-agent platform: HITL approvals, budget gates, audit chain, effect ledger.
Supervised API-write gateway for AI agents with policy, human approval and execution receipts.
Security gateway for AI agents: policy, approval, and audited execution, no secrets shared.
Autonomous and governed SRE & MLOps control plane for AI agent platforms.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceEnables natural language control of ArduPilot drones via MAVLink, supporting arm, takeoff, mode changes, and mission uploads.9GPL 3.0
- AlicenseNot gradedqualityCmaintenanceEnables AI agents to interact with an ArduPilot vehicle in real-time via MAVLink, including reading state, inspecting and changing parameters, switching flight modes, diagnosing arming failures, and gated arming/disarming.5MIT
- AlicenseNot gradedqualityBmaintenanceEnables AI clients to read live drone status, telemetry, and parameters, and to control drone operations with scoped permissions, confirmation steps, and audit trails.MIT
- AlicenseAqualityDmaintenanceConnects AI agents to MAVLink drones (PX4, ArduPilot) via a capability layer with safety guardrails, enabling telemetry, flight control, and mission management through natural language.122MIT