fix(runtime): a2a_mcp_server __name__ guard — module-as-script + test imports #16

Closed
infra-runtime-be wants to merge 1 commits from runtime/fix-a2a-mcp-module-invocation into main

1 Commits

Author SHA1 Message Date
0e67b0d005 fix(runtime): __name__ guard in a2a_mcp_server allows module-as-script and test imports
Some checks failed
ci / mirror-guard (pull_request) Failing after 5s
Secret scan / Scan diff for credential-shaped strings (pull_request) Successful in 5s
- Restructure main() to accept (transport, port) params so argparse
  moves into the __name__ guard block, not the function body.
- Replace the fragile __spec__.name check with a reliable basename
  comparison: os.path.basename(sys.argv[0]) == os.path.basename(__spec__.origin).
  Fires for `python a2a_mcp_server.py` and `python -m
  molecule_runtime.a2a_mcp_server`, but NOT for test imports where
  sys.argv[0] is the outer runner (pytest, python -c, etc.).
- Add missing `import uvicorn` inside _run_http_server() so the HTTP
  transport actually starts (was a pre-existing bug — uvicorn was used
  but never imported).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-12 04:40:12 +00:00