feat: Implement SEP-986: Tool Name Guidance#1550
Open
vincent0426 wants to merge 5 commits intomodelcontextprotocol:mainfrom
Open
feat: Implement SEP-986: Tool Name Guidance#1550vincent0426 wants to merge 5 commits intomodelcontextprotocol:mainfrom
vincent0426 wants to merge 5 commits intomodelcontextprotocol:mainfrom
Conversation
Kludex
reviewed
Oct 31, 2025
src/mcp/types.py
Outdated
Comment on lines
899
to
913
| @field_validator("name") | ||
| @classmethod | ||
| def _validate_tool_name(cls, value: str) -> str: | ||
| if not (1 <= len(value) <= 128): | ||
| raise ValueError(f"Invalid tool name length: {len(value)}. Tool name must be between 1 and 128 characters.") | ||
|
|
||
| if not TOOL_NAME_PATTERN.fullmatch(value): | ||
| raise ValueError("Invalid tool name characters. Allowed: A-Z, a-z, 0-9, underscore (_), dash (-), dot (.).") | ||
|
|
||
| return value | ||
|
|
||
| """ | ||
| See [MCP specification](https://modelcontextprotocol.io/specification/draft/server/tools#tool-names) | ||
| for more information on tool naming conventions. | ||
| """ |
Member
There was a problem hiding this comment.
@maxisbey This is a less verbose way to write the same thing:
from typing import Annotated
from pydantic import StringConstraints
tool: Annotated[str, StringConstraints(max_length=128, pattern=r"^[A-Za-z0-9_.-]+$")]I'm not sure if this should be applied on BaseMetadata, but if not, please drop the inheritance, and apply this here.
Member
There was a problem hiding this comment.
Btw, most or all the field_validators in this code source can be replaced by proper annotated versions - that you can see are cuter.
Member
There was a problem hiding this comment.
I personally don't think there's a need to test that Pydantic is working as expected.
maxisbey
requested changes
Nov 13, 2025
src/mcp/types.py
Outdated
Comment on lines
902
to
908
| if not (1 <= len(value) <= 128): | ||
| raise ValueError(f"Invalid tool name length: {len(value)}. Tool name must be between 1 and 128 characters.") | ||
|
|
||
| if not TOOL_NAME_PATTERN.fullmatch(value): | ||
| raise ValueError("Invalid tool name characters. Allowed: A-Z, a-z, 0-9, underscore (_), dash (-), dot (.).") | ||
|
|
||
| return value |
Contributor
There was a problem hiding this comment.
We don't want it to actually fail, instead we'd want it to raise a deprecation warning
05c145d to
45b1ed6
Compare
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.
Implement SEP-986: Tool Name Guidance for Tool Type
Changes
re.compile(r"^[A-Za-z0-9_.-]+$")that raises an error for invalid characters:Motivation and Context
Related issues: SEP-986 #1537
Implements the guidance from modelcontextprotocol/modelcontextprotocol#986
How Has This Been Tested?
Unit Tests
Valid Values
getUserDATA_EXPORT_v2admin.tools.listaZ9_.-"x" * 128(max length)Invalid Values
""(empty string)"x" * 129(exceeds max length)has spacecomma,namenot/allowedname@name#name$Breaking Changes
Types of changes
Checklist
Additional context