Khởi chạy Nhanh (10 phút)

Làm theo 4 bước ngắn dưới đây để khởi chạy siêu đồ thị mẫu Walking Skeleton — ghép nối cửa hàng REST OpenAPI (shop) với máy chủ MCP (notes) trong đúng một truy vấn GraphQL.

Bạn sẽ nắm được gì

  • Kiểm tra cấu hình an toàn bằng gap config check và gap doctor.
  • Khởi chạy hai upstream mẫu REST + MCP và tiến trình gap serve.
  • Thực thi câu truy vấn gộp dữ liệu từ cả hai nguồn trong một request duy nhất.
Trong trang này

Chuẩn bị Trước khi Chạy

  • Binary gap đã biên dịch (từ bản phát hành hoặc chạy ./dist/build-reproducible.sh --offline tạo ra ./target/dist/gap).
  • Python 3.10+ để chạy hai dịch vụ giả lập mẫu trong examples/walking-skeleton/fixtures/.

Hướng dẫn Từng bước

  1. Kiểm tra hợp lệ tệp cấu hình

    Chạy kiểm tra tĩnh với examples/walking-skeleton/gap.toml. GAP từ chối khởi động ngay nếu thấy trường lạ, bí mật ghi trần không qua biến môi trường hoặc thiếu tệp spec:

    terminal Terminal — Kiểm tra gap.toml
    ./target/dist/gap config check examples/walking-skeleton/gap.toml
    ./target/dist/gap doctor --config examples/walking-skeleton/gap.toml
    text Kết quả Mong đợi (Mã thoát 0 · OPS-044)
    ok: `examples/walking-skeleton/gap.toml` valid (2 branches)
    [ok] config.parse: parsed examples/walking-skeleton/gap.toml (profile=dev)
    [ok] security.sandbox: OS sandbox operational
    [ok] security.egress_guard: egress SSRF self-test matrix passed
    [warn] models.s1: model cache incomplete offline; degrades safely to baseline (RTE-044)
    summary: 11 ok, 1 warn, 0 fail, 0 skip
    • Lưu ý: Cả hai lệnh trả về mã thoát 0 (OPS-044). Khóa API dev-agent được lưu bằng mã băm BLAKE3 trong TOML.
  2. Khởi chạy hai máy chủ upstream mẫu

    Bật giả lập REST API trên cổng 9101 và máy chủ MCP trên cổng 9102:

    terminal Terminal — Hai Máy chủ Upstream Giả lập
    python3 examples/walking-skeleton/fixtures/rest_fixture.py --port 9101 &
    python3 examples/walking-skeleton/fixtures/mcp_fixture.py --port 9102 &
  3. Khởi chạy Cổng GAP Gateway

    Chạy lệnh gap serve trỏ tới cấu hình Walking Skeleton:

    terminal Terminal — Khởi chạy Gateway
    ./target/dist/gap serve --config examples/walking-skeleton/gap.toml
    • Kiểm tra sẵn sàng: GET http://127.0.0.1:8080/readyz trả HTTP 200 ({"status":"ready","generation":1}) ngay khi thế hệ snapshot 1 được nạp xong.
  4. Gửi truy vấn gộp liên nhánh đầu tiên

    Lấy hồ sơ khách hàng + đơn hàng từ nhánh OpenAPI shop kèm JSON ghi chú từ nhánh MCP notes trong 1 lần gọi HTTP (chú ý customer_notes trả về kiểu vô hướng JSON nên gọi trực tiếp không mở ngoặc con):

    terminal Terminal — Truy vấn GraphQL Gộp 2 Nhánh
    curl -sS -X POST http://127.0.0.1:8080/graphql \
      -H "Content-Type: application/json" \
      -H "Accept: application/graphql-response+json" \
      -H "Authorization: Bearer gap_dev_skeleton_key_01" \
      -d '{"query": "{ customer(id: 1) { id name tier } orders(customer_id: 1) { id total_cents status } customer_notes(customer_id: 1) }"}' | python3 -m json.tool
    json Kết quả Mong đợi — HTTP 200 JSON
    {
      "data": {
        "customer": { "id": 1, "name": "Ada Lovelace", "tier": "vip" },
        "orders": [
          { "id": 101, "total_cents": 4200, "status": "paid" },
          { "id": 103, "total_cents": 8500, "status": "pending" }
        ],
        "customer_notes": {
          "customer_id": 1,
          "notes": [{ "note_id": "n-1", "customer_id": 1, "summary": "Prefers consolidated monthly invoice" }]
        }
      },
      "extensions": {
        "gap": { "cost": { "actual": 7, "planned": 306 }, "generation": 1, "partial": false }
      }
    }

Bước 5: Gắn vào MCP Host hoặc Phát Luồng AG-UI

Thay vì cấu hình từng công cụ REST rời rạc, hãy trỏ AI host vào MCP server 5 tool cố định của GAP qua stdio, hoặc nhận luồng sự kiện AG-UI v1.0 qua SSE. Xem chi tiết tích hợp tại Tích hợp MCP, A2A & AG-UI.

json mcp_servers.json — Cấu hình Client Stdio
{
  "mcpServers": {
    "gap-gateway": {
      "command": "/path/to/GraphProtocol/target/dist/gap",
      "args": ["serve", "--config", "examples/walking-skeleton/gap.toml", "--stdio"]
    }
  }
}
terminal Terminal — Luồng SSE AG-UI v1.0 Trực tiếp
curl -sS -N -X POST http://127.0.0.1:8080/ag-ui \
  -H "Content-Type: application/json" \
  -H "Accept: text/event-stream" \
  -H "Authorization: Bearer gap_dev_skeleton_key_01" \
  -d '{"threadId":"t1","runId":"r1","messages":[],"forwardedProps":{"graphql":{"query":"{ customer(id: 1) { id name } customer_notes(customer_id: 1) }"}}}'