Skip to content

Commit 6b6c962

Browse files
judusCodeWithKyrian
authored andcommitted
Normalize stdClass to array in Request::fromArray() for param type safety
Converts stdClass to an associative array when decoding 'params' in JsonRpc\Request, ensuring type compliance with downstream DTOs. Fixes php-mcp/server#53 See php-mcp/server#53 (comment)
1 parent de8a32e commit 6b6c962

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/JsonRpc/Request.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ public static function fromArray(array $data): static
4242
throw new \InvalidArgumentException('Invalid or missing "method" for Request.');
4343
}
4444
$params = $data['params'] ?? null;
45+
if ($params instanceof \stdClass) {
46+
$params = (array) $params;
47+
}
4548
if ($params !== null && !is_array($params)) {
4649
throw new \InvalidArgumentException('"params" for Request must be an array/object or null.');
4750
}

0 commit comments

Comments
 (0)