Skip to content

Commit ac23f60

Browse files
authored
Merge pull request #22 from symfony/mcp-bundle-integration
MCP Bundle Integration
2 parents 510a37a + 5b03ae8 commit ac23f60

File tree

18 files changed

+560
-0
lines changed

18 files changed

+560
-0
lines changed

src/mcp-bundle/.gitattributes

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/.github export-ignore
2+
.gitattributes export-ignore
3+
.gitignore export-ignore
4+
phpstan.dist.neon export-ignore
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Please do not submit any Pull Requests here. They will be closed.
2+
---
3+
4+
Please submit your PR here instead:
5+
https://github.com/symfony/ai
6+
7+
This repository is what we call a "subtree split": a read-only subset of that main repository.
8+
We're looking forward to your PR there!
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Close Pull Request
2+
3+
on:
4+
pull_request_target:
5+
types: [opened]
6+
7+
jobs:
8+
run:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: superbrothers/close-pull-request@v3
12+
with:
13+
comment: |
14+
Thanks for your Pull Request! We love contributions.
15+
16+
However, you should instead open your PR on the main repository:
17+
https://github.com/symfony/ai
18+
19+
This repository is what we call a "subtree split": a read-only subset of that main repository.
20+
We're looking forward to your PR there!

src/mcp-bundle/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
vendor
2+
composer.lock
3+
.php-cs-fixer.cache

src/mcp-bundle/LICENSE

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2025-present Fabien Potencier
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is furnished
8+
to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.

src/mcp-bundle/README.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# MCP Bundle [WIP]
2+
3+
Symfony integration bundle for [Model Context Protocol](https://modelcontextprotocol.io/) using the Symfony AI
4+
MCP SDK [symfony/mcp-sdk](https://github.com/symfony/mcp-sdk).
5+
6+
**Currently only supports tools as server via Server-Sent Events (SSE) and STDIO.**
7+
8+
## Installation
9+
10+
```bash
11+
composer require symfony/mcp-bundle
12+
```
13+
14+
## Usage
15+
16+
At first, you need to decide whether your application should act as a MCP server or client. Both can be configured
17+
in the `mcp` section of your `config/packages/mcp.yaml` file.
18+
19+
### Act as Server
20+
21+
**Currently only supports tools.**
22+
23+
To use your application as an MCP server, exposing tools to clients like [Claude Desktop](https://claude.ai/download),
24+
you need to configure in the `client_transports` section the transports you want to expose to clients.
25+
You can use either STDIO or SSE.
26+
27+
### Act as Client
28+
29+
**Not implemented yet.**
30+
31+
To use your application as an MCP client, integrating other MCP servers, you need to configure the `servers` you want to
32+
connect to. You can use either STDIO or Server-Sent Events (SSE) as transport methods.
33+
34+
You can find a list of example Servers in the [MCP Server List](https://modelcontextprotocol.io/examples).
35+
36+
Tools of those servers are available in your [AI Bundle](https://github.com/symfony/ai-bundle)
37+
configuration and usable in your agents.
38+
39+
## Configuration
40+
41+
```yaml
42+
mcp:
43+
app: 'app' # Application name to be exposed to clients
44+
version: '1.0.0' # Application version to be exposed to clients
45+
46+
# Configure this application to act as an MCP server
47+
# Currently exposes tools registered in Symfony AI Bundle
48+
client_transports:
49+
stdio: true # Enable STDIO via command
50+
sse: true # Enable Server-Sent Event via controller
51+
52+
# Configure MCP servers to be used by this application
53+
# Not implemented yet
54+
servers:
55+
name:
56+
transport: 'stdio' # Transport method to use, either 'stdio' or 'sse'
57+
stdio:
58+
command: 'php /path/bin/console mcp' # Command to execute to start the client
59+
arguments: [] # Arguments to pass to the command
60+
sse:
61+
url: 'http://localhost:8000/sse' # URL to SSE endpoint of MCP server
62+
63+
```

src/mcp-bundle/composer.json

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"name": "symfony/mcp-bundle",
3+
"type": "symfony-bundle",
4+
"description": "Symfony integration bundle for Model Context Protocol (via symfony/mcp-sdk)",
5+
"license": "MIT",
6+
"authors": [
7+
{
8+
"name": "Christopher Hertel",
9+
"email": "[email protected]"
10+
}
11+
],
12+
"require": {
13+
"symfony/config": "^6.4 || ^7.0",
14+
"symfony/console": "^6.4 || ^7.0",
15+
"symfony/dependency-injection": "^6.4 || ^7.0",
16+
"symfony/framework-bundle": "^6.4 || ^7.0",
17+
"symfony/http-foundation": "^6.4 || ^7.0",
18+
"symfony/http-kernel": "^6.4 || ^7.0",
19+
"symfony/mcp-sdk": "@dev",
20+
"symfony/routing": "^6.4 || ^7.0"
21+
},
22+
"require-dev": {
23+
"phpstan/phpstan": "^2.1",
24+
"phpunit/phpunit": "^11.5"
25+
},
26+
"config": {
27+
"sort-packages": true
28+
},
29+
"autoload": {
30+
"psr-4": {
31+
"Symfony\\AI\\McpBundle\\": "src/"
32+
}
33+
},
34+
"minimum-stability": "dev",
35+
"prefer-stable": true,
36+
"repositories": [
37+
{ "type": "path", "url": "../mcp-sdk" }
38+
]
39+
}

src/mcp-bundle/phpstan.dist.neon

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
parameters:
2+
level: 6
3+
paths:
4+
- src/
5+
excludePaths:
6+
analyse:
7+
- src/DependencyInjection/Configuration.php

src/mcp-bundle/phpunit.xml.dist

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.5/phpunit.xsd"
4+
bootstrap="vendor/autoload.php"
5+
cacheDirectory=".phpunit.cache"
6+
colors="true"
7+
executionOrder="depends,defects"
8+
requireCoverageMetadata="true"
9+
beStrictAboutCoverageMetadata="true"
10+
beStrictAboutOutputDuringTests="true"
11+
failOnRisky="true"
12+
failOnWarning="true">
13+
<testsuites>
14+
<testsuite name="default">
15+
<directory>tests</directory>
16+
</testsuite>
17+
</testsuites>
18+
19+
<source ignoreIndirectDeprecations="true" restrictNotices="true" restrictWarnings="true">
20+
<include>
21+
<directory>src</directory>
22+
</include>
23+
</source>
24+
</phpunit>
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 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\Command;
13+
14+
use Symfony\AI\McpSdk\Server;
15+
use Symfony\AI\McpSdk\Server\Transport\Stdio\SymfonyConsoleTransport;
16+
use Symfony\Component\Console\Attribute\AsCommand;
17+
use Symfony\Component\Console\Command\Command;
18+
use Symfony\Component\Console\Input\InputInterface;
19+
use Symfony\Component\Console\Output\OutputInterface;
20+
21+
#[AsCommand('mcp:server', 'Starts an MCP server')]
22+
class McpCommand extends Command
23+
{
24+
public function __construct(
25+
private readonly Server $server,
26+
) {
27+
parent::__construct();
28+
}
29+
30+
protected function execute(InputInterface $input, OutputInterface $output): int
31+
{
32+
$this->server->connect(
33+
new SymfonyConsoleTransport($input, $output)
34+
);
35+
36+
return Command::SUCCESS;
37+
}
38+
}

0 commit comments

Comments
 (0)