Repository navigation
Description
Description
Observed the same behavior on two OpenAI-compatible Responses API backends:
- local LM Studio host
- Aliyun-hosted model service
On both backends, a simple local stdio MCP server such as calculator works on the same Agent Framework + MCPStdioTool + /v1/responses path, but the official matlab-mcp-core-server does not and fails before a real tool invocation completes.
This suggests the problem is narrower than "Responses API does not support local MCP" or "all local MCP servers fail". It appears to be specific to this class of MCP server.
Because Agent Framework implements local MCP by loading MCP tools and exposing them as normal tools/function calls, the current suspicion is that the incompatibility happens in that decomposition step: simpler MCP servers such as calculator still work, but matlab-mcp-core-server does not.
Code Sample
# Code Sample
## MATLAB ver.
import asyncio
import traceback
from pathlib import Path
from agent_framework import Agent, MCPStdioTool
from agent_framework.openai import OpenAIResponsesClient
BASE_URL = "http://127.0.0.1:1234/v1"
MODEL = "qwen/qwen3.5-9b"
PROMPT = "Please call detect_matlab_toolboxes and summarize the detected MATLAB version and toolbox names."
WORKING_DIR = Path("/Users/***/projects/skills-demo")
MATLAB_MCP_COMMAND = "/Users/***/Developer/mcp-servers/matlab-core/matlab-mcp-core-server"
MATLAB_ROOT = "/Applications/MATLAB_R2025b.app"
MATLAB_DISPLAY_MODE = "nodesktop"
ALLOWED_TOOLS = ["detect_matlab_toolboxes"]
async def main() -> int:
client = OpenAIResponsesClient(
model_id=MODEL,
base_url=BASE_URL,
api_key="lm-studio",
)
tool = MCPStdioTool(
name="matlab",
command=MATLAB_MCP_COMMAND,
args=[
f"--initial-working-folder={WORKING_DIR.resolve()}",
"--disable-telemetry=true",
f"--matlab-root={MATLAB_ROOT}",
f"--matlab-display-mode={MATLAB_DISPLAY_MODE}",
],
allowed_tools=ALLOWED_TOOLS or None,
request_timeout=120,
description="Official MATLAB MCP core server",
)
agent = Agent(
client=client,
instructions="Use the available tools when needed and answer the user request.",
tools=[tool],
)
try:
response = await agent.run(PROMPT)
except Exception as exc:
print(f"{type(exc).__name__}: {exc}")
traceback.print_exc()
return 1
print(response.text)
return 0
asyncio.run(main())
## Calculator ver.
Use the same structure as above, and replace only the MCP-specific constants, tool construction, and prompt:
- PROMPT = "Please call detect_matlab_toolboxes and summarize the detected MATLAB version and toolbox names."
- WORKING_DIR = Path("/Users/***/projects/skills-demo")
- MATLAB_MCP_COMMAND = "/Users/***/Developer/mcp-servers/matlab-core/matlab-mcp-core-server"
- MATLAB_ROOT = "/Applications/MATLAB_R2025b.app"
- MATLAB_DISPLAY_MODE = "nodesktop"
- ALLOWED_TOOLS = ["detect_matlab_toolboxes"]
+ PROMPT = "Please use the calculator tool to compute 17 * (5 + 3), and return only the final numeric result."
+ CALCULATOR_MCP_COMMAND = "uvx"
+ CALCULATOR_MCP_ARGS = ["mcp-server-calculator"]
+ ALLOWED_TOOLS = ["calculate"]
- tool = MCPStdioTool(
- name="matlab",
- command=MATLAB_MCP_COMMAND,
- args=[
- f"--initial-working-folder={WORKING_DIR.resolve()}",
- "--disable-telemetry=true",
- f"--matlab-root={MATLAB_ROOT}",
- f"--matlab-display-mode={MATLAB_DISPLAY_MODE}",
- ],
- allowed_tools=ALLOWED_TOOLS or None,
- request_timeout=120,
- description="Official MATLAB MCP core server",
- )
+ tool = MCPStdioTool(
+ name="calculator",
+ command=CALCULATOR_MCP_COMMAND,
+ args=CALCULATOR_MCP_ARGS,
+ allowed_tools=ALLOWED_TOOLS or None,
+ request_timeout=120,
+ description="Simple calculator MCP server",
+ )Error Messages / Stack Traces
## MATLAB Script
The main failure is a `400 invalid_request_error` returned from the OpenAI-compatible `Responses API` backend:
openai.BadRequestError: Error code: 400 - {
'error': {
'message': 'Invalid',
'type': 'invalid_request_error',
'param': 'tools.0.type',
'code': 'invalid_string'
}
}
Agent Framework then surfaces that as:
agent_framework.exceptions.ChatClientException:
<class 'agent_framework.openai._responses_client.OpenAIResponsesClient'>
service failed to complete the prompt:
Error code: 400 - {
'error': {
'message': 'Invalid',
'type': 'invalid_request_error',
'param': 'tools.0.type',
'code': 'invalid_string'
}
}
Minimal traceback:
File ".../mcp-test/repro_matlab_mcp.py", line 46, in main
response = await agent.run(PROMPT)
File ".../site-packages/agent_framework/_agents.py", line 838, in _run_non_streaming
response = await self.client.get_response(...)
File ".../site-packages/agent_framework/_tools.py", line 2139, in _get_response
response = await super_get_response(...)
File ".../site-packages/agent_framework/openai/_responses_client.py", line 341, in _get_response
self._handle_request_error(ex)
File ".../site-packages/agent_framework/openai/_responses_client.py", line 266, in _handle_request_error
raise ChatClientException(...)
## Cleanup-time error
After the main MATLAB failure, there is also a separate cleanup-time exception from the stdio client:
RuntimeError: Attempted to exit cancel scope in a different task than it was entered in
This same cleanup issue can also appear after successful MCP runs, so it does not appear to be the primary cause of the MATLAB incompatibility.Package Versions
agent-framework-core 1.0.0rc2, openai 2.24.0, mcp 1.26.0, anyio 4.12.1
Python Version
Python 3.13
Additional Context
No response
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
Python: Sanitize MCP tool schemas before sending to LLM APIs
eavanvalkenburg commentedon Mar 11, 2026
So does this work against the OpenAI itself? if it's not a problem there, then we shouldn't fix this in our code, then we should raise a issue in LM Studio. CC Giles Odigwe (@giles17)
o3o1 commentedon Mar 11, 2026
Not working on OpenAI itself as well. Using
v1/responsewithgpt-5-mini-2025-08-07, get the same results(works fine on calculator but failed with Matlab). The error message is as follows:Got the same cleanup issue as well.
RuntimeError: Attempted to exit cancel scope in a different task than it was entered ineavanvalkenburg commentedon Mar 12, 2026
can you share what the actual failing schema is?
o3o1 commentedon Mar 12, 2026
Code
Console Output
eavanvalkenburg commentedon Mar 12, 2026
I would like the see the generated schema of the tools, not the code, I don't know this:
MATLAB_MCP_COMMAND = "/Users/***/Developer/mcp-servers/matlab-core/matlab-mcp-core-server"o3o1 commentedon Mar 12, 2026
I captured the full request payloads sent to
/v1/responses.The failing MATLAB case is:
{ "tools": [ { "name": "detect_matlab_toolboxes", "parameters": { "type": "object", "additionalProperties": false }, "strict": false, "type": "function", "description": "Returns information about installed MATLAB and toolboxes, including version numbers." } ], "input": [ { "type": "message", "role": "system", "content": [ { "type": "input_text", "text": "Use the available tools when needed and answer the user request." } ] }, { "type": "message", "role": "user", "content": [ { "type": "input_text", "text": "Please call detect_matlab_toolboxes and summarize the detected MATLAB version and toolbox names." } ] } ], "model": "gpt-5-mini-2025-08-07", "tool_choice": "auto" }The working calculator case is:
{ "tools": [ { "name": "calculate", "parameters": { "properties": { "expression": { "title": "Expression", "type": "string" } }, "required": [ "expression" ], "title": "calculateArguments", "type": "object", "additionalProperties": false }, "strict": false, "type": "function", "description": "Calculates/evaluates the given expression." } ], "input": [ { "type": "message", "role": "system", "content": [ { "type": "input_text", "text": "Use the available tools when needed and answer the user request." } ] }, { "type": "message", "role": "user", "content": [ { "type": "input_text", "text": "Please use the calculator tool to compute 17 * (5 + 3), and return only the final numeric result." } ] } ], "model": "gpt-5-mini-2025-08-07", "tool_choice": "auto" }The main structural difference is that the MATLAB tool is a zero argument tool and its parameters schema is an empty object schema.
Fix zero-argument MCP tool schema missing 'properties' key (microsoft…
Address review feedback for microsoft#4540: improve test robustness a…
Address review feedback for microsoft#4540: Python: [Bug]: Local stdi…
Python: Fix MCP tool schema normalization for zero-argument tools mis…