Repository navigation
Closed
Labels
ServerIssues & PRs related to the Server component
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 themI'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
toolNamewhich 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 callswithContexton 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
ServerIssues & PRs related to the Server component
Activity
[-]Handler context[/-][+][Server] Handler context[/+]chr-hertel commentedon Oct 20, 2025
Is context only
toolNameor basically the entireTool&Requestobject?Can you check if partially reverting #100 would help with your situation?
cc @CodeWithKyrian
soyuka commentedon Oct 24, 2025
Probably that #111 helps with that I'll report back once I'm done with that part.
CodeWithKyrian commentedon Oct 25, 2025
Still doesn't does it?
soyuka commentedon Oct 25, 2025
With the registry loader I now have access to the registry it may help I need to try this.
chr-hertel commentedon Jan 23, 2026
Hey @soyuka, can we close here? your use case covered or still sth to follow up on?
soyuka commentedon Jan 24, 2026
Completely resolved! For anyone interested in how I did check out api-platform/core#7595
rvanlaak commentedon Jan 24, 2026
Exciting, congrats! Any ETA when a RC of APIP 4.3 could be expected?