Skip to content

refactor: Make ServerCallContext a required parameter for RequestHandler methods#782

Merged
sokoliva merged 2 commits intoa2aproject:1.0-devfrom
sokoliva:ServerCallContext-mandatory
Mar 6, 2026
Merged

refactor: Make ServerCallContext a required parameter for RequestHandler methods#782
sokoliva merged 2 commits intoa2aproject:1.0-devfrom
sokoliva:ServerCallContext-mandatory

Conversation

@sokoliva
Copy link
Copy Markdown
Member

@sokoliva sokoliva commented Mar 6, 2026

Changes

  • make ServerCallContext a required parameter for RequestHandler methods
  • update corresponding tests

Note

I will make ServerCallContext a required parameter for the rest of the Server in other PRs

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:

Contributing Guide

  • Follow the CONTRIBUTING Guide.
  • Make your Pull Request title in the https://www.conventionalcommits.org/ specification.
    • Important Prefixes for release-please:
      • fix: which represents bug fixes, and correlates to a SemVer patch.
      • feat: represents a new feature, and correlates to a SemVer minor.
      • feat!:, or fix!:, refactor!:, etc., which represent a breaking change (indicated by the !) and will result in a SemVer major.
  • Ensure the tests and linter pass (Run bash scripts/format.sh from the repository root to format)
  • Appropriate docs were updated (if necessary)

Fixes #718 🦕

…andler` methods and update corresponding tests.
@sokoliva sokoliva requested a review from ishymko March 6, 2026 14:33
@sokoliva sokoliva requested a review from a team as a code owner March 6, 2026 14:33
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 introduces a significant refactoring by enforcing the presence of ServerCallContext in all RequestHandler methods. This change aims to standardize the API, ensuring that context information is always available for server operations and simplifying method signatures by removing optional None checks. The update impacts the core request handling logic and its JSON-RPC implementation, along with necessary adjustments to existing tests.

Highlights

  • Parameter Requirement: The ServerCallContext parameter has been made mandatory for all RequestHandler methods, removing its optional None type hint.
  • Type Hint Updates: Type hints for the context parameter across various handler methods were updated from ServerCallContext | None to ServerCallContext.
  • Test Adjustments: Corresponding unit tests were modified to explicitly pass a ServerCallContext instance where previously it might have been omitted or implicitly None.
Changelog
  • src/a2a/server/request_handlers/default_request_handler.py
    • Updated on_get_task method signature to require context: ServerCallContext.
    • Updated on_list_tasks method signature to require context: ServerCallContext.
    • Updated on_cancel_task method signature to require context: ServerCallContext.
    • Updated _setup_message_execution method signature to require context: ServerCallContext.
    • Updated on_message_send method signature to require context: ServerCallContext.
    • Updated on_message_send_stream method signature to require context: ServerCallContext.
    • Updated on_create_task_push_notification_config method signature to require context: ServerCallContext.
    • Updated on_get_task_push_notification_config method signature to require context: ServerCallContext.
    • Updated on_subscribe_to_task method signature to require context: ServerCallContext.
    • Updated on_list_task_push_notification_configs method signature to require context: ServerCallContext.
    • Updated on_delete_task_push_notification_config method signature to require context: ServerCallContext.
  • src/a2a/server/request_handlers/jsonrpc_handler.py
    • Updated on_message_send method signature to require context: ServerCallContext.
    • Updated on_message_send_stream method signature to require context: ServerCallContext.
    • Updated on_cancel_task method signature to require context: ServerCallContext.
    • Updated on_subscribe_to_task method signature to require context: ServerCallContext.
    • Updated get_push_notification_config method signature to require context: ServerCallContext.
    • Updated set_push_notification_config method signature to require context: ServerCallContext.
    • Updated on_get_task method signature to require context: ServerCallContext.
    • Updated list_tasks method signature to require context: ServerCallContext.
    • Updated list_push_notification_configs method signature to require context: ServerCallContext.
    • Updated delete_push_notification_config method signature to require context: ServerCallContext.
    • Updated get_authenticated_extended_card method signature to require context: ServerCallContext.
  • src/a2a/server/request_handlers/request_handler.py
    • Updated on_get_task abstract method signature to require context: ServerCallContext.
    • Updated on_list_tasks abstract method signature to require context: ServerCallContext.
    • Updated on_cancel_task abstract method signature to require context: ServerCallContext.
    • Updated on_message_send abstract method signature to require context: ServerCallContext.
    • Updated on_message_send_stream abstract method signature to require context: ServerCallContext.
    • Updated on_create_task_push_notification_config abstract method signature to require context: ServerCallContext.
    • Updated on_get_task_push_notification_config abstract method signature to require context: ServerCallContext.
    • Updated on_subscribe_to_task abstract method signature to require context: ServerCallContext.
    • Updated on_list_task_push_notification_configs abstract method signature to require context: ServerCallContext.
    • Updated on_delete_task_push_notification_config abstract method signature to require context: ServerCallContext.
  • tests/server/request_handlers/test_jsonrpc_handler.py
    • Modified calls to on_message_send to pass ServerCallContext().
    • Modified calls to on_message_send_stream to pass ServerCallContext().
    • Modified calls to set_push_notification_config to pass ServerCallContext().
    • Modified calls to get_push_notification_config to pass ServerCallContext().
    • Modified calls to on_subscribe_to_task to pass ServerCallContext().
    • Modified calls to list_push_notification_configs to pass ServerCallContext().
    • Modified calls to delete_push_notification_config to pass ServerCallContext().
Activity
  • The pull request was opened by sokoliva with the stated goal of making ServerCallContext a required parameter for RequestHandler methods.
  • The author noted that this change is part of a larger refactoring effort, with additional related PRs planned for other server components.
  • The PR description includes standard contributing guidelines and conventional commit specifications, indicating adherence to project development practices.
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 by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

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 pull request 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

The pull request updates the type hints for the context parameter in various asynchronous methods across default_request_handler.py, jsonrpc_handler.py, and request_handler.py. Specifically, the context parameter, previously typed as ServerCallContext | None = None (making it optional), has been changed to ServerCallContext, indicating it is now a mandatory argument. Corresponding test cases in test_jsonrpc_handler.py have been updated to explicitly pass a ServerCallContext() object to these methods, aligning with the new mandatory parameter requirement. There are no review comments provided.

@sokoliva sokoliva merged commit f124ddd into a2aproject:1.0-dev Mar 6, 2026
6 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.

2 participants