Skip to content

Commit d22bc8a

Browse files
Change the approach used, removing the compiler pass
1 parent 20ef42c commit d22bc8a

File tree

6 files changed

+17
-60
lines changed

6 files changed

+17
-60
lines changed

demo/src/MCP/Tools/CurrentTimeTool.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,10 @@
1515
use Symfony\AI\McpSdk\Capability\Tool\ToolCall;
1616
use Symfony\AI\McpSdk\Capability\Tool\ToolCallResult;
1717
use Symfony\AI\McpSdk\Capability\Tool\ToolExecutorInterface;
18-
use Symfony\Component\DependencyInjection\Attribute\AutoconfigureTag;
1918

2019
/**
2120
* @author Tom Hart <[email protected]>
2221
*/
23-
#[AutoconfigureTag('mcp.tool')]
2422
class CurrentTimeTool implements MetadataInterface, ToolExecutorInterface
2523
{
2624
public function call(ToolCall $input): ToolCallResult

src/mcp-bundle/CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@ CHANGELOG
1818
* Add bundle configuration for enabling/disabling transports
1919
* Add cache-based SSE message storage
2020
* Add service configuration for MCP server setup
21-
* Add `Symfony\AI\McpBundle\DependencyInjection\ContainerBuilder\McpToolChainCompilerPass`
22-
to find services tagged `mcp.tool` and register them in the MCP tool chain.
21+
* Classes extending `\Symfony\AI\McpSdk\Capability\Tool\IdentifierInterface` automatically
22+
get the `mcp.tool` tag for MCP tool discovery

src/mcp-bundle/config/services.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
1313

14+
use Symfony\AI\McpSdk\Capability\Tool\IdentifierInterface;
15+
use Symfony\AI\McpSdk\Capability\ToolChain;
1416
use Symfony\AI\McpSdk\Message\Factory;
1517
use Symfony\AI\McpSdk\Server;
1618
use Symfony\AI\McpSdk\Server\JsonRpcHandler;
@@ -71,5 +73,11 @@
7173
->args([
7274
service('cache.app'),
7375
])
76+
->set('mcp.tool_chain', ToolChain::class)
77+
->args([
78+
tagged_iterator('mcp.tool')
79+
])
80+
->alias('mcp.tool_executor', 'mcp.tool_chain')
81+
->alias('mcp.tool_collection', 'mcp.tool_chain')
7482
;
7583
};

src/mcp-bundle/src/DependencyInjection/ContainerBuilder/McpToolChainCompilerPass.php

Lines changed: 0 additions & 48 deletions
This file was deleted.

src/mcp-bundle/src/McpBundle.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313

1414
use Symfony\AI\McpBundle\Command\McpCommand;
1515
use Symfony\AI\McpBundle\Controller\McpController;
16-
use Symfony\AI\McpBundle\DependencyInjection\ContainerBuilder\McpToolChainCompilerPass;
1716
use Symfony\AI\McpBundle\Routing\RouteLoader;
17+
use Symfony\AI\McpSdk\Capability\Tool\IdentifierInterface;
1818
use Symfony\Component\Config\Definition\Configurator\DefinitionConfigurator;
1919
use Symfony\Component\DependencyInjection\ContainerBuilder;
2020
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
@@ -23,12 +23,6 @@
2323

2424
final class McpBundle extends AbstractBundle
2525
{
26-
public function build(ContainerBuilder $container): void
27-
{
28-
parent::build($container);
29-
30-
$container->addCompilerPass(new McpToolChainCompilerPass());
31-
}
3226

3327
public function configure(DefinitionConfigurator $definition): void
3428
{
@@ -48,6 +42,11 @@ public function loadExtension(array $config, ContainerConfigurator $container, C
4842
if (isset($config['client_transports'])) {
4943
$this->configureClient($config['client_transports'], $builder);
5044
}
45+
46+
$builder
47+
->registerForAutoconfiguration(IdentifierInterface::class)
48+
->addTag('mcp.tool')
49+
;
5150
}
5251

5352
/**

src/mcp-sdk/src/Capability/ToolChain.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function __construct(
3030
/**
3131
* @var IdentifierInterface[] $items
3232
*/
33-
private readonly array $items,
33+
private readonly iterable $items,
3434
) {
3535
}
3636

0 commit comments

Comments
 (0)