Skip to content

Commit 2a87046

Browse files
authored
fix(server): forward requestContext through approve/decline tool-call REST handlers (#15620)
1 parent 96f6fb2 commit 2a87046

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@mastra/server': patch
3+
---
4+
5+
Forward `requestContext` from the `/approve-tool-call`, `/decline-tool-call`, `/approve-tool-call-generate` and `/decline-tool-call-generate` REST handlers to `agent.approveToolCall(...)` / `declineToolCall(...)` / `approveToolCallGenerate(...)` / `declineToolCallGenerate(...)`.
6+
7+
Previously `requestContext` was destructured from the handler arguments but never passed through. On resume, `dynamicInstructions` ran with `requestContext: undefined`, so any value placed on the per-request `RequestContext` by upstream middleware (or by `body.requestContext` auto-merge) was lost for the rest of the turn. Agents whose prompt assembly depends on request-scoped data (e.g. read-only state from the frontend) produced blank or placeholder responses after the user approved a HITL tool call. Other agent entry points (`stream`, `generate`) already forwarded `requestContext` correctly; this brings the approval routes in line.

packages/server/src/server/handlers/agents.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1453,6 +1453,7 @@ export const APPROVE_TOOL_CALL_ROUTE = createRoute({
14531453

14541454
const streamResult = await agent.approveToolCall({
14551455
...params,
1456+
requestContext,
14561457
abortSignal,
14571458
});
14581459

@@ -1497,6 +1498,7 @@ export const DECLINE_TOOL_CALL_ROUTE = createRoute({
14971498

14981499
const streamResult = await agent.declineToolCall({
14991500
...params,
1501+
requestContext,
15001502
abortSignal,
15011503
});
15021504

@@ -1540,6 +1542,7 @@ export const APPROVE_TOOL_CALL_GENERATE_ROUTE = createRoute({
15401542

15411543
const result = await agent.approveToolCallGenerate({
15421544
...params,
1545+
requestContext,
15431546
abortSignal,
15441547
});
15451548

@@ -1583,6 +1586,7 @@ export const DECLINE_TOOL_CALL_GENERATE_ROUTE = createRoute({
15831586

15841587
const result = await agent.declineToolCallGenerate({
15851588
...params,
1589+
requestContext,
15861590
abortSignal,
15871591
});
15881592

0 commit comments

Comments
 (0)