Skip to content
Open
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
2 changes: 1 addition & 1 deletion python/semantic_kernel/connectors/mcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def _get_parameter_dict_from_mcp_prompt(prompt: types.Prompt) -> list[dict[str,
{
"name": prompt_argument.name,
"description": prompt_argument.description,
"is_required": True,
"is_required": bool(prompt_argument.required),
"type_object": str,
}
for prompt_argument in prompt.arguments
Expand Down
33 changes: 33 additions & 0 deletions python/tests/unit/connectors/mcp/test_mcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -900,3 +900,36 @@ def echo() -> str:
result = await client.call_tool(expected_name, {})
assert not result.isError
assert result.content == [types.TextContent(type="text", text="hello")]


async def test_mcp_prompt_optional_arguments_are_not_required():
plugin = MCPStdioPlugin(name="test", command="echo", load_tools=False)
plugin.session = AsyncMock(spec=ClientSession)
plugin.session.list_prompts.return_value = types.ListPromptsResult(
prompts=[
types.Prompt(
name="review",
arguments=[
types.PromptArgument(name="code", required=True),
types.PromptArgument(name="style", required=False),
types.PromptArgument(name="language"),
],
)
]
)
plugin.session.get_prompt.return_value = types.GetPromptResult(
messages=[types.PromptMessage(role="user", content=types.TextContent(type="text", text="review this"))]
)
await plugin.load_prompts()
kernel = Kernel()
kernel.add_plugin(plugin, "test")
function = kernel.get_function("test", "review")

assert {p.name: p.is_required for p in function.metadata.parameters} == {
"code": True,
"style": False,
"language": False,
}
result = await kernel.invoke(function, code="x = 1")
assert str(result) == "review this"
plugin.session.get_prompt.assert_awaited_once_with("review", arguments={"code": "x = 1"})
Loading