@@ -178,8 +178,30 @@ protected function createHandlerFunction(string $toolName, array $definition): c
178178 return fn ($ script = null ): string => $ this ->callMCPTool ($ toolName , ['script ' => $ script ]);
179179 }
180180
181- // Default generic handler for any other tool
182- return fn ($ parameters = []): string => $ this ->callMCPTool ($ toolName , $ parameters );
181+ // Default generic handler for any other tool - handle both individual params and array
182+ return function (...$ args ) use ($ toolName , $ definition ): string {
183+ // Check if we have named parameters (associative array)
184+ if ($ args !== [] && array_keys ($ args ) !== range (0 , count ($ args ) - 1 )) {
185+ // We have named parameters, use them directly
186+ return $ this ->callMCPTool ($ toolName , $ args );
187+ }
188+ // If first argument is an array, use it as parameters
189+ if (count ($ args ) === 1 && isset ($ args [0 ]) && is_array ($ args [0 ])) {
190+ return $ this ->callMCPTool ($ toolName , $ args [0 ]);
191+ }
192+
193+ // Otherwise, map positional arguments to parameter names
194+ $ requiredParams = $ this ->getRequiredParameters ($ definition );
195+ $ parameters = [];
196+
197+ foreach ($ requiredParams as $ index => $ paramName ) {
198+ if (isset ($ args [$ index ])) {
199+ $ parameters [$ paramName ] = $ args [$ index ];
200+ }
201+ }
202+
203+ return $ this ->callMCPTool ($ toolName , $ parameters );
204+ };
183205 }
184206
185207 /**
@@ -319,7 +341,7 @@ protected function addParameter(Tool $tool, string $name, string $type, string $
319341 }
320342
321343 /**
322- * @param array<string, mixed>|object|string $parameters
344+ * @param array<string|int , mixed>|object|string $parameters
323345 *
324346 * @throws ToolCallException
325347 */
@@ -350,7 +372,7 @@ protected function extractBaseToolName(string $toolName): string
350372 }
351373
352374 /**
353- * @param array<string, mixed>|object|string $parameters
375+ * @param array<string|int , mixed>|object|string $parameters
354376 * @return array<string, mixed>
355377 */
356378 protected function normalizeParameters (string $ baseToolName , $ parameters ): array
@@ -395,11 +417,13 @@ protected function executeMCPToolCall(string $toolName, array $parameters): arra
395417 // MCP requires arguments to be an object, not an array
396418 $ normalizedParamsObject = (object ) $ parameters ;
397419
398- // Call the tool using JSON-RPC format with correct MCP endpoint: tools/call
399- return $ this ->transport ->sendRequest ('tools/call ' , [
420+ $ requestParams = [
400421 'name ' => $ toolName ,
401422 'arguments ' => $ normalizedParamsObject ,
402- ]);
423+ ];
424+
425+ // Call the tool using JSON-RPC format with correct MCP endpoint: tools/call
426+ return $ this ->transport ->sendRequest ('tools/call ' , $ requestParams );
403427 }
404428
405429 /**
0 commit comments