Feat/expose mcps streamable http custom httpx factory parameter
Reopen of https://github.com/google/adk-python/pull/2997 after the accepted changes in that PR were reverted by https://github.com/google/adk-python/commit/e15e19da05ee1b763228467e83f6f73e0eced4b5
This PR addresses https://github.com/google/adk-python/issues/3005 and https://github.com/google/adk-python/issues/2963 to allow control over the ssl cert used when connecting to an mcp server by exposing the httpx_client_factory parameter exposed when creating a MCPSessionManager in adk. Overlaps with https://github.com/google/adk-python/pull/2966 but I don't believe that that PR's implementation will work. streamablehttp_client needs a client factory, not a client.
testing plan
Adds test checking that streamablehttp_client uses the custom httpx factory. Could also test that a factory which obeys the McpHttpClientFactory protocol produces valid behavior when the session is opened?
related issues
#2227 and #2881 both request slightly different options to control the ssl certs used internally by adk. I think exposing a httpx factory is a good pattern which could be followed for those issues too.
Summary of Changes
Hello @mikeedjones, I'm Gemini Code Assist[^1]! 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 re-implements a previously reverted feature, allowing developers to provide a custom httpx_client_factory when initializing an MCPSessionManager for Streamable HTTP. This change significantly enhances flexibility by enabling fine-grained control over the underlying HTTP client, particularly for managing SSL certificate configurations, thereby resolving critical issues related to secure communication with MCP servers.
Highlights
- Reintroduces httpx_client_factory parameter: This PR reopens a previous change to expose a custom httpx_client_factory when creating an MCPSessionManager for Streamable HTTP connections.
- Enables SSL certificate control: By exposing the httpx_client_factory, users can now control the SSL certificates used for MCP server connections, addressing issues #3005 and #2963.
- Introduces CheckableMcpHttpClientFactory: A new runtime_checkable protocol is added to type-check custom HTTPX client factories, ensuring type safety and adherence to the expected interface.
- Adds comprehensive unit tests: New tests ensure that both custom and default httpx_client_factory instances are correctly utilized by streamablehttp_client, verifying the intended behavior.
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 :thumbsup: and :thumbsdown: 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.
[^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.
Hi @mikeedjones, Thank you for your contribution! We appreciate you taking the time to submit this pull request. Your PR has been received by the team and is currently under review. We will provide feedback as soon as we have an update to share.
Hi @DeanChensj , can you please review this.