python-sdk icon indicating copy to clipboard operation
python-sdk copied to clipboard

feat: Implement SEP-986: Tool Name Guidance

Open vincent0426 opened this issue 2 months ago • 0 comments

Implement SEP-986: Tool Name Guidance for Tool Type

Changes

  • Added a length check that raises an error when the tool name is not within the allowed range:
    raise ValueError(f"Invalid tool name length: {len(value)}. Tool name must be between 1 and 128 characters.")
    
  • Added a regex validation using re.compile(r"^[A-Za-z0-9_.-]+$") that raises an error for invalid characters:
    raise ValueError("Invalid tool name characters. Allowed: A-Z, a-z, 0-9, underscore (_), dash (-), dot (.).")
    

Motivation and Context

Related issues: SEP-986 https://github.com/modelcontextprotocol/python-sdk/issues/1537

Implements the guidance from https://github.com/modelcontextprotocol/modelcontextprotocol/issues/986

- Tool names SHOULD be between 1 and 128 characters in length (inclusive).
- Tool names SHOULD be considered case-sensitive.
- The following SHOULD be the only allowed characters: uppercase and lowercase ASCII letters (A-Z, a-z), digits
  (0-9), underscore (\_), dash (-), and dot (.)
- Tool names SHOULD NOT contain spaces, commas, or other special characters.
- Tool names SHOULD be unique within a server.
- Example valid tool names:
  - getUser
  - DATA_EXPORT_v2
  - admin.tools.list

How Has This Been Tested?

Unit Tests

Valid Values

  • getUser
  • DATA_EXPORT_v2
  • admin.tools.list
  • a
  • Z9_.-
  • "x" * 128 (max length)

Invalid Values

  • "" (empty string)
  • "x" * 129 (exceeds max length)
  • has space
  • comma,name
  • not/allowed
  • name@
  • name#
  • name$

Breaking Changes

Types of changes

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

Checklist

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

Additional context

vincent0426 avatar Oct 30 '25 17:10 vincent0426