Skip to main content

MCP: controlled AI access to Vaazhvu

Vaazhvu exposes a small, deliberate set of capabilities over the Model Context Protocol. The set follows one rule: the AI can read Vaazhvu and run labelled simulations, while deterministic Vaazhvu code makes every decision. No MCP tool dispatches, approves, overrides, reroutes, changes a destination or edits policy. An AI assistant can explain a decision, but it cannot make one.

There are two ways to reach the tools, and both use the same MCP server:

SurfaceWhereWho uses it
Dispatcher CopilotTerminal panel Copilot (g p, or palette → Copilot: …)Dispatchers and supervisors
MCP serverPOST /api/mcp (Streamable HTTP), plus python -m app.mcp.bridge (stdio)Claude Code, Claude Desktop, MCP Inspector, any MCP client

Tools​

ToolKindPermissionWhat it answers
list_incidentsreadincident.readOpen incidents with status, effective severity, priority, place, units, hospital, NEWS2 and whether simulated
get_incidentreadincident.readOne incident: the triage severity distribution and grounded findings, the safety policy's flags and effective severity, location, NEWS2 / vitals / escalations, the response, a pending approval, duplicates
get_timelinereadincident.readThe audited event history in plain words, and every change of plan with its reason
find_duplicatesreadincident.readThe engine's duplicate match and its reasons, and other open incidents nearby
explain_dispatchreadincident.readThe engine's recorded decision: the selected response, the nearest and the nearest capable unit with the ETA difference and why each was not sent, other options with the engine's reasons, required capabilities, policy flags, ALS backup requests
explain_hospitalreadincident.readThe destination, the patient's needs, ranked receiving hospitals with drive time and readiness, ER refusals and diversion. Given a hospital_id, it says why that hospital was not chosen, using the engine's own fit / admissible
find_unitsreadincident.readAmbulances (or police / fire first responders) near an incident, a place or a point, with road ETA, capabilities, status and current job
find_hospitalsreadhospital.readReceiving hospitals offering every listed need (services, plus ventilator / icu_bed / er_bed from the hospital's record), sorted by drive time, with ED status and diversion
search_facilitiesreadhospital.readThe statewide facility map (7,000+ facilities, all districts) by district or name
list_scenariosreadincident.readSimulation presets, demo storylines and deterioration levels
simulate_incidentsimsim.run + intake.createPlaces a demo call through the real pipeline (triage → geocoder → safety policy → dispatch), waits for it to finish, and returns what Vaazhvu did
simulate_deteriorationsimsim.runThe patient's monitor reports worse vitals (moderate = NEWS2 medium band, severe = high band). Vaazhvu's own closed loop then runs: re-triage → ALS backup / hospital re-selection → ER re-alert
set_sim_clocksimsim.runSpeeds up, pauses or resumes the simulation clock
run_storylinesimsim.runPlays a scripted storyline from config/demo.yaml

There is also an MCP prompt, incident_brief(incident_id), that briefs a model on one incident.

Code: backend/app/mcp/tools.py (the registry), views.py (read-only projections), sim.py (simulation), server.py (the protocol server) and bridge.py (stdio). The Copilot is backend/app/copilot.py and frontend/src/terminal/CopilotPanel.jsx. Its configuration, including the brief, presets and deterioration vitals, is in config/copilot.yaml.

Safety boundary​

  • Decisions stay deterministic. Explanations are read from what the engine recorded (inc.decision, hospital options, the event log). MCP never calls the dispatch engine to decide anything.
  • Permissions are the caller's own. Every call is checked against config/platform.yaml for the principal making it. Over HTTP that is the request's API key, session or role header. In the Copilot it is the signed-in dispatcher. A viewer can ask questions but cannot run simulations.
  • Simulation goes through the real front door and is labelled.
    • A simulated call uses the demo caller (inc.demo = true), so analytics and hotspots leave it out.
    • Simulated vitals carry source: monitor-sim/mcp, and the console shows them as SIM.
    • Every simulation tool call writes an audit row (mcp.<tool>) and publishes an mcp.action event.
  • Caller identity is never exposed. The tools do not return the caller's number, device, profile or raw transcript. Only the grounded findings and the evidence quotes from triage are shown.
  • LLMOps traces every Copilot model call as copilot.turn, with no content, like every other model call. vaazhvu_mcp_tool_calls_total{tool,outcome} and vaazhvu_mcp_tool_duration_seconds count tool use.

Give other people access​

Other people use Vaazhvu's MCP server from their own Claude Code, Cursor, VS Code or any MCP client. Three pieces make that safe:

  1. The public edge publishes only MCP. The mcp-gateway service (backend/app/mcp/gateway.py, 127.0.0.1:8790, started by make up and make voice) serves exactly POST /mcp and forwards it to the api's /api/mcp. The console, the crew and ER apps and every other API are not served on that port.
  2. A personal key is required. The gateway refuses calls without a key, and the api refuses unknown or revoked keys (401) before any MCP method runs. The key's scopes decide what its holder may do, its own rate limit applies, and every simulation is audited under its name. Cookies and role headers are not forwarded.
  3. A tunnel gives the gateway an HTTPS URL.
brew install cloudflared # once
make mcp-public # prints https://<random>.trycloudflare.com/mcp; Ctrl+C stops it
make mcp-key NAME="Priya" # read-only key + ready-to-send setup commands with that URL
make mcp-key NAME="Arun" SIM=1 # read + run labelled simulations
make mcp-keys # who has a key, last used
make mcp-revoke ID=key_... # cut someone off at once
make mcp-status # gateway, api and public URL

The quick tunnel URL changes every time make mcp-public starts. For a fixed URL, use a named Cloudflare tunnel, or Tailscale Funnel on a Tailscale-hosted tailnet (tailscale funnel --bg 8790; Headscale tailnets have no Funnel). Either way, point it at 127.0.0.1:8790, never at the api's port.

What the other person runs (printed by make mcp-key):

claude mcp add --transport http vaazhvu https://<url>/mcp --header "X-API-Key: vz_..."
{"mcpServers": {"vaazhvu": {"url": "https://<url>/mcp", "headers": {"X-API-Key": "vz_..."}}}}
npx -y mcp-remote https://<url>/mcp --header "X-API-Key:vz_..." # stdio-only clients

The claude.ai and Claude Desktop custom connectors take only a URL with no headers, so they are not supported.

Connecting a client (on this machine)​

The server runs inside the api process, because the live dispatch world lives there.

Claude Code. The repository's .mcp.json points at the Docker api:

claude mcp list # vaazhvu → http://localhost:8001/api/mcp

Without credentials, the api's default role applies, which is viewer (read-only). To run simulations, a supervisor creates an API key in Integrations → API keys with the scopes incident.read hospital.read sim.run intake.create, then exports it before starting Claude Code:

export VAAZHVU_API_KEY=vz_…

.mcp.json sends it as X-API-Key. With VAAZHVU_DEFAULT_ROLE=supervisor in .env (local demo only), no key is needed.

Claude Desktop, or any client that launches a command, uses the stdio bridge:

{
"mcpServers": {
"vaazhvu": {
"command": "uv",
"args": ["run", "--project", "/path/to/winning-REC", "python", "-m", "app.mcp.bridge"],
"env": {
"PYTHONPATH": "/path/to/winning-REC/backend",
"VAAZHVU_MCP_URL": "http://127.0.0.1:8001/api/mcp",
"VAAZHVU_API_KEY": "vz_…"
}
}
}
}

MCP Inspector: run npx @modelcontextprotocol/inspector, then choose transport Streamable HTTP and URL http://localhost:8001/api/mcp.

On this machine /api/mcp accepts anonymous calls with the api's default role, like the rest of the api; a key that is sent must be valid. The endpoint is stateless and returns JSON. It accepts POST only: GET /api/mcp answers 405, because the server never pushes messages.

Dispatcher Copilot​

The Copilot panel sends each question to POST /api/ops/copilot, which streams back SSE frames: tool_call, tool_result, answer and error. Each turn works like this:

  • The turn runs up to generation.max_steps model rounds. In each round the model calls tools through an in-process MCP client session, as the dispatcher.
  • The configured LLM provider answers (VAAZHVU_LLM_PROVIDER=openai, e.g. DeepSeek, with native tool calling). Local Ollama takes over if the provider fails.
  • Every tool the model used appears in the panel as a chip: MCP · explain_dispatch · 42 ms. A simulation tool's chip carries a SIM badge.
  • When a simulated call creates an incident, the terminal selects it, so the map follows it.
  • If the incident selected on the terminal is shown as a chip, it is the context for "this incident".
  • With no model available (LLM off or down), the Copilot still answers. It reads get_incident and explain_dispatch (or list_incidents) and renders those facts without generation, marked model offline.

An example session​

  1. "Simulate a critical trauma emergency near Guindy." → simulate_incident(trauma_guindy). The incident appears on the map, and the answer lists triage, policy and dispatch.
  2. "What ambulance should respond?" → explain_dispatch, find_units.
  3. "Why not the nearest ambulance?" → the nearest unit's capability, the ETA difference, and the engine's reason in its own words.
  4. "Which hospital should receive the patient?" → explain_hospital, find_hospitals.
  5. "The patient's condition is deteriorating." → simulate_deterioration(severe). The SIM chip appears, then NEWS2 high, re-triage and the ER re-alert. This patient already has ALS, so the plan holds.
  6. For the full closed loop: "Simulate the urgent bike fall in Anna Nagar." (urgent_bike_fall_anna_nagar, urgent, a BLS unit is sent), then "That patient is deteriorating badly." Vaazhvu escalates urgent → critical, requests an ALS backup, re-selects the hospital and re-alerts the ER, all in one tool result.
  7. "Summarise." → what changed, what Vaazhvu did, why, and what happens next.

The same session works from any MCP client against /api/mcp.