Laravel with MCP — Complete WorkFlow

In This Article
Laravel MCP (Model Context Protocol) allows your Laravel application to connect directly with AI systems like ChatGPT, Claude, Gemini, etc.
What Can AI Do With MCP?
Using MCP, AI can: • Call functions inside your Laravel app • Read and write database data • Use tools (actions) • Use prompts (templates) • Access resources (documents or files)
Table of Contents
1. What Is Laravel MCP? 2. Install Laravel 3. Install MCP Package 4. Publish MCP Routes 5. Create MCP Server 6. Register MCP Server Route 7. Create a Tool 8. Add Tool to Server 9. Test with MCP Inspector 10. Real Example: AI Creates a User 11. Create Prompts 12. Create Resources 13. AI Reading or Writing Database 14. Summary
What Is Laravel MCP?
Laravel MCP is a bridge between AI and your Laravel application. It allows AI to: • Run actions (tools) • Read data (resources) • Use templates (prompts) • Update your database Install Laravel composer create-project laravel/laravel my-app cd my-appInstall MCP Packagecomposer require laravel/mcp
Publish MCP Routes
php artisan vendor:publish --tag=ai-routes This creates: routes/ai.php This file is used to register MCP servers.
Create MCP Server
A server is the main controller for MCP. php artisan make:mcp-server WeatherServer Example server:
<?php
namespace App\Mcp\Servers;
use Laravel\Mcp\Server;
class WeatherServer extends Server
{
protected string $name = 'Weather Server';
protected string $version = '1.0.0';
protected string $instructions = 'This server provides weather information.';
protected array $tools = [];
protected array $resources = [];
protected array $prompts = [];
}

