Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Mcp Bundle Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Domain Suitability: The 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:
    • Symfony Component Integration: Leveraging HttpFoundation, DependencyInjection, and HttpKernel for compatibility.
    • MCP SDK Agnosticism: The underlying mcp/sdk is PHP-agnostic, enabling Laravel adoption with minimal changes.
  • Use Case Alignment:
    • Multi-Model Orchestration: Ideal for apps requiring dynamic model switching (e.g., LLMs, embeddings, or custom models).
    • Context-Aware APIs: Enables tenant/user-specific model behavior without custom middleware.
    • Microservices: Standardizes context propagation across service boundaries.
  • Anti-Patterns:
    • Overhead for Non-AI Use Cases: Not suitable for traditional CRUD apps without AI/ML components.
    • Symfony Dependency: Laravel teams must abstract Symfony-specific logic (e.g., EventDispatcher, Validator).

Integration Feasibility

  • Core Features Adaptable to Laravel:
    • Model Context Routing: Replace Symfony routes with Laravel routes mapped to MCP endpoints.
    • Dependency Injection: Register MCP clients as Laravel services via AppServiceProvider.
    • Middleware: Use Laravel’s middleware pipeline for MCP-specific logic (e.g., auth, rate limiting).
    • HTTP Transport: Directly integrate mcp/sdk's McpHttpTransport with Laravel’s HTTP client.
  • Key Integration Points:
    // 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');
    
  • Symfony-Specific Workarounds:
    • Event System: Replace Symfony events with Laravel events (e.g., McpModelCalled).
    • Validator: Use Laravel’s Validator facade instead of Symfony’s ValidatorInterface.
    • HttpFoundation: Install symfony/http-foundation for request/response compatibility.

Technical Risk

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.

Key Questions

  1. Architectural Alignment:
    • Does the app require dynamic model orchestration (e.g., switching between OpenAI, Hugging Face, or custom models), or is MCP primarily for context propagation?
  2. Symfony vs. Laravel Trade-offs:
    • Is the team open to partial Symfony adoption (e.g., using HttpFoundation for MCP-specific logic)?
    • Or should the integration be fully Laravel-native (requiring custom wrappers)?
  3. Model Provider Strategy:
    • Will the app support non-MCP models (e.g., direct REST calls to proprietary APIs), or is MCP the sole model interface?
  4. Authentication/Authorization:
    • How will MCP API keys/secrets be managed (Laravel .env, Vault, or Symfony ParameterBag)?
    • Are there custom auth requirements (e.g., OAuth, API gateways) for MCP endpoints?
  5. Fallback Mechanisms:
    • What’s the degradation strategy if MCP endpoints fail (e.g., retry logic, circuit breakers, or direct model calls)?
  6. Monitoring and Observability:
    • How will MCP requests/responses be logged and monitored (e.g., Laravel’s Log facade vs. Symfony’s Monolog)?
  7. Team Expertise:
    • Does the team have experience with Symfony components or MCP, or will this require upskilling?

Integration Approach

Stack Fit

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)

Migration Path

Phase 1: Proof of Concept (2-3 weeks)

Goal: Validate MCP integration with a single model (e.g., text generation). Steps:

  1. Install Dependencies:
    composer require mcp/sdk symfony/http-foundation
    
  2. Register MCP Client:
    • Create a Laravel service provider to bind McpClient.
  3. Test with a Mock Endpoint:
    • Use a local MCP-compatible server (e.g., mcp-server or a mock).
    • Verify requests/responses via curl or Postman.
  4. Deliverable:
    • A working Laravel route that proxies to MCP (e.g., /api/mcp/generate).

Phase 2: Core Integration (4-6 weeks)

Goal: Integrate MCP into the model orchestration layer. Steps:

  1. Replace Direct Model Calls:
    • Migrate from direct API calls (e.g., curl to OpenAI) to MCP routes.
  2. Implement Middleware:
    • Add McpAuthMiddleware for authentication/rate limiting.
    • Example:
      public function handle($request, Closure $next)
      {
          $request->merge(['mcp_auth' => config('mcp.api_key')]);
          return $next($request);
      }
      
  3. Dependency Injection:
    • Inject McpClient into model services (e.g., TextGenerationService).
  4. Deliverable:
    • MCP-powered model routing for 80% of use cases.
    • Middleware for auth/rate limiting.

Phase 3: Full Adoption (6-8 weeks)

Goal: Replace all non-MCP model interactions. Steps:

  1. Migrate Legacy Services:
    • Refactor model services to use MCP interfaces (e.g., McpModelInterface).
  2. Add Fallback Logic:
    • Implement retry/circuit breaker logic for MCP failures.
    • Example:
      try {
          return $mcpClient->call('generate', $prompt);
      } catch (McpException $e) {
          return $fallbackService->generate($prompt);
      }
      
  3. Optimize Performance:
    • Cache MCP responses (e.g., using Laravel’s Cache facade).
    • Benchmark and optimize HTTP round-trips.
  4. Deliverable:
    • Full MCP adoption with monitoring, fallback logic, and performance optimizations.

Compatibility

  • Symfony Component Adapters:
    • HttpFoundation: Install 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();
          }
      }
      
    • Event System: Replace Symfony events with Laravel events:
      // Symfony Event (Original)
      $dispatcher->dispatch(new McpModelCalledEvent($model, $context));
      
      // Laravel Event (Adapted)
      event(new \Illuminate\Queue\Events\JobProcessed(
          $model,
          $context
      ));
      
  • Routing:
    • Map MCP endpoints to Laravel routes using route model binding:
      Route::post('/api/mcp/{model}', [McpController
      
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
emuniq/filament-browser-notifications
syriable/filament-translator
hungnm28/livewire-form
wenprise/eloquent
crudly/encrypted
fadion/bouncy
cuci/prototurk-sdk
gos/pubsub-router-bundle
cuci/prototurk-sdk-symfony
clementtalleu/easyadmin-markdown-bundle
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui