Repository navigation
test(sdk): stabilize MCP stdio integration tests - #4301
Conversation
Co-authored-by: openhands <openhands@all-hands.dev>
Python API breakage checks — ✅ PASSEDResult: ✅ PASSED |
REST API breakage checks (OpenAPI) — ✅ PASSEDResult: ✅ PASSED |
all-hands-bot
left a comment
There was a problem hiding this comment.
✅ QA Report: PASS
The MCP stdio stabilization works as intended: the old external uvx mcp-server-fetch path reproduced the reported failure, while the PR's local stdio FastMCP server was discovered and executed successfully.
Does this PR achieve its stated goal?
Yes. The stated goal was to fix CI instability caused by mcp-server-fetch importing the removed McpError symbol from newer MCP packages. I reproduced that exact failure on the base branch, then exercised the PR head with a real SDK create_mcp_tools(...) stdio connection: it discovered one fetch tool in ~0.75s, exposed the expected url/max_length schema, and returned expected content for normal and truncated calls.
| Phase | Result |
|---|---|
| Environment Setup | ✅ make build completed successfully; no tests, linters, formatters, or pre-commit hooks were run by QA. |
| CI Status | ⏳ At review time: 20 checks successful, 8 still in progress, 2 skipped, no failures observed. |
| Functional Verification | ✅ Real SDK MCP stdio discovery and tool execution worked on the PR path; base path reproduced the external dependency failure. |
Functional Verification
Test 1: MCP stdio fetch server discovery and execution
Step 1 — Reproduce / establish baseline without the fix:
Checked out origin/main in a temporary worktree, bootstrapped it with make build, then ran the old external-server path through the SDK entry point:
OPENHANDS_SUPPRESS_BANNER=1 uv run python - <<'PY'
import time
from openhands.sdk.mcp import create_mcp_tools
from openhands.sdk.mcp.config import coerce_mcp_config
start = time.monotonic()
config = {"fetch": {"command": "uvx", "args": ["mcp-server-fetch"]}}
try:
client = create_mcp_tools(coerce_mcp_config(config), timeout=20.0)
try:
print(f"RESULT: success tool_count={len(client.tools)} names={[tool.name for tool in client.tools]} elapsed={time.monotonic()-start:.2f}s")
finally:
client.sync_close()
except Exception as exc:
print(f"RESULT: failure type={type(exc).__name__} elapsed={time.monotonic()-start:.2f}s")
print(str(exc))
PYObserved output excerpt:
Traceback (most recent call last):
File "/home/runner/.cache/uv/archive-v0/opPyryf62_MauXY-/bin/mcp-server-fetch", line 6, in <module>
from mcp_server_fetch import main
File "/home/runner/.cache/uv/archive-v0/opPyryf62_MauXY-/lib/python3.13/site-packages/mcp_server_fetch/server.py", line 6, in <module>
from mcp.shared.exceptions import McpError
ImportError: cannot import name 'McpError' from 'mcp.shared.exceptions' (...). Did you mean: 'MCPError'?
RESULT: failure type=McpError elapsed=0.81s
Connection closed
This confirms the reported bug exists on the old path: the external mcp-server-fetch process crashes during startup before the SDK can complete stdio MCP discovery.
Step 2 — Apply the PR's changes:
Switched back to PR head bb62891b152ceb905f8a488764e92d6d9b8bb0d0, which uses the in-repository stdio FastMCP server launched with the active Python interpreter.
Step 3 — Re-run with the fix in place:
Ran the equivalent SDK flow against the PR's local stdio server and made real tool calls:
OPENHANDS_SUPPRESS_BANNER=1 uv run python - <<'PY'
import sys
import time
from pathlib import Path
from openhands.sdk.mcp import create_mcp_tools
from openhands.sdk.mcp.config import coerce_mcp_config
start = time.monotonic()
config = {
"fetch": {
"command": sys.executable,
"args": ["-m", "tests.sdk.mcp.stdio_test_server"],
"cwd": str(Path.cwd()),
}
}
client = create_mcp_tools(coerce_mcp_config(config), timeout=10.0)
try:
tool = client.tools[0]
dump = tool.model_dump()
print(f"DISCOVERY: tool_count={len(client.tools)} names={[tool.name for tool in client.tools]} elapsed={time.monotonic()-start:.2f}s")
print(f"SCHEMA_PROPERTIES: {sorted(dump['mcp_tool']['inputSchema']['properties'])}")
print(f"SCHEMA_REQUIRED: {dump['mcp_tool']['inputSchema'].get('required')}")
normal = client.call_async_from_sync(client.call_tool_mcp, "fetch", {"url": "https://example.com/qa", "max_length": 5000}, timeout=10.0)
truncated = client.call_async_from_sync(client.call_tool_mcp, "fetch", {"url": "https://example.com/qa", "max_length": 12}, timeout=10.0)
print(f"NORMAL_CONTENT: {normal.content[0].text!r}")
print(f"TRUNCATED_CONTENT: {truncated.content[0].text!r}")
finally:
client.sync_close()
PYObserved output excerpt:
INFO Starting MCP server 'stdio-test-server' with transport 'stdio'
{"message": "Created 1 MCP tools", ...}
DISCOVERY: tool_count=1 names=['fetch'] elapsed=0.75s
SCHEMA_PROPERTIES: ['max_length', 'url']
SCHEMA_REQUIRED: ['url']
NORMAL_CONTENT: 'Fetched https://example.com/qa'
TRUNCATED_CONTENT: 'Fetched http'
This confirms the PR removes the failing external dependency from the stdio path while preserving real subprocess startup, MCP tool discovery, the expected fetch input shape, and actual tool execution under the reduced 10s timeout.
Issues Found
None.
This review was created by an AI agent (OpenHands) on behalf of the user.
HUMAN:
Fix CI failure with MCP stdio
AGENT:
Why
The SDK test suite installs
mcp-server-fetchat runtime throughuvx. MCP SDK 2.0.0 removed the oldMcpErrorsymbol while the fetch server still imports it, so five stdio integration tests began failing without an SDK code change.Summary
fetchinput shape used by the affected tests.Issue Number
N/A — external dependency CI regression after MCP SDK 2.0.0.
How to Test
The focused integration path launches the local server in a real subprocess and exercises MCP discovery and execution over stdio.
uv run pytest -q tests/sdk/mcp/test_create_mcp_tool.py::test_create_mcp_tools_stdio_server tests/sdk/mcp/test_mcp_tool_kind_field.pyResult:
5 passed in 3.12sCI=true uv run python -m pytest -q -n auto tests/sdk/mcpResult:
122 passed in 8.75suv run pre-commit run --files tests/sdk/mcp/stdio_test_server.py tests/sdk/mcp/test_create_mcp_tool.py tests/sdk/mcp/test_mcp_tool_kind_field.pyResult: all checks passed.
Video/Screenshots
N/A — test-only change.
Type
Notes
This extracts the MCP stdio test stabilization already validated in #3948 into a focused PR. It changes no production code and includes no Windows-related changes.
Agent Server images for this PR
• GHCR package: https://github.com/OpenHands/agent-sdk/pkgs/container/agent-server
Variants & Base Images
eclipse-temurin:17-jdknikolaik/python-nodejs:python3.13-nodejs22-slimgolang:1.21-bookwormPull (multi-arch manifest)
# Each variant is a multi-arch manifest supporting both amd64 and arm64 docker pull ghcr.io/openhands/agent-server:bb62891-pythonRun
All tags pushed for this build
About Multi-Architecture Support
bb62891-python) is a multi-arch manifest supporting both amd64 and arm64bb62891-python-amd64) are also available if needed