Skip to content

Conversation

@mikeas1
Copy link
Contributor

@mikeas1 mikeas1 commented May 22, 2025

Description

This introduces a ServerCallContext class that can be used for a few purposes:

  1. Configuring SDK behavior for a single request (such as timeouts).
  2. Plumbing user-data through SDK layers.
  3. Providing common request-level metadata (such as authentication) through SDK layers.

For now, the ServerCallContext is extremely barebones: just a holder for a state property for storing arbitrary key-values. I plan to extend this soon with request User details, similar to Starlette.

The bulk of this change is just plumbing this parameter all over the place. That plumbing is the value-add: you can put stuff in this context and we'll shuttle it everywhere for you.

Alternatives to this design are:

  1. Having some kind of IoC + DI container that manages plumbing data for you. This is probably how you'd want to do this in, e.g., C# or Java, where such systems are commonplace.
  2. Using ContextVars. This works, but I find ContextVars much harder to reason about for testing -- they act as hidden dependencies for a module when used this way, so discovering all the necessary ContextVars is quite annoying.

Thank you for opening a Pull Request!
Before submitting your PR, there are a few things you can do to make sure it goes smoothly:

@mikeas1 mikeas1 requested a review from a team as a code owner May 22, 2025 17:41
@mikeas1 mikeas1 force-pushed the server-call-context branch from c38da31 to 2f9ccd9 Compare May 22, 2025 17:57
@mikeas1 mikeas1 enabled auto-merge (squash) May 22, 2025 20:51
@mikeas1 mikeas1 merged commit 85b521d into main May 22, 2025
6 checks passed
@mikeas1 mikeas1 deleted the server-call-context branch May 22, 2025 20:52
martimfasantos pushed a commit to martimfasantos/a2a-python that referenced this pull request May 23, 2025
* Introduce a ServerCallContext parameter

* Finish comment

* Remove Starlette-specific DefaultCallContextBuilder

* Update comment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants