Skip to content

[Server] Passing tool handler using instance method throws "Invalid array handler" #369

@perk11

Description

@perk11

Describe the bug
A clear and concise description of what the bug is.

To Reproduce


use Mcp\Server;

require_once __DIR__ . '/vendor/autoload.php';

class Foo
{
    public function bar()
    {
    }
}

$foo = new Foo();
$mcpServerInstance = Server::builder()
    ->addTool(
        handler: [$foo, 'bar'],
        name:    'foo',
    )
    ->build();
    

After running this I get

PHP Fatal error:  Uncaught Mcp\Exception\InvalidArgumentException: Invalid array handler format. Expected [ClassName::class, 'methodName']. in /app/vendor/mcp/sdk/src/Capability/Discovery/HandlerResolver.php:45

Expected behavior
Per documentation this should be possible

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions