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 Laravel Package

laravel/mcp

Build MCP (Model Context Protocol) servers in Laravel so AI clients can securely interact with your app. Expose tools, resources, and prompts using familiar Laravel patterns, with docs and integrations designed for rapid setup and deployment.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • MCP Protocol Alignment: The package enables seamless integration with the Model Context Protocol (MCP), a standardized interface for AI agents to interact with Laravel applications. This aligns well with modern AI-driven architectures where agents need structured, real-time access to backend services.
  • Laravel-Native Design: Built as a first-class Laravel package, it leverages Laravel’s service providers, facades, and testing utilities, reducing friction for teams already using Laravel.
  • Modular Tooling: Supports structured schemas, annotations, and resource templates, allowing granular control over API endpoints exposed to AI clients. This fits well with microservice-like modularity within a monolith.
  • Event-Driven Extensibility: Events like SessionInitialized enable reactive programming (e.g., logging, analytics, or dynamic tool registration).

Integration Feasibility

  • Low-Coupling Design: MCP operates as a layered abstraction over Laravel’s HTTP stack, requiring minimal changes to existing controllers or routes. Existing APIs can be gradually exposed to MCP without full rewrites.
  • OAuth2 Support: Built-in OAuth2 registration simplifies secure AI-agent authentication, though teams must configure issuers, scopes, and client credentials (a non-trivial but manageable task).
  • Schema Validation: JSON Schema integration ensures structured input/output validation, reducing runtime errors from malformed AI requests.

Technical Risk

  • Protocol Complexity: MCP’s dual-layer protocol (JSON-RPC + HTTP) may require teams unfamiliar with AI-agent interactions to invest time in understanding session management, tool registration, and structured content handling.
  • Breaking Changes: Recent versions (e.g., v0.4.0) introduced case-sensitive role names and contract interface updates, which could disrupt existing implementations.
  • Performance Overhead: Streaming generators (e.g., for large responses) may introduce latency or memory spikes under high concurrency, especially without Octane or queue-based processing.
  • Testing Gaps: While test coverage is improving, edge cases (e.g., malformed OAuth flows, nested tool errors) may need custom validation logic.

Key Questions

  1. Use Case Clarity:
    • Are we exposing read-only APIs (e.g., knowledge bases) or write-heavy tools (e.g., CRM updates)? MCP’s tool-based model may require idempotency guarantees for write operations.
  2. Authentication Strategy:
    • How will AI agents authenticate? Will we use pre-registered OAuth clients or dynamic registration?
  3. Schema Management:
    • Will tools use Laravel’s Eloquent models as schemas, or custom JSON Schema definitions? The latter may require additional validation layers.
  4. Scaling Assumptions:
    • Will MCP servers run in shared hosting (e.g., Forge) or scalable environments (e.g., Kubernetes)? Some features (e.g., dynamic ports) assume local/dev flexibility.
  5. Monitoring:
    • How will we track tool usage, errors, and performance? MCP lacks built-in observability; teams may need to integrate Laravel Telescope or custom logging.

Integration Approach

Stack Fit

  • Laravel 10/11: Officially supports Laravel 13, but backports to 10+ are feasible with minor adjustments (e.g., PHP 8.1+).
  • PHP 8.5+: Requires attributes, enums, and modern type hints, which may necessitate dependency updates (e.g., illuminate/json-schema).
  • Octane Compatibility: Supports Swoole/Preact for streaming responses, but queue workers may still be needed for long-running tools.
  • Database Agnostic: No direct DB dependencies, but tool implementations may rely on Eloquent or raw queries.

Migration Path

  1. Assessment Phase:
    • Audit existing APIs to identify candidate tools (e.g., getUserOrders(), updatePaymentStatus()).
    • Define MCP roles (e.g., Assistant, User) and scopes (e.g., orders:read).
  2. Scaffold Setup:
    • Install via Composer:
      composer require laravel/mcp
      
    • Publish config/stubs:
      php artisan vendor:publish --provider="Laravel\Mcp\McpServiceProvider"
      
    • Configure config/mcp.php (e.g., OAuth issuer URL, supported protocols).
  3. Tool Implementation:
    • Option A: Annotate existing controllers:
      use Laravel\Mcp\Attributes\Tool;
      
      #[Tool(name: 'fetch_orders', description: 'Retrieve user orders')]
      public function fetchOrders(Request $request) { ... }
      
    • Option B: Create dedicated tool classes:
      use Laravel\Mcp\Tool;
      
      class OrderTool extends Tool {
          public function handle(FetchOrders $request) { ... }
      }
      
  4. OAuth Configuration:
    • Register AI clients via php artisan mcp:oauth-register.
    • Configure redirect URIs and scopes for each client.
  5. Testing:
    • Use McpTestCase for tool validation:
      public function test_fetch_orders_tool() {
          $response = $this->mcp->postJson('/mcp/tools/fetch_orders', ['user_id' => 1]);
          $response->assertStructuredContent(fn (array $data) => ...);
      }
      

Compatibility

  • Existing APIs: Non-MCP routes remain unchanged; MCP adds a parallel endpoint (/mcp/tools/{name}).
  • Authentication: Works with Laravel Sanctum/Passport, but OAuth2 registration is MCP-specific.
  • Caching: Tools can leverage Laravel’s cache, but session state (e.g., MCP-Session-Id) must be handled explicitly.

Sequencing

  1. Phase 1: Expose read-only tools (e.g., data retrieval) with minimal validation.
  2. Phase 2: Add write tools with transactional safeguards (e.g., rollback on failure).
  3. Phase 3: Implement dynamic tool registration (e.g., runtime schema updates) if needed.
  4. Phase 4: Optimize for scaling (e.g., rate limiting, async processing).

Operational Impact

Maintenance

  • Dependency Updates: Laravel MCP is actively maintained, but breaking changes (e.g., v0.4.0) require backward-compatibility checks.
  • Tool Lifecycle: Tools are versioned via schemas, but deprecation requires manual handling (e.g., sunsetting old tool names).
  • Security Patches: OAuth-related fixes (e.g., CVE-2026-OAUTH) may need urgent updates.

Support

  • Debugging Tools:
    • php artisan mcp:inspect for runtime diagnostics.
    • McpTestCase for automated validation.
  • Common Issues:
    • OAuth Misconfigurations: Redirect URI mismatches or scope errors.
    • Schema Mismatches: AI clients sending malformed JSON-RPC requests.
    • Session Timeouts: Requires explicit MCP-Session-Id handling.
  • Community: Limited to Laravel ecosystem; Stack Overflow/GitHub Discussions are primary support channels.

Scaling

  • Horizontal Scaling: MCP is stateless (except for sessions), so it scales horizontally like standard Laravel APIs.
  • Concurrency Limits:
    • Streaming responses (e.g., large file uploads) may need queue-based processing.
    • Tool rate limiting should be implemented via Laravel’s throttle middleware.
  • Database Load: Tools using Eloquent must account for N+1 query risks (e.g., eager loading).

Failure Modes

Failure Scenario Impact Mitigation
OAuth registration failure AI agents cannot authenticate Retry logic + fallback to API keys
Schema validation errors Tool invocations fail silently Structured error responses + logging
Session timeout Incomplete tool workflows Extend session TTL or use persistent IDs
Database connection drops Tool queries fail Retry with exponential backoff
High concurrency on /mcp/tools/* Throttling or crashes Rate limiting + queue workers

Ramp-Up

  • Developer Onboarding:
    • 1–2 days: Familiarization with MCP concepts (tools, sessions, schemas).
    • 3–5 days: Implementing first tool + OAuth setup.
  • Key Learning Curves:
    • JSON-RPC vs. HTTP: Understanding request/response cycles for AI agents.
    • Schema Design: Balancing flexibility (for AI creativity) and strictness (for data integrity).
    • Testing: Writing assertStructuredContent tests for tool outputs
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.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport
twbs/bootstrap4