-
Notifications
You must be signed in to change notification settings - Fork 61
[Server] Implement variadic parameter handling in ReferenceHandler #36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
- 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.
There was a problem hiding this 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 |
There was a problem hiding this comment.
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
// Handle variadic parameters |
foreach ($arguments as $key => $value) { | ||
if (is_numeric($key) && $key >= $paramPosition) { |
There was a problem hiding this comment.
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 👍
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); | ||
} |
There was a problem hiding this comment.
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?
Fixes the TODO item in ReferenceHandler.php line 88 and enables proper handling of functions with variadic parameters in MCP tools and resources.