Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions python/packages/core/agent_framework/_mcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
15 changes: 15 additions & 0 deletions python/packages/core/tests/core/test_mcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=[])
Expand Down
Loading