Skip to content

Commit 66fff92

Browse files
committed
feature #168 [McpBundle] Compiler pass for tools (tom-hart-sky-uk)
This PR was merged into the main branch. Discussion ---------- [McpBundle] Compiler pass for tools | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | Docs? | yes | Issues | N/A | License | MIT Add a Compiler Pass to find tools and register them in the ToolChain Commits ------- 0a77af8 Added Compiler Pass to build ToolChain
2 parents 09ac08d + 0a77af8 commit 66fff92

File tree

5 files changed

+17
-10
lines changed

5 files changed

+17
-10
lines changed

demo/config/services.yaml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,3 @@ services:
1818
- '../src/DependencyInjection/'
1919
- '../src/Entity/'
2020
- '../src/Kernel.php'
21-
22-
mcp.tool_executor:
23-
class: Symfony\AI\McpSdk\Capability\ToolChain
24-
arguments:
25-
- ['@App\MCP\Tools\CurrentTimeTool']
26-
27-
mcp.tool_collection:
28-
alias: mcp.tool_executor

src/mcp-bundle/CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,6 @@ CHANGELOG
1717
* Add `McpCommand` providing STDIO interface
1818
* Add bundle configuration for enabling/disabling transports
1919
* Add cache-based SSE message storage
20-
* Add service configuration for MCP server setup
20+
* Add service configuration for MCP server setup
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: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

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

14+
use Symfony\AI\McpSdk\Capability\ToolChain;
1415
use Symfony\AI\McpSdk\Message\Factory;
1516
use Symfony\AI\McpSdk\Server;
1617
use Symfony\AI\McpSdk\Server\JsonRpcHandler;
@@ -66,5 +67,11 @@
6667
->args([
6768
service('cache.app'),
6869
])
70+
->set('mcp.tool_chain', ToolChain::class)
71+
->args([
72+
tagged_iterator('mcp.tool'),
73+
])
74+
->alias('mcp.tool_executor', 'mcp.tool_chain')
75+
->alias('mcp.tool_collection', 'mcp.tool_chain')
6976
;
7077
};

src/mcp-bundle/src/McpBundle.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Symfony\AI\McpBundle\Command\McpCommand;
1515
use Symfony\AI\McpBundle\Controller\McpController;
1616
use Symfony\AI\McpBundle\Routing\RouteLoader;
17+
use Symfony\AI\McpSdk\Capability\Tool\IdentifierInterface;
1718
use Symfony\AI\McpSdk\Server\NotificationHandlerInterface;
1819
use Symfony\AI\McpSdk\Server\RequestHandlerInterface;
1920
use Symfony\Component\Config\Definition\Configurator\DefinitionConfigurator;
@@ -42,6 +43,11 @@ public function loadExtension(array $config, ContainerConfigurator $container, C
4243
if (isset($config['client_transports'])) {
4344
$this->configureClient($config['client_transports'], $builder);
4445
}
46+
47+
$builder
48+
->registerForAutoconfiguration(IdentifierInterface::class)
49+
->addTag('mcp.tool')
50+
;
4551
}
4652

4753
/**

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)