diff --git a/demo/config/services.yaml b/demo/config/services.yaml index 8ba8eec0..ceb2c178 100644 --- a/demo/config/services.yaml +++ b/demo/config/services.yaml @@ -18,11 +18,3 @@ services: - '../src/DependencyInjection/' - '../src/Entity/' - '../src/Kernel.php' - - mcp.tool_executor: - class: Symfony\AI\McpSdk\Capability\ToolChain - arguments: - - ['@App\MCP\Tools\CurrentTimeTool'] - - mcp.tool_collection: - alias: mcp.tool_executor diff --git a/src/mcp-bundle/CHANGELOG.md b/src/mcp-bundle/CHANGELOG.md index 13099753..7397baea 100644 --- a/src/mcp-bundle/CHANGELOG.md +++ b/src/mcp-bundle/CHANGELOG.md @@ -17,4 +17,6 @@ CHANGELOG * Add `McpCommand` providing STDIO interface * Add bundle configuration for enabling/disabling transports * Add cache-based SSE message storage - * Add service configuration for MCP server setup \ No newline at end of file + * Add service configuration for MCP server setup + * Classes extending `\Symfony\AI\McpSdk\Capability\Tool\IdentifierInterface` automatically + get the `mcp.tool` tag for MCP tool discovery diff --git a/src/mcp-bundle/config/services.php b/src/mcp-bundle/config/services.php index c714cf0c..23af88bc 100644 --- a/src/mcp-bundle/config/services.php +++ b/src/mcp-bundle/config/services.php @@ -11,6 +11,7 @@ namespace Symfony\Component\DependencyInjection\Loader\Configurator; +use Symfony\AI\McpSdk\Capability\ToolChain; use Symfony\AI\McpSdk\Message\Factory; use Symfony\AI\McpSdk\Server; use Symfony\AI\McpSdk\Server\JsonRpcHandler; @@ -66,5 +67,11 @@ ->args([ service('cache.app'), ]) + ->set('mcp.tool_chain', ToolChain::class) + ->args([ + tagged_iterator('mcp.tool'), + ]) + ->alias('mcp.tool_executor', 'mcp.tool_chain') + ->alias('mcp.tool_collection', 'mcp.tool_chain') ; }; diff --git a/src/mcp-bundle/src/McpBundle.php b/src/mcp-bundle/src/McpBundle.php index f8eb4ce0..8656a8e6 100644 --- a/src/mcp-bundle/src/McpBundle.php +++ b/src/mcp-bundle/src/McpBundle.php @@ -14,6 +14,7 @@ use Symfony\AI\McpBundle\Command\McpCommand; use Symfony\AI\McpBundle\Controller\McpController; use Symfony\AI\McpBundle\Routing\RouteLoader; +use Symfony\AI\McpSdk\Capability\Tool\IdentifierInterface; use Symfony\AI\McpSdk\Server\NotificationHandlerInterface; use Symfony\AI\McpSdk\Server\RequestHandlerInterface; use Symfony\Component\Config\Definition\Configurator\DefinitionConfigurator; @@ -42,6 +43,11 @@ public function loadExtension(array $config, ContainerConfigurator $container, C if (isset($config['client_transports'])) { $this->configureClient($config['client_transports'], $builder); } + + $builder + ->registerForAutoconfiguration(IdentifierInterface::class) + ->addTag('mcp.tool') + ; } /** diff --git a/src/mcp-sdk/src/Capability/ToolChain.php b/src/mcp-sdk/src/Capability/ToolChain.php index 06ca1d04..12bba83a 100644 --- a/src/mcp-sdk/src/Capability/ToolChain.php +++ b/src/mcp-sdk/src/Capability/ToolChain.php @@ -30,7 +30,7 @@ public function __construct( /** * @var IdentifierInterface[] $items */ - private readonly array $items, + private readonly iterable $items, ) { }