# A2ADemo IEx test harness for the A2A protocol. Provides two demo functions that exercise the full agent discovery → task send → task retrieval flow. ## Functions ### `run_local()` Direct module calls — no HTTP, no server required. Uses a hardcoded user (ID 1) with admin permissions. Exercises `A2AServer` functions directly. **Flow:** 1. `A2AServer.agent_card/1` — discover skills for the user 2. `A2AServer.handle_send/2` — send `add_numbers(3, 7)` task 3. `A2AServer.handle_get/2` — retrieve the task by ID ```elixir iex> A2ADemo.run_local() === A2A Local Demo === 1. Agent Card (Discovery): Name: elixir-mcp-agent Skills: 42 - add_numbers: Add two numbers together ... 2. Sending task (add_numbers 3 + 7): Task ID: 1709395200000 State: completed Result: 10 3. Retrieving task: State: completed Timestamp: 2026-03-02T12:00:00.000Z === Demo Complete === ``` ### `run(cookie \\ nil)` Full HTTP round-trip via `A2AClient`. Requires the HTTPS server to be running on `https://localhost` and a valid authentication cookie. **Flow:** 1. `A2AClient.discover/1` — public agent card (no auth) 2. `A2AClient.send_task/3` — send `add_numbers(5, 12)` with cookie auth 3. `A2AClient.get_task/3` — retrieve the task by ID Without a cookie, only discovery runs. Authenticated steps are skipped with a message. ```elixir iex> A2ADemo.run(cookie) === A2A HTTP Demo === 1. Discovering agent at https://localhost: Name: elixir-mcp-agent URL: https://localhost/a2a Skills: 5 - get_greeting: Returns a greeting message ... 2. Sending task (add_numbers 5 + 12): Task ID: 1709395200000 State: completed Result: 17 3. Retrieving task 1709395200000: State: completed Timestamp: 2026-03-02T12:00:00.000Z === Demo Complete === ``` ## Generating a Cookie From IEx: ```elixir {:ok, user} = User.find_by_username("james") secret = Plug.Crypto.KeyGenerator.generate( Application.get_env(:mcp, :secret_key_base), Application.get_env(:mcp, :cookie_salt), length: 32 ) cookie = Plug.Crypto.MessageEncryptor.encrypt( to_string(user.id), secret, Application.get_env(:mcp, :cookie_salt) ) A2ADemo.run(cookie) ``` ## Why Two Modes - **`run_local/0`** — fast feedback during development, no network dependencies, tests `A2AServer` logic in isolation - **`run/1`** — validates the full stack: HTTP routing, cookie authentication, TLS, JSON-RPC serialization, and `A2AClient` correctness ## Source `lib/a2a_demo.ex`