Skip to content

Commit 3c972a6

Browse files
committed
Fix
1 parent 4ea61dc commit 3c972a6

File tree

3 files changed

+39
-19
lines changed

3 files changed

+39
-19
lines changed

packages/agents-core/src/runState.ts

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import * as protocol from './types/protocol';
3131
import { AgentInputItem, UnknownContext } from './types';
3232
import type { InputGuardrailResult, OutputGuardrailResult } from './guardrail';
3333
import { safeExecute } from './utils/safeExecute';
34+
import { HostedMCPTool } from './tool';
3435

3536
/**
3637
* The schema version of the serialized run state. This is used to ensure that the serialized
@@ -152,12 +153,28 @@ const serializedProcessedResponseSchema = z.object({
152153
computer: z.any(),
153154
}),
154155
),
155-
mcpApprovalRequests: z.array(
156-
z.object({
157-
requestItem: z.any(),
158-
mcpTool: z.any(),
159-
}),
160-
),
156+
mcpApprovalRequests: z
157+
.array(
158+
z.object({
159+
requestItem: z.object({
160+
// protocol.HostedToolCallItem
161+
rawItem: z.object({
162+
type: z.literal('hosted_tool_call'),
163+
name: z.string(),
164+
arguments: z.string().optional(),
165+
status: z.string().optional(),
166+
output: z.string().optional(),
167+
}),
168+
}),
169+
// HostedMCPTool
170+
mcpTool: z.object({
171+
type: z.literal('hosted_tool'),
172+
name: z.literal('hosted_mcp'),
173+
providerData: z.record(z.string(), z.any()),
174+
}),
175+
}),
176+
)
177+
.optional(),
161178
});
162179

163180
const guardrailFunctionOutputSchema = z.object({
@@ -740,15 +757,16 @@ async function deserializeProcessedResponse<TContext = UnknownContext>(
740757
};
741758
},
742759
),
743-
mcpApprovalRequests: serializedProcessedResponse.mcpApprovalRequests.map(
744-
(approvalRequest) => ({
745-
requestItem: new RunToolApprovalItem(
746-
approvalRequest.requestItem.rawItem,
747-
currentAgent,
748-
),
749-
mcpTool: approvalRequest.mcpTool,
750-
}),
751-
),
760+
mcpApprovalRequests: (
761+
serializedProcessedResponse.mcpApprovalRequests ?? []
762+
).map((approvalRequest) => ({
763+
requestItem: new RunToolApprovalItem(
764+
approvalRequest.requestItem
765+
.rawItem as unknown as protocol.HostedToolCallItem,
766+
currentAgent,
767+
),
768+
mcpTool: approvalRequest.mcpTool as unknown as HostedMCPTool,
769+
})),
752770
};
753771

754772
return {
@@ -757,6 +775,7 @@ async function deserializeProcessedResponse<TContext = UnknownContext>(
757775
return (
758776
result.handoffs.length > 0 ||
759777
result.functions.length > 0 ||
778+
result.mcpApprovalRequests.length > 0 ||
760779
result.computerActions.length > 0
761780
);
762781
},

packages/agents-core/test/run.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ describe('Runner.run', () => {
8888

8989
const rawItem = {
9090
name: 'toolZ',
91-
call_id: 'c1',
91+
callId: 'c1',
9292
type: 'function_call',
9393
arguments: '{}',
9494
} as any;
@@ -126,6 +126,7 @@ describe('Runner.run', () => {
126126
},
127127
],
128128
handoffs: [],
129+
mcpApprovalRequests: [],
129130
computerActions: [],
130131
} as any;
131132

packages/agents-openai/test/openaiResponsesModel.helpers.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,9 @@ describe('converTool', () => {
130130
type: 'hosted_tool',
131131
providerData: {
132132
type: 'mcp',
133-
server_label: 'deepwiki',
134-
server_url: 'https://mcp.deepwiki.com/mcp',
135-
require_approval: 'never',
133+
serverLabel: 'deepwiki',
134+
serverUrl: 'https://mcp.deepwiki.com/mcp',
135+
requireApproval: 'never',
136136
},
137137
} as any);
138138

0 commit comments

Comments
 (0)