-
-
Notifications
You must be signed in to change notification settings - Fork 12
Open
Description
Summary
When MCP servers define tool parameters with type: "array"
, the Relay package incorrectly converts them to string parameters instead of array parameters, causing schema validation failures with AI providers like Anthropic.
Environment
- Relay version: Latest from composer
- PHP version: 8.x
- MCP Server: Gmail MCP Server (@gongrzhe/server-gmail-autoauth-mcp)
- AI Provider: Anthropic
Steps to Reproduce
- Configure an MCP server that returns tool definitions with array parameters:
{
"name": "send_email",
"inputSchema": {
"properties": {
"to": {
"type": "array",
"items": {"type": "string"},
"description": "List of recipient email addresses"
}
}
}
}
- Load tools using
Relay::tools('server-name')
- Check the parameter schema:
$tool->parametersAsArray()
Expected Behavior
The parameter should be converted to an array type:
"to": {
"description": "List of recipient email addresses",
"type": "array",
"items": {
"type": "string"
}
}
Actual Behavior
The parameter is incorrectly converted to a string type:
"to": {
"description": "List of recipient email addresses",
"type": "string"
}
Root Cause
In src/Relay.php
, the addParametersToTool
method (around line 335-340) only handles these types:
string
number
/integer
boolean
default
(falls back to string)
Array types are not handled and fall through to the default
case, becoming string parameters.
Current Code (Problematic)
match ($type) {
'string' => $tool->withStringParameter($name, $description, $required),
'number', 'integer' => $tool->withNumberParameter($name, $description, $required),
'boolean' => $tool->withBooleanParameter($name, $description, $required),
default => $tool->withStringParameter($name, $description, $required), // Arrays end up here!
};
Suggested Fix
Add array type handling:
match ($type) {
'string' => $tool->withStringParameter($name, $description, $required),
'number', 'integer' => $tool->withNumberParameter($name, $description, $required),
'boolean' => $tool->withBooleanParameter($name, $description, $required),
'array' => {
$items = $property['items'] ?? [];
$itemType = $items['type'] ?? 'string';
$itemSchema = match ($itemType) {
'string' => new StringSchema(name: 'item', description: 'Array item'),
'number', 'integer' => new NumberSchema(name: 'item', description: 'Array item'),
'boolean' => new BooleanSchema(name: 'item', description: 'Array item'),
default => new StringSchema(name: 'item', description: 'Array item'),
};
$tool->withArrayParameter($name, $description, $itemSchema, $required);
},
default => $tool->withStringParameter($name, $description, $required),
};
Impact
This bug affects any MCP server that uses array parameters, causing:
- Schema validation failures with AI providers
- Incorrect tool call arguments (strings instead of arrays)
- Runtime errors when tools expect arrays but receive strings
hipigBoweFrankema
Metadata
Metadata
Assignees
Labels
No labels