Skip to content

Commit d136520

Browse files
committed
event listeners
1 parent a054c01 commit d136520

File tree

4 files changed

+79
-21
lines changed

4 files changed

+79
-21
lines changed

src/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,8 @@ public function load(array $configs, ContainerBuilder $container): void
202202
}
203203

204204
if (($config['mcp']['enabled'] ?? false) && class_exists(McpBundle::class)) {
205-
$loader->load('mcp.php');
205+
$loader->load('mcp/mcp.php');
206+
$loader->load($config['use_symfony_listeners'] ? 'mcp/events.php' : 'mcp/state.php');
206207
}
207208

208209
$container->registerForAutoconfiguration(FilterInterface::class)
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the API Platform project.
5+
*
6+
* (c) Kévin Dunglas <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
15+
16+
use ApiPlatform\Mcp\Server\Handler;
17+
use ApiPlatform\Mcp\State\StructuredContentProcessor;
18+
19+
return function (ContainerConfigurator $container) {
20+
$services = $container->services();
21+
22+
$services->set('api_platform.mcp.handler', Handler::class)
23+
->args([
24+
service('api_platform.mcp.metadata.operation.mcp_factory'),
25+
service('api_platform.state_provider.locator'),
26+
service('api_platform.state_processor.serialize'),
27+
service('request_stack'),
28+
service('monolog.logger.mcp'),
29+
])
30+
->tag('mcp.request_handler');
31+
32+
$services->set('api_platform.mcp.state_processor.structured_content', StructuredContentProcessor::class)
33+
->args([
34+
null,
35+
service('api_platform.serializer'),
36+
service('api_platform.serializer.context_builder'),
37+
]);
38+
};

src/Symfony/Bundle/Resources/config/mcp.php renamed to src/Symfony/Bundle/Resources/config/mcp/mcp.php

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
use ApiPlatform\Mcp\Capability\Registry\Loader;
1717
use ApiPlatform\Mcp\Metadata\Operation\Factory\OperationMetadataFactory;
1818
use ApiPlatform\Mcp\Routing\IriConverter;
19-
use ApiPlatform\Mcp\Server\Handler;
20-
use ApiPlatform\Mcp\State\StructuredContentProcessor;
2119
use ApiPlatform\Mcp\State\ToolProvider;
2220

2321
return function (ContainerConfigurator $container) {
@@ -37,16 +35,6 @@
3735
service('api_platform.mcp.iri_converter.inner'),
3836
]);
3937

40-
$services->set('api_platform.mcp.handler', Handler::class)
41-
->args([
42-
service('api_platform.mcp.metadata.operation.mcp_factory'),
43-
service('api_platform.state_provider.main'),
44-
service('api_platform.state_processor.main'),
45-
service('request_stack'),
46-
service('monolog.logger.mcp'),
47-
])
48-
->tag('mcp.request_handler');
49-
5038
$services->set('api_platform.mcp.state.tool_provider', ToolProvider::class)
5139
->args([
5240
service('object_mapper'),
@@ -58,12 +46,4 @@
5846
service('api_platform.metadata.resource.name_collection_factory'),
5947
service('api_platform.metadata.resource.metadata_collection_factory'),
6048
]);
61-
62-
$services->set('api_platform.mcp.state_processor.structured_content', StructuredContentProcessor::class)
63-
->decorate('api_platform.state_processor.main', null, 200)
64-
->args([
65-
service('api_platform.serializer'),
66-
service('api_platform.serializer.context_builder'),
67-
service('api_platform.mcp.state_processor.structured_content.inner'),
68-
]);
6949
};
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the API Platform project.
5+
*
6+
* (c) Kévin Dunglas <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
15+
16+
use ApiPlatform\Mcp\Server\Handler;
17+
use ApiPlatform\Mcp\State\StructuredContentProcessor;
18+
19+
return function (ContainerConfigurator $container) {
20+
$services = $container->services();
21+
22+
$services->set('api_platform.mcp.handler', Handler::class)
23+
->args([
24+
service('api_platform.mcp.metadata.operation.mcp_factory'),
25+
service('api_platform.state_provider.main'),
26+
service('api_platform.state_processor.main'),
27+
service('request_stack'),
28+
service('monolog.logger.mcp'),
29+
])
30+
->tag('mcp.request_handler');
31+
32+
$services->set('api_platform.mcp.state_processor.structured_content', StructuredContentProcessor::class)
33+
->decorate('api_platform.state_processor.main', null, 200)
34+
->args([
35+
service('api_platform.serializer'),
36+
service('api_platform.serializer.context_builder'),
37+
service('api_platform.mcp.state_processor.structured_content.inner'),
38+
]);
39+
};

0 commit comments

Comments
 (0)