Skip to content

Conversation

monayemislam
Copy link

  • Add support for variadic parameters (...) in prepareArguments method
  • Collect all numeric-indexed arguments starting from parameter position
  • Add proper error handling for variadic parameter processing
  • Remove TODO comment and complete the implementation
  • Maintain backward compatibility with existing parameter handling

Fixes the TODO item in ReferenceHandler.php line 88 and enables proper handling of functions with variadic parameters in MCP tools and resources.

- Add support for variadic parameters (...) in prepareArguments method
- Collect all numeric-indexed arguments starting from parameter position
- Add proper error handling for variadic parameter processing
- Remove TODO comment and complete the implementation
- Maintain backward compatibility with existing parameter handling

Fixes the TODO item in ReferenceHandler.php line 88 and enables
proper handling of functions with variadic parameters in MCP tools
and resources.
Copy link
Member

@chr-hertel chr-hertel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @monayemislam, good catch that todo comment - thanks for picking up on that!

I made some smaller comments, but can you share how you tested this?

$paramName = $parameter->getName();
$paramPosition = $parameter->getPosition();

// Handle variadic parameters
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think this is clear with the next line of code already and we can remove this comment

Suggested change
// Handle variadic parameters

Comment on lines +95 to +96
foreach ($arguments as $key => $value) {
if (is_numeric($key) && $key >= $paramPosition) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this reads like array_slice could be of help 👍

Comment on lines +97 to +103
try {
$variadicArgs[] = $this->castArgumentType($value, $parameter);
} catch (InvalidArgumentException $e) {
throw RegistryException::invalidParams($e->getMessage(), $e);
} catch (\Throwable $e) {
throw RegistryException::internalError("Error processing variadic parameter `{$paramName}`: {$e->getMessage()}", $e);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is basically the same like in line 112-118 - does it make sense to shift the throw RegistryException into the castArgumentType method instead and skip the try-catch in both cases?

or somehow merge this block into lower if-else part as well?

@chr-hertel chr-hertel changed the title feat: implement variadic parameter handling in ReferenceHandler [Server] Implement variadic parameter handling in ReferenceHandler Sep 21, 2025
@chr-hertel chr-hertel added the Server Issues & PRs related to the Server component label Sep 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Server Issues & PRs related to the Server component Status: Needs Work
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants