Title: serve(transport="both") + callable public_url crashes at startup: 'function' object has no attribute 'router' · Issue #676 · adcontextprotocol/adcp-client-python · GitHub
Open Graph Title: serve(transport="both") + callable public_url crashes at startup: 'function' object has no attribute 'router' · Issue #676 · adcontextprotocol/adcp-client-python
X Title: serve(transport="both") + callable public_url crashes at startup: 'function' object has no attribute 'router' · Issue #676 · adcontextprotocol/adcp-client-python
Description: Repro def my_resolver(request): return f"https://{request.headers.get('host')}/" serve(handler, transport="both", public_url=my_resolver) Observed Process exits cleanly with code 0 at lifespan startup; uvicorn logs: ERROR: Application st...
Open Graph Description: Repro def my_resolver(request): return f"https://{request.headers.get('host')}/" serve(handler, transport="both", public_url=my_resolver) Observed Process exits cleanly with code 0 at lifespan star...
X Description: Repro def my_resolver(request): return f"https://{request.headers.get('host')}/" serve(handler, transport="both", public_url=my_resolver) Observed Process exits cleanly ...
Opengraph URL: https://github.com/adcontextprotocol/adcp-client-python/issues/676
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"serve(transport=\"both\") + callable public_url crashes at startup: 'function' object has no attribute 'router'","articleBody":"## Repro\n\n```python\ndef my_resolver(request):\n return f\"https://{request.headers.get('host')}/\"\n\nserve(handler, transport=\"both\", public_url=my_resolver)\n```\n\n## Observed\n\nProcess exits cleanly with code 0 at lifespan startup; uvicorn logs:\n\n```\nERROR: Application startup failed. Exiting.\nAttributeError: 'function' object has no attribute 'router'\n```\n\nFull traceback:\n\n```\nFile \"/.venv/.../adcp/server/serve.py\", line 1705, in _composed_lifespan\n async with a2a_inner.router.lifespan_context(a2a_inner):\n ^^^^^^^^^^^^^^^^\nAttributeError: 'function' object has no attribute 'router'\n```\n\n## Root cause\n\nIn `_serve_mcp_and_a2a` (`adcp/server/serve.py`), the lifespan composer at lines 1702–1706 assumes both `mcp_inner` and `a2a_inner` are Starlette apps with `.router`:\n\n```python\nasync def _composed_lifespan(_app):\n async with mcp_inner.router.lifespan_context(mcp_inner):\n async with a2a_inner.router.lifespan_context(a2a_inner):\n yield\n```\n\nBut `a2a_inner` is assigned from `create_a2a_server(..., public_url=public_url)` (line 1672). When `public_url` is a callable, `create_a2a_server` returns the `_wrap_with_per_request_card` middleware function (an `async def _middleware(scope, receive, send): ...`), not a Starlette app. The middleware has no `.router`.\n\nThe string and `None` cases pass `create_a2a_server`'s \"use the static URL or the bound localhost\" branch and return a Starlette app — that's why `transport=\"a2a\"` alone works (it doesn't go through `_composed_lifespan`) and `transport=\"both\"` works with non-callable `public_url`.\n\n## Impact\n\nAdopters following the docstring's per-tenant `PublicUrlResolver` pattern (parity with JS `createTenantRegistry`) on the unified MCP+A2A binary can't actually use the feature. Drove ~half a day of debugging on our side, including a CI run where every E2E and quickstart job timed out on \"Server did not become healthy in time\" because the container exited 0 instead of crashing loud.\n\n## Suggested fix\n\nEither:\n\n1. **Have `_wrap_with_per_request_card` wrap the inner app instead of replacing it.** Keep `a2a_inner` as the Starlette app `create_a2a_server` would have built with `public_url=None`, then layer the per-request handler as middleware. The lifespan composer keeps working unchanged.\n\n2. **Or make `_composed_lifespan` reach for the underlying app.** When `a2a_inner` doesn't have `.router`, walk a known attribute (`.app`, or store the inner reference on the wrapper).\n\nOption 1 keeps the lifespan composer trivial; option 2 is a local fix.\n\n## Workaround\n\nPass `public_url` as a string (e.g. from `PUBLIC_URL` env) and run your own ASGI middleware to rewrite `/.well-known/agent-card.json` from `X-Forwarded-Host` — same as the pre-5.1 pattern. We restored our 189-line `AgentCardPublicUrlMiddleware` for exactly this.\n\n## Environment\n\n- `adcp==5.2.0`\n- Python 3.12\n- `transport=\"both\"`, multi-tenant subdomain deployment","author":{"url":"https://github.com/bokelley","@type":"Person","name":"bokelley"},"datePublished":"2026-05-11T20:13:05Z","url":"https://github.com/adcontextprotocol/adcp-client-python/issues/676"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:0185adf0-b118-6e43-decb-f2719712a7aa |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8A66:26ECEB:FC5078:143CA12:6B00FEFE |
| html-safe-nonce | 3dfd3ab91172f8ba405c0fc275d3ee1267b6308c4728b61984167afd9087bdf4 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4QTY2OjI2RUNFQjpGQzUwNzg6MTQzQ0ExMjo2QjAwRkVGRSIsInZpc2l0b3JfaWQiOiIyOTQwNDI4NTk1MTExMTk4NDYzIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | bbafdae8f701e55e781b1b911f4995276ff3fb551c26be6c298023b5a57d6858 |
| hovercard-subject-tag | issue:4423964831 |
| github-keyboard-shortcuts | repository,issues,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/_view_fragments/issues/show/adcontextprotocol/adcp-client-python/676/issue_layout |
| twitter:image | https://opengraph.githubassets.com/305bf257a503c90f1afce753d542a2fb13e871b50e594b00518a71cd341f7073/adcontextprotocol/adcp-client-python/issues/676 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/305bf257a503c90f1afce753d542a2fb13e871b50e594b00518a71cd341f7073/adcontextprotocol/adcp-client-python/issues/676 |
| og:image:alt | Repro def my_resolver(request): return f"https://{request.headers.get('host')}/" serve(handler, transport="both", public_url=my_resolver) Observed Process exits cleanly with code 0 at lifespan star... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | bokelley |
| hostname | github.com |
| expected-hostname | github.com |
| None | cb7fa109eca7d4156c889f474306b0e91336055e9adf8fd4684b61e49094d124 |
| turbo-cache-control | no-preview |
| go-import | github.com/adcontextprotocol/adcp-client-python git https://github.com/adcontextprotocol/adcp-client-python.git |
| octolytics-dimension-user_id | 221690821 |
| octolytics-dimension-user_login | adcontextprotocol |
| octolytics-dimension-repository_id | 1090305973 |
| octolytics-dimension-repository_nwo | adcontextprotocol/adcp-client-python |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1090305973 |
| octolytics-dimension-repository_network_root_nwo | adcontextprotocol/adcp-client-python |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 2b59d31a4e44f08b7af67a4b67f8fd0af3befe2a |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width