The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(mcp): read the elicitation schema under the SDK's real field name
elphamale23a86594cc18
diff --git a/tests/tools/test_mcp_elicitation.py b/tests/tools/test_mcp_elicitation.pyindex a7506f41ab5..628ac5cf643 100644--- a/tests/tools/test_mcp_elicitation.py+++ b/tests/tools/test_mcp_elicitation.py@@ -282,3 +282,51 @@ class TestElicitationHandlerContextBridge:result = asyncio.run(handler(context=None, params=params))assert result.action == "decline"+++class TestRequestedSchemaFieldName:+ """The requested schema must be read off the *real* SDK model.++ Every other test in this file builds a duck-typed ``SimpleNamespace``+ stand-in for the params object. That keeps them cheap, but it means none+ of them can catch the handler reading a field name the SDK model does not+ actually have -- the stand-in simply has whatever name the test wrote.++ The SDK spells this field ``requestedSchema`` on mcp 1.x and+ ``requested_schema`` on 2.0 (which renamed model fields to snake_case and+ kept camelCase only as a serialization alias, which pydantic does not+ expose to attribute access). Constructing with the camelCase spelling+ works on both -- 2.0 accepts it as the alias -- so this test pins the+ behaviour to the real model on whichever SDK is installed.+ """++ def test_real_sdk_params_schema_reaches_the_consent_description(self):+ from mcp.types import ElicitRequestFormParams++ params = ElicitRequestFormParams(+ message="authorize a payment of $0.50",+ requestedSchema={+ "type": "object",+ "properties": {+ "card_number": {+ "type": "string",+ "description": "card to charge",+ },+ },+ },+ )+ handler = ElicitationHandler("pay", {"timeout": 5})+ captured: dict = {}++ def _capture(*args, **kwargs):+ captured["description"] = kwargs.get("description") or (+ args[1] if len(args) > 1 else ""+ )+ return "decline"++ with patch("tools.approval.request_elicitation_consent", _capture):+ asyncio.run(handler(context=None, params=params))++ # An empty schema renders the generic "Approval requested by ..."+ # fallback, so the field name is what proves the schema was read.+ assert "card_number" in (captured.get("description") or ""), captureddiff --git a/tools/mcp_tool.py b/tools/mcp_tool.pyindex bd8b273b5ee..297b83cc552 100644--- a/tools/mcp_tool.py+++ b/tools/mcp_tool.py@@ -2144,7 +2144,19 @@ class ElicitationHandler:message = getattr(params, "message", "") or (f"MCP server '{self.server_name}' is requesting your approval")- schema = getattr(params, "requested_schema", {}) or {}+ # The SDK model spells this field ``requestedSchema`` on mcp 1.x (the+ # pinned version) and ``requested_schema`` on 2.0, which renamed model+ # fields to snake_case and kept camelCase only as a serialization+ # alias -- and pydantic aliases do not apply to attribute access. A+ # single-spelling read therefore returns the ``{}`` default on the+ # other generation, and _format_elicitation_schema_summary degrades to+ # its generic "Approval requested by ..." line, so the user is asked to+ # approve without being told which fields the server wants.+ schema = (+ getattr(params, "requestedSchema", None)+ or getattr(params, "requested_schema", None)+ or {}+ )description = _format_elicitation_schema_summary(schema, self.server_name)logger.info(