Skip to content

feat: add JSON-RPC method to ServerCallContext.state#463

Merged
holtskinner merged 3 commits intoa2aproject:mainfrom
ovidiutaralesca:feat_add_method_to_context_state
Sep 9, 2025
Merged

feat: add JSON-RPC method to ServerCallContext.state#463
holtskinner merged 3 commits intoa2aproject:mainfrom
ovidiutaralesca:feat_add_method_to_context_state

Conversation

@ovidiutaralesca
Copy link
Copy Markdown
Contributor

@ovidiutaralesca ovidiutaralesca commented Sep 5, 2025

BEGIN_COMMIT_OVERRIDE
feat: add JSON-RPC method to ServerCallContext.state
Release-As: 0.3.6

END_COMMIT_OVERRIDE

Improvement

SDK users sometimes need to know which JSON-RPC method is being processed to adjust their implementation, e.g.:

  • If the method is message/send, they may want to use invoke()/run() when calling their LLM API, and stream()/run_streamed() for message/stream.

Implementation

Added a method field to ServerCallContext.state, similar to headers.

Tests

Added a small test to ensure that method parsing is correct.

Fixes #451

@ovidiutaralesca ovidiutaralesca requested a review from a team as a code owner September 5, 2025 10:34
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary of Changes

Hello @ovidiutaralesca, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the SDK's ServerCallContext by making the JSON-RPC method available within its state. This allows developers to create more adaptive and method-aware application logic, improving the flexibility and utility of the SDK for various JSON-RPC interactions.

Highlights

  • Exposing JSON-RPC Method: The method field from JSON-RPC requests is now accessible via ServerCallContext.state, enabling SDK users to tailor their logic based on the specific method being called (e.g., message/send vs message/stream).
  • Enhanced Contextual Information: This change provides more granular context to handlers, similar to how headers are already exposed, allowing for more dynamic and method-specific behavior within the SDK.
  • Test Coverage: A new test case has been added to test_jsonrpc_app.py to ensure the method is correctly parsed and stored in the ServerCallContext.state.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds the JSON-RPC method name to the ServerCallContext.state so that SDK users can access it. The implementation is straightforward and includes a new test to verify the behavior. My review includes a suggestion to improve the design by making method a first-class attribute of ServerCallContext for better type safety and discoverability, rather than adding it to the generic state dictionary. This would make the API clearer for consumers.

Comment thread src/a2a/server/apps/jsonrpc/jsonrpc_app.py
Comment thread tests/server/apps/jsonrpc/test_jsonrpc_app.py
@ovidiutaralesca
Copy link
Copy Markdown
Contributor Author

ovidiutaralesca commented Sep 5, 2025

Gemini suggests adding method: str | None = None to the ServerCallContext model in src/a2a/server/context.py. I think it does make sense in a way, since method is not truly arbitrary user data, but it's not really an A2A construct either. I'd let a maintainer share a point of view here.

@holtskinner holtskinner enabled auto-merge (squash) September 9, 2025 15:09
@holtskinner holtskinner merged commit d62df7a into a2aproject:main Sep 9, 2025
5 checks passed
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.

[Feat]: RequestContext supports distinguishing between message/send and message/stream

4 participants