Skip to content

[Server] Handler context #108

Description

@soyuka

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

  1. 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
  2. Add an interface ContextAwareHandlerInterface, userland can implement this and the sdk calls withContext on the handler
  3. 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)
  4. 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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    ServerIssues & PRs related to the Server component

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions