Skip to content

feat(server): expose RequestContext.transport (mcp | a2a) #617

@bokelley

Description

@bokelley

Problem

RequestContext doesn't carry the inbound transport identifier. Auth and tenant are exposed via ContextVars (adcp.server.auth.current_principal, etc.), but the request's transport is not.

Webhook payload shape selection is transport-dependent: A2A buyers expect Task / TaskStatusUpdateEvent envelopes; MCP buyers expect McpWebhookPayload. Platform methods that fire webhooks (or the in-house webhook service that does so on their behalf) need this signal — without it the platform defaults to one transport and the other side gets the wrong shape (we hit this as #202 locally).

Workaround

We run an 85-LOC ASGI middleware (TransportDetectMiddleware) that classifies the URL path (/mcp or /mcp/* → MCP; host root including /.well-known/agent-card.json → A2A; admin paths → no-op) and stuffs the result into a current_transport ContextVar that platform code reads. Works, but it's URL-path inference outside the SDK's dispatch, and any change to how the framework routes transports silently breaks our detection.

Proposed SDK shape

from adcp.server import current_transport  # contextvar set by the dispatcher

# Or as a field on RequestContext:
@dataclass
class RequestContext:
    ...
    transport: Literal["mcp", "a2a"]

The dispatcher already knows which transport invoked it (it picked the route). It's just not surfacing the value to handlers.

Files

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions