Course 2: MCP, AG-UI & AI Assistants
Course 2 shows you how AI assistants interact with hundreds of capabilities without overflowing their context window—using MCP 2026-07-28 progressive discovery (L0 -> L1 -> L2) and AG-UI v1.0 live SSE streaming.
What you'll learn
- Compare
203,421-token flattools/listbloat vs. GAP's fixed651-token 5-tool MCP surface. - Execute
gap_describe(L0/L2), authorizedgap_search(L1,INV-05), andgap_querystep by step. - Configure
--stdiohost clients (Claude/Cursor/Antigravity) and inspect AG-UIv1.0/ag-uiSSE events.
On this page
Lesson 1: Stopping 203,421-Token Prompt Bloat (tools/list = 651 Tokens)
In standard flat MCP integrations, connecting 100 microservices means tools/list returns ~1,000 raw JSON schemas totaling 203,421 tokens on every cold turn. GAP exposes an invariant catalog of 5 static tools costing 651 tokens from N=10 to N=1,000:
Key Takeaways
- GAP holds
tools/listconstant at 5 static tools (651tokens) regardless of upstream branch count. - Discovery becomes explicit three-level on-demand hydration (
L0,L1,L2).
Lesson 2: Driving Progressive Discovery (L0 -> L1 -> L2 -> gap_query)
An AI agent moves through three deterministic hops—filtering out forbidden tools via the Cedar visibility bitset before ranking scores (INV-05):
// L0 Overview (<= 24 tok/branch)
{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"gap_describe","arguments":{"overview":true}}}
// L1 Authorized Search
{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"gap_search","arguments":{"query":"customer orders","limit":5}}}
// L2 Hydrate Exact Compiled Types
{"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"gap_describe","arguments":{"types":["shop_CustomersResult","shop_OrdersResult"],"depth":1}}}
Request Exact Composed Types at L2
Fill in the exact compiled OpenAPI return type name for Walking Skeleton customers inside gap_describe:
{
"name": "gap_describe",
"arguments": { "types": ["____"], "depth": 1 }
}
Key Takeaways
- Use
gap_describe({overview: true})at L0,gap_searchat L1, andgap_describe({types: [...]})at L2. - Cedar visibility bitsets mask disallowed operations prior to BM25/HNSW scoring (
INV-05).
Lesson 3: Connecting Desktop & IDE Agents via --stdio or HTTP
Desktop hosts like Claude Desktop, Cursor, or Antigravity speak either newline-delimited --stdio JSON-RPC or Streamable HTTP POST /mcp (protocol header MCP-Protocol-Version: 2026-07-28). Configure --stdio cleanly while sending logs solely to stderr:
{
"mcpServers": {
"gap-gateway": {
"command": "./target/dist/gap",
"args": ["serve", "--config", "examples/walking-skeleton/gap.toml", "--stdio"],
"env": { "GAP_TOKEN": "gap_dev_skeleton_key_01" }
}
}
}
Key Takeaways
- Under
--stdio, stdout carries strictly valid JSON-RPC lines while structured logs write to stderr. - Set
MCP-Protocol-Version: 2026-07-28when drivingPOST /mcpover HTTP/2 or HTTP/3.
Lesson 4: Streaming Interactive UI State with AG-UI v1.0
Human-facing web copilot interfaces connect over POST /ag-ui Server-Sent Events (SSE), receiving typed RUN_STARTED, TOOL_CALL_RESULT, STATE_SNAPSHOT, interrupt prompts, and escaped <gap:untrusted> payloads:
curl -sS -N http://127.0.0.1:8080/ag-ui \
-H "Authorization: Bearer gap_dev_skeleton_key_01" \
-H "Content-Type: application/json" \
-d '{"threadId":"t-1","runId":"r-1","messages":[{"id":"m-1","role":"user","content":"Show VIP customer 1"}],"state":{"generation":1}}'
How does GAP prevent an unauthorized MCP agent from discovering even the existence of admin-only tools?
Key Takeaways
POST /ag-uistreams structured SSE events (RUN_STARTED -> STATE_SNAPSHOT -> RUN_FINISHED) with human-in-the-loop interrupts.- One gateway serves
/graphql,/mcp,/ag-ui, and A2Av1.0over a single immutable Snapshot.