fix(validation): allow tool names starting with underscore or number#2534
Merged
crivetimihai merged 1 commit intomainfrom Jan 28, 2026
Merged
fix(validation): allow tool names starting with underscore or number#2534crivetimihai merged 1 commit intomainfrom
crivetimihai merged 1 commit intomainfrom
Conversation
7 tasks
5a8d43b to
2fd8ccb
Compare
The MCP specification does not mandate that tool names must start with a letter - tool names are simply strings without pattern restrictions. This fix updates the validation pattern to align with SEP-986. Changes: - Update VALIDATION_TOOL_NAME_PATTERN from ^[a-zA-Z][a-zA-Z0-9._-]*$ to ^[a-zA-Z0-9_][a-zA-Z0-9._/-]*$ per SEP-986 - Allow leading underscore/number and slashes in tool names - Remove / from HTML special characters regex (not XSS-relevant) - Update all error messages, docstrings, and documentation - Update tests to verify new valid cases Tool names like `_5gpt_query_by_market_id` and `namespace/tool` are now accepted. Closes #2528 Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
2fd8ccb to
6522a87
Compare
kevalmahajan
approved these changes
Jan 28, 2026
Member
kevalmahajan
left a comment
There was a problem hiding this comment.
Reviewed and tested the changes and verified them against the SEP-986 specification for MCP tool names.
-
Regex Compliance: The updated regex ^[a-zA-Z0-9_][a-zA-Z0-9._/-]*$ correctly implements the SEP-986 standard:
- Allows forward slashes / for namespacing.
- Allows starting with valid characters (including numbers/underscores) that were previously restricted.
- Excludes invalid starting characters like hyphens (correctly blocked).
-
Shared Length Limit:
- The code uses VALIDATION_MAX_NAME_LENGTH (default 255) for tool names.
- While SEP-986 recommends a 64-character limit, using 255 is acceptable as a permissive gateway limit (it's a superset).
- Note: Since this constant is shared with validate_display_name, validate_identifier, and validate_uri, changing it would have side effects. If strict 64-char enforcement is required for tool names later, we should introduce a dedicated VALIDATION_MAX_TOOL_NAME_LENGTH.
hughhennelly
pushed a commit
to hughhennelly/mcp-context-forge
that referenced
this pull request
Feb 8, 2026
…BM#2534) The MCP specification does not mandate that tool names must start with a letter - tool names are simply strings without pattern restrictions. This fix updates the validation pattern to align with SEP-986. Changes: - Update VALIDATION_TOOL_NAME_PATTERN from ^[a-zA-Z][a-zA-Z0-9._-]*$ to ^[a-zA-Z0-9_][a-zA-Z0-9._/-]*$ per SEP-986 - Allow leading underscore/number and slashes in tool names - Remove / from HTML special characters regex (not XSS-relevant) - Update all error messages, docstrings, and documentation - Update tests to verify new valid cases Tool names like `_5gpt_query_by_market_id` and `namespace/tool` are now accepted. Closes IBM#2528 Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> Signed-off-by: hughhennnelly <hughhennelly06@gmail.com>
kcostell06
pushed a commit
to kcostell06/mcp-context-forge
that referenced
this pull request
Feb 24, 2026
…BM#2534) The MCP specification does not mandate that tool names must start with a letter - tool names are simply strings without pattern restrictions. This fix updates the validation pattern to align with SEP-986. Changes: - Update VALIDATION_TOOL_NAME_PATTERN from ^[a-zA-Z][a-zA-Z0-9._-]*$ to ^[a-zA-Z0-9_][a-zA-Z0-9._/-]*$ per SEP-986 - Allow leading underscore/number and slashes in tool names - Remove / from HTML special characters regex (not XSS-relevant) - Update all error messages, docstrings, and documentation - Update tests to verify new valid cases Tool names like `_5gpt_query_by_market_id` and `namespace/tool` are now accepted. Closes IBM#2528 Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
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.
Summary
Fixes the validation pattern for MCP tool names to align with SEP-986, which does not mandate that tool names must start with a letter.
VALIDATION_TOOL_NAME_PATTERNfrom^[a-zA-Z][a-zA-Z0-9._-]*$to^[a-zA-Z0-9_][a-zA-Z0-9._/-]*$_5gpt_query_by_market_id) or number (e.g.,123_tool) are now acceptednamespace/subtool) are now accepted per SEP-986-tool) remain invalid for safety/from HTML special characters regex (not XSS-relevant)Files Changed
Core validation:
mcpgateway/config.py- Default patternmcpgateway/common/validators.py- Validation logic, error messages, HTML regexmcpgateway/schemas.py- Pydantic schema docstringsmcpgateway/utils/error_formatter.py- User-friendly error mappingConfiguration:
.env.example- Documented defaultcharts/mcp-stack/values.yaml- Helm chart defaultcharts/mcp-stack/README.md- Helm documentationTests:
tests/unit/mcpgateway/validation/test_validators.pytests/unit/mcpgateway/validation/test_validators_advanced.pytests/unit/mcpgateway/utils/test_error_formatter.pyDocumentation:
docs/docs/testing/acceptance.mdVerification
Tested against running docker-compose deployment:
Closes #2528