Class ToolNameValidator

java.lang.Object
io.modelcontextprotocol.util.ToolNameValidator

public final class ToolNameValidator extends Object
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 Details

    • STRICT_VALIDATION_PROPERTY

      public static final String 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

      public static void validate(String name, boolean strict)
      Validates a tool name according to MCP specification.
      Parameters:
      name - the tool name to validate
      strict - if true, throws exception on invalid name; if false, logs warning only
      Throws:
      IllegalArgumentException - if validation fails and strict is true