Describe the bug
When an MCP tool is defined with a nullable Enum parameter (?MyEnum $param = null), the generated JSON schema includes "null" in the type array, but does not include null in the enum array.
Because JSON Schema requires the value to strictly match one of the elements in the enum array when the keyword is present, validation fails if a client sends an explicit null payload for this parameter.
To Reproduce
enum MyEnum: string
{
case FOO = 'FOO';
case BAR = 'BAR';
}
#[McpTool]
public function myTool(?MyEnum $myEnum = null): int
{
return 42;
}
Actual behavior
The tools/list endpoint returns the following schema:
{
"tools": [
{
"name": "myTool",
"inputSchema": {
"type": "object",
"properties": {
"myEnum": {
"type": [
"null",
"string"
],
"default": null,
"enum": [
"FOO",
"BAR"
]
}
}
}
}
]
}
When calling the tool with an explicit null
{"name": "myTool", "arguments": {"myEnum": null}}
the following error is thrown:
{
error: "MCP error -32602: Invalid parameters for tool 'myTool': Property '/myEnum': Value must be one of the allowed values: "FOO", "BAR"."
}
Expected behavior
The generated schema should accept explicit null payloads when the enum type is nullable
Describe the bug
When an MCP tool is defined with a nullable Enum parameter (
?MyEnum $param = null), the generated JSON schema includes "null" in the type array, but does not include null in the enum array.Because JSON Schema requires the value to strictly match one of the elements in the enum array when the keyword is present, validation fails if a client sends an explicit null payload for this parameter.
To Reproduce
Actual behavior
The
tools/listendpoint returns the following schema:{ "tools": [ { "name": "myTool", "inputSchema": { "type": "object", "properties": { "myEnum": { "type": [ "null", "string" ], "default": null, "enum": [ "FOO", "BAR" ] } } } } ] }When calling the tool with an explicit null
{"name": "myTool", "arguments": {"myEnum": null}}the following error is thrown:
{ error: "MCP error -32602: Invalid parameters for tool 'myTool': Property '/myEnum': Value must be one of the allowed values: "FOO", "BAR"." }Expected behavior
The generated schema should accept explicit null payloads when the enum type is nullable