Laravel Magazine

Laravel MCP: Turn Your App Into an AI-Ready Server

Eric Van Johnson · News
Laravel MCP: Turn Your App Into an AI-Ready Server

There is a recurring frustration with AI coding assistants: they know a lot about Laravel in general, but they know nothing about your Laravel app specifically. They invent column names. They generate routes that do not exist. They suggest package versions that do not match what is in your composer.json. The assistant is guessing, and every wrong guess costs you time.

The Laravel team's answer to this is Laravel MCP, and it shipped the laravel/mcp package in early 2026 to address exactly this problem.

What Is MCP?

MCP stands for Model Context Protocol. Anthropic introduced it as an open standard in November 2024 to define how AI agents communicate with external tools and data sources. Before MCP, every AI tool that wanted to connect to your data built its own proprietary integration. MCP replaces that chaos with a single standard protocol.

Any MCP-compatible client — Claude, Cursor, GitHub Copilot, ChatGPT — can connect to any MCP-compatible server, including one you build in Laravel. Once connected, the AI client stops guessing and starts querying.

With an MCP server running against your app, your coding agent can tell you which columns exist in your orders table, run a live database query to verify results before writing a migration, and look up the exact Filament version you have installed rather than relying on cached documentation.

Three Capabilities: Tools, Resources, and Prompts

The Laravel MCP package exposes three types of capabilities to connected AI clients:

Tools are callable functions the agent can invoke. Think of them as actions: query a list of recent orders, create an invoice, look up a user by email. Tools are the primary surface AI clients interact with.

Resources are readable data exposed by URI. A resource might be orders://reports/monthly or config://app — structured data the client can read without necessarily triggering any side effects.

Prompts are reusable conversation templates. You define a prompt once on the server, and any connected client can invoke it for consistent behavior across different AI tools.

Getting Started

Install the package and publish the routes file:

composer require laravel/mcp
php artisan mcp:install

This creates routes/ai.php. Register your server there:

use Laravel\Mcp\Facades\Mcp;

Mcp::web('my-app-server', MyAppServer::class);

Generate the server class:

php artisan make:mcp-server MyAppServer

A server class is a container for your tools, resources, and prompts. PHP attributes define its metadata:

use Laravel\Mcp\Attributes\McpServer;

#[McpServer(
    name: 'my-app-server',
    description: 'Tools and data for the My App Laravel application'
)]
class MyAppServer extends Server
{
    public function tools(): array
    {
        return [
            new GetRecentOrdersTool(),
            new CreateInvoiceTool(),
        ];
    }
}

Defining a Tool

Generate a tool and register it on your server:

php artisan make:mcp-tool GetRecentOrders
use Laravel\Mcp\Attributes\McpTool;

#[McpTool(description: 'Returns the 10 most recent orders for a given user')]
class GetRecentOrdersTool extends Tool
{
    public function schema(): array
    {
        return [
            'userId' => Schema::integer('The user ID to fetch orders for'),
        ];
    }

    public function handle(int $userId, OrderRepository $orders): string
    {
        return $orders->recentForUser($userId, limit: 10)->toJson();
    }
}

If your tool needs a service from the container, add it to the handle method signature and Laravel resolves it automatically.

Authentication

For MCP servers exposed to remote clients, protect the routes with middleware. The package supports OAuth 2.1 via Laravel Passport and token auth via Sanctum:

Mcp::web('my-app-server', MyAppServer::class)
    ->middleware(['auth:sanctum']);

For OAuth 2.1, call Mcp::oauthRoutes() in routes/ai.php to register the necessary endpoints, and publish the auth views.

Locket: A Real-World Demo

The Laravel team built Locket, a demo application showing MCP in a realistic product context. The source code is public and the demo is live at locket.laravel.cloud. If you want to see how tools, resources, and authentication wire together in a real app rather than a contrived tutorial, that is the best place to look.

Why This Matters for Your Team

For solo developers, the payoff is an AI assistant that actually knows your schema, your routes, and your installed packages. For teams, it is more significant: instead of every developer on the team maintaining their own bespoke AI tool integrations, you define the server once and every client that connects gets the same structured, authenticated access.

The laravel/mcp package documentation lives at laravel.com/docs/mcp. If you have been living with an AI assistant that invents column names, this is the fix.


Sources: Laravel Blog · laravel/mcp docs · Locket demo

Stay Updated

Subscribe to our newsletter

Get latest news, tutorials, community articles and podcast episodes delivered to your inbox.

Weekly articles
We send a new issue of the newsletter every week on Friday.
No spam
We'll never share your email address and you can opt out at any time.