diff --git a/src/JsonRpc/Request.php b/src/JsonRpc/Request.php index 7b008f0..03298f9 100644 --- a/src/JsonRpc/Request.php +++ b/src/JsonRpc/Request.php @@ -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.'); } diff --git a/src/Request/CallToolRequest.php b/src/Request/CallToolRequest.php index 487302d..c57c713 100644 --- a/src/Request/CallToolRequest.php +++ b/src/Request/CallToolRequest.php @@ -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 + ); } }