ExMCP.Validation.ToolName (ex_mcp v0.9.2)

View Source

Validates MCP tool names according to the 2025-11-25 specification.

Tool names must:

  • Be 1-128 characters long
  • Only contain alphanumeric characters, dots, hyphens, and underscores
  • Match the pattern: ^[a-zA-Z0-9_.\-]+$

Summary

Functions

Returns true if the tool name is valid.

Validates a tool name.

Functions

valid?(name)

@spec valid?(String.t()) :: boolean()

Returns true if the tool name is valid.

validate(name)

@spec validate(String.t()) :: {:ok, String.t()} | {:error, String.t()}

Validates a tool name.

Returns {:ok, name} if valid, {:error, reason} if invalid.

Examples

iex> ExMCP.Validation.ToolName.validate("my_tool")
{:ok, "my_tool"}

iex> ExMCP.Validation.ToolName.validate("my tool")
{:error, "Tool name contains invalid characters. Must match [a-zA-Z0-9_.\\-]+"}

iex> ExMCP.Validation.ToolName.validate("")
{:error, "Tool name must be between 1 and 128 characters"}