-
Notifications
You must be signed in to change notification settings - Fork 294
feat: Add HeaderProvider to mcptoolset #338
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Summary of ChangesHello @kaugesaar, 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 significantly enhances the Go MCP toolset by aligning its behavior with the existing Highlights
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this 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 introduces HeaderProvider support to the mcptoolset, enabling dynamic, context-aware HTTP headers for tool calls, and adds session pooling based on these headers. The changes align the Go MCP toolset with the Python implementation. The implementation looks solid, with a new sessionManager to handle session pooling and a comprehensive set of tests. I have a few suggestions to improve performance, security posture, and code clarity, mainly in the new session_manager.go file. My main concerns are around the use of a weak hashing algorithm and a locking pattern that could cause performance issues under load.
| } | ||
| jsonStr := "{" + strings.Join(pairs, ",") + "}" | ||
|
|
||
| h := md5.Sum([]byte(jsonStr)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The use of crypto/md5 is discouraged as it's a weak cryptographic hash function. While not used for a security-critical purpose here, it's best practice to use a stronger hash function like SHA-256 to prevent potential hash collisions and to satisfy security scanners. You'll also need to update the import from crypto/md5 to crypto/sha256.
| h := md5.Sum([]byte(jsonStr)) | |
| h := sha256.Sum256([]byte(jsonStr)) |
Overview
This PR aligns the Go MCP toolset with the adk-python implementation by introducing:
1. HeaderProvider support
Allows tool calls to attach context-aware HTTP headers (auth tokens, user/session IDs, tenant headers, etc). Headers are generated per call with
agent.ReadonlyContextcontext.2. Session pooling keyed by headers
Adds a new
sessionManagerthat reuses MCP sessions when headers are identical and creates new ones only when necessary.3. Updated example:
examples/mcp/main.gonow supports a third mode (AGENT_MODE=custom-headers) that usesHeaderProviderto attach a GitHub PAT + optional context headers.Summary of Changes
mcptoolset/set.goHeaderProvidertoConfigsessionManagerinstance tosetgetSessionnow:agent.ReadonlyContextmcptoolset/session_manager.go(new)RoundTripperfor static header injectionPingClose()to cleanly shut down all sessionsmcptoolset/session_manager_test.go(new)examples/mcp/main.goAlignment with Python
This matches the adk-python behavior in:
Example
Known Limitation
Sessions are pooled based on headers from
HeaderProvideronly. Headers added by customHTTPClienttransports (e.g.,oauth2.NewClient) are not visible to the session manager and do not affect pooling.