Package io.modelcontextprotocol.util
Class ToolNameValidator
java.lang.Object
io.modelcontextprotocol.util.ToolNameValidator
Validates tool names according to the MCP specification.
Tool names must conform to the following rules:
- Must be between 1 and 128 characters in length
- May only contain: A-Z, a-z, 0-9, underscore (_), hyphen (-), and dot (.)
- Must not contain spaces, commas, or other special characters
- Author:
- Andrei Shakirin
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringSystem property for strict tool name validation. -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanReturns the default strict validation setting from system property.static voidValidates a tool name according to MCP specification.
-
Field Details
-
STRICT_VALIDATION_PROPERTY
System property for strict tool name validation. Set to "false" to warn only instead of throwing exceptions. Default is true (strict).- See Also:
-
-
Method Details
-
isStrictByDefault
public static boolean isStrictByDefault()Returns the default strict validation setting from system property.- Returns:
- true if strict validation is enabled (default), false if disabled via system property
-
validate
Validates a tool name according to MCP specification.- Parameters:
name- the tool name to validatestrict- if true, throws exception on invalid name; if false, logs warning only- Throws:
IllegalArgumentException- if validation fails and strict is true
-