Skip to content

Responses API: Wrong chunk name for the MCP Call arguments #2412

Open
@lemeb

Description

@lemeb

Confirm this is an issue with the Python library and not an underlying OpenAI API

  • This is an issue with the Python library

Describe the bug

Hi everyone,

I think there is a bug in the way that you process event chunks related to MCP.

According to the API reference, events referring to MCP Call arguments should have response.mcp_call.arguments.delta and response.mcp_call.arguments.done as types.

But the current code expects response.mcp_call.arguments_delta and response.mcp_call.arguments_done.

Funnily enough, you can't really fix that bug right now. As it happens, the API is currently sending a third chunk type, so you will have to wait for the API to be fixed before you can be aligned with the spec and the API's actual behavior.

Cheers!

To Reproduce

from openai.types import responses as rt
from pydantic import TypeAdapter
from pydantic_core import ValidationError

current_api_behavior: list[dict[str, str | int]] = [
    {
        "type": "response.mcp_call_arguments.delta",
        "sequence_number": 10,
        "output_index": 2,
        "item_id": "mcp_684ff3a22a60819c90fa205XXXXXXXXXXX",
        "delta": '{"repoName":"modelcontextprotocol/modelcontextprotocol"}',
    },
    {
        "type": "response.mcp_call_arguments.done",
        "sequence_number": 11,
        "output_index": 2,
        "item_id": "mcp_684ff3a22a60819c90fa205XXXXXXXXXXX",
        "arguments": '{"repoName":"modelcontextprotocol/modelcontextprotocol"}',
    },
]


api_behavior_according_to_spec = [
    {
        "type": "response.mcp_call.arguments.delta",
        "sequence_number": 10,
        "output_index": 2,
        "item_id": "mcp_684ff3a22a60819c90fa205XXXXXXXXXXX",
        "delta": '{"repoName":"modelcontextprotocol/modelcontextprotocol"}',
    },
    {
        "type": "response.mcp_call.arguments.done",
        "sequence_number": 11,
        "output_index": 2,
        "item_id": "mcp_684ff3a22a60819c90fa205XXXXXXXXXXX",
        "arguments": '{"repoName":"modelcontextprotocol/modelcontextprotocol"}',
    },
]

api_behavior_expected_by_sdk = [
    {
        "type": "response.mcp_call.arguments_delta",
        "sequence_number": 10,
        "output_index": 2,
        "item_id": "mcp_684ff3a22a60819c90fa205XXXXXXXXXXX",
        "delta": '{"repoName":"modelcontextprotocol/modelcontextprotocol"}',
    },
    {
        "type": "response.mcp_call.arguments_done",
        "sequence_number": 11,
        "output_index": 2,
        "item_id": "mcp_684ff3a22a60819c90fa205XXXXXXXXXXX",
        "arguments": '{"repoName":"modelcontextprotocol/modelcontextprotocol"}',
    },
]

for events, description in [
    (current_api_behavior, "current_api_behavior"),
    (api_behavior_according_to_spec, "api_behavior_according_to_spec"),
    (api_behavior_expected_by_sdk, "api_behavior_expected_by_sdk"),
]:
    try:
        _ = TypeAdapter(list[rt.ResponseStreamEvent]).validate_python(events)
    except ValidationError as e:
        print(f"Error validating {description}")
        print(events)
    else:
        print(f"Validated {description} successfully")
Error validating current_api_behavior
[{'type': 'response.mcp_call_arguments.delta', 'sequence_number': 10, 'output_index': 2, 'item_id': 'mcp_684ff3a22a60819c90fa205XXXXXXXXXXX', 'delta': '{"repoName":"modelcontextprotocol/modelcontextprotocol"}'}, {'type': 'response.mcp_call_arguments.done', 'sequence_number': 11, 'output_index': 2, 'item_id': 'mcp_684ff3a22a60819c90fa205XXXXXXXXXXX', 'arguments': '{"repoName":"modelcontextprotocol/modelcontextprotocol"}'}]
Error validating api_behavior_according_to_spec
[{'type': 'response.mcp_call.arguments.delta', 'sequence_number': 10, 'output_index': 2, 'item_id': 'mcp_684ff3a22a60819c90fa205XXXXXXXXXXX', 'delta': '{"repoName":"modelcontextprotocol/modelcontextprotocol"}'}, {'type': 'response.mcp_call.arguments.done', 'sequence_number': 11, 'output_index': 2, 'item_id': 'mcp_684ff3a22a60819c90fa205XXXXXXXXXXX', 'arguments': '{"repoName":"modelcontextprotocol/modelcontextprotocol"}'}]
Validated api_behavior_expected_by_sdk successfully

Code snippets

OS

macOS

Python version

Python v.3.12.8

Library version

openai v.1.86.0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions