Title: test: convert test_integration.py to in-memory transport (fix flaky) by maxisbey · Pull Request #2277 · modelcontextprotocol/python-sdk · GitHub
Open Graph Title: test: convert test_integration.py to in-memory transport (fix flaky) by maxisbey · Pull Request #2277 · modelcontextprotocol/python-sdk
X Title: test: convert test_integration.py to in-memory transport (fix flaky) by maxisbey · Pull Request #2277 · modelcontextprotocol/python-sdk
Description: Summary Converts tests/server/mcpserver/test_integration.py from subprocess+TCP to the in-memory Client(mcp) pattern, eliminating port-race flakiness under pytest-xdist. Closes #1776. Root Cause The server_port fixture allocates a port by binding to 0 then releasing the socket before the subprocess can bind it: @pytest.fixture def server_port() -> int: with socket.socket() as s: s.bind(("127.0.0.1", 0)) return s.getsockname()[1] # socket closed → port released → TOCTOU window With pytest -n auto, another xdist worker's subprocess can grab the same port first. wait_for_server only checks TCP connect, so it happily accepts a connection to the wrong server. CI evidence in job 66317185239 shows a 7ms 404 on /sse — not enough time for a subprocess to start, meaning wait_for_server saw a different worker's server. Verification this is a port race, not a uvicorn lifespan gap mcp.sse_app() returns Starlette(routes=routes) with no lifespan — routes are synchronously constructed. Uvicorn+Starlette never serves 404 before 200 for a no-lifespan app; a 404 on /sse can only mean a different server bound that port. Fix None of these 20 parametrized tests (10 × 2 transports) exercise transport-specific behavior — they test MCP protocol features (tools, resources, prompts, progress, sampling, elicitation, notifications, completion, structured output). Converted all to use Client(mcp) in-memory, matching the established pattern in test_server.py (×16) and test_url_elicitation.py (×11). Transport behavior remains covered separately in tests/server/test_sse_security.py, test_streamable_http_{manager,security}.py, and tests/shared/test_{sse,streamable_http,ws}.py. Impact Before After Tests 20 (parametrized over 2 transports) 10 Runtime ~20s (subprocess spawn + uvicorn startup) ~0.5s Lines 643 359 (−284) Flakiness Port race under xdist None (in-process, deterministic) AI Disclaimer
Open Graph Description: Summary Converts tests/server/mcpserver/test_integration.py from subprocess+TCP to the in-memory Client(mcp) pattern, eliminating port-race flakiness under pytest-xdist. Closes #1776. Root Cause Th...
X Description: Summary Converts tests/server/mcpserver/test_integration.py from subprocess+TCP to the in-memory Client(mcp) pattern, eliminating port-race flakiness under pytest-xdist. Closes #1776. Root Cause Th...
Opengraph URL: https://github.com/modelcontextprotocol/python-sdk/pull/2277
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:4dc5cb99-afb1-0d7d-8df4-2facf6950595 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | E2B4:2F3B67:6929BD:8A3761:6A5B34A1 |
| html-safe-nonce | 4b4769d8d2be5bf00016a318566da3e3500877bd2f1476787b09e17af425991e |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMkI0OjJGM0I2Nzo2OTI5QkQ6OEEzNzYxOjZBNUIzNEExIiwidmlzaXRvcl9pZCI6IjY4NTk1NzgzMjQxOTA3MDQ4MDEiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 40e72cdfd5a9eefe6efb99075067096284b22808def389260c072922451e8cbc |
| hovercard-subject-tag | pull_request:3385472719 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/modelcontextprotocol/python-sdk/pull/2277/files |
| twitter:image | https://avatars.githubusercontent.com/u/224885523?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/224885523?s=400&v=4 |
| og:image:alt | Summary Converts tests/server/mcpserver/test_integration.py from subprocess+TCP to the in-memory Client(mcp) pattern, eliminating port-race flakiness under pytest-xdist. Closes #1776. Root Cause Th... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5290d7e14309ad1e76106a9c4237bd1041517e83ea182c8ab756752cb0c6940b |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/modelcontextprotocol/python-sdk git https://github.com/modelcontextprotocol/python-sdk.git |
| octolytics-dimension-user_id | 182288589 |
| octolytics-dimension-user_login | modelcontextprotocol |
| octolytics-dimension-repository_id | 862584018 |
| octolytics-dimension-repository_nwo | modelcontextprotocol/python-sdk |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 862584018 |
| octolytics-dimension-repository_network_root_nwo | modelcontextprotocol/python-sdk |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 9c975978430e9ad293956f2bbdaf153b1bd84a99 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width