symfony/mcp-bundle
Experimental Symfony bundle integrating Model Context Protocol (MCP) via the official PHP SDK. Build MCP servers exposing tools, prompts, and resources over HTTP transport or STDIO; resource templates are prepared pending SDK support.
symfony/mcp-bundle is designed for Symfony applications leveraging the Model Context Protocol (MCP), primarily targeting AI/ML workflows, multi-model orchestration, and context-aware data access. While Laravel lacks native MCP support, the bundle’s core functionality—dynamic model routing, context propagation, and HTTP/STDIO transport—can be adapted for Laravel via:
HttpFoundation, DependencyInjection, and HttpKernel for compatibility.mcp/sdk is PHP-agnostic, enabling Laravel adoption with minimal changes.EventDispatcher, Validator).AppServiceProvider.mcp/sdk's McpHttpTransport with Laravel’s HTTP client.// Laravel Service Provider (MCP Client Registration)
public function register()
{
$this->app->singleton(McpClient::class, function ($app) {
return new \Mcp\Client\McpClient(
new \Mcp\Transport\HttpTransport(config('mcp.endpoint'))
);
});
}
// Laravel Route (MCP Endpoint)
Route::post('/api/mcp/{model}', [McpController::class, 'handle'])
->middleware('throttle:mcp');
McpModelCalled).Validator facade instead of Symfony’s ValidatorInterface.symfony/http-foundation for request/response compatibility.| Risk Area | Severity | Mitigation Strategy |
|---|---|---|
| Symfony Dependency | High | Abstract Symfony components behind interfaces (e.g., HttpFoundationAdapter). |
| MCP SDK Stability | Medium | Pin SDK version in composer.json and test against multiple MCP endpoints. |
| Performance Overhead | Medium | Benchmark HTTP round-trips vs. direct model calls; cache MCP responses. |
| Laravel-Symfony Gaps | High | Use symfony/polyfill or custom adapters for missing components. |
| Version Skew | Low | Monitor MCP SDK releases and update incrementally. |
| Experimental Status | Medium | Start with non-critical features; avoid relying on unsupported MCP capabilities. |
HttpFoundation for MCP-specific logic)?.env, Vault, or Symfony ParameterBag)?Log facade vs. Symfony’s Monolog)?| Component | Laravel Compatibility | Workaround Needed |
|---|---|---|
| MCP SDK | ✅ (PHP-agnostic) | No |
| Symfony DI | ❌ | Yes (emulate via Laravel Service Container) |
| HttpFoundation | ❌ | Yes (install symfony/http-foundation) |
| Event System | ❌ | Yes (replace with Laravel Events) |
| Validator | ❌ | Yes (use Laravel’s Validator) |
| HttpKernel | ❌ | Yes (custom middleware/routing) |
| Middleware | ✅ | No |
| Routing | ✅ | No (map MCP endpoints to Laravel routes) |
Goal: Validate MCP integration with a single model (e.g., text generation). Steps:
composer require mcp/sdk symfony/http-foundation
McpClient.mcp-server or a mock).curl or Postman./api/mcp/generate).Goal: Integrate MCP into the model orchestration layer. Steps:
curl to OpenAI) to MCP routes.McpAuthMiddleware for authentication/rate limiting.public function handle($request, Closure $next)
{
$request->merge(['mcp_auth' => config('mcp.api_key')]);
return $next($request);
}
McpClient into model services (e.g., TextGenerationService).Goal: Replace all non-MCP model interactions. Steps:
McpModelInterface).try {
return $mcpClient->call('generate', $prompt);
} catch (McpException $e) {
return $fallbackService->generate($prompt);
}
Cache facade).symfony/http-foundation and create adapters for Laravel’s Request/Response.
use Symfony\Component\HttpFoundation\Request as SymfonyRequest;
class LaravelToSymfonyRequestAdapter
{
public static function adapt(\Illuminate\Http\Request $request): SymfonyRequest
{
return SymfonyRequest::createFromGlobals();
}
}
// Symfony Event (Original)
$dispatcher->dispatch(new McpModelCalledEvent($model, $context));
// Laravel Event (Adapted)
event(new \Illuminate\Queue\Events\JobProcessed(
$model,
$context
));
Route::post('/api/mcp/{model}', [McpController
How can I help you explore Laravel packages today?