[Bugfix] Support MCP SDK 2.x tool input schemas (#53870)
Signed-off-by: chaunceyjiang <chaunceyjiang@gmail.com>
This commit is contained in:
@@ -51,7 +51,7 @@ setproctitle # Used to set process names for better debugging and monitoring
|
||||
openai-harmony >= 0.0.3 # Required for gpt-oss
|
||||
anthropic >= 0.71.0
|
||||
model-hosting-container-standards >= 0.1.14, < 1.0.0
|
||||
mcp
|
||||
mcp >= 2.0.0, < 3.0.0
|
||||
opentelemetry-sdk >= 1.27.0
|
||||
opentelemetry-api >= 1.27.0
|
||||
opentelemetry-exporter-otlp >= 1.27.0
|
||||
|
||||
@@ -37,6 +37,7 @@ anyio==4.14.1
|
||||
# via
|
||||
# anthropic
|
||||
# httpx
|
||||
# httpx2
|
||||
# mcp
|
||||
# openai
|
||||
# sse-starlette
|
||||
@@ -304,9 +305,10 @@ grpcio==1.78.0
|
||||
# ray
|
||||
grpcio-reflection==1.78.0
|
||||
# via -r requirements/test/cuda.in
|
||||
h11==0.14.0
|
||||
h11==0.16.0
|
||||
# via
|
||||
# httpcore
|
||||
# httpcore2
|
||||
# uvicorn
|
||||
h2==4.3.0
|
||||
# via httpx
|
||||
@@ -320,8 +322,10 @@ hpack==4.1.0
|
||||
# via h2
|
||||
html2text==2025.4.15
|
||||
# via gpt-oss
|
||||
httpcore==1.0.6
|
||||
httpcore==1.0.9
|
||||
# via httpx
|
||||
httpcore2==2.12.0
|
||||
# via httpx2
|
||||
httptools==0.8.0
|
||||
# via uvicorn
|
||||
httpx==0.27.2
|
||||
@@ -332,12 +336,11 @@ httpx==0.27.2
|
||||
# fastapi
|
||||
# fastapi-cloud-cli
|
||||
# huggingface-hub
|
||||
# mcp
|
||||
# model-hosting-container-standards
|
||||
# openai
|
||||
# perceptron
|
||||
# schemathesis
|
||||
httpx-sse==0.4.3
|
||||
httpx2==2.12.0
|
||||
# via mcp
|
||||
huggingface-hub==1.28.0
|
||||
# via
|
||||
@@ -366,11 +369,12 @@ hypothesis-graphql==0.13.0
|
||||
# via schemathesis
|
||||
hypothesis-jsonschema==0.23.1
|
||||
# via schemathesis
|
||||
idna==3.10
|
||||
idna==3.19
|
||||
# via
|
||||
# anyio
|
||||
# email-validator
|
||||
# httpx
|
||||
# httpx2
|
||||
# requests
|
||||
# yarl
|
||||
ijson==3.5.0
|
||||
@@ -476,8 +480,10 @@ mbstrdecoder==1.1.3
|
||||
# dataproperty
|
||||
# pytablewriter
|
||||
# typepy
|
||||
mcp==1.28.1
|
||||
mcp==2.1.1
|
||||
# via -r requirements/test/../common.txt
|
||||
mcp-types==2.1.1
|
||||
# via mcp
|
||||
mdurl==0.1.2
|
||||
# via markdown-it-py
|
||||
mistral-common==1.11.6
|
||||
@@ -596,6 +602,7 @@ openpyxl==3.1.5
|
||||
opentelemetry-api==1.35.0
|
||||
# via
|
||||
# -r requirements/test/../common.txt
|
||||
# mcp
|
||||
# opentelemetry-exporter-otlp-proto-grpc
|
||||
# opentelemetry-exporter-otlp-proto-http
|
||||
# opentelemetry-exporter-prometheus
|
||||
@@ -782,6 +789,7 @@ pydantic==2.12.0
|
||||
# gpt-oss
|
||||
# lm-format-enforcer
|
||||
# mcp
|
||||
# mcp-types
|
||||
# mistral-common
|
||||
# model-hosting-container-standards
|
||||
# mteb
|
||||
@@ -800,9 +808,7 @@ pydantic-extra-types==2.10.5
|
||||
# fastapi
|
||||
# mistral-common
|
||||
pydantic-settings==2.14.2
|
||||
# via
|
||||
# fastapi
|
||||
# mcp
|
||||
# via fastapi
|
||||
pygments==2.18.0
|
||||
# via
|
||||
# pytest
|
||||
@@ -1185,6 +1191,10 @@ triton==3.6.0
|
||||
# via xgrammar
|
||||
tritonclient==2.64.0
|
||||
# via -r requirements/test/cuda.in
|
||||
truststore==0.10.4
|
||||
# via
|
||||
# httpcore2
|
||||
# httpx2
|
||||
typepy==1.3.2
|
||||
# via
|
||||
# dataproperty
|
||||
@@ -1215,10 +1225,12 @@ typing-extensions==4.15.0
|
||||
# cohere
|
||||
# fastapi
|
||||
# grpcio
|
||||
# httpx2
|
||||
# huggingface-hub
|
||||
# librosa
|
||||
# lm-eval
|
||||
# mcp
|
||||
# mcp-types
|
||||
# mistral-common
|
||||
# mteb
|
||||
# openai
|
||||
|
||||
+24
-10
@@ -40,6 +40,7 @@ anyio==4.14.1
|
||||
# via
|
||||
# anthropic
|
||||
# httpx
|
||||
# httpx2
|
||||
# mcp
|
||||
# openai
|
||||
# sse-starlette
|
||||
@@ -323,9 +324,10 @@ grpcio==1.78.0
|
||||
# ray
|
||||
grpcio-reflection==1.78.0
|
||||
# via -r requirements/test/cuda.in
|
||||
h11==0.14.0
|
||||
h11==0.16.0
|
||||
# via
|
||||
# httpcore
|
||||
# httpcore2
|
||||
# uvicorn
|
||||
h2==4.3.0
|
||||
# via httpx
|
||||
@@ -339,8 +341,10 @@ hpack==4.1.0
|
||||
# via h2
|
||||
html2text==2025.4.15
|
||||
# via gpt-oss
|
||||
httpcore==1.0.6
|
||||
httpcore==1.0.9
|
||||
# via httpx
|
||||
httpcore2==2.12.0
|
||||
# via httpx2
|
||||
httptools==0.8.0
|
||||
# via uvicorn
|
||||
httpx==0.27.2
|
||||
@@ -351,12 +355,11 @@ httpx==0.27.2
|
||||
# fastapi
|
||||
# fastapi-cloud-cli
|
||||
# huggingface-hub
|
||||
# mcp
|
||||
# model-hosting-container-standards
|
||||
# openai
|
||||
# perceptron
|
||||
# schemathesis
|
||||
httpx-sse==0.4.3
|
||||
httpx2==2.12.0
|
||||
# via mcp
|
||||
huggingface-hub==1.28.0
|
||||
# via
|
||||
@@ -386,11 +389,12 @@ hypothesis-graphql==0.13.0
|
||||
# via schemathesis
|
||||
hypothesis-jsonschema==0.23.1
|
||||
# via schemathesis
|
||||
idna==3.10
|
||||
idna==3.19
|
||||
# via
|
||||
# anyio
|
||||
# email-validator
|
||||
# httpx
|
||||
# httpx2
|
||||
# requests
|
||||
# yarl
|
||||
ijson==3.5.0
|
||||
@@ -505,8 +509,12 @@ mbstrdecoder==1.1.3
|
||||
# dataproperty
|
||||
# pytablewriter
|
||||
# typepy
|
||||
mcp==1.28.1
|
||||
# via -r requirements/test/../common.txt
|
||||
mcp==2.1.1
|
||||
# via
|
||||
# -c requirements/common.txt
|
||||
# -r requirements/test/../common.txt
|
||||
mcp-types==2.1.1
|
||||
# via mcp
|
||||
mdurl==0.1.2
|
||||
# via markdown-it-py
|
||||
mistral-common==1.11.6
|
||||
@@ -675,6 +683,7 @@ opentelemetry-api==1.35.0
|
||||
# via
|
||||
# -c requirements/common.txt
|
||||
# -r requirements/test/../common.txt
|
||||
# mcp
|
||||
# opentelemetry-exporter-otlp-proto-grpc
|
||||
# opentelemetry-exporter-otlp-proto-http
|
||||
# opentelemetry-exporter-prometheus
|
||||
@@ -873,6 +882,7 @@ pydantic==2.12.0
|
||||
# gpt-oss
|
||||
# lm-format-enforcer
|
||||
# mcp
|
||||
# mcp-types
|
||||
# mistral-common
|
||||
# model-hosting-container-standards
|
||||
# mteb
|
||||
@@ -891,9 +901,7 @@ pydantic-extra-types==2.10.5
|
||||
# fastapi
|
||||
# mistral-common
|
||||
pydantic-settings==2.14.2
|
||||
# via
|
||||
# fastapi
|
||||
# mcp
|
||||
# via fastapi
|
||||
pygments==2.18.0
|
||||
# via
|
||||
# pytest
|
||||
@@ -1293,6 +1301,10 @@ triton==3.7.1
|
||||
# xgrammar
|
||||
tritonclient==2.64.0
|
||||
# via -r requirements/test/cuda.in
|
||||
truststore==0.10.4
|
||||
# via
|
||||
# httpcore2
|
||||
# httpx2
|
||||
typepy==1.3.2
|
||||
# via
|
||||
# dataproperty
|
||||
@@ -1324,10 +1336,12 @@ typing-extensions==4.15.0
|
||||
# cohere
|
||||
# fastapi
|
||||
# grpcio
|
||||
# httpx2
|
||||
# huggingface-hub
|
||||
# librosa
|
||||
# lm-eval
|
||||
# mcp
|
||||
# mcp-types
|
||||
# mistral-common
|
||||
# mteb
|
||||
# openai
|
||||
|
||||
@@ -37,6 +37,7 @@ anyio==4.13.0
|
||||
# via
|
||||
# anthropic
|
||||
# httpx
|
||||
# httpx2
|
||||
# mcp
|
||||
# openai
|
||||
# sse-starlette
|
||||
@@ -319,6 +320,7 @@ grpcio-reflection==1.78.0
|
||||
h11==0.16.0
|
||||
# via
|
||||
# httpcore
|
||||
# httpcore2
|
||||
# uvicorn
|
||||
h2==4.3.0
|
||||
# via httpx
|
||||
@@ -334,6 +336,8 @@ html2text==2025.4.15
|
||||
# via gpt-oss
|
||||
httpcore==1.0.9
|
||||
# via httpx
|
||||
httpcore2==2.12.0
|
||||
# via httpx2
|
||||
httptools==0.7.1
|
||||
# via uvicorn
|
||||
httpx==0.27.2
|
||||
@@ -344,12 +348,11 @@ httpx==0.27.2
|
||||
# fastapi
|
||||
# fastapi-cloud-cli
|
||||
# huggingface-hub
|
||||
# mcp
|
||||
# model-hosting-container-standards
|
||||
# openai
|
||||
# perceptron
|
||||
# schemathesis
|
||||
httpx-sse==0.4.3
|
||||
httpx2==2.12.0
|
||||
# via mcp
|
||||
huggingface-hub==1.28.0
|
||||
# via
|
||||
@@ -379,11 +382,12 @@ hypothesis-graphql==0.13.0
|
||||
# via schemathesis
|
||||
hypothesis-jsonschema==0.23.1
|
||||
# via schemathesis
|
||||
idna==3.11
|
||||
idna==3.19
|
||||
# via
|
||||
# anyio
|
||||
# email-validator
|
||||
# httpx
|
||||
# httpx2
|
||||
# requests
|
||||
# yarl
|
||||
ijson==3.5.0
|
||||
@@ -500,8 +504,12 @@ mbstrdecoder==1.1.4
|
||||
# dataproperty
|
||||
# pytablewriter
|
||||
# typepy
|
||||
mcp==1.27.0
|
||||
# via -r requirements/test/../common.txt
|
||||
mcp==2.1.1
|
||||
# via
|
||||
# -c requirements/common.txt
|
||||
# -r requirements/test/../common.txt
|
||||
mcp-types==2.1.1
|
||||
# via mcp
|
||||
mdurl==0.1.2
|
||||
# via markdown-it-py
|
||||
mistral-common==1.11.6
|
||||
@@ -642,6 +650,7 @@ opentelemetry-api==1.40.0
|
||||
# via
|
||||
# -c requirements/common.txt
|
||||
# -r requirements/test/../common.txt
|
||||
# mcp
|
||||
# opentelemetry-exporter-otlp-proto-grpc
|
||||
# opentelemetry-exporter-otlp-proto-http
|
||||
# opentelemetry-exporter-prometheus
|
||||
@@ -847,6 +856,7 @@ pydantic==2.12.5
|
||||
# gpt-oss
|
||||
# lm-format-enforcer
|
||||
# mcp
|
||||
# mcp-types
|
||||
# mistral-common
|
||||
# model-hosting-container-standards
|
||||
# mteb
|
||||
@@ -865,9 +875,7 @@ pydantic-extra-types==2.11.1
|
||||
# fastapi
|
||||
# mistral-common
|
||||
pydantic-settings==2.13.1
|
||||
# via
|
||||
# fastapi
|
||||
# mcp
|
||||
# via fastapi
|
||||
pygments==2.19.2
|
||||
# via
|
||||
# pytest
|
||||
@@ -1241,6 +1249,10 @@ transformers-stream-generator==0.0.5
|
||||
# via -r requirements/test/rocm.in
|
||||
tritonclient==2.66.0
|
||||
# via -r requirements/test/rocm.in
|
||||
truststore==0.10.4
|
||||
# via
|
||||
# httpcore2
|
||||
# httpx2
|
||||
typeguard==4.5.1
|
||||
# via inflect
|
||||
typepy==1.3.4
|
||||
@@ -1274,10 +1286,12 @@ typing-extensions==4.15.0
|
||||
# cohere
|
||||
# fastapi
|
||||
# grpcio
|
||||
# httpx2
|
||||
# huggingface-hub
|
||||
# librosa
|
||||
# lm-eval
|
||||
# mcp
|
||||
# mcp-types
|
||||
# mistral-common
|
||||
# mteb
|
||||
# openai
|
||||
|
||||
@@ -375,9 +375,11 @@ mbstrdecoder==1.1.5
|
||||
# dataproperty
|
||||
# pytablewriter
|
||||
# typepy
|
||||
mcp==2.0.0
|
||||
# via -r requirements/test/../common.txt
|
||||
mcp-types==2.0.0
|
||||
mcp==2.1.1
|
||||
# via
|
||||
# -c requirements/common.txt
|
||||
# -r requirements/test/../common.txt
|
||||
mcp-types==2.1.1
|
||||
# via mcp
|
||||
mdurl==0.1.2
|
||||
# via markdown-it-py
|
||||
|
||||
@@ -10,7 +10,10 @@ from openai import OpenAI
|
||||
from openai_harmony import Message, ToolDescription, ToolNamespaceConfig
|
||||
|
||||
from tests.utils import RemoteOpenAIServer
|
||||
from vllm.entrypoints.mcp.tool_server import MCPToolServer
|
||||
from vllm.entrypoints.mcp.tool_server import (
|
||||
MCPToolServer,
|
||||
post_process_tools_description,
|
||||
)
|
||||
|
||||
from .conftest import (
|
||||
BASE_TEST_ENV,
|
||||
@@ -36,8 +39,9 @@ _PYTHON_TOOL_INSTRUCTION = (
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.skip_global_cleanup
|
||||
class TestMCPToolServerUnit:
|
||||
"""Test MCPToolServer.get_tool_description filtering logic.
|
||||
"""Test MCP tool description processing and filtering.
|
||||
|
||||
Note: The wildcard "*" is normalized to None by
|
||||
_extract_allowed_tools_from_mcp_requests before reaching this layer,
|
||||
@@ -96,6 +100,41 @@ class TestMCPToolServerUnit:
|
||||
# Empty list - returns None
|
||||
assert server.get_tool_description("test_server", allowed_tools=[]) is None
|
||||
|
||||
def test_post_process_tools_description_uses_trim_schema_result(self, monkeypatch):
|
||||
mcp_types = pytest.importorskip("mcp.types")
|
||||
tool = mcp_types.Tool(
|
||||
name="tool",
|
||||
input_schema={"type": "object"},
|
||||
)
|
||||
result = mcp_types.ListToolsResult(tools=[tool])
|
||||
trimmed_schema = {"type": "object", "properties": {}}
|
||||
|
||||
monkeypatch.setattr(
|
||||
"vllm.entrypoints.mcp.tool_server.trim_schema",
|
||||
lambda _schema: trimmed_schema,
|
||||
)
|
||||
|
||||
post_process_tools_description(result)
|
||||
|
||||
assert tool.input_schema is trimmed_schema
|
||||
|
||||
def test_post_process_tools_description_honors_meta_opt_out(self):
|
||||
mcp_types = pytest.importorskip("mcp.types")
|
||||
included = mcp_types.Tool(
|
||||
name="included",
|
||||
input_schema={"type": "object"},
|
||||
)
|
||||
excluded = mcp_types.Tool(
|
||||
name="excluded",
|
||||
input_schema={"type": "object"},
|
||||
meta={"include_in_prompt": False},
|
||||
)
|
||||
result = mcp_types.ListToolsResult(tools=[included, excluded])
|
||||
|
||||
post_process_tools_description(result)
|
||||
|
||||
assert result.tools == [included]
|
||||
|
||||
def test_builtin_tools_consistency(self):
|
||||
"""MCP_BUILTIN_TOOLS must match BUILTIN_TOOL_TO_MCP_SERVER_LABEL values."""
|
||||
from vllm.entrypoints.openai.parser.harmony_utils import (
|
||||
|
||||
@@ -58,14 +58,14 @@ def post_process_tools_description(
|
||||
) -> "ListToolsResult":
|
||||
# Adapt the MCP tool result for Harmony
|
||||
for tool in list_tools_result.tools:
|
||||
tool.inputSchema = trim_schema(tool.inputSchema)
|
||||
tool.input_schema = trim_schema(tool.input_schema)
|
||||
|
||||
# Some tools schema don't need to be part of the prompt (e.g. simple text
|
||||
# in text out for Python)
|
||||
list_tools_result.tools = [
|
||||
tool
|
||||
for tool in list_tools_result.tools
|
||||
if getattr(tool.annotations, "include_in_prompt", True)
|
||||
if (tool.meta or {}).get("include_in_prompt", True)
|
||||
]
|
||||
|
||||
return list_tools_result
|
||||
@@ -121,13 +121,13 @@ class MCPToolServer(ToolServer):
|
||||
list_tools_response = post_process_tools_description(list_tools_response)
|
||||
|
||||
tool_from_mcp = ToolNamespaceConfig(
|
||||
name=initialize_response.serverInfo.name,
|
||||
name=initialize_response.server_info.name,
|
||||
description=initialize_response.instructions,
|
||||
tools=[
|
||||
ToolDescription.new(
|
||||
name=tool.name,
|
||||
description=tool.description,
|
||||
parameters=tool.inputSchema,
|
||||
parameters=tool.input_schema,
|
||||
)
|
||||
for tool in list_tools_response.tools
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user