rasuvaeff / symfony-mcp
Symfony integration of the rasuvaeff/mcp server
Package info
github.com/rasuvaeff/symfony-mcp
Type:symfony-bundle
pkg:composer/rasuvaeff/symfony-mcp
Requires
- php: 8.3 - 8.6
- mcp/sdk: ~0.10.0
- nyholm/psr7: ^1.8
- psr/cache: ^2.0 || ^3.0
- psr/container: ^2.0
- psr/http-client: ^1.0
- psr/http-factory: ^1.1
- psr/http-message: ^2.0
- psr/http-server-handler: ^1.0
- psr/http-server-middleware: ^1.0
- psr/log: ^2.0 || ^3.0
- psr/simple-cache: ^2.0 || ^3.0
- rasuvaeff/mcp: ^0.1.4
- rasuvaeff/mcp-openapi: ^0.1.3
- symfony/cache: ^7.4.12 || ^8.0.12
- symfony/config: ^7.4.23 || ^8.1.11
- symfony/console: ^7.4 || ^8.0
- symfony/dependency-injection: ^7.4 || ^8.0
- symfony/http-foundation: ^7.4.23 || ^8.1.11
- symfony/http-kernel: ^7.4.24 || ^8.1.12
- symfony/psr-http-message-bridge: ^7.4 || ^8.0
- symfony/service-contracts: ^2.5 || ^3.0
Requires (Dev)
- ergebnis/composer-normalize: ^2.51
- friendsofphp/php-cs-fixer: ^3.95
- infection/infection: ^0.35
- maglnet/composer-require-checker: ^4.17
- rasuvaeff/rector-named-literals: ^1.0
- rector/rector: ^2.4
- roave/backward-compatibility-check: ^8.0
- symfony/framework-bundle: ^7.4 || ^8.0
- testo/bridge-infection: ^0.1.6
- testo/testo: ^0.10.25
- vimeo/psalm: ^7.0
Suggests
- firebase/php-jwt: JWT validation for the OAuth guard (^7.0)
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-11-27 14:16:59 UTC
README
Symfony integration of rasuvaeff/mcp, a Model Context
Protocol server over the official mcp/sdk: tools from
the container, an HTTP endpoint, console commands, and the
OpenAPI bridge.
symfony/mcp-bundle is the official bundle, on the same mcp/sdk. Choose it unless you need what this one is for: the same server code in several frameworks, the OpenAPI bridge, or the rasuvaeff/mcp interceptors and visibility.
Using an AI coding assistant? llms.txt contains a compact API reference you can share with the model. Contributors: see AGENTS.md. Projects using the llm/skills Composer plugin also get this package's agent skill synced into
.agents/skills/automatically on install.
Requirements
| Requirement | Version |
|---|---|
| PHP | 8.3 – 8.6 |
| Symfony | ^7.4 || ^8.0; some components need a later patch release without security advisories, see composer.json |
rasuvaeff/mcp |
^0.1.4 |
rasuvaeff/mcp-openapi |
^0.1.3 |
firebase/php-jwt |
optional, ^7.0: JWT validation for OAuth |
Installation
composer require rasuvaeff/symfony-mcp
// config/bundles.php Rasuvaeff\SymfonyMcp\RasuvaeffMcpBundle::class => ['all' => true], // config/routes/rasuvaeff_mcp.php return static function (RoutingConfigurator $routes): void { $routes->import('@RasuvaeffMcpBundle/config/routes.php'); };
Usage
use Mcp\Server\Capability\Attribute\McpTool; final readonly class OrderTools { public function __construct(private OrderRepository $orders) {} #[McpTool(name: 'order.status')] public function status(string $orderId): string { return $this->orders->status($orderId); } }
# config/packages/rasuvaeff_mcp.yaml parameters: # without a default an unset variable fails the request instead of the 503 below env(MCP_SECRET): '' rasuvaeff_mcp: server_name: my-app tools: ['App\Mcp\OrderTools'] endpoint_secret: '%env(MCP_SECRET)%' allowed_hosts: ['mcp.example.com']
The endpoint is /mcp. Without a secret it answers 503 to everything.
bin/console mcp:list # what is served bin/console mcp:serve # stdio, for a local agent
Configuration
guard is secret or oauth. Every other key is the one rasuvaeff/yii3-mcp uses; see the
documentation. The options are validated when the server is
first built, not when the container is compiled, so %env()% works everywhere except in
class names and notifications.bus. A later config file replaces a top-level key as a whole.
Serve ProtectedResourceMetadataHandler (a service) from a route of your own at
/.well-known/oauth-protected-resource/<path>:
#[Route('/.well-known/oauth-protected-resource/mcp', methods: 'GET')] public function metadata(Request $request, ProtectedResourceMetadataHandler $handler): Response { $factory = new Psr17Factory(); $psr = (new PsrHttpFactory($factory, $factory, $factory, $factory))->createRequest($request); return (new HttpFoundationFactory())->createResponse($handler->handle($psr)); }
Code outside MCP announces a change of a resource through the ResourceUpdateNotifier service
(needs notifications.bus).
Several nodes
Stateless calls need nothing. For sessions define a shared store; notifications and the call budget follow the cache of the application, so point it at Redis:
# config/services.yaml services: Mcp\Server\Session\SessionStoreInterface: class: Mcp\Server\Session\Psr6SessionStore arguments: ['@cache.app']
The call budget counts over PSR-16, which has no atomic increment: calls sent at the same moment may all pass. It stops a loop, it is not a quota.
A Symfony cache pool hides the failure of its backend: while Redis is down, set() returns false instead of throwing. The server reads that as a failed write and rejects the call: a store that is down fails closed instead of lifting the budget.
Keycloak puts your endpoint in aud only through an audience mapper on the client; without it
every token is refused with 401.
While the session store is unavailable, initialize still answers with a session id: the SDK logs the failed save, and the next request with that id gets 404, after which the client opens a new session.
Long-running workers
- Checked on FrankenPHP (classic and worker), Swoole and RoadRunner. Under RoadRunner a
subscriptions/listenstream arrives in one piece when it ends: the PSR-7 bridge captures the whole body. Keepnotifications.subscription_lifetimeshort there, or serve listen streams from another runtime. guardother thansecretoroauth, an empty one included, fails withUnknown MCP guard.- Classes named in the options are registered autowired and private; a service of yours with the same id wins.
- The server is dropped by
kernel.resetbetween requests of a worker. Sessions on disk and the notification bus stay. - A tool object is an ordinary service and lives across the requests of a worker: its properties are seen by the next client. Keep no request state in them, or implement
ResetInterface. - Do not
exclude:a tool class inservices.yaml: the container does not compile ("reference to an abstract definition"). - The option alias is
rasuvaeff_mcp:mcpbelongs tosymfony/mcp-bundle.
Components
| Class | Role |
|---|---|
RasuvaeffMcpBundle |
the bundle |
McpController |
route action: guard, then the MCP endpoint |
McpRuntime |
builds and resets the server |
Guard |
secret or oauth |
Security
- The endpoint is trusted-only. Without
endpoint_secret,client_secretsoroauthevery request is refused. - Set
allowed_hoststo the public hostname: it is the DNS-rebinding protection, only localhost is allowed without it. - Several clients need
client_secrets: a session belongs to the client that opened it. - A failure inside a tool is logged; the client never gets its message.
Examples
See examples/: the script runs offline.
Development
No PHP/Composer on the host, run in Docker via the composer:2 image:
docker run --rm -v "$PWD":/app -w /app composer:2 composer build
Or with Make: make build, make cs-fix, make psalm, make test.
License
BSD-3-Clause. See LICENSE.md.