Skip to content

Commit aeddc6d

Browse files
author
Copilot
committed
Address review feedback for microsoft#4540: Python: [Bug]: Local stdio MCP works for calculator but fails for official matlab-mcp-core-server on LM Studio /v1/responses
1 parent 5f0b3b9 commit aeddc6d

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

‎python/packages/core/agent_framework/_mcp.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -905,6 +905,8 @@ async def load_tools(self) -> None:
905905
# Normalize inputSchema: ensure "properties" exists for object schemas.
906906
# Some MCP servers (e.g. zero-argument tools) omit "properties",
907907
# which causes OpenAI API to reject the schema with a 400 error.
908+
# Guard against non-conforming MCP servers that send inputSchema=None
909+
# despite the MCP spec typing it as dict[str, Any].
908910
input_schema = dict(tool.inputSchema or {})
909911
if input_schema.get("type") == "object" and "properties" not in input_schema:
910912
input_schema["properties"] = {}

‎python/packages/core/tests/core/test_mcp.py‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2087,13 +2087,21 @@ async def test_load_tools_adds_properties_to_zero_arg_tool_schema():
20872087
inputSchema=original_empty_schema,
20882088
),
20892089
]
2090+
2091+
# Simulate a non-conforming MCP server that sends inputSchema=None.
2092+
# types.Tool requires inputSchema to be a dict, so we use a MagicMock.
2093+
none_schema_tool = MagicMock()
2094+
none_schema_tool.name = "none_schema_tool"
2095+
none_schema_tool.description = "A tool with None inputSchema"
2096+
none_schema_tool.inputSchema = None
2097+
page.tools.append(none_schema_tool)
20902098
page.nextCursor = None
20912099

20922100
mock_session.list_tools = AsyncMock(return_value=page)
20932101

20942102
await tool.load_tools()
20952103

2096-
assert len(tool._functions) == 4
2104+
assert len(tool._functions) == 5
20972105

20982106
funcs_by_name = {f.name: f for f in tool._functions}
20992107

@@ -2118,6 +2126,10 @@ async def test_load_tools_adds_properties_to_zero_arg_tool_schema():
21182126
empty_params = funcs_by_name["empty_schema_tool"].parameters()
21192127
assert "properties" not in empty_params
21202128

2129+
# None inputSchema must produce an empty dict (guard against non-conforming servers)
2130+
none_params = funcs_by_name["none_schema_tool"].parameters()
2131+
assert none_params == {}
2132+
21212133
# Original inputSchema dicts must not be mutated
21222134
assert "properties" not in original_zero_arg_schema
21232135
assert "properties" not in original_string_schema

0 commit comments

Comments
 (0)