diff --git a/src/Responses/Responses/Tool/RemoteMcpTool.php b/src/Responses/Responses/Tool/RemoteMcpTool.php index 9c49005c..00d2a6fb 100644 --- a/src/Responses/Responses/Tool/RemoteMcpTool.php +++ b/src/Responses/Responses/Tool/RemoteMcpTool.php @@ -49,9 +49,12 @@ public static function from(array $attributes): self { $requireApproval = $attributes['require_approval'] ?? null; if (is_array($requireApproval)) { - $requireApproval = array_map(function (array $approvalAttributes): McpToolNamesFilter { - return McpToolNamesFilter::from($approvalAttributes); - }, $requireApproval); + $requireApproval = array_map( + function (array $approvalAttributes): McpToolNamesFilter { + return McpToolNamesFilter::from($approvalAttributes); + }, + array_filter($requireApproval, fn (?array $item) => $item !== null) + ); } $allowedTools = $attributes['allowed_tools'] ?? null; diff --git a/tests/Fixtures/Responses.php b/tests/Fixtures/Responses.php index c14e7462..e50e0cbf 100644 --- a/tests/Fixtures/Responses.php +++ b/tests/Fixtures/Responses.php @@ -626,6 +626,28 @@ function toolRemoteMcp(): array ]; } +/** + * @return array + */ +function toolRemoveMcpRequireApproval(): array +{ + return [ + 'type' => 'mcp', + 'server_label' => 'My test MCP server', + 'server_url' => 'https://server.example.com/mcp', + 'require_approval' => [ + 'never' => [ + 'read_only' => null, + 'tool_names' => ['ask_question', 'read_wiki_structure'], + ], + 'always' => null, + ], + 'allowed_tools' => null, + 'headers' => null, + 'server_description' => null, + ]; +} + /** * @return array */ diff --git a/tests/Responses/Responses/Tool/RemoteMcpTool.php b/tests/Responses/Responses/Tool/RemoteMcpTool.php index 517cdf0c..dfda7ab7 100644 --- a/tests/Responses/Responses/Tool/RemoteMcpTool.php +++ b/tests/Responses/Responses/Tool/RemoteMcpTool.php @@ -45,6 +45,14 @@ ->requireApproval->toBeArray(); }); +test('from object as specific approved tools', function () { + $response = RemoteMcpTool::from(toolRemoveMcpRequireApproval()); + + expect($response) + ->toBeInstanceOf(RemoteMcpTool::class) + ->requireApproval->toBeArray(); +}); + test('from object as allowed_tools', function () { $payload = toolRemoteMcp(); $payload['allowed_tools'] = [