diff --git a/src/Responses/Responses/Output/OutputMcpCall.php b/src/Responses/Responses/Output/OutputMcpCall.php index 9fbf250e..c3a0630c 100644 --- a/src/Responses/Responses/Output/OutputMcpCall.php +++ b/src/Responses/Responses/Output/OutputMcpCall.php @@ -69,9 +69,9 @@ public static function from(array $attributes): self type: $attributes['type'], arguments: $attributes['arguments'], name: $attributes['name'], - approvalRequestId: $attributes['approval_request_id'], + approvalRequestId: $attributes['approval_request_id'] ?? null, error: $errorType, - output: $attributes['output'], + output: $attributes['output'] ?? null, ); } diff --git a/src/Responses/Responses/Tool/WebSearchUserLocation.php b/src/Responses/Responses/Tool/WebSearchUserLocation.php index 601726ef..a9026136 100644 --- a/src/Responses/Responses/Tool/WebSearchUserLocation.php +++ b/src/Responses/Responses/Tool/WebSearchUserLocation.php @@ -40,10 +40,10 @@ public static function from(array $attributes): self { return new self( type: $attributes['type'], - city: $attributes['city'], + city: $attributes['city'] ?? null, country: $attributes['country'], - region: $attributes['region'], - timezone: $attributes['timezone'], + region: $attributes['region'] ?? null, + timezone: $attributes['timezone'] ?? null, ); } diff --git a/tests/Responses/Responses/Output/OutputMcpCall.php b/tests/Responses/Responses/Output/OutputMcpCall.php index 50edeeed..4fd4917a 100644 --- a/tests/Responses/Responses/Output/OutputMcpCall.php +++ b/tests/Responses/Responses/Output/OutputMcpCall.php @@ -19,6 +19,25 @@ ->output->toBeNull(); }); +test('from without optional keys', function () { + $attributes = outputMcpCall(); + + unset($attributes['approval_request_id'], $attributes['output']); + + set_error_handler(static fn (int $errno, string $errstr): bool => throw new ErrorException($errstr), E_WARNING); + + try { + $response = OutputMcpCall::from($attributes); + } finally { + restore_error_handler(); + } + + expect($response) + ->toBeInstanceOf(OutputMcpCall::class) + ->approvalRequestId->toBeNull() + ->output->toBeNull(); +}); + test('from error as http object', function () { $response = OutputMcpCall::from(outputMcpErrorCallObject()); diff --git a/tests/Responses/Responses/Tool/WebSearchUserLocation.php b/tests/Responses/Responses/Tool/WebSearchUserLocation.php new file mode 100644 index 00000000..7b4cf169 --- /dev/null +++ b/tests/Responses/Responses/Tool/WebSearchUserLocation.php @@ -0,0 +1,42 @@ + 'approximate', + 'city' => 'San Francisco', + 'country' => 'US', + 'region' => 'California', + 'timezone' => 'America/Los_Angeles', + ]); + + expect($response) + ->toBeInstanceOf(WebSearchUserLocation::class) + ->type->toBe('approximate') + ->city->toBe('San Francisco') + ->country->toBe('US') + ->region->toBe('California') + ->timezone->toBe('America/Los_Angeles'); +}); + +test('from without optional keys', function () { + set_error_handler(static fn (int $errno, string $errstr): bool => throw new ErrorException($errstr), E_WARNING); + + try { + $response = WebSearchUserLocation::from([ + 'type' => 'approximate', + 'country' => 'US', + ]); + } finally { + restore_error_handler(); + } + + expect($response) + ->toBeInstanceOf(WebSearchUserLocation::class) + ->type->toBe('approximate') + ->country->toBe('US') + ->city->toBeNull() + ->region->toBeNull() + ->timezone->toBeNull(); +});