- How do I integrate the MCP SDK into a Laravel application for exposing internal tools to AI agents?
- Wrap the MCP SDK in a Laravel service provider (e.g., `McpServerServiceProvider`) to register the server and client bindings in the container. Use attributes like `#[McpTool]` on controller methods or Eloquent models to expose them as MCP resources. For HTTP transport, leverage Laravel’s middleware pipeline with `StreamableHttpTransport` to handle routing and authentication.
- What Laravel versions and PHP requirements does the MCP SDK support?
- The MCP SDK is tested with PHP 8.1+ and officially supports Laravel 10 and 11. Ensure your project meets these requirements, as the SDK relies on Symfony components (e.g., HttpFoundation, Cache) that Laravel already uses. Check the [README](https://github.com/modelcontextprotocol/php-sdk) for updates on compatibility.
- Can I use the MCP SDK to expose Eloquent models as AI tools in Laravel?
- Yes. Use the `#[McpResource]` attribute on Eloquent models to expose them as MCP resources (e.g., `db://users`). For dynamic queries, define resource templates like `db://users/{id}`. The SDK abstracts database interactions while maintaining Laravel’s ORM patterns, but ensure your session storage (e.g., Redis) aligns with MCP’s PSR-16 caching requirements.
- How does MCP’s authentication (e.g., OAuth) integrate with Laravel’s existing auth systems like Sanctum or Passport?
- MCP’s HTTP transport supports OAuth, which can be mapped to Laravel’s Sanctum or Passport for seamless authentication. Configure the `StreamableHttpTransport` middleware to validate MCP tokens against Laravel’s auth guards. For CLI tools using STDIO transport, implement custom auth logic within the tool’s context.
- What are the performance implications of using MCP’s STDIO vs. HTTP transport in Laravel?
- STDIO transport is blocking and best suited for CLI tools or low-throughput scenarios. HTTP transport introduces latency but integrates with Laravel’s HTTP layer. Avoid mixing transports in high-frequency APIs; instead, use HTTP for web APIs and STDIO for background jobs or CLI commands. Monitor middleware overhead in production.
- How can I log MCP events (e.g., tool calls) in Laravel’s monitoring tools like Sentry or Debugbar?
- MCP’s event system (e.g., `ServerLifecycleEvents`) can dispatch events to Laravel’s event system. Bind MCP events to Laravel listeners that log to Sentry or Debugbar. For example, create a `McpToolCalledListener` that forwards MCP tool invocation data to your monitoring stack. Ensure PSR-3 logging compatibility is maintained.
- Is the MCP SDK stable enough for production use in Laravel, or should I wait for v1.0?
- The SDK is experimental (v0.6.0) and may introduce breaking changes. For production, start with a pilot phase using STDIO transport for CLI tools or low-risk features. Monitor the [roadmap](https://github.com/modelcontextprotocol/php-sdk/blob/main/ROADMAP.md) for v1.0 milestones. Test thoroughly in staging before scaling.
- How do I handle schema validation conflicts between MCP’s strict JSON Schema and Laravel’s request validation?
- MCP enforces JSON Schema validation for tools/resources, which may differ from Laravel’s Form Request validation. Use Laravel’s `FormRequest` for HTTP inputs and validate MCP-specific schemas in tool/resource definitions. For hybrid setups, create a middleware to reconcile both validation layers before processing MCP requests.
- Can I use MCP to create a hybrid system where some tools are exposed via attributes and others are registered manually?
- Yes. The SDK supports hybrid registration: use attributes (e.g., `#[McpTool]`) for internal Laravel logic and manual registration (e.g., `server->registerTool()`) for external APIs. This approach works well for gradual adoption, but ensure tool naming avoids collisions with Laravel’s reserved routes (e.g., `mcp://` vs. `api/`).
- What alternatives exist for exposing Laravel logic to AI agents if MCP’s experimental status is a concern?
- Alternatives include custom HTTP APIs with Laravel’s built-in tools (e.g., API resources, Sanctum auth) or frameworks like LangChain’s PHP integrations. For protocol-driven AI interactions, consider OpenAPI/Swagger with tools like `darkaonline/l5-swagger`. However, MCP offers native support for AI tool contexts (e.g., prompts, resources) that may require more workarounds with alternatives.