- What is Laravel MCP and how does it differ from REST APIs for AI integration?
- Laravel MCP is a package that lets you expose Laravel models, resources, and logic as tools via the Model Context Protocol (MCP), a standardized way for AI clients to interact with your backend. Unlike REST APIs, MCP uses structured schemas (JSON Schema) for inputs/outputs, supports dynamic tool registration, and integrates natively with AI frameworks like LangChain or CrewAI. It’s ideal for AI agents that need to invoke Laravel logic as tools rather than raw HTTP endpoints.
- Which Laravel and PHP versions does Laravel MCP support?
- Laravel MCP requires Laravel 10+ and PHP 8.2+. Earlier versions (e.g., Laravel 9 or PHP 8.1) are unsupported due to dropped compatibility in v0.5.4+. Always check the [latest release notes](https://github.com/laravel/mcp/releases) for version-specific requirements before installing.
- How do I define a tool in Laravel MCP? Can I use Eloquent models directly?
- You define tools using PHP 8.0+ attributes (annotations) like `#[McpTool]` or via XML/JSON schemas. For Eloquent models, you can convert them into tools with minimal boilerplate by implementing the `schema()` and `handle()` methods. The package provides helpers to map Laravel validation rules to JSON Schema automatically, reducing duplication.
- Does Laravel MCP support OAuth2 for AI client authentication?
- Yes, Laravel MCP includes built-in OAuth2 support with dynamic client registration via the `/oauth/register` endpoint. You configure authorization servers in `config/mcp.php` and ensure CORS/CSRF protections are in place. This allows AI agents to authenticate securely without manual client setup, though you’ll need to handle PKCE flows for public clients.
- Can I use Laravel MCP with existing Laravel auth systems like Sanctum or Passport?
- Laravel MCP’s OAuth2 integration is designed to work alongside Sanctum or Passport, but it requires explicit configuration to avoid conflicts. For example, you may need to merge authorization servers or customize the `issuer` path. The package prioritizes MCP’s OAuth2 spec, so existing auth systems should be adapted to align with its requirements.
- How do I handle schema changes in tools without breaking AI clients?
- Schema changes can break AI clients if not managed carefully. Laravel MCP recommends versioning tool schemas (e.g., by including a `version` field in the schema) and using backward-compatible updates. You can also implement migration logic in your `handle()` method to transform inputs/outputs between versions. Always test with your AI client’s schema validation before deploying updates.
- What’s the performance impact of using Laravel MCP in production?
- Laravel MCP adds minimal overhead—typically 10–30ms per request due to JSON-RPC processing and OAuth2 validation. Benchmark your tools under load, especially if they involve complex business logic. For high-throughput scenarios, consider caching tool schemas or using Laravel Octane to offload MCP requests to a queue.
- Are there alternatives to Laravel MCP for AI-Laravel integration?
- Alternatives include building custom REST/gRPC APIs or using packages like Laravel’s built-in API resources with AI-specific wrappers (e.g., LangChain’s HTTP connectors). However, MCP is unique in providing a standardized protocol for tool-based interactions, which simplifies AI client integration and reduces boilerplate for common patterns like RAG pipelines or agent workflows.
- How do I test MCP tools in Laravel?
- Testing MCP tools requires asserting structured content (e.g., JSON Schema validation) and OAuth2 flows. Laravel MCP provides helpers like `assertStructuredContent()` for schema validation, while you can use Laravel’s HTTP tests to simulate AI client requests. Mock OAuth2 clients with tools like `laravel/oauth-server-provider` to test authentication scenarios.
- Can I use Laravel MCP for non-AI use cases, like internal microservices?
- While Laravel MCP is optimized for AI agents, you can repurpose it for internal microservices by treating tools as RPC endpoints. However, the package adds complexity (e.g., OAuth2, JSON Schema) that may be overkill for simple internal APIs. For non-AI use cases, consider lighter alternatives like Laravel’s built-in API resources or custom HTTP middleware.