@mastra/client-js 1.18.0 → 1.18.1-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # @mastra/client-js
2
2
 
3
+ ## 1.18.1-alpha.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [[`3e63fca`](https://github.com/mastra-ai/mastra/commit/3e63fca7aa41269b2a9518effdd09b8ab8f1ff04), [`bc386e0`](https://github.com/mastra-ai/mastra/commit/bc386e08249dd30f3e66cf59de0c151a8dc26afb)]:
8
+ - @mastra/core@1.33.1-alpha.1
9
+
10
+ ## 1.18.1-alpha.0
11
+
12
+ ### Patch Changes
13
+
14
+ - Updated dependencies [[`6ba46dc`](https://github.com/mastra-ai/mastra/commit/6ba46dc1ac04af635d0f59377d7384ca6af44cd1)]:
15
+ - @mastra/core@1.33.1-alpha.0
16
+
3
17
  ## 1.18.0
4
18
 
5
19
  ### Minor Changes
@@ -3,7 +3,7 @@ name: mastra-client-js
3
3
  description: Documentation for @mastra/client-js. Use when working with @mastra/client-js APIs, configuration, or implementation.
4
4
  metadata:
5
5
  package: "@mastra/client-js"
6
- version: "1.18.0"
6
+ version: "1.18.1-alpha.1"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -16,6 +16,7 @@ Read the individual reference documents for detailed explanations and code examp
16
16
 
17
17
  ### Docs
18
18
 
19
+ - [A2A](references/docs-agents-a2a.md) - Expose and call remote Mastra agents over the Agent-to-Agent protocol.
19
20
  - [Signals](references/docs-agents-signals.md) - Learn how to send real-time context into a Mastra agent thread.
20
21
  - [Editor overview](references/docs-editor-overview.md) - Let non-technical team members iterate on agents, version every change, and run experiments without redeploying.
21
22
  - [Auth0](references/docs-server-auth-auth0.md) - Documentation for the @mastra/auth-auth0 package, which authenticates Mastra applications using Auth0 authentication.
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.18.0",
2
+ "version": "1.18.1-alpha.1",
3
3
  "package": "@mastra/client-js",
4
4
  "exports": {
5
5
  "RequestContext": {
@@ -0,0 +1,235 @@
1
+ # A2A (Agent-to-Agent)
2
+
3
+ Mastra supports the Agent-to-Agent (A2A) protocol for exposing agents as remote agents that other agents and services can discover, call, and track over time. A2A is useful when an agent needs to cross a network boundary without exposing the remote agent's internal tools, memory, prompts, or implementation.
4
+
5
+ ## When to use A2A
6
+
7
+ - A parent agent should delegate work to a specialized agent owned by another service or team.
8
+ - A remote agent should keep its tools, prompts, memory, workflows, and infrastructure private.
9
+ - A backend, browser app, or another A2A-compatible system needs programmatic access to a Mastra agent.
10
+ - Long-running remote work needs task IDs, status updates, artifacts, cancellation, resubscription, or push notifications.
11
+
12
+ ## How A2A works
13
+
14
+ A2A maps to the roles described in the [A2A core concepts](https://a2a-protocol.org/latest/topics/key-concepts/):
15
+
16
+ - **User**: The human, service, or process that asks for work.
17
+ - **Client agent**: The caller that discovers a remote agent, sends messages, and listens for task updates.
18
+ - **Remote agent**: The Mastra agent running behind an A2A endpoint.
19
+
20
+ Any registered Mastra agent can be called as an A2A remote agent. It keeps using its own instructions, tools, memory, workflows, and server configuration; A2A changes how the agent is reached, not how it's authored.
21
+
22
+ The flow is:
23
+
24
+ 1. Register a standard Mastra agent in your `Mastra` instance.
25
+ 2. Start Mastra Server or mount Mastra routes into your own server.
26
+ 3. Mastra exposes the agent through an agent card at `/.well-known/:agentId/agent-card.json` and an execution endpoint at `/a2a/:agentId`.
27
+ 4. A client reads the card, sends A2A JSON-RPC methods such as `message/send`, `message/stream`, `tasks/get`, `tasks/cancel`, or `tasks/resubscribe`, then receives task, artifact, and status events.
28
+
29
+ Agent cards describe the remote agent's name, description, provider, endpoint URL, capabilities, security metadata, and skills. Capabilities advertise features such as streaming and push notifications. Skills describe what the remote agent can do so callers can decide whether it fits the task.
30
+
31
+ A2A represents work as messages and tasks. Messages carry text, file, or structured data parts. Tasks are stateful units of work with IDs and lifecycle states, so clients can follow long-running work, send follow-up turns, cancel work, or resubscribe after a disconnect. Remote agents can also return artifacts, such as text, files, or structured data, during or after a task.
32
+
33
+ ## Quickstart
34
+
35
+ Start with any agent registered in your `Mastra` instance. When Mastra Server runs, the agent is available as a remote A2A agent through its registered ID.
36
+
37
+ For an agent registered as `research-agent`, Mastra exposes:
38
+
39
+ - Agent card: `/.well-known/research-agent/agent-card.json`
40
+ - Execution endpoint: `/a2a/research-agent`
41
+
42
+ Use `MastraClient.getA2A()` to fetch the agent card and call the remote agent:
43
+
44
+ ```typescript
45
+ import { MastraClient } from '@mastra/client-js'
46
+
47
+ const client = new MastraClient({
48
+ baseUrl: 'https://agent.example.com',
49
+ })
50
+
51
+ const a2a = client.getA2A('research-agent')
52
+ const card = await a2a.getAgentCard()
53
+
54
+ console.log(card.name, card.capabilities)
55
+ ```
56
+
57
+ ## Discover and call remote agents
58
+
59
+ A2A discovery starts with the agent card. The [A2A discovery guide](https://a2a-protocol.org/latest/topics/agent-discovery/) describes well-known URI discovery, registries, and direct configuration. Mastra supports the well-known route for registered agents at `/.well-known/:agentId/agent-card.json`.
60
+
61
+ Use `sendMessageStream()` to receive task status and artifact updates over Server-Sent Events (SSE):
62
+
63
+ ```typescript
64
+ const stream = a2a.sendMessageStream({
65
+ message: {
66
+ kind: 'message',
67
+ role: 'user',
68
+ messageId: crypto.randomUUID(),
69
+ parts: [{ kind: 'text', text: 'Summarize this incident report.' }],
70
+ },
71
+ })
72
+
73
+ for await (const event of stream) {
74
+ if (event.kind === 'artifact-update') {
75
+ console.log(event.artifact.parts)
76
+ }
77
+ }
78
+ ```
79
+
80
+ If a stream disconnects while a task is still running, use `resubscribeTask()` to receive live updates for the in-progress task:
81
+
82
+ ```typescript
83
+ const updates = a2a.resubscribeTask({
84
+ id: 'task-123',
85
+ })
86
+
87
+ for await (const event of updates) {
88
+ console.log(event)
89
+ }
90
+ ```
91
+
92
+ Agent cards can contain sensitive information, such as internal URLs or private skill descriptions. Protect restricted cards with access controls, and use agent card verification when a client needs to validate that a card came from a trusted source.
93
+
94
+ ## Push notifications
95
+
96
+ Mastra supports A2A push notifications for remote agents that advertise `capabilities.pushNotifications`. Use push notifications when a client can't keep a stream open, or when a long-running task should update a callback URL after the original request ends.
97
+
98
+ After a client has a task ID, it can register a callback URL for that task:
99
+
100
+ ```typescript
101
+ await a2a.setTaskPushNotificationConfig({
102
+ taskId: 'task-123',
103
+ pushNotificationConfig: {
104
+ url: 'https://app.example.com/a2a/tasks',
105
+ token: process.env.A2A_WEBHOOK_TOKEN,
106
+ },
107
+ })
108
+ ```
109
+
110
+ Mastra Server sends the current task snapshot to registered callbacks when the task reaches `completed`, `failed`, `canceled`, or `input-required`. Push notification delivery is best-effort. Protect callback URLs, validate notification tokens, and avoid exposing internal network targets as push notification destinations.
111
+
112
+ ## Sign and verify agent cards
113
+
114
+ Mastra supports signed A2A agent cards so clients can verify that a discovered card came from a trusted publisher and wasn't changed in transit. Configure signing on the Mastra server that exposes the remote agent:
115
+
116
+ ```typescript
117
+ import { Mastra } from '@mastra/core/mastra'
118
+
119
+ export const mastra = new Mastra({
120
+ server: {
121
+ a2a: {
122
+ agentCardSigning: {
123
+ privateKey: process.env.A2A_AGENT_CARD_PRIVATE_KEY!,
124
+ protectedHeader: {
125
+ alg: 'ES256',
126
+ kid: 'agent-card-key',
127
+ },
128
+ },
129
+ },
130
+ },
131
+ })
132
+ ```
133
+
134
+ When signing is configured, Mastra includes a `signatures` array on the agent card. Client verification is opt-in, and unsigned cards still return unchanged.
135
+
136
+ Verify a signed card with `MastraClient.getA2A()`:
137
+
138
+ ```typescript
139
+ const card = await a2a.getAgentCard({
140
+ verifySignature: {
141
+ algorithms: ['ES256'],
142
+ keyProvider: async ({ kid, jku }) => {
143
+ return fetchTrustedPublicJwk({ kid, jku })
144
+ },
145
+ },
146
+ })
147
+ ```
148
+
149
+ Use client-side signature verification to enforce trusted keys before calling the remote agent.
150
+
151
+ ## Use remote agents as subagents
152
+
153
+ Use `A2AAgent` when a Mastra parent agent should call a remote A2A agent as a subagent. Create an `A2AAgent` with a remote agent card URL or single-agent domain, then register it in the parent agent's `agents` map.
154
+
155
+ ```typescript
156
+ import { Agent } from '@mastra/core/agent'
157
+ import { A2AAgent } from '@mastra/core/a2a'
158
+
159
+ const remoteWeatherAgent = new A2AAgent({
160
+ url: 'https://weather.example.com',
161
+ })
162
+
163
+ export const supportAgent = new Agent({
164
+ id: 'support-agent',
165
+ name: 'Support Agent',
166
+ instructions: 'Answer user questions and delegate weather questions when needed.',
167
+ model: 'openai/gpt-5.4',
168
+ agents: {
169
+ remoteWeatherAgent,
170
+ },
171
+ })
172
+ ```
173
+
174
+ > **Tip:** If `url` points to a domain, `A2AAgent` fetches the agent card from `/.well-known/agent-card.json`. Use this for single-agent servers. For multi-agent servers, pass the explicit card URL, such as `https://agent.example.com/.well-known/:agentId/agent-card.json`. If `url` already ends with `/agent-card.json`, Mastra uses that URL directly. `A2AAgent` doesn't discover agent IDs beyond the URL you provide.
175
+
176
+ `A2AAgent` implements Mastra's subagent interface. The parent agent can call it like any other subagent, while `A2AAgent` handles the protocol details.
177
+
178
+ During execution, `A2AAgent`:
179
+
180
+ - Fetches and caches the remote agent card.
181
+ - Reads the execution URL and capabilities from the card.
182
+ - Calls `message/send` for non-streaming runs or `message/stream` when streaming is supported.
183
+ - Converts remote messages, tasks, artifacts, and status updates into Mastra subagent results.
184
+ - Supports `resumeGenerate()` and `resumeStream()` when the remote task requires follow-up input or resubscription.
185
+
186
+ If the remote card doesn't advertise streaming support, `A2AAgent.stream()` falls back to the non-streaming generate path and returns a buffered stream result.
187
+
188
+ ## Configure subagent calls
189
+
190
+ `A2AAgent` accepts request options for authenticated or constrained environments:
191
+
192
+ ```typescript
193
+ import { A2AAgent } from '@mastra/core/a2a'
194
+
195
+ const remoteWeatherAgent = new A2AAgent({
196
+ url: 'https://weather.example.com',
197
+ headers: {
198
+ Authorization: `Bearer ${process.env.WEATHER_AGENT_TOKEN}`,
199
+ },
200
+ retries: 2,
201
+ backoffMs: 250,
202
+ maxBackoffMs: 1000,
203
+ timeoutMs: 30_000,
204
+ })
205
+ ```
206
+
207
+ You can also pass `credentials`, `fetch`, and `abortSignal` when the runtime needs custom fetch behavior or request cancellation.
208
+
209
+ ## Verify subagent cards
210
+
211
+ Use `verifyAgentCard` when a parent agent should validate a remote agent before delegating work to it. The verification hook receives the fetched agent card and context about where and when it was fetched.
212
+
213
+ ```typescript
214
+ import { A2AAgent } from '@mastra/core/a2a'
215
+
216
+ const remoteWeatherAgent = new A2AAgent({
217
+ url: 'https://weather.example.com/.well-known/agent-card.json',
218
+ verifyAgentCard: {
219
+ verify: async (card, context) => {
220
+ if (card.provider?.organization !== 'Weather Inc') {
221
+ throw new Error(`Unexpected provider for ${context.cardUrl}`)
222
+ }
223
+ },
224
+ },
225
+ })
226
+ ```
227
+
228
+ Use this hook to enforce expected providers, expected endpoints, certificate-bound identities, signed cards, or other trust requirements before a parent agent delegates to the remote agent.
229
+
230
+ ## Related
231
+
232
+ - [Agent reference](https://mastra.ai/reference/agents/agent)
233
+ - [JavaScript client agents reference](https://mastra.ai/reference/client-js/agents)
234
+ - [A2A core concepts](https://a2a-protocol.org/latest/topics/key-concepts/)
235
+ - [A2A discovery guide](https://a2a-protocol.org/latest/topics/agent-discovery/)
@@ -1,6 +1,6 @@
1
1
  # Signals
2
2
 
3
- > **Experimental:** Agent signals are experimental. The API may change in a future release.
3
+ > **Experimental:** Agent signals are experimental. Breaking changes may occur without a major version bump until the API is stable.
4
4
 
5
5
  Signals are a way to interact with an agent through a thread. Instead of starting every interaction with `agent.stream()`, subscribe to a thread and send signals. Mastra either wakes the agent when the thread is idle or drops the signal into the running agent loop.
6
6
 
@@ -57,6 +57,7 @@ export const mastraClient = new MastraClient({
57
57
  The Mastra Client SDK exposes all resources served by the Mastra Server.
58
58
 
59
59
  - **[Agents](https://mastra.ai/reference/client-js/agents)**: Generate responses and stream conversations.
60
+ - **[A2A](https://mastra.ai/docs/agents/a2a)**: Discover agents through agent cards and work with task-based A2A streams.
60
61
  - **[Memory](https://mastra.ai/reference/client-js/memory)**: Manage conversation threads and message history.
61
62
  - **[Tools](https://mastra.ai/reference/client-js/tools)**: Executed and managed tools.
62
63
  - **[Workflows](https://mastra.ai/reference/client-js/workflows)**: Trigger workflows and track their execution.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/client-js",
3
- "version": "1.18.0",
3
+ "version": "1.18.1-alpha.1",
4
4
  "description": "The official TypeScript library for the Mastra Client API",
5
5
  "author": "",
6
6
  "type": "module",
@@ -39,8 +39,8 @@
39
39
  "canonicalize": "^1.0.8",
40
40
  "jose": "^6.2.1",
41
41
  "json-schema": "^0.4.0",
42
- "@mastra/core": "1.33.0",
43
- "@mastra/schema-compat": "1.2.10"
42
+ "@mastra/schema-compat": "1.2.10",
43
+ "@mastra/core": "1.33.1-alpha.1"
44
44
  },
45
45
  "peerDependencies": {
46
46
  "zod": "^3.25.0 || ^4.0.0"