Skip to content

Handle Realtime MCP event response.mcp_call.completed#193

Open
Panha-Sim wants to merge 1 commit intojamesrochabrun:mainfrom
Panha-Sim:main
Open

Handle Realtime MCP event response.mcp_call.completed#193
Panha-Sim wants to merge 1 commit intojamesrochabrun:mainfrom
Panha-Sim:main

Conversation

@Panha-Sim
Copy link

Problem

When using MCP tools with the Realtime API:

  1. The model initiates an MCP call.
  2. The MCP server completes successfully.
  3. The Realtime API emits response.mcp_call.completed.
  4. SwiftOpenAI logs the event as unhandled and drops it.
    Because the event is not exposed to the client, applications cannot trigger a follow-up response.create call. This can lead to a stalled conversation where no response.audio.delta events are emitted until the user sends another input.

Solution

This PR:

  • Adds support for decoding response.mcp_call.completed.
  • Surfaces the event through a new OpenAIRealtimeMessage case.
  • Allows client applications to react appropriately (e.g., sending response.create to continue generation).
    This keeps the SDK behavior consistent with other surfaced Realtime events and avoids silently discarding valid protocol messages.

Example Usage

After this change, applications can handle MCP completion like this:

case .responseMcpCallCompleted:
    await session.sendMessage(OpenAIRealtimeResponseCreate())

This enables proper continuation of assistant output (including audio streaming) after MCP tool execution.

Compatibility

  • No breaking changes.
  • Existing behavior remains unchanged for users not using MCP tools.
  • Adds support for an already-emitted but previously unhandled Realtime event.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant