Skip to content

[McpSdk] Improve the relation between Tool Metadata and Tool Executor #89

Open
@Kocal

Description

@Kocal

Hey!

I quickly read the MCP SDK Capabilities documentation, and some code examples seem confusing to me.

I feel like there is no real link between a tool metadata and its executor. IINW, both are resolved/linked on-the-fly thanks to getName() or name comparaison from https://github.com/symfony/ai/blob/main/src/mcp-sdk/src/Capability/ToolChain.php#L37-L74

I feel like we can get some inspiration from the Symfony Messenger/Console components or other existing MCP-SDK, by using a PHP Attribute AsTool for describing the Tool's metadata, on an invokable class?

<?php
#[AsTool(
    name: 'Current time',
    description: 'Returns the current time in UTC',
    // or through a static method
    inputSchema: [
        'type' => 'object',
        'properties' => [
            'format' => [
                'type' => 'string',
                'description' => 'The format of the time to return, e.g. "Y-m-d H:i:s"',
            ],
        ],
    ]
)]
class CurrentTimeTool implements ToolExecutorInterface
{
    // or through the attribute `AsTool`
    public static function getInputSchema(): array
    {
        return [
            'type' => 'object',
            'properties' => [
                'format' => [
                    'type' => 'string',
                    'description' => 'The format of the time to return, e.g. "Y-m-d H:i:s"',
                ],
            ],
            'required' => ['format'],
        ];
    }

    public function __invoke(ToolCall $input): ToolCallResult
    {
        // ...
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    MCP SDKIssues & PRs about the MCP SDK

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions