Skip to content

test(sdk): stabilize MCP stdio integration tests - #4301

Merged
neubig merged 2 commits into
mainfrom
fix-mcp-stdio-tests
Jul 29, 2026
Merged

neubig merged 2 commits into
mainfrom
fix-mcp-stdio-tests

Conversation

@simonrosenberg

@simonrosenberg simonrosenberg commented Jul 29, 2026 •

Copy link
Copy Markdown
Member

HUMAN:

Fix CI failure with MCP stdio


AGENT:

Why

The SDK test suite installs mcp-server-fetch at runtime through uvx. MCP SDK 2.0.0 removed the old McpError symbol while the fetch server still imports it, so five stdio integration tests began failing without an SDK code change.

Summary

  • Add a deterministic in-repository FastMCP stdio server with the same fetch input shape used by the affected tests.
  • Run it with the active Python interpreter instead of resolving and downloading a floating external package.
  • Keep real subprocess, stdio handshake, tool discovery, schema, and tool-call coverage while reducing the setup timeout from 120 seconds to 10 seconds.

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.py

Result: 5 passed in 3.12s

CI=true uv run python -m pytest -q -n auto tests/sdk/mcp

Result: 122 passed in 8.75s

uv 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.py

Result: all checks passed.

Video/Screenshots

N/A — test-only change.

Type

  • Bug fix
  • Feature
  • Refactor
  • Breaking change
  • Docs / chore

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

Variant Architectures Base Image Docs / Tags
java amd64, arm64 eclipse-temurin:17-jdk Link
python amd64, arm64 nikolaik/python-nodejs:python3.13-nodejs22-slim Link
golang amd64, arm64 golang:1.21-bookworm Link

Pull (multi-arch manifest)

# Each variant is a multi-arch manifest supporting both amd64 and arm64
docker pull ghcr.io/openhands/agent-server:bb62891-python

Run

docker run -it --rm \
  -p 8000:8000 \
  --name agent-server-bb62891-python \
  ghcr.io/openhands/agent-server:bb62891-python

All tags pushed for this build

ghcr.io/openhands/agent-server:bb62891-golang-amd64
ghcr.io/openhands/agent-server:bb62891b152ceb905f8a488764e92d6d9b8bb0d0-golang-amd64
ghcr.io/openhands/agent-server:fix-mcp-stdio-tests-golang-amd64
ghcr.io/openhands/agent-server:bb62891-golang_tag_1.21-bookworm-amd64
ghcr.io/openhands/agent-server:bb62891-golang-arm64
ghcr.io/openhands/agent-server:bb62891b152ceb905f8a488764e92d6d9b8bb0d0-golang-arm64
ghcr.io/openhands/agent-server:fix-mcp-stdio-tests-golang-arm64
ghcr.io/openhands/agent-server:bb62891-golang_tag_1.21-bookworm-arm64
ghcr.io/openhands/agent-server:bb62891-java-amd64
ghcr.io/openhands/agent-server:bb62891b152ceb905f8a488764e92d6d9b8bb0d0-java-amd64
ghcr.io/openhands/agent-server:fix-mcp-stdio-tests-java-amd64
ghcr.io/openhands/agent-server:bb62891-eclipse-temurin_tag_17-jdk-amd64
ghcr.io/openhands/agent-server:bb62891-java-arm64
ghcr.io/openhands/agent-server:bb62891b152ceb905f8a488764e92d6d9b8bb0d0-java-arm64
ghcr.io/openhands/agent-server:fix-mcp-stdio-tests-java-arm64
ghcr.io/openhands/agent-server:bb62891-eclipse-temurin_tag_17-jdk-arm64
ghcr.io/openhands/agent-server:bb62891-python-amd64
ghcr.io/openhands/agent-server:bb62891b152ceb905f8a488764e92d6d9b8bb0d0-python-amd64
ghcr.io/openhands/agent-server:fix-mcp-stdio-tests-python-amd64
ghcr.io/openhands/agent-server:bb62891-nikolaik_s_python-nodejs_tag_python3.13-nodejs22-slim-amd64
ghcr.io/openhands/agent-server:bb62891-python-arm64
ghcr.io/openhands/agent-server:bb62891b152ceb905f8a488764e92d6d9b8bb0d0-python-arm64
ghcr.io/openhands/agent-server:fix-mcp-stdio-tests-python-arm64
ghcr.io/openhands/agent-server:bb62891-nikolaik_s_python-nodejs_tag_python3.13-nodejs22-slim-arm64
ghcr.io/openhands/agent-server:bb62891-golang
ghcr.io/openhands/agent-server:bb62891b152ceb905f8a488764e92d6d9b8bb0d0-golang
ghcr.io/openhands/agent-server:fix-mcp-stdio-tests-golang
ghcr.io/openhands/agent-server:bb62891-golang_tag_1.21-bookworm
ghcr.io/openhands/agent-server:bb62891-java
ghcr.io/openhands/agent-server:bb62891b152ceb905f8a488764e92d6d9b8bb0d0-java
ghcr.io/openhands/agent-server:fix-mcp-stdio-tests-java
ghcr.io/openhands/agent-server:bb62891-eclipse-temurin_tag_17-jdk
ghcr.io/openhands/agent-server:bb62891-python
ghcr.io/openhands/agent-server:bb62891b152ceb905f8a488764e92d6d9b8bb0d0-python
ghcr.io/openhands/agent-server:fix-mcp-stdio-tests-python
ghcr.io/openhands/agent-server:bb62891-nikolaik_s_python-nodejs_tag_python3.13-nodejs22-slim

About Multi-Architecture Support

  • Each variant tag (e.g., bb62891-python) is a multi-arch manifest supporting both amd64 and arm64
  • Docker automatically pulls the correct architecture for your platform
  • Individual architecture tags (e.g., bb62891-python-amd64) are also available if needed

Co-authored-by: openhands <openhands@all-hands.dev>
@github-actions

github-actions Bot commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

Python API breakage checks — ✅ PASSED

Result: ✅ PASSED

Action log

@github-actions

github-actions Bot commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

REST API breakage checks (OpenAPI) — ✅ PASSED

Result: ✅ PASSED

Action log

@github-actions

github-actions Bot commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

Coverage

Coverage Report •
FileStmtsMissCoverMissing
TOTAL385801106571% 
report-only-changed-files is enabled. No files were changed during this commit :)

@simonrosenberg
simonrosenberg marked this pull request as ready for review July 29, 2026 10:53

@all-hands-bot all-hands-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 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))
PY

Observed 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()
PY

Observed 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.

@neubig
neubig merged commit 9627f82 into main Jul 29, 2026
41 checks passed
@neubig
neubig deleted the fix-mcp-stdio-tests branch July 29, 2026 11:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants