AI Incident Assistant is a production-style incident response playground. Operators sign in, chat with an LLM, create and update Sev1 incidents, load templates (CAN, Sev1 canvas, RCA), and generate documents from structured incident data.
It shows gateway-routed models, MCP-backed tools, Supabase-backed auth and sessions, rolling per-user chat quotas, and two layers of observability: gateway-level metrics plus trace-level tooling.
The stack, layer by layer
Layer
What runs there
Interface
What runs thereNext.js and TypeScript, deployed on Vercel
Models
What runs thereVercel AI Gateway routes each request to the configured model; LangChain trims the history
Tools
What runs thereAn MCP server with incident, template and document tools, storing its data as local JSON
Auth and data
What runs thereSupabase Auth, and Postgres for chat sessions and the per-user quota
Abuse protection
What runs thereCloudflare Turnstile and a rolling per-user chat quota
Observability
What runs thereGateway-level metrics plus LangSmith traces
What each area does
Capability matrix: what each area does
Area
How it works
Chat orchestration
How it worksA route handler picks the model, binds the tools, trims the token history and keeps the session in sync.
Context
How it worksA thin system prompt, history trimmed with LangChain, and the saved session memory folded into the system string.
Authentication
How it worksSupabase Auth with middleware guards at the edge, behind Cloudflare Turnstile.
Session memory
How it worksA Postgres JSONB envelope holds the raw messages, a structured memory summary and key facts. It is re-injected on every turn and written back to the same row the user owns under row level security.
Abuse controls
How it worksA rolling per-user window, counted through a Supabase RPC and enforced on the chat API.
MCP tools
MCP tools by group
Group
Tools
Incident
Tools
create_incident
get_incident
update_incident
list_incidents
Templates
Tools
get_can_templates
get_sev1_canvas
get_rca_templates
load_template
Documents
Tools
generate_can_document
generate_rca_document
Meta
Tools
list_tools
Incident and template storage is local JSON in the MCP server's data directory, with validation, safer writes and bounded runtime.
How a request flows
Three views of one chat turn: how the prompt is built, how memory is kept between turns, and the order of calls from submit to response.
Request pipeline
The system prompt is thin, the history is trimmed with LangChain, and the saved session memory is folded into the system string. The request then branches into a model-only path or a tool-enabled one.
The chat route checks the session and quota first, then builds a small prompt with memory folded in. The decision gate only reaches for tools when the turn needs them.
Context retention
From the browser, the envelope is loaded and merged, optional CAN guardrails apply, the history is trimmed to a token budget and the model generates. Memory is written back to the same row the user already owns under RLS.
Memory lives in the same chat_sessions row the user already owns under RLS: read at the start of a turn, updated before the model call.
End-to-end runtime
The request runs from the user's submit through API orchestration and the decision gates to optional MCP calls, then the response.
Every turn in order, with replies dashed or muted. Cobalt marks the path from the user's prompt to the rendered answer.