Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/JsonRpc/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ public static function fromArray(array $data): static
throw new \InvalidArgumentException('Invalid or missing "method" for Request.');
}
$params = $data['params'] ?? null;
if ($params instanceof \stdClass) {
$params = (array) $params;
}
if ($params !== null && !is_array($params)) {
throw new \InvalidArgumentException('"params" for Request must be an array/object or null.');
}
Expand Down
22 changes: 16 additions & 6 deletions src/Request/CallToolRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,27 @@ public static function fromRequest(Request $request): static
throw new \InvalidArgumentException('Request is not a call tool request');
}

$params = $request->params;
$params = $request->params ?? [];

if (! isset($params['name']) || ! is_string($params['name'])) {
if (!isset($params['name']) || !is_string($params['name'])) {
throw new \InvalidArgumentException("Missing or invalid 'name' parameter for tools/call.");
}

$arguments = $params['arguments'] ?? new \stdClass();
if (! is_array($arguments) && ! $arguments instanceof \stdClass) {
throw new \InvalidArgumentException("Parameter 'arguments' must be an object/array for tools/call.");
$arguments = $params['arguments'] ?? [];

if ($arguments instanceof \stdClass) {
$arguments = (array) $arguments;
}

if (!is_array($arguments)) {
throw new \InvalidArgumentException("Parameter 'arguments' must be an array.");
}

return new static($request->id, $params['name'], $arguments, $params['_meta'] ?? null);
return new static(
$request->id,
$params['name'],
$arguments,
$params['_meta'] ?? null
);
}
}