1818use Piwik \Plugins \McpServer \Contracts \Records \Reports \ReportMetadataRecord ;
1919use Piwik \Plugins \McpServer \Contracts \Ports \Reports \ReportMetadataQueryServiceInterface ;
2020use Piwik \Plugins \McpServer \Schemas \Reports \ReportMetadataToolOutputSchema ;
21+ use Piwik \Plugins \McpServer \Support \Normalization \ToolDataNormalizer ;
2122
2223/**
2324 * @phpstan-import-type ReportMetadataArray from ReportMetadataRecord
@@ -76,9 +77,18 @@ public function __construct(private ReportMetadataQueryServiceInterface $querySe
7677 'description ' => 'Date for module/action metadata lookup (default today). ' ,
7778 ],
7879 'apiParameters ' => [
79- 'type ' => 'object ' ,
80- 'description ' => 'Optional report parameter object used with module/action lookup. ' ,
81- 'additionalProperties ' => true ,
80+ 'oneOf ' => [
81+ [
82+ 'type ' => 'object ' ,
83+ 'description ' => 'Optional report parameter object used with module/action lookup. ' ,
84+ 'additionalProperties ' => true ,
85+ ],
86+ [
87+ 'type ' => 'array ' ,
88+ 'maxItems ' => 0 ,
89+ 'description ' => 'Empty array is accepted and normalized as no apiParameters. ' ,
90+ ],
91+ ],
8292 ],
8393 ],
8494 'required ' => ['idSite ' ],
@@ -100,7 +110,21 @@ public function __construct(private ReportMetadataQueryServiceInterface $querySe
100110 ],
101111 ['required ' => ['reportUniqueId ' , 'apiModule ' ]],
102112 ['required ' => ['reportUniqueId ' , 'apiAction ' ]],
103- ['required ' => ['reportUniqueId ' , 'apiParameters ' ]],
113+ [
114+ 'allOf ' => [
115+ ['required ' => ['reportUniqueId ' , 'apiParameters ' ]],
116+ [
117+ 'properties ' => [
118+ 'apiParameters ' => [
119+ 'not ' => [
120+ 'type ' => 'array ' ,
121+ 'maxItems ' => 0 ,
122+ ],
123+ ],
124+ ],
125+ ],
126+ ],
127+ ],
104128 [
105129 'required ' => ['apiModule ' ],
106130 'not ' => ['required ' => ['apiAction ' ]],
@@ -122,11 +146,15 @@ public function get(
122146 ?string $ date = null ,
123147 ?array $ apiParameters = null
124148 ): array {
149+ $ apiParameters = $ apiParameters === null
150+ ? null
151+ : ToolDataNormalizer::requireStringKeyedArrayOrEmptyList ($ apiParameters , 'apiParameters ' );
152+
125153 if ($ reportUniqueId !== null ) {
126154 if (
127155 $ apiModule !== null
128156 || $ apiAction !== null
129- || $ apiParameters !== null
157+ || ( $ apiParameters !== null && $ apiParameters !== [])
130158 ) {
131159 throw new ToolCallException (
132160 'Invalid parameter combination: reportUniqueId cannot be combined '
0 commit comments