-
Notifications
You must be signed in to change notification settings - Fork 69
Open
Description
Is your feature request related to a problem? Please describe.
I'd like to implement a generic handler, for this I'm registering programmatically a few tools and resources. Basically a tool gets registered like this:
yield [
'type' => 'resource',
'definition' => [
'handler' => self::HANDLER,
'uri' => $uri,
'name' => $mcpName,
'description' => $operation->getDescription(),
],
];
// later we decorate the server builder and add them
I'd like for the handler
to be aware of a few of these parameters. Currently the CallToolHandler
does:
$toolName = $request->name;
$arguments = $request->arguments ?? [];
$reference = $this->referenceProvider->getTool($toolName);
$result = $this->referenceHandler->handle($reference, $arguments);
Describe the solution you'd like
I'm wondering if there would be ways to be aware of a given static context.
Describe alternatives you've considered
- Implement my own reference provider (I'll do this as I can return a wrapper around my handler with the
toolName
which is sufficient (for now)) edit: [Server] Add getRegistry() method to Server class for debugging access #75 registry isn't available therefore hard to hook on that - Add an interface
ContextAwareHandlerInterface
, userland can implement this and the sdk callswithContext
on the handler - Use a closure as a handler that has
use ($toolName)
and then to call the handler with that argument and the actual arguments of the tool (closures are hard to cache for now and need to be hold in memory at rutime, opposed to an array-callable) - declare one service per
toolName
(which overloads the container for no reason)
Additional context
As I needed that I thought that maybe others will. I'm willing to contribute to a patch if one of the proposed alternatives is considered.
Thanks for reading.
Metadata
Metadata
Assignees
Labels
No labels