-
-
Notifications
You must be signed in to change notification settings - Fork 12k
[Frontend] Add MCP tool streaming support to Responses API #30192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
daniel-salib
wants to merge
2
commits into
vllm-project:main
Choose a base branch
from
daniel-salib:pr3-mcp-streaming
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+820
−83
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,9 +3,9 @@ | |
|
|
||
| import pytest | ||
| import pytest_asyncio | ||
| from openai import OpenAI | ||
| from openai_harmony import ToolDescription, ToolNamespaceConfig | ||
|
|
||
| from openai import OpenAI | ||
| from vllm.entrypoints.tool_server import MCPToolServer | ||
|
|
||
| from ...utils import RemoteOpenAIServer | ||
|
|
@@ -206,6 +206,65 @@ async def test_mcp_tool_env_flag_disabled(mcp_disabled_client: OpenAI, model_nam | |
| ) | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| @pytest.mark.parametrize("model_name", [MODEL_NAME]) | ||
| async def test_mcp_tool_calling_streaming_types( | ||
| mcp_enabled_client: OpenAI, model_name: str | ||
| ): | ||
| pairs_of_event_types = { | ||
| "response.completed": "response.created", | ||
| "response.output_item.done": "response.output_item.added", | ||
| "response.content_part.done": "response.content_part.added", | ||
| "response.output_text.done": "response.output_text.delta", | ||
| "response.reasoning_text.done": "response.reasoning_text.delta", | ||
| "response.reasoning_part.done": "response.reasoning_part.added", | ||
| "response.mcp_call_arguments.done": "response.mcp_call_arguments.delta", | ||
| "response.mcp_call.completed": "response.mcp_call.in_progress", | ||
| } | ||
|
|
||
| tools = [ | ||
| { | ||
| "type": "mcp", | ||
| "server_label": "code_interpreter", | ||
| } | ||
| ] | ||
| input_text = "What is 13 * 24? Use python to calculate the result." | ||
|
|
||
| stream_response = await mcp_enabled_client.responses.create( | ||
| model=model_name, | ||
| input=input_text, | ||
| tools=tools, | ||
| stream=True, | ||
| instructions=( | ||
| "You must use the Python tool to execute code. Never simulate execution." | ||
| ), | ||
| ) | ||
|
|
||
| stack_of_event_types = [] | ||
| async for event in stream_response: | ||
| assert "mcp_call" in event.type | ||
|
|
||
| if event.type == "response.created": | ||
| stack_of_event_types.append(event.type) | ||
| elif event.type == "response.completed": | ||
| assert stack_of_event_types[-1] == pairs_of_event_types[event.type] | ||
| stack_of_event_types.pop() | ||
| if ( | ||
| event.type.endswith("added") | ||
| or event.type == "response.mcp_call.in_progress" | ||
| ): | ||
| stack_of_event_types.append(event.type) | ||
| elif event.type.endswith("delta"): | ||
| if stack_of_event_types[-1] == event.type: | ||
| continue | ||
| stack_of_event_types.append(event.type) | ||
| elif event.type.endswith("done") or event.type == "response.mcp_call.completed": | ||
| assert stack_of_event_types[-1] == pairs_of_event_types[event.type] | ||
| stack_of_event_types.pop() | ||
|
|
||
| assert len(stack_of_event_types) == 0 | ||
|
Comment on lines
+244
to
+265
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The logic in this test has a couple of issues:
I've suggested a fix that addresses both points by introducing a flag to check for MCP events and correcting the conditional logic. mcp_event_seen = False
stack_of_event_types = []
async for event in stream_response:
if "mcp_call" in event.type:
mcp_event_seen = True
if event.type == "response.created":
stack_of_event_types.append(event.type)
elif event.type == "response.completed":
assert stack_of_event_types.pop() == pairs_of_event_types[event.type]
elif (
event.type.endswith("added")
or event.type == "response.mcp_call.in_progress"
):
stack_of_event_types.append(event.type)
elif event.type.endswith("delta"):
if not stack_of_event_types or stack_of_event_types[-1] != event.type:
stack_of_event_types.append(event.type)
elif event.type.endswith("done") or event.type == "response.mcp_call.completed":
assert stack_of_event_types.pop() == pairs_of_event_types[event.type]
assert mcp_event_seen, "No MCP call events were observed in the stream."
assert len(stack_of_event_types) == 0 |
||
|
|
||
|
|
||
| def test_get_tool_description(): | ||
| """Test MCPToolServer.get_tool_description filtering logic. | ||
|
|
||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In
test_mcp_tool_calling_streaming_typesevery streamed event is immediately asserted to contain the substring"mcp_call"before any dispatch logic runs. The Responses API stream always begins withresponse.created(andresponse.in_progress) which do not include that substring, so this assertion fails on the first event and the rest of the test logic never executes. As written the test cannot pass even when the streaming implementation is correct; the assertion needs to be limited to the MCP events it is intended to check.Useful? React with 👍 / 👎.