feat(server): add asgi_middleware param to serve()#441
Merged
Conversation
4 tasks
…lewareEntry alias Fixes the tuple form annotation so functools.partial is accepted as the first element without a mypy error. Adds ASGIMiddlewareEntry type alias to reduce repetition across five annotation sites. Adds a logger.warning when asgi_middleware is passed with transport='stdio' (where it is silently ignored). https://claude.ai/code/session_01GttQNCHuVSVUyRW5knbitw
Mirrors the SkillMiddleware export pattern so users can annotate their own asgi_middleware lists with the canonical type alias. https://claude.ai/code/session_01GttQNCHuVSVUyRW5knbitw
18c1a7d to
a19d64b
Compare
bokelley
added a commit
that referenced
this pull request
May 3, 2026
Bring the branch up to date with main (PRs #441, #444, #445, #446, #447). Conflicts resolved: * ``.github/workflows/ci.yml`` — keep main's restructured v3 storyboard job (translator-pattern upstream mock + readiness loop) and apply the poll-fix pattern (``||`` outside command substitution) to both the upstream-mock readiness loop and main's new seller-readiness loop. * ``src/adcp/server/serve.py`` — combine main's strict-by-default ``validation=DEFAULT_VALIDATION`` flip with the three transport- security kwargs added on this branch (``allowed_hosts``, ``allowed_origins``, ``enable_dns_rebinding_protection``). Auto-merged: ``examples/v3_reference_seller/src/app.py`` (translator rewrite + this branch's webhook/dispose/DNS-rebinding kwargs), ``examples/v3_reference_seller/tests/test_smoke.py`` (translator rewrite + this branch's port-stripping regression test), ``src/adcp/server/mcp_tools.py`` (lazy schema gen + this branch's ``setdefault("type", "object")`` for union outputSchemas), ``examples/seller_agent.py`` (channels filter intact).
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.
Closes #415
Adds
asgi_middlewaretoserve(),_serve_mcp(),_run_mcp_http(), and_serve_a2a(). The parameter accepts a sequence of entries that are each either a(callable, kwargs)tuple or a bare callable factoryf(app) -> app. Both forms compose outermost-first. Applied on HTTP transports (streamable-http,sse,a2a); silently ignored (with alogger.warning) onstdio.A module-level
ASGIMiddlewareEntrytype alias is added and exported fromadcp.server, mirroring theSkillMiddlewarepattern.What was tested
pytest tests/test_serve_asgi_middleware.py— 6 new tests: no-op, outermost-first ordering, kwargs passthrough, callable factory,functools.partialfactory, mixed tuple+callable ordering. All pass.pytest tests/ --ignore=tests/integration) — 2318 passed, 21 skipped, 1 xfailed (pre-existing network test excluded).ruff check src/adcp/server/serve.py src/adcp/server/__init__.py— clean.mypy src/adcp/server/serve.py— no new errors (pre-existing missing-stub errors for optional deps are unaffected).Pre-PR review
logger.warning) and commit title accuracy (addressed).type→Callable[..., Any]in the tuple annotation sofunctools.partialas the tuple's first element passes mypy. Also flagged missingASGIMiddlewareEntryexport (fixed).Remaining nits (surfaced, not fixed):
_apply_asgi_middlewarehas no validation guard for malformed entries (e.g. 3-tuples produce a decontextualizedValueError). Follow-up issue welcome.size_limitordering invariant (_wrap_with_size_limitalways outermost). Worth a follow-up.create_mcp_server()auth docs referenceadd_middleware()as an alternative pattern without cross-referencingasgi_middleware=. Docs follow-up.Session: https://claude.ai/code/session_01GttQNCHuVSVUyRW5knbitw
Generated by Claude Code