From d25d53f612de2ab072b6c2cff847d5c74d518627 Mon Sep 17 00:00:00 2001 From: Anish Mehta Date: Thu, 24 Sep 2026 22:44:21 +0530 Subject: [PATCH] Python: fix(core): leave out description for MCP prompt arguments that have none --- python/packages/core/agent_framework/_mcp.py | 9 +++++---- python/packages/core/tests/core/test_mcp.py | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/python/packages/core/agent_framework/_mcp.py b/python/packages/core/agent_framework/_mcp.py index 8c626de1309..b97f38802d7 100644 --- a/python/packages/core/agent_framework/_mcp.py +++ b/python/packages/core/agent_framework/_mcp.py @@ -529,10 +529,11 @@ def _get_input_model_from_mcp_prompt(prompt: types.Prompt) -> dict[str, Any]: for prompt_argument in prompt.arguments: # For prompts, all arguments are typically string type unless specified otherwise - properties[prompt_argument.name] = { - "type": "string", - "description": prompt_argument.description if hasattr(prompt_argument, "description") else "", - } + # `description` is optional on PromptArgument and None when absent, which is not + # a valid JSON Schema description, so leave the key out instead. + properties[prompt_argument.name] = {"type": "string"} + if prompt_argument.description is not None: + properties[prompt_argument.name]["description"] = prompt_argument.description if prompt_argument.required: required.append(prompt_argument.name) diff --git a/python/packages/core/tests/core/test_mcp.py b/python/packages/core/tests/core/test_mcp.py index 90eb00620b6..ee57332aaac 100644 --- a/python/packages/core/tests/core/test_mcp.py +++ b/python/packages/core/tests/core/test_mcp.py @@ -2203,6 +2203,21 @@ def test_get_input_model_from_mcp_prompt(): assert "arg2" not in result["required"] +def test_get_input_model_from_mcp_prompt_argument_without_description(): + """An argument with no description gets no description key, not `"description": None`.""" + prompt = types.Prompt( + name="test_prompt", + arguments=[ + types.PromptArgument(name="topic", required=True), + types.PromptArgument(name="tone", description="Tone of voice"), + ], + ) + result = _get_input_model_from_mcp_prompt(prompt) + + assert result["properties"]["topic"] == {"type": "string"} + assert result["properties"]["tone"] == {"type": "string", "description": "Tone of voice"} + + def test_get_input_model_from_mcp_prompt_without_arguments(): """Test prompt schema generation when no prompt arguments are defined.""" prompt = types.Prompt(name="empty_prompt", description="No args prompt", arguments=[])