Repository navigation
fix(examples): mcp_tool_example --serve awaits serve_async - #378
Conversation
main_serve() runs under asyncio.run() and called the synchronous b2a_sdk.mcp.serve(), which calls asyncio.run() again, so --serve exited 1 with "asyncio.run() cannot be called from a running event loop". Await serve_async() instead. Fixes #359 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: CS <cs@CSs-MacBook-Pro.local>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 45 minutes. View limit details
Pre-merge checks:
|
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
…mcp-example-serve Signed-off-by: GitHub <noreply@github.com> # Conflicts: # examples/tests/test_example_scripts.py Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
|
READY FOR QA a7b564d Fixes #359. fix(examples): mcp_tool_example --serve awaits serve_async. The branch was updated from main, so this head replaces any earlier one. CI result, License result and gitleaks are green on this commit, the PR is up to date with main, and there are no open review threads. |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: PetrefiedThunder <131207452+PetrefiedThunder@users.noreply.github.com>
PetrefiedThunder
left a comment
There was a problem hiding this comment.
Independent review (claude): PASS
Branch updated: merged origin/main (d4f330e) into fix/359-mcp-example-serve with a normal merge commit, new head e89aef4. All checks on e89aef4 pass, including CI result, License result, and gitleaks; merge state CLEAN. No conflicts; main only touched gateway, CI config, and docs, none of which overlap this PR.
Correctness
- examples/mcp_tool_example.py:204-213: main_serve() is dispatched by asyncio.run(main_serve()) at examples/mcp_tool_example.py:235, so awaiting serve_async() is the right fix. The arguments (transport, api_url) match the serve_async signature at sdk/python/src/b2a_sdk/mcp.py:257. serve_async itself awaits mcp.run_stdio_async() (sdk/python/src/b2a_sdk/mcp.py:408), so there is no second nested loop further down. No SDK change is needed.
- The inline comment at examples/mcp_tool_example.py:208-209 matches the code.
Tests
- examples/tests/test_example_scripts.py:165: I confirmed the regression test fails against the pre-fix example from main with "RuntimeError: asyncio.run() cannot be called from a running event loop" and passes on this branch. Patching serve with a nested asyncio.run sentinel (line 182) makes the old code path fail loudly, which is a good guard.
- Local runs on the merged head (Python 3.12): sdk/python/tests 476 passed. examples/tests 55 passed, 1 failed; the failure is test_permit_stripe_refund_retry.py::test_retry_returns_same_receipt_one_debit_and_skips_stripe ("unable to open database file"). It passes when its file runs alone and still fails with this PR's new test deselected, so it is a pre-existing cross-test interaction on main, not caused by this PR or the merge.
- Ruff check and format on both changed files: clean.
Non-blocking notes
- CI does not run examples/tests. .github/workflows/ci.yml:146-152 only adds examples/ subprojects to the matrix, and the detect_projects.py output does not include examples. So the new regression test (and the "55 passed" claim in the PR body) is only verified locally. Worth a follow-up issue to gate examples/tests in CI; out of scope here.
- The pre-existing order-dependent failure above should get its own issue as well.
- Merge order: #380 is still open and also appends to examples/tests/test_example_scripts.py. Whichever lands second needs a main merge keeping both test blocks, as the PR body already says.
Docs claims in the PR body (root cause, fix, test failing on main) match the code.
IntelliJ inspection could not run: the worktree is not open as an IntelliJ project. I used ruff on the changed files instead.
Fixes #359
Root cause
examples/mcp_tool_example.pydispatches--servethroughasyncio.run(main_serve()), andmain_serve()called the synchronousb2a_sdk.mcp.serve(), which callsasyncio.run()again. Python refuses a nestedasyncio.run(), so the command exited 1 withRuntimeError: asyncio.run() cannot be called from a running event loop.Fix
main_serve()now awaitsb2a_sdk.mcp.serve_async()with the same arguments. No SDK change.Verification
examples/tests/test_example_scripts.pyrunsmain_serve()underasyncio.run()and checks that the async server is awaited with the configured URL. It fails onmainand passes here.main,python examples/mcp_tool_example.py --serveexits 1. On this branch anmcp1.30 stdioClientSessionstarted on the same command initializes and lists['partner.notes.write'].python -m pytest examples/tests: 55 passed.python -m pytest sdk/python/tests: 472 passed. Ruff check and format on all detected projects: clean.uv build sdk/python: builds wheel and sdist.Related: the tools served by
--serveadvertise akwargswrapper schema onmain; that is #360, fixed separately in #374.Merge order note
#380 (issue #361) also appends tests to the end of
examples/tests/test_example_scripts.py. Whichever of #378 and #380 merges second will need its branch updated from main, with both test blocks kept.🤖 Generated with Claude Code
Note
Low Risk
Example script and test-only changes; no SDK or gateway behavior modified.
Overview
Fixes
python examples/mcp_tool_example.py --servefailing with a nested event loop when the CLI already runsmain_serve()underasyncio.run().main_serve()nowawaitsb2a_sdk.mcp.serve_async()with the same stdio transport andB2A_API_URLinstead of calling the syncserve()wrapper (which starts its ownasyncio.run()).A regression test
test_serve_awaits_the_async_server_inside_the_running_loopmonkeypatches the MCP helpers and assertsmain_serve()awaits the async server with the expected kwargs when a loop is already running (issue #359). Minor test-file import ordering cleanup only.Reviewed by Cursor Bugbot for commit e89aef4. Bugbot is set up for automated code reviews on this repo. Configure here.