Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/mcp-bundle/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/.github export-ignore
.gitattributes export-ignore
.gitignore export-ignore
phpstan.dist.neon export-ignore
8 changes: 8 additions & 0 deletions src/mcp-bundle/.github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Please do not submit any Pull Requests here. They will be closed.
---

Please submit your PR here instead:
https://github.com/symfony/ai

This repository is what we call a "subtree split": a read-only subset of that main repository.
We're looking forward to your PR there!
20 changes: 20 additions & 0 deletions src/mcp-bundle/.github/workflows/close-pull-request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Close Pull Request

on:
pull_request_target:
types: [opened]

jobs:
run:
runs-on: ubuntu-latest
steps:
- uses: superbrothers/close-pull-request@v3
with:
comment: |
Thanks for your Pull Request! We love contributions.

However, you should instead open your PR on the main repository:
https://github.com/symfony/ai

This repository is what we call a "subtree split": a read-only subset of that main repository.
We're looking forward to your PR there!
3 changes: 3 additions & 0 deletions src/mcp-bundle/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
vendor
composer.lock
.php-cs-fixer.cache
19 changes: 19 additions & 0 deletions src/mcp-bundle/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (c) 2025-present Fabien Potencier

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
63 changes: 63 additions & 0 deletions src/mcp-bundle/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# MCP Bundle [WIP]

Symfony integration bundle for [Model Context Protocol](https://modelcontextprotocol.io/) using the Symfony AI
MCP SDK [symfony/mcp-sdk](https://github.com/symfony/mcp-sdk).

**Currently only supports tools as server via Server-Sent Events (SSE) and STDIO.**

## Installation

```bash
composer require symfony/mcp-bundle
```

## Usage

At first, you need to decide whether your application should act as a MCP server or client. Both can be configured
in the `mcp` section of your `config/packages/mcp.yaml` file.

### Act as Server

**Currently only supports tools.**

To use your application as an MCP server, exposing tools to clients like [Claude Desktop](https://claude.ai/download),
you need to configure in the `client_transports` section the transports you want to expose to clients.
You can use either STDIO or SSE.

### Act as Client

**Not implemented yet.**

To use your application as an MCP client, integrating other MCP servers, you need to configure the `servers` you want to
connect to. You can use either STDIO or Server-Sent Events (SSE) as transport methods.

You can find a list of example Servers in the [MCP Server List](https://modelcontextprotocol.io/examples).

Tools of those servers are available in your [AI Bundle](https://github.com/symfony/ai-bundle)
configuration and usable in your agents.

## Configuration

```yaml
mcp:
app: 'app' # Application name to be exposed to clients
version: '1.0.0' # Application version to be exposed to clients

# Configure this application to act as an MCP server
# Currently exposes tools registered in Symfony AI Bundle
client_transports:
stdio: true # Enable STDIO via command
sse: true # Enable Server-Sent Event via controller

# Configure MCP servers to be used by this application
# Not implemented yet
servers:
name:
transport: 'stdio' # Transport method to use, either 'stdio' or 'sse'
stdio:
command: 'php /path/bin/console mcp' # Command to execute to start the client
arguments: [] # Arguments to pass to the command
sse:
url: 'http://localhost:8000/sse' # URL to SSE endpoint of MCP server

```
39 changes: 39 additions & 0 deletions src/mcp-bundle/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"name": "symfony/mcp-bundle",
"type": "symfony-bundle",
"description": "Symfony integration bundle for Model Context Protocol (via symfony/mcp-sdk)",
"license": "MIT",
"authors": [
{
"name": "Christopher Hertel",
"email": "mail@christopher-hertel.de"
}
],
"require": {
"symfony/config": "^6.4 || ^7.0",
"symfony/console": "^6.4 || ^7.0",
"symfony/dependency-injection": "^6.4 || ^7.0",
"symfony/framework-bundle": "^6.4 || ^7.0",
"symfony/http-foundation": "^6.4 || ^7.0",
"symfony/http-kernel": "^6.4 || ^7.0",
"symfony/mcp-sdk": "@dev",
"symfony/routing": "^6.4 || ^7.0"
},
"require-dev": {
"phpstan/phpstan": "^2.1",
"phpunit/phpunit": "^11.5"
},
"config": {
"sort-packages": true
},
"autoload": {
"psr-4": {
"Symfony\\AI\\McpBundle\\": "src/"
}
},
"minimum-stability": "dev",
"prefer-stable": true,
"repositories": [
{ "type": "path", "url": "../mcp-sdk" }
]
}
7 changes: 7 additions & 0 deletions src/mcp-bundle/phpstan.dist.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
parameters:
level: 6
paths:
- src/
excludePaths:
analyse:
- src/DependencyInjection/Configuration.php
24 changes: 24 additions & 0 deletions src/mcp-bundle/phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.5/phpunit.xsd"
bootstrap="vendor/autoload.php"
cacheDirectory=".phpunit.cache"
colors="true"
executionOrder="depends,defects"
requireCoverageMetadata="true"
beStrictAboutCoverageMetadata="true"
beStrictAboutOutputDuringTests="true"
failOnRisky="true"
failOnWarning="true">
<testsuites>
<testsuite name="default">
<directory>tests</directory>
</testsuite>
</testsuites>

<source ignoreIndirectDeprecations="true" restrictNotices="true" restrictWarnings="true">
<include>
<directory>src</directory>
</include>
</source>
</phpunit>
38 changes: 38 additions & 0 deletions src/mcp-bundle/src/Command/McpCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\AI\McpBundle\Command;

use Symfony\AI\McpSdk\Server;
use Symfony\AI\McpSdk\Server\Transport\Stdio\SymfonyConsoleTransport;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

#[AsCommand('mcp:server', 'Starts an MCP server')]
class McpCommand extends Command
{
public function __construct(
private readonly Server $server,
) {
parent::__construct();
}

protected function execute(InputInterface $input, OutputInterface $output): int
{
$this->server->connect(
new SymfonyConsoleTransport($input, $output)
);

return Command::SUCCESS;
}
}
51 changes: 51 additions & 0 deletions src/mcp-bundle/src/Controller/McpController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\AI\McpBundle\Controller;

use Symfony\AI\McpSdk\Server;
use Symfony\AI\McpSdk\Server\Transport\Sse\Store\CachePoolStore;
use Symfony\AI\McpSdk\Server\Transport\Sse\StreamTransport;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\StreamedResponse;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Uid\Uuid;

final readonly class McpController
{
public function __construct(
private Server $server,
private CachePoolStore $store,
private UrlGeneratorInterface $urlGenerator,
) {
}

public function sse(): StreamedResponse
{
$id = Uuid::v4();
$endpoint = $this->urlGenerator->generate('_mcp_messages', ['id' => $id], UrlGeneratorInterface::ABSOLUTE_URL);
$transport = new StreamTransport($endpoint, $this->store, $id);

return new StreamedResponse(fn () => $this->server->connect($transport), headers: [
'Content-Type' => 'text/event-stream',
'Cache-Control' => 'no-cache',
'X-Accel-Buffering' => 'no',
]);
}

public function messages(Request $request, Uuid $id): Response
{
$this->store->push($id, $request->getContent());

return new Response();
}
}
77 changes: 77 additions & 0 deletions src/mcp-bundle/src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\AI\McpBundle\DependencyInjection;

use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;

final class Configuration implements ConfigurationInterface
{
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder('mcp');
$rootNode = $treeBuilder->getRootNode();

$rootNode
->children()
->scalarNode('app')->defaultValue('app')->end()
->scalarNode('version')->defaultValue('0.0.1')->end()
// ->arrayNode('servers')
// ->useAttributeAsKey('name')
// ->arrayPrototype()
// ->children()
// ->enumNode('transport')
// ->values(['stdio', 'sse'])
// ->isRequired()
// ->end()
// ->arrayNode('stdio')
// ->children()
// ->scalarNode('command')->isRequired()->end()
// ->arrayNode('arguments')
// ->scalarPrototype()->end()
// ->defaultValue([])
// ->end()
// ->end()
// ->end()
// ->arrayNode('sse')
// ->children()
// ->scalarNode('url')->isRequired()->end()
// ->end()
// ->end()
// ->end()
// ->validate()
// ->ifTrue(function ($v) {
// if ('stdio' === $v['transport'] && !isset($v['stdio'])) {
// return true;
// }
// if ('sse' === $v['transport'] && !isset($v['sse'])) {
// return true;
// }
//
// return false;
// })
// ->thenInvalid('When transport is "%s", you must configure the corresponding section.')
// ->end()
// ->end()
// ->end()
->arrayNode('client_transports')
->children()
->booleanNode('stdio')->defaultFalse()->end()
->booleanNode('sse')->defaultFalse()->end()
->end()
->end()
->end()
;

return $treeBuilder;
}
}
Loading