- How do I install Laravel MCP in my Laravel 11+ project?
- Run `composer require laravel/mcp` in your project directory. Ensure you’re using PHP 8.2+ and Laravel 10+. The package integrates via service provider and requires no manual configuration for basic setup—just define tools in your routes.
- Can I use Laravel MCP with existing REST APIs without rewriting everything?
- Yes, but with effort. MCP encourages a tool-first approach, so you’ll need to wrap existing routes in tool definitions with JSON Schema validation. Start by exposing high-value endpoints as tools and gradually migrate others.
- What’s the difference between MCP tools and traditional Laravel routes?
- MCP tools are structured, schema-validated endpoints designed for AI clients, while traditional routes are generic HTTP handlers. Tools include metadata (description, parameters), enforce JSON Schema, and support rich responses like images or audio—unlike REST’s uniform interface.
- Does Laravel MCP support OAuth2 for AI client authentication?
- Yes, MCP integrates with Laravel’s OAuth2/Passport or third-party providers (Auth0, Keycloak). Configure the issuer URL and redirect URIs in your MCP server setup to authenticate AI clients via MCP’s OAuth2 flow.
- How do I validate tool inputs using JSON Schema in MCP?
- Define schemas in your tool definitions using Laravel’s `JsonSchema` contracts. For example, specify `parameters: ['type' => 'object', 'properties' => [...]]` in your tool’s metadata. Invalid requests trigger automatic 422 errors with schema details.
- Will Laravel MCP work with Laravel Octane for async/streaming responses?
- Yes, MCP supports Octane for async tool execution and streaming responses (e.g., real-time data). Use `MCP::tool()->stream()` to return generators or async responses. Traditional requests fall back to synchronous handling.
- Are there performance considerations for high-traffic MCP tools?
- Optimize by caching tool schemas, using Octane for async tools, and batching database queries. Monitor tool execution time—MCP adds validation overhead. For critical paths, consider pre-validating inputs or using Laravel’s queue system.
- How do I test MCP tools in my Laravel app?
- Use Laravel’s testing tools with MCP-specific assertions like `assertToolResponse()` or `assertStructuredContent()`. Test OAuth flows with `McpTesting::actingAsClient()`, and validate schemas with `JsonSchema::validate()`. Mock AI clients to simulate requests.
- Can I expose sensitive data (e.g., user PII) via MCP tools?
- No, MCP enforces data protection guidelines. Avoid exposing PII directly; use tool parameters to reference IDs (e.g., `userId`) and fetch data internally. Implement rate-limiting and audit logs for sensitive tools.
- What alternatives exist if Laravel MCP doesn’t fit my needs?
- For REST APIs, use Laravel’s built-in routing. For gRPC, integrate `grpc/grpc` or `rector/rector`. If you need lightweight AI tooling, consider custom middleware or packages like `spatie/laravel-ai-tools`. MCP is ideal for AI-native Laravel apps.