Skip to content

enum types in schema giving validation errors for valid values #90

@mbklein

Description

@mbklein

Using this tool:

defmodule EnumTest.MCPServer.TestTool do
  alias Anubis.Server.Response

  use Anubis.Server.Component,
    type: :tool,
    description: "A tool to test enum types in MCP"

  schema do
    field :size, :string, enum: ["small", "medium", "large"], description: "Choose a size"
    field :color, :string, enum: ["red", "green", "blue"], description: "Choose a color"
    field :shape, :string, enum: ["circle", "square", "triangle"], description: "Choose a shape"
  end

  def execute(params, frame) do
    {:reply, Response.tool() |> Response.text("You chose a #{params.size} #{params.color} #{params.shape}!"), frame}
  end
end

I get this result:

mix anubis.streamable_http.interactive --base-url=http://localhost:4000/mcp

16:04:49.834 [warning] Session store enabled but adapter not available

┌─────────────────────────────────────────┐
│       ANUBIS MCP STREAMABLE HTTP INTERACTIVE│
└─────────────────────────────────────────┘


Connecting to Streamable HTTP server at: http://localhost:4000/mcp/mcp

• Starting client...
✓ Client started
• Starting transport...
✓ Transport started
• Checking connection...
Server capabilities: %{"tools" => %{}}
✓ Successfully connected to server

Type help for available commands

mcp> list_tools

Fetching tools...
Timeout in ms (optional, press Enter for default): 
Found 1 tools

Available tools:
  test_tool
    
    Arguments:
      color: string
        Choose a color
      shape: string
        Choose a shape
      size: string
        Choose a size

mcp> call_tool
Tool name: test_tool
Tool arguments (JSON or @filepath): {"color": "blue", "shape": "triangle", "size": "large"}
Timeout in ms (optional, press Enter for default): 

Calling tool test_tool...
Error: invalid_params %{
  "message" => "shape: expected type of {:string, {:enum, [\"circle\", \"square\", \"triangle\"]}} received \"triangle\" value; color: expected type of {:string, {:enum, [\"red\", \"green\", \"blue\"]}} received \"blue\" value; size: expected type of {:string, {:enum, [\"small\", \"medium\", \"large\"]}} received \"large\" value"
}

mcp> 

I get the same error using Postman where it reads the schema and offers me selectors for the enum types:
Image
and the server log gives me the same error as the interactive test task:

16:12:21.751 [warning] MCP server event: request_error

16:12:21.752 [warning] MCP event details: %{error: #MCP.Error<invalid_params: Invalid params %{
  message: "shape: expected type of {:string, {:enum, [\"circle\", \"square\", \"triangle\"]}} received \"triangle\" value; color: expected type of {:string, {:enum, [\"red\", \"green\", \"blue\"]}} received \"blue\" value; size: expected type of {:string, {:enum, [\"small\", \"medium\", \"large\"]}} received \"large\" value"
}>, id: 4, method: "tools/call"}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions