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 flat tools/list bloat vs. GAP's fixed 651-token 5-tool MCP surface.
  • Execute gap_describe (L0/L2), authorized gap_search (L1, INV-05), and gap_query step by step.
  • Configure --stdio host clients (Claude/Cursor/Antigravity) and inspect AG-UI v1.0 /ag-ui SSE events.
On this page

Lesson 1: Stopping 203,421-Token Prompt Bloat (tools/list = 651 Tokens)

Course 2: MCP & AI Assistants · 20 min · 4 lessons 0 / 4 completed

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:

Progressive Discovery L0 to L2 Flow (Fixed 651-Token tools/list) 0. Static tools/list 5 static tools (651 tok) 1. L0: gap_describe overview: true (<=24 tok/branch) 2. L1: gap_search BM25 + Cedar Bitset (INV-05) 3. L2: gap_describe types: ["shop_CustomersResult"] 4. gap_query / gap_mutate Typed batched GraphQL execution
Progressive Discovery L0 to L2 Flow (Fixed 651-Token tools/list)

Key Takeaways

  • GAP holds tools/list constant at 5 static tools (651 tokens) 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):

json MCP 2026-07-28 — L0, L1, and L2 Discovery Sequence
// 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}}}
Code Challenge

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 }
}
Quick hints:

Key Takeaways

  • Use gap_describe({overview: true}) at L0, gap_search at L1, and gap_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:

json Host MCP Configuration (--stdio)
{
  "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-28 when driving POST /mcp over 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:

terminal Terminal — Live AG-UI v1.0 SSE Run
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}}'
Knowledge Check

How does GAP prevent an unauthorized MCP agent from discovering even the existence of admin-only tools?

Key Takeaways

  • POST /ag-ui streams structured SSE events (RUN_STARTED -> STATE_SNAPSHOT -> RUN_FINISHED) with human-in-the-loop interrupts.
  • One gateway serves /graphql, /mcp, /ag-ui, and A2A v1.0 over a single immutable Snapshot.