Skip to content

[Bug]: ServerCallContext is missing state bag and CallContextBuilder — parity gap with Python SDK #416

Description

@ikubicki

What happened?

Problem

The TypeScript A2A SDK's ServerCallContext lacks a state property that exists in the Python SDK. This creates a fundamental feature gap that makes it impossible to faithfully port Python-based agent implementations to TypeScript without architectural workarounds.

The Python SDK's ServerCallContext exposes a state: MutableMapping[str, Any] — an arbitrary key/value bag used to pass request-scoped metadata through the call pipeline. The Python app layer actively relies on it (e.g. call_context.state['method'] = method), and downstream implementations use it to carry data like tenant IDs, auth tokens, or raw request headers.

The TypeScript SDK has no equivalent.

Impact

Any agent or middleware relying on context.state in the Python SDK has no direct equivalent in TypeScript. Developers migrating Python agents to TypeScript must invent their own out-of-band solutions (e.g. request-scoped stores, middleware globals), which undermines SDK consistency and increases migration friction.

Proposed Solution

Add the following to ServerCallContext in the TypeScript SDK:

  • A state property — a Map<string, unknown> key/value bag, mirroring Python's state: MutableMapping[str, Any]
  • A ServerCallContextBuilder type — mirroring Python's abstract CallContextBuilder.build(request) pattern
  • A defaultServerCallContextBuilder — a default implementation that pre-populates state with raw request headers (mirroring Python's DefaultCallContextBuilder)
  • Optional contextBuilder parameter on Express (jsonRpcHandler, restHandler) and gRPC handlers, falling back to the default builder

References

Relevant log output

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions