Skip to content

Conversation

@felixweinberger
Copy link
Contributor

@felixweinberger felixweinberger commented Nov 23, 2025

Motivation and Context

modelcontextprotocol/modelcontextprotocol#986

Implements tool name validation according to SEP-986 specification. Tool names are validated at registration time in both FastMCP and low-level server paths, issuing warnings for non-conforming names without blocking registration.

Taking similar approach to reference implementation in TS: modelcontextprotocol/typescript-sdk#900

How Has This Been Tested?

Unit tests - 29 new tests for the validation module covering:

  • Valid names (alphanumeric, underscores, dashes, dots, max length)
  • Invalid names (empty, too long, invalid characters, unicode)
  • Warning patterns (leading/trailing dash/dot)
  • Edge cases

All existing tests continue to pass.

Breaking Changes

None, but console warnings may appear for SDK users who have tool names that do not satisfy the SEP.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Add validation for tool names according to SEP-986 specification. Tool names
are now validated at registration time in both FastMCP and low-level server:

- Names must be 1-128 characters
- Only A-Za-z0-9._- characters allowed
- Warnings issued for non-conforming names (doesn't block registration)
- Leading/trailing dots or dashes trigger advisory warnings

Validation is implemented in mcp.shared.tool_name_validation module with
comprehensive test coverage.

Github-Issue:#1537
@felixweinberger felixweinberger linked an issue Nov 23, 2025 that may be closed by this pull request
@felixweinberger felixweinberger marked this pull request as ready for review November 23, 2025 23:20
@felixweinberger felixweinberger enabled auto-merge (squash) November 24, 2025 11:47
Co-authored-by: Paul Carleton <paulcarletonjr@gmail.com>
TOOL_NAME_REGEX = re.compile(r"^[A-Za-z0-9._-]{1,128}$")

# SEP reference URL for warning messages
SEP_986_URL = "https://github.com/modelcontextprotocol/modelcontextprotocol/issues/986"
Copy link
Member

@pcarleton pcarleton Nov 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
SEP_986_URL = "https://github.com/modelcontextprotocol/modelcontextprotocol/issues/986"
SEP_986_URL = "https://modelcontextprotocol.io/specification/2025-11-25/server/tools#tool-names"

digits (0-9), underscore (_), dash (-), and dot (.).
Tool names SHOULD NOT contain spaces, commas, or other special characters.

See: https://modelcontextprotocol.io/specification/draft/server/tools#tool-names
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
See: https://modelcontextprotocol.io/specification/draft/server/tools#tool-names
See: https://modelcontextprotocol.io/specification/2025-11-25/server/tools#tool-names

Copy link
Member

@pcarleton pcarleton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

approved w/ url fix

@felixweinberger felixweinberger merged commit 091afb8 into main Nov 24, 2025
21 checks passed
@felixweinberger felixweinberger deleted the fweinberger/sep-986-tool-name-validation branch November 24, 2025 16:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement SEP-986: Tool Name Guidance

3 participants