@salesforce/sfdx-agent-harness-mastra 0.18.0 → 0.19.0

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
@@ -3,6 +3,15 @@
3
3
  All notable changes to `@salesforce/sfdx-agent-harness-mastra` are documented in this file.
4
4
  Format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
5
5
 
6
+ ## [0.19.0] - 2026-06-12
7
+
8
+ ### Features
9
+ - **agent-sdk,harness-mastra,harness-claude**: add tool-call-delta ChatEvent for streaming tool-call args @W-22965697@ ([#597](https://github.com/forcedotcom/agentic-dx/pull/597))
10
+ - **agent-sdk,harness-mastra,harness-claude**: add tool-progress ChatEvent variant @W-22951127@ ([#594](https://github.com/forcedotcom/agentic-dx/pull/594))
11
+
12
+ ### Fixes
13
+ - **harness-claude**: map SDKResultSuccess.is_error to ChatEvent.error ([#593](https://github.com/forcedotcom/agentic-dx/pull/593))
14
+
6
15
  ## [0.18.0] - 2026-06-11
7
16
 
8
17
  ### Fixes
@@ -142,6 +142,29 @@ export declare class MastraApprovalCoordinator {
142
142
  * `agent.approveToolCall(...)` / `declineToolCall(...)`.
143
143
  */
144
144
  private currentRunId;
145
+ /**
146
+ * `toolCallId` of the MCP tool call currently in-flight on this turn,
147
+ * or `null` when no MCP tool is awaiting a result. Tracked at
148
+ * `routeEnriched` time: set when a MCP-namespaced `tool-call` arrives,
149
+ * cleared on the matching `tool-result`.
150
+ *
151
+ * Used by {@link emitMcpProgress} to attribute incoming
152
+ * `notifications/progress` (which only carry a `progressToken`) to the
153
+ * right `toolCallId` for the `tool-progress` ChatEvent.
154
+ *
155
+ * Mastra serializes MCP tool execution per workflow step, so at most
156
+ * one MCP tool call is in flight per coordinator at any time —
157
+ * matching the "currentMcpToolCallId" field's scalar shape.
158
+ */
159
+ private currentMcpToolCallId;
160
+ /**
161
+ * Captures the (Mastra-namespaced) tool name for each `toolCallId`
162
+ * routed through `routeEnriched`. Used by {@link emitMcpProgress} to
163
+ * stamp `toolName` on the `tool-progress` ChatEvent so AG-UI Activity
164
+ * translators don't have to consult the originating `tool-call` event
165
+ * to route progress chunks.
166
+ */
167
+ private readonly toolNameForCallId;
145
168
  /**
146
169
  * ToolCallIds Mastra is currently suspended on. Mastra retains a separate
147
170
  * workflow snapshot step per id, so the pump must drive one resume per
@@ -175,6 +198,33 @@ export declare class MastraApprovalCoordinator {
175
198
  private timedOut;
176
199
  constructor(opts: MastraApprovalCoordinatorOptions);
177
200
  initialSink(): GenSink<ChatEvent>;
201
+ /**
202
+ * Mastra's current run id. The harness's MCP-progress dispatcher uses
203
+ * this to filter incoming `notifications/progress` to the coordinator
204
+ * whose run produced the originating tool call (the upstream server
205
+ * received the progressToken Mastra injected from `context.runId`).
206
+ */
207
+ getCurrentRunId(): string;
208
+ /**
209
+ * Issue #591: dispatch an MCP `notifications/progress` notification
210
+ * received via `mcpClient.progress.onUpdate(...)` to the consumer's
211
+ * eventStream as a `tool-progress` ChatEvent.
212
+ *
213
+ * Caller (the harness MCP-progress listener) is responsible for
214
+ * filtering by `progressToken === coordinator.getCurrentRunId()` so this
215
+ * method only sees notifications belonging to its own turn.
216
+ *
217
+ * Drops the notification (no event surfaced) when no MCP tool call is
218
+ * currently in flight — the only path that produces `currentMcpToolCallId
219
+ * === null` after a turn started is "progress arrived after the matching
220
+ * tool-result." Losing a stragglier is preferable to surfacing a
221
+ * progress event without a meaningful toolCallId.
222
+ */
223
+ emitMcpProgress(params: {
224
+ progress: number;
225
+ total?: number;
226
+ message?: string;
227
+ }): void;
178
228
  onTeardown(callback: () => void): void;
179
229
  private runTeardownCallbacks;
180
230
  /**
@@ -78,6 +78,29 @@ export class MastraApprovalCoordinator {
78
78
  * `agent.approveToolCall(...)` / `declineToolCall(...)`.
79
79
  */
80
80
  currentRunId = '';
81
+ /**
82
+ * `toolCallId` of the MCP tool call currently in-flight on this turn,
83
+ * or `null` when no MCP tool is awaiting a result. Tracked at
84
+ * `routeEnriched` time: set when a MCP-namespaced `tool-call` arrives,
85
+ * cleared on the matching `tool-result`.
86
+ *
87
+ * Used by {@link emitMcpProgress} to attribute incoming
88
+ * `notifications/progress` (which only carry a `progressToken`) to the
89
+ * right `toolCallId` for the `tool-progress` ChatEvent.
90
+ *
91
+ * Mastra serializes MCP tool execution per workflow step, so at most
92
+ * one MCP tool call is in flight per coordinator at any time —
93
+ * matching the "currentMcpToolCallId" field's scalar shape.
94
+ */
95
+ currentMcpToolCallId = null;
96
+ /**
97
+ * Captures the (Mastra-namespaced) tool name for each `toolCallId`
98
+ * routed through `routeEnriched`. Used by {@link emitMcpProgress} to
99
+ * stamp `toolName` on the `tool-progress` ChatEvent so AG-UI Activity
100
+ * translators don't have to consult the originating `tool-call` event
101
+ * to route progress chunks.
102
+ */
103
+ toolNameForCallId = new Map();
81
104
  /**
82
105
  * ToolCallIds Mastra is currently suspended on. Mastra retains a separate
83
106
  * workflow snapshot step per id, so the pump must drive one resume per
@@ -123,6 +146,43 @@ export class MastraApprovalCoordinator {
123
146
  initialSink() {
124
147
  return this.initial;
125
148
  }
149
+ /**
150
+ * Mastra's current run id. The harness's MCP-progress dispatcher uses
151
+ * this to filter incoming `notifications/progress` to the coordinator
152
+ * whose run produced the originating tool call (the upstream server
153
+ * received the progressToken Mastra injected from `context.runId`).
154
+ */
155
+ getCurrentRunId() {
156
+ return this.currentRunId;
157
+ }
158
+ /**
159
+ * Issue #591: dispatch an MCP `notifications/progress` notification
160
+ * received via `mcpClient.progress.onUpdate(...)` to the consumer's
161
+ * eventStream as a `tool-progress` ChatEvent.
162
+ *
163
+ * Caller (the harness MCP-progress listener) is responsible for
164
+ * filtering by `progressToken === coordinator.getCurrentRunId()` so this
165
+ * method only sees notifications belonging to its own turn.
166
+ *
167
+ * Drops the notification (no event surfaced) when no MCP tool call is
168
+ * currently in flight — the only path that produces `currentMcpToolCallId
169
+ * === null` after a turn started is "progress arrived after the matching
170
+ * tool-result." Losing a stragglier is preferable to surfacing a
171
+ * progress event without a meaningful toolCallId.
172
+ */
173
+ emitMcpProgress(params) {
174
+ if (this.aborted || this.disposed)
175
+ return;
176
+ const toolCallId = this.currentMcpToolCallId;
177
+ if (!toolCallId)
178
+ return;
179
+ this.initial.push({
180
+ type: 'tool-progress',
181
+ toolCallId,
182
+ toolName: this.toolNameForCallId.get(toolCallId) ?? 'unknown',
183
+ output: { ...params },
184
+ });
185
+ }
126
186
  onTeardown(callback) {
127
187
  if (this.aborted || this.disposed) {
128
188
  queueMicrotask(callback);
@@ -548,6 +608,21 @@ export class MastraApprovalCoordinator {
548
608
  if (this.aborted || this.disposed)
549
609
  return;
550
610
  const enriched = this.maybeEnrich(event);
611
+ // Issue #591: track in-flight MCP tool call so progress notifications
612
+ // arriving via `progress.onUpdate(...)` can be attributed to the
613
+ // right `toolCallId`. Set on enriched (i.e. MCP-namespaced) tool-call;
614
+ // cleared on the matching tool-result. Non-MCP tools don't carry
615
+ // `serverName` (the lookup returns undefined) so this never fires
616
+ // for built-ins, consumer-declared tools, or workspace tools.
617
+ if (enriched.type === 'tool-call' && enriched.serverName !== undefined) {
618
+ this.currentMcpToolCallId = enriched.toolCallId;
619
+ this.toolNameForCallId.set(enriched.toolCallId, enriched.toolName);
620
+ }
621
+ else if (enriched.type === 'tool-result' &&
622
+ enriched.serverName !== undefined &&
623
+ this.currentMcpToolCallId === enriched.toolCallId) {
624
+ this.currentMcpToolCallId = null;
625
+ }
551
626
  this.initial.push(enriched);
552
627
  }
553
628
  maybeEnrich(event) {
@@ -33,6 +33,8 @@ import type { ChatEvent } from '@salesforce/sfdx-agent-sdk';
33
33
  * | `tool-call-approval` | `tool-approval-request` | `{ toolCall: { toolCallId, toolName, args } }` — stream suspends |
34
34
  * | `tool-result` | `tool-result` | `{ toolCallId, toolName, result, isError: false }` |
35
35
  * | `tool-error` | `tool-result` | `{ toolCallId, toolName, result: error, isError: true}`|
36
+ * | `tool-output` | `tool-progress` | `{ toolCallId, toolName, output }` |
37
+ * | `tool-call-delta` | `tool-call-delta` | `{ toolCallId, toolName?, argsTextDelta }` |
36
38
  * | `step-start` | `step-start` | `{ stepIndex }` from step metadata |
37
39
  * | `step-finish` | `step-finish` | `{ stepIndex, finishReason, usage }` from `stepResult` |
38
40
  * | `finish` | `finish` | `{ finishReason, usage }` from `output` |
@@ -44,9 +46,8 @@ import type { ChatEvent } from '@salesforce/sfdx-agent-sdk';
44
46
  * | `reasoning-start`, | | |
45
47
  * | `reasoning-end` | | |
46
48
  * | `source`, `file`, | *(skipped)* | Known but unsupported — future ChatEvent candidates |
47
- * | `tool-call-delta`, | | |
48
49
  * | `tool-call-suspended`, | | |
49
- * | `object`, `tool-output` | | |
50
+ * | `object` | | |
50
51
  * | *(all others)* | *(skipped)* | Logged via `LogBus.debug` with `{ chunkType, rawChunk }` |
51
52
  *
52
53
  * Stateful per stream — a new instance must be created for each `MastraHarness.stream()` call.
@@ -34,6 +34,8 @@
34
34
  * | `tool-call-approval` | `tool-approval-request` | `{ toolCall: { toolCallId, toolName, args } }` — stream suspends |
35
35
  * | `tool-result` | `tool-result` | `{ toolCallId, toolName, result, isError: false }` |
36
36
  * | `tool-error` | `tool-result` | `{ toolCallId, toolName, result: error, isError: true}`|
37
+ * | `tool-output` | `tool-progress` | `{ toolCallId, toolName, output }` |
38
+ * | `tool-call-delta` | `tool-call-delta` | `{ toolCallId, toolName?, argsTextDelta }` |
37
39
  * | `step-start` | `step-start` | `{ stepIndex }` from step metadata |
38
40
  * | `step-finish` | `step-finish` | `{ stepIndex, finishReason, usage }` from `stepResult` |
39
41
  * | `finish` | `finish` | `{ finishReason, usage }` from `output` |
@@ -45,9 +47,8 @@
45
47
  * | `reasoning-start`, | | |
46
48
  * | `reasoning-end` | | |
47
49
  * | `source`, `file`, | *(skipped)* | Known but unsupported — future ChatEvent candidates |
48
- * | `tool-call-delta`, | | |
49
50
  * | `tool-call-suspended`, | | |
50
- * | `object`, `tool-output` | | |
51
+ * | `object` | | |
51
52
  * | *(all others)* | *(skipped)* | Logged via `LogBus.debug` with `{ chunkType, rawChunk }` |
52
53
  *
53
54
  * Stateful per stream — a new instance must be created for each `MastraHarness.stream()` call.
@@ -169,19 +170,35 @@ export class MastraEventAdapter {
169
170
  case 'reasoning-end':
170
171
  this.logBus?.debug('Skipping informational Mastra chunk', { chunkType: chunk.type });
171
172
  return undefined;
173
+ case 'tool-output':
174
+ return {
175
+ type: 'tool-progress',
176
+ toolCallId: chunk.payload.toolCallId,
177
+ toolName: chunk.payload.toolName ?? 'unknown',
178
+ output: chunk.payload.output,
179
+ };
180
+ case 'tool-call-delta':
181
+ return {
182
+ type: 'tool-call-delta',
183
+ toolCallId: chunk.payload.toolCallId,
184
+ // Strict `!== undefined` (not truthy) so an empty-string
185
+ // toolName from upstream — unlikely but possible — is
186
+ // forwarded honestly instead of silently swallowed.
187
+ ...(chunk.payload.toolName !== undefined ? { toolName: chunk.payload.toolName } : {}),
188
+ argsTextDelta: chunk.payload.argsTextDelta,
189
+ };
172
190
  // Known harness chunk types not yet supported in the SDK's ChatEvent
173
191
  // model. Silently dropped to avoid leaking harness internals onto the
174
192
  // public stream. Candidates for future ChatEvent variants when the
175
- // corresponding features (citations, file generation, tool arg
176
- // streaming, tool suspension, structured output) are supported.
193
+ // corresponding features (citations, file generation, tool input
194
+ // lifecycle bookends, tool suspension, structured output) are
195
+ // supported.
177
196
  case 'source':
178
197
  case 'file':
179
- case 'tool-call-delta':
180
198
  case 'tool-call-input-streaming-start':
181
199
  case 'tool-call-input-streaming-end':
182
200
  case 'tool-call-suspended':
183
201
  case 'object':
184
- case 'tool-output':
185
202
  this.logBus?.debug('Skipping unsupported Mastra chunk type', { chunkType: chunk.type });
186
203
  return undefined;
187
204
  default:
@@ -478,6 +478,22 @@ export declare class MastraHarness implements MastraAgentHarness {
478
478
  * after `shutdown()` has disposed the buses.
479
479
  */
480
480
  private prepareMcpStatusChange;
481
+ /**
482
+ * Issue #591: install a `progress.onUpdate(serverName, ...)` listener
483
+ * on the MCP client. Incoming `notifications/progress` are dispatched
484
+ * to the active coordinator on this agent whose `currentRunId` matches
485
+ * the notification's `progressToken` — `enableProgressTracking: true`
486
+ * makes `@mastra/mcp` inject `_meta.progressToken = context.runId` into
487
+ * every tool call, so the token uniquely identifies the originating
488
+ * turn even across concurrent threads on the same agent.
489
+ *
490
+ * `progress.onUpdate` is async (it lazily connects the underlying
491
+ * internal client). We swallow rejections inside a fire-and-forget
492
+ * wrapper rather than blocking `createAgent`/`updateAgent` — discovery
493
+ * and progress tracking are independent: a server that fails to wire
494
+ * progress still works for tool calls, just without progress events.
495
+ */
496
+ private registerMcpProgressListener;
481
497
  /**
482
498
  * Runs MCP discovery for one server: emits the
483
499
  * `mcp-server-discovery-started` / `…-completed` / `…-failed` telemetry
@@ -473,6 +473,9 @@ export class MastraHarness {
473
473
  };
474
474
  mcpServerStates.set(serverName, entry);
475
475
  entry.ready = this.runMcpDiscovery(agentId, serverName, client, mcpServerStates, 0, options?.abortSignal);
476
+ // Issue #591: bridge MCP `notifications/progress` onto the
477
+ // coordinator's per-turn sink as `tool-progress` ChatEvents.
478
+ this.registerMcpProgressListener(agentId, serverName, client);
476
479
  }
477
480
  }
478
481
  // Issue #529 step 2c: the bridge `execute` handler resolves the
@@ -893,6 +896,8 @@ export class MastraHarness {
893
896
  };
894
897
  state.mcpServers.set(name, entry);
895
898
  entry.ready = this.runMcpDiscovery(agentId, name, client, state.mcpServers, 0, options?.abortSignal);
899
+ // Issue #591: same MCP-progress wiring as createAgent path.
900
+ this.registerMcpProgressListener(agentId, name, client);
896
901
  }
897
902
  }
898
903
  }
@@ -1528,6 +1533,52 @@ export class MastraHarness {
1528
1533
  }
1529
1534
  };
1530
1535
  }
1536
+ /**
1537
+ * Issue #591: install a `progress.onUpdate(serverName, ...)` listener
1538
+ * on the MCP client. Incoming `notifications/progress` are dispatched
1539
+ * to the active coordinator on this agent whose `currentRunId` matches
1540
+ * the notification's `progressToken` — `enableProgressTracking: true`
1541
+ * makes `@mastra/mcp` inject `_meta.progressToken = context.runId` into
1542
+ * every tool call, so the token uniquely identifies the originating
1543
+ * turn even across concurrent threads on the same agent.
1544
+ *
1545
+ * `progress.onUpdate` is async (it lazily connects the underlying
1546
+ * internal client). We swallow rejections inside a fire-and-forget
1547
+ * wrapper rather than blocking `createAgent`/`updateAgent` — discovery
1548
+ * and progress tracking are independent: a server that fails to wire
1549
+ * progress still works for tool calls, just without progress events.
1550
+ */
1551
+ registerMcpProgressListener(agentId, serverName, client) {
1552
+ client.progress
1553
+ .onUpdate(serverName, (params) => {
1554
+ const agentState = this.activeAgents.get(agentId);
1555
+ if (!agentState)
1556
+ return;
1557
+ // Walk per-thread coordinators to find the one whose current
1558
+ // run produced this progressToken. Mastra's
1559
+ // `enableProgressTracking` injects `progressToken =
1560
+ // context.runId`, so `progressToken === coordinator.runId`
1561
+ // is an exact, single-match filter.
1562
+ const targetToken = String(params.progressToken);
1563
+ for (const coordinator of agentState.coordinators.values()) {
1564
+ if (coordinator.getCurrentRunId() === targetToken) {
1565
+ coordinator.emitMcpProgress({
1566
+ progress: params.progress,
1567
+ ...(params.total !== undefined && { total: params.total }),
1568
+ ...(params.message !== undefined && { message: params.message }),
1569
+ });
1570
+ return;
1571
+ }
1572
+ }
1573
+ })
1574
+ .catch((err) => {
1575
+ this.buses.getLogBus()?.warn('Failed to register MCP progress listener', {
1576
+ agentId,
1577
+ serverName,
1578
+ error: getErrorMessage(err),
1579
+ });
1580
+ });
1581
+ }
1531
1582
  /**
1532
1583
  * Runs MCP discovery for one server: emits the
1533
1584
  * `mcp-server-discovery-started` / `…-completed` / `…-failed` telemetry
@@ -56,6 +56,13 @@ export function mapToMastraMCPServers(config, orgJwt) {
56
56
  ...(serverConfig.args !== undefined && { args: serverConfig.args }),
57
57
  ...(serverConfig.env !== undefined && { env: serverConfig.env }),
58
58
  ...(serverConfig.timeout !== undefined && { timeout: serverConfig.timeout }),
59
+ // Issue #591: opt every server in to MCP progress notifications
60
+ // so the upstream server knows it can send `notifications/progress`
61
+ // (the harness bridges those to `tool-progress` ChatEvents via
62
+ // `mcpClient.progress.onUpdate(...)`). Default in `@mastra/mcp` is
63
+ // off, so without this the spec-compliant progressToken is never
64
+ // injected into `_meta` and servers send no progress.
65
+ enableProgressTracking: true,
59
66
  };
60
67
  result[name] = def;
61
68
  }
@@ -77,6 +84,8 @@ export function mapToMastraMCPServers(config, orgJwt) {
77
84
  ...serverConfig.reconnectionOptions,
78
85
  },
79
86
  }),
87
+ // Issue #591: same rationale as stdio.
88
+ enableProgressTracking: true,
80
89
  };
81
90
  result[name] = def;
82
91
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/sfdx-agent-harness-mastra",
3
- "version": "0.18.0",
3
+ "version": "0.19.0",
4
4
  "description": "Mastra-backed AgentHarness implementation for @salesforce/sfdx-agent-sdk",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -38,11 +38,11 @@
38
38
  "@salesforce/llm-gateway-sdk": "0.14.0"
39
39
  },
40
40
  "peerDependencies": {
41
- "@salesforce/sfdx-agent-sdk": "0.19.0"
41
+ "@salesforce/sfdx-agent-sdk": "0.20.0"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@eslint/js": "^10.0.1",
45
- "@salesforce/sfdx-agent-sdk": "0.19.0",
45
+ "@salesforce/sfdx-agent-sdk": "0.20.0",
46
46
  "@types/node": "^22.19.20",
47
47
  "@vitest/coverage-istanbul": "^4.1.8",
48
48
  "@vitest/eslint-plugin": "^1.6.19",