Skip to content

Commit f1aa4e8

Browse files
committed
minor #229 [MCP Bundle] Add test case for configuration (OskarStark)
This PR was squashed before being merged into the main branch. Discussion ---------- [MCP Bundle] Add test case for configuration | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | Docs? | no | Issues | -- | License | MIT This commit adds comprehensive tests for the McpBundle configuration: - Tests default configuration values - Tests custom configuration for app name and version - Tests client transport configurations (stdio and sse) - Tests service registration based on transport settings - Tests autoconfiguration of MCP interfaces Commits ------- fbb4a9c [MCP Bundle] Add test case for configuration
2 parents 57d39f1 + fbb4a9c commit f1aa4e8

File tree

2 files changed

+161
-0
lines changed

2 files changed

+161
-0
lines changed

src/mcp-bundle/phpstan.dist.neon

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ parameters:
77
- src/
88
- tests/
99
ignoreErrors:
10+
-
11+
identifier: missingType.iterableValue
12+
path: tests/*
1013
-
1114
message: "#^Method .*::test.*\\(\\) has no return type specified\\.$#"
1215
reportUnmatched: false # we don't have tests yet
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[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+
namespace Symfony\AI\McpBundle\Tests\DependencyInjection;
13+
14+
use PHPUnit\Framework\Attributes\CoversClass;
15+
use PHPUnit\Framework\Attributes\DataProvider;
16+
use PHPUnit\Framework\TestCase;
17+
use Symfony\AI\McpBundle\McpBundle;
18+
use Symfony\AI\McpSdk\Capability\Tool\IdentifierInterface;
19+
use Symfony\AI\McpSdk\Server\NotificationHandlerInterface;
20+
use Symfony\AI\McpSdk\Server\RequestHandlerInterface;
21+
use Symfony\Component\DependencyInjection\ContainerBuilder;
22+
23+
#[CoversClass(McpBundle::class)]
24+
class McpBundleTest extends TestCase
25+
{
26+
public function testDefaultConfiguration()
27+
{
28+
$container = $this->buildContainer([]);
29+
30+
$this->assertSame('app', $container->getParameter('mcp.app'));
31+
$this->assertSame('0.0.1', $container->getParameter('mcp.version'));
32+
}
33+
34+
public function testCustomConfiguration()
35+
{
36+
$container = $this->buildContainer([
37+
'mcp' => [
38+
'app' => 'my-mcp-app',
39+
'version' => '1.2.3',
40+
],
41+
]);
42+
43+
$this->assertSame('my-mcp-app', $container->getParameter('mcp.app'));
44+
$this->assertSame('1.2.3', $container->getParameter('mcp.version'));
45+
}
46+
47+
#[DataProvider('provideClientTransportsConfiguration')]
48+
public function testClientTransportsConfiguration(array $config, array $expectedServices)
49+
{
50+
$container = $this->buildContainer([
51+
'mcp' => [
52+
'client_transports' => $config,
53+
],
54+
]);
55+
56+
foreach ($expectedServices as $serviceId => $shouldExist) {
57+
if ($shouldExist) {
58+
$this->assertTrue($container->hasDefinition($serviceId), \sprintf('Service "%s" should exist', $serviceId));
59+
} else {
60+
$this->assertFalse($container->hasDefinition($serviceId), \sprintf('Service "%s" should not exist', $serviceId));
61+
}
62+
}
63+
}
64+
65+
public static function provideClientTransportsConfiguration(): iterable
66+
{
67+
yield 'no transports enabled' => [
68+
'config' => [
69+
'stdio' => false,
70+
'sse' => false,
71+
],
72+
'expectedServices' => [
73+
'mcp.server.command' => false,
74+
'mcp.server.controller' => false,
75+
'mcp.server.route_loader' => false,
76+
],
77+
];
78+
79+
yield 'stdio transport enabled' => [
80+
'config' => [
81+
'stdio' => true,
82+
'sse' => false,
83+
],
84+
'expectedServices' => [
85+
'mcp.server.command' => true,
86+
'mcp.server.controller' => false,
87+
'mcp.server.route_loader' => true,
88+
],
89+
];
90+
91+
yield 'sse transport enabled' => [
92+
'config' => [
93+
'stdio' => false,
94+
'sse' => true,
95+
],
96+
'expectedServices' => [
97+
'mcp.server.command' => false,
98+
'mcp.server.controller' => true,
99+
'mcp.server.route_loader' => true,
100+
],
101+
];
102+
103+
yield 'both transports enabled' => [
104+
'config' => [
105+
'stdio' => true,
106+
'sse' => true,
107+
],
108+
'expectedServices' => [
109+
'mcp.server.command' => true,
110+
'mcp.server.controller' => true,
111+
'mcp.server.route_loader' => true,
112+
],
113+
];
114+
}
115+
116+
public function testToolAutoconfiguration()
117+
{
118+
$container = $this->buildContainer([]);
119+
120+
$autoconfiguredInstances = $container->getAutoconfiguredInstanceof();
121+
122+
$this->assertArrayHasKey(IdentifierInterface::class, $autoconfiguredInstances);
123+
$this->assertArrayHasKey('mcp.tool', $autoconfiguredInstances[IdentifierInterface::class]->getTags());
124+
}
125+
126+
public function testServerAutoconfigurations()
127+
{
128+
$container = $this->buildContainer([
129+
'mcp' => [
130+
'client_transports' => [
131+
'stdio' => true,
132+
'sse' => true,
133+
],
134+
],
135+
]);
136+
137+
$autoconfiguredInstances = $container->getAutoconfiguredInstanceof();
138+
139+
$this->assertArrayHasKey(NotificationHandlerInterface::class, $autoconfiguredInstances);
140+
$this->assertArrayHasKey(RequestHandlerInterface::class, $autoconfiguredInstances);
141+
142+
$this->assertArrayHasKey('mcp.server.notification_handler', $autoconfiguredInstances[NotificationHandlerInterface::class]->getTags());
143+
$this->assertArrayHasKey('mcp.server.request_handler', $autoconfiguredInstances[RequestHandlerInterface::class]->getTags());
144+
}
145+
146+
private function buildContainer(array $configuration): ContainerBuilder
147+
{
148+
$container = new ContainerBuilder();
149+
$container->setParameter('kernel.debug', true);
150+
$container->setParameter('kernel.environment', 'test');
151+
$container->setParameter('kernel.build_dir', 'public');
152+
153+
$extension = (new McpBundle())->getContainerExtension();
154+
$extension->load($configuration, $container);
155+
156+
return $container;
157+
}
158+
}

0 commit comments

Comments
 (0)