| 59 | * of these per session and may re-pin a resolved single-agent default. |
| 60 | */ |
| 61 | export class McpClient { |
| 62 | readonly sdk: E2AClient; |
| 63 | /** Default per-agent address; mirrors the old flat `agentEmail`. */ |
| 64 | readonly agentEmail: string; |
| 65 | /** |
| 66 | * The connecting credential's scope (§6a tier-gating signal). Resolved at |
| 67 | * session init from whoami (GET /account). Defaults to "account" (full |
| 68 | * surface) so direct constructions / tests are unchanged; buildSessionClient |
| 69 | * sets the real value per credential. |
| 70 | */ |
| 71 | readonly scope: Scope; |
| 72 | |
| 73 | constructor(sdk: E2AClient, agentEmail = "", scope: Scope = "account") { |
| 74 | this.sdk = sdk; |
| 75 | this.agentEmail = agentEmail; |
| 76 | this.scope = scope; |
| 77 | } |
| 78 | |
| 79 | // resolveAddress picks the explicit per-call address, falling back to |
| 80 | // the pinned default. Throws a directive error when neither resolves. |
| 81 | private resolveAddress(explicit?: string): string { |
| 82 | const addr = explicit || this.agentEmail; |
| 83 | if (!addr) { |
| 84 | throw new Error( |
| 85 | "email is required — pass it explicitly, or connect with an agent-scoped credential (which resolves the agent for you). Run list_agents to see your agents.", |
| 86 | ); |
| 87 | } |
| 88 | return addr; |
| 89 | } |
| 90 | |
| 91 | // ── Account / identity ────────────────────────────────────────── |
| 92 | |
| 93 | // whoami → GET /account (§6a): the authenticated principal (user + scope; |
| 94 | // agent_address only for agent-scoped credentials) + plan/limits. NOT an |
| 95 | // agent — discover agents via list_agents. |
| 96 | whoami(): Promise<AccountView> { |
| 97 | return this.sdk.account.get(); |
| 98 | } |
| 99 | |
| 100 | // ── Agents ────────────────────────────────────────────────────── |
| 101 | |
| 102 | async listAgents(): Promise<AgentView[]> { |
| 103 | return this.sdk.agents.list().toArray({ limit: DEFAULT_LIST_LIMIT }); |
| 104 | } |
| 105 | |
| 106 | getAgent(address: string): Promise<AgentView> { |
| 107 | return this.sdk.agents.get(address); |
| 108 | } |
| 109 | |
| 110 | // create_agent takes a full email (§6a / AG-1/2): a custom-domain agent on a |
| 111 | // verified owned domain, or an email on the shared domain. slug/agent_mode/ |
| 112 | // webhook_url are gone. Returns the full AgentView. |
| 113 | createAgent(body: { email: string; name?: string }): Promise<AgentView> { |
| 114 | return this.sdk.agents.create(body); |
| 115 | } |
| 116 | |
| 117 | // Consume the generated UpdateAgentRequest directly (no hand-declared |
| 118 | // duplicate, no cast): a field removed/renamed at the API layer is a compile |
nothing calls this directly
no outgoing calls
no test coverage detected