Fix #26325: Sanitize MCP Tool Names for Bedrock Compatibility#26353
Open
david-fraley wants to merge 1 commit into
Open
Fix #26325: Sanitize MCP Tool Names for Bedrock Compatibility#26353david-fraley wants to merge 1 commit into
david-fraley wants to merge 1 commit into
Conversation
AWS Bedrock requires tool names to match the pattern ^[a-zA-Z0-9_-]{1,128}$.
MCP tools often have names with dots and other special characters that violate
this requirement, causing HTTP 400 errors when tool names are sent to Bedrock.
Changes:
- Added sanitizeToolName() function to replace invalid characters with underscores
and truncate to 128 characters
- Added sanitizedToolNames field to interceptionBase struct to track mapping from
sanitized names back to original MCP tool IDs
- Updated injectTools() in base.go to sanitize tool names before sending to Bedrock
- Added resolveToolID() method to resolve sanitized names back to original IDs when
processing model responses
- Updated blocking.go and streaming.go to resolve tool IDs before looking up tools
from the MCP proxy, ensuring we use the original tool ID for execution
- Added comprehensive unit tests for sanitizeToolName() covering edge cases
This ensures tool names sent to Bedrock are always valid, while maintaining
proper tool execution with the correct original MCP tool IDs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
AWS Bedrock requires tool names to match the pattern
^[a-zA-Z0-9_-]{1,128}$. MCP tools often have names containing dots and other special characters that violate this requirement, causing HTTP 400 errors when tool names are sent to Bedrock, which breaks the agent turn.Solution
Implement tool name sanitization by:
Changes
aibridge/intercept/messages/base.gosanitizedToolNamesfield tointerceptionBasestruct to track mappinginjectTools()method to sanitize tool names before sending to BedrocksanitizeToolName()function that:resolveToolID()method to resolve sanitized names back to original IDsaibridge/intercept/messages/blocking.goresolveToolID()before callingGetTool()aibridge/intercept/messages/streaming.goaibridge/intercept/messages/base_internal_test.gosanitizeToolName()covering:Testing
✅ All new unit tests pass (8 test cases for sanitizeToolName)
✅ Existing tests continue to pass
✅ Code formatting verified with
go fmtExample