Add host-owned ASGI route registration#484
Open
dcaayushd wants to merge 3 commits into
Open
Conversation
Collaborator
|
Hey @dcaayushd , Thanks for jumping on this! This looks like we're headed in the right direction - though I don't have a strong pref towards shipping the StarletteAdapter as apart of apps - @heyitsaamir do you have any particular ops? |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR implements a first-class “host-owned ASGI lifecycle” integration for the Teams Python SDK by splitting synchronous route registration from async plugin initialization, and by shipping a supported Starlette adapter.
Changes:
- Added
App.register_routes()(sync) andApp.start_plugins()(async) to support caller-owned ASGI app lifecycles while keeping pluginon_initdecoupled from route contribution. - Updated
HttpServer.initialize()to return a publicHttpRoutetable and to exposeHttpServer.routes. - Promoted
StarletteAdapterfrom example-only to a shipped adapter and updated docs/examples/tests accordingly.
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/apps/src/microsoft_teams/apps/app.py | Adds lifecycle split (register_routes, start_plugins) and internal flags for initialization state. |
| packages/apps/src/microsoft_teams/apps/http/http_server.py | Returns and stores HttpRoute registrations; adds routes accessor. |
| packages/apps/src/microsoft_teams/apps/http/adapter.py | Introduces HttpRoute as a framework-agnostic route table entry. |
| packages/apps/src/microsoft_teams/apps/http/starlette_adapter.py | Ships Starlette-based adapter implementation with managed/non-managed lifecycle behavior. |
| packages/apps/src/microsoft_teams/apps/http/init.py | Exports HttpRoute and StarletteAdapter from the http package. |
| packages/apps/src/microsoft_teams/apps/init.py | Re-exports HttpRoute and StarletteAdapter at the apps package level. |
| packages/apps/tests/test_app.py | Adds coverage for the new register_routes() / start_plugins() lifecycle split. |
| packages/apps/tests/test_http_server.py | Updates HttpServer tests for route-table return + adds StarletteAdapter tests. |
| packages/apps/README.md | Documents the host-owned ASGI lifecycle pattern for FastAPI and Starlette hosts. |
| examples/http-adapters/src/fastapi_non_managed.py | Updates non-managed FastAPI example to use register_routes() + start_plugins(). |
| examples/http-adapters/src/starlette_echo.py | Updates Starlette example to use shipped StarletteAdapter. |
| examples/http-adapters/README.md | Updates adapter examples documentation to reflect the new lifecycle split and shipped adapter. |
| examples/http-adapters/pyproject.toml | Updates example description to match shipped-adapter framing. |
| examples/mcp-server/src/main.py | Ensures Teams routes are registered before mounting MCP app (route priority), now via register_routes(). |
| examples/a2a/src/main.py | Ensures Teams routes are registered synchronously before host-owned route table is finalized. |
Comments suppressed due to low confidence (1)
packages/apps/src/microsoft_teams/apps/http/starlette_adapter.py:77
- StarletteAdapter.start() reuses an existing uvicorn.Server instance, which can cause
start(port)to silently ignore a newportvalue and can prevent clean restarts afterstop()(sincestop()setsshould_exitbut the adapter keeps_server). Recreate the server when the requested port differs or when the previous server was asked to exit, sostart()reliably honors itsportargument.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #447.
Adds a public lifecycle split for host-owned ASGI integrations:
App.register_routes()to synchronously register the Teams messaging endpoint without starting a server or running async plugin init.App.start_plugins()so hosts can run pluginon_inithooks later from their ASGI startup lifecycle.HttpRouteroute table from registration.StarletteAdapteras part ofmicrosoft_teams.apps.httpinstead of leaving it example-only.Validation