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.
SessionInitialized enable reactive programming (e.g., logging, analytics, or dynamic tool registration).illuminate/json-schema).getUserOrders(), updatePaymentStatus()).Assistant, User) and scopes (e.g., orders:read).composer require laravel/mcp
php artisan vendor:publish --provider="Laravel\Mcp\McpServiceProvider"
config/mcp.php (e.g., OAuth issuer URL, supported protocols).use Laravel\Mcp\Attributes\Tool;
#[Tool(name: 'fetch_orders', description: 'Retrieve user orders')]
public function fetchOrders(Request $request) { ... }
use Laravel\Mcp\Tool;
class OrderTool extends Tool {
public function handle(FetchOrders $request) { ... }
}
php artisan mcp:oauth-register.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) => ...);
}
/mcp/tools/{name}).MCP-Session-Id) must be handled explicitly.php artisan mcp:inspect for runtime diagnostics.McpTestCase for automated validation.MCP-Session-Id handling.throttle middleware.| 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 |
assertStructuredContent tests for tool outputsHow can I help you explore Laravel packages today?