Skip to content

feat(openai): complete MCP approval request/response round trip #637

Description

@franciscojavierarceo

Parent

Part of #26 and #93.

Problem

The Responses agentic loop can detect an MCP call that requires approval, but the approval lifecycle is not complete:

  1. openai_mcp_dispatch appends an mcp_approval_request item to ResponsesState::accumulated_output during response processing, after agentic_loop has already finalized the client response body. The approval item can therefore be absent from the returned response.
  2. No request path recognizes an OpenAI mcp_approval_response input item, correlates it to the pending approval request, and resumes the original MCP call.

The existing #558 covers argument double-encoding inside an approval request, but not visibility or resumption.

Scope

  • Return the generated mcp_approval_request in the non-streaming Responses output before ending the loop.
  • Parse mcp_approval_response input items and correlate approval_request_id with the pending call.
  • On approval, execute the original MCP call exactly once and resume inference with its result.
  • On denial, do not call the MCP server and return a Responses-compatible outcome preserving the denial reason when supplied.
  • Reject unknown, stale, duplicated, or mismatched approval identifiers safely.
  • Preserve the original tool name, server label, call ID, and arguments across the round trip.
  • Keep future streaming event emission aligned with stream_events: synthesize SSE for locally executed tools #276.

Acceptance criteria

  • An approval-required request returns an mcp_approval_request output item.
  • A follow-up request containing an approving mcp_approval_response performs one tools/call and completes the model → tool → model loop.
  • A denied approval performs zero tools/call requests.
  • Replaying an approval response cannot execute the tool twice.
  • Unit and end-to-end tests cover approve, deny, malformed ID, and argument preservation.

Related

Metadata

Metadata

Assignees

Projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions