Skip to content

Commit 361f6de

Browse files
authored
Fix #131 Human in the Loop MCP approval fails (#156)
1 parent e07ac8e commit 361f6de

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

packages/agents-core/src/runState.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,8 @@ const serializedProcessedResponseSchema = z.object({
165165
arguments: z.string().optional(),
166166
status: z.string().optional(),
167167
output: z.string().optional(),
168+
// this always exists but marked as optional for early version compatibility; when releasing 1.0, we can remove the nullable and optional
169+
providerData: z.record(z.string(), z.any()).nullable().optional(),
168170
}),
169171
}),
170172
// HostedMCPTool

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

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,50 @@ describe('deserialize helpers', () => {
278278
functions: [],
279279
handoffs: [],
280280
computerActions: [{ toolCall: call, computer: tool }],
281-
mcpApprovalRequests: [],
281+
mcpApprovalRequests: [
282+
{
283+
requestItem: {
284+
rawItem: {
285+
type: 'hosted_tool_call',
286+
name: 'fetch_generic_url_content',
287+
status: 'in_progress',
288+
providerData: {
289+
id: 'mcpr_685bc3c47ed88192977549b5206db77504d4306d5de6ab36',
290+
type: 'mcp_approval_request',
291+
arguments:
292+
'{"url":"https://raw.githubusercontent.com/openai/codex/main/README.md"}',
293+
name: 'fetch_generic_url_content',
294+
server_label: 'gitmcp',
295+
},
296+
},
297+
type: 'tool_approval_item',
298+
agent: new Agent({ name: 'foo ' }),
299+
toJSON: function (): any {
300+
throw new Error('Function not implemented.');
301+
},
302+
},
303+
mcpTool: {
304+
type: 'hosted_tool',
305+
name: 'hosted_mcp',
306+
providerData: {
307+
type: 'mcp',
308+
server_label: 'gitmcp',
309+
server_url: 'https://gitmcp.io/openai/codex',
310+
require_approval: {
311+
always: {
312+
tool_names: ['fetch_generic_url_content'],
313+
},
314+
never: {
315+
tool_names: [
316+
'search_codex_code',
317+
'fetch_codex_documentation',
318+
],
319+
},
320+
},
321+
},
322+
},
323+
},
324+
],
282325
toolsUsed: [],
283326
hasToolsOrApprovalsToRun: () => true,
284327
};
@@ -292,5 +335,15 @@ describe('deserialize helpers', () => {
292335
if (restored._currentStep?.type === 'next_step_handoff') {
293336
expect(restored._currentStep.newAgent).toBe(agent);
294337
}
338+
expect(
339+
restored._lastProcessedResponse?.mcpApprovalRequests[0].mcpTool,
340+
).toEqual(state._lastProcessedResponse?.mcpApprovalRequests[0].mcpTool);
341+
expect(
342+
restored._lastProcessedResponse?.mcpApprovalRequests[0].requestItem
343+
.rawItem.providerData,
344+
).toEqual(
345+
state._lastProcessedResponse?.mcpApprovalRequests[0].requestItem.rawItem
346+
.providerData,
347+
);
295348
});
296349
});

0 commit comments

Comments
 (0)