DEV Community

Ethan Lee
Ethan Lee

Posted on

What is Laravel MCP?

Laravel MCP is a library that allows you to build Model Context Protocol (MCP) servers within your Laravel applications. It provides a structured method for AI clients, such as ChatGPT, Claude, and Cursor, to interact with your application's functionality. The public beta for Laravel MCP was launched around September 18, 2025.

Laravel MCP just out

What is the Model Context Protocol (MCP)?

The Model Context Protocol (MCP) is an open standard that enables AI assistants to securely connect with and utilize external tools and data sources. Instead of creating custom integrations for each AI model, MCP offers a universal API specifically designed for AI agents.

Laravel MCP supports the three main primitives of the protocol :

  • Tools: Allow AI agents to perform actions and execute code. This can range from sending an email to creating an invoice in your application.
  • Resources: Enable users to select and share content from your application with an AI agent. This could be anything from a document to a user profile.
  • Prompts: Provide reusable templates for interacting with the AI, ensuring consistent and reliable outputs for common tasks like content vetting or code reviews.

Getting Started with Laravel MCP

Try Laravel MCP

Requirements
Before installation, ensure your development environment meets the following requirements:

  • PHP 8.1+
  • Laravel 10, 11, or 12

Installation
You can install Laravel MCP into your project using the Composer package manager :

composer require laravel/mcp
Enter fullscreen mode Exit fullscreen mode

After installation, you need to publish the routes/ai.php file, where you will define your MCP servers :

php artisan vendor:publish --tag=ai-routes
Enter fullscreen mode Exit fullscreen mode

Core Concepts and Usage

Servers

Servers are the central communication point for exposing your application's capabilities to AI clients. You can create a new server class using the make:mcp-server Artisan command .

Laravel MCP supports two types of servers:

  • Web Servers: Accessible via HTTP, making them suitable for remote AI clients. You can register a web server in your routes/ai.php file using the Mcp::web() method.
  • Local Servers: Run as Artisan commands, which is ideal for local development integrations like Laravel Boost. These are registered using the Mcp::local() method .

Tools

Tools expose your application's functionality for AI clients to call.

  1. Create a Tool: Use the Artisan command make:mcp-tool <ToolName> .
  2. Define Logic: In the generated tool class, you define the input schema, handle incoming requests, and return a response. You can use Laravel's validation and dependency injection features within the tool's handle method .
  3. Register the Tool: Add your new tool class to the $tools array in your server class .

Tools can return various types of responses, including simple text, errors, multiple content blocks, and even streaming responses for long-running tasks using PHP generators .

Resources

Resources expose data and content that AI clients can use as context.

  1. Create a Resource: Use the command make:mcp-resource <ResourceName> .
  2. Define Content: Implement the handle method to return the resource's content. Resources are identified by a unique URI and have an associated MIME type (e.g., text/plain, application/pdf) .
  3. Register the Resource: Add the resource class to the $resources array in your server .

Prompts

Prompts offer reusable templates for common AI interactions.

  1. Create a Prompt: Use the make:mcp-prompt <PromptName> command .
  2. Define Arguments: You can define arguments that allow the AI client to customize the prompt .
  3. Register the Prompt: Add the prompt to the $prompts array in your server class .

Authentication and Authorization

You can protect your web-based MCP servers using middleware. Laravel MCP supports two primary authentication methods :

  • OAuth 2.1 with Laravel Passport: This is the most robust and widely supported method among MCP clients. It requires setting up Passport and applying the auth:api middleware to your server route .
  • Token-based with Laravel Sanctum: A simpler approach where you protect your server with Sanctum's auth:sanctum middleware. The AI client must then provide a bearer token in the Authorization header .

Once a user is authenticated, you can perform authorization checks within your tools, resources, and prompts by accessing the user object from the request ($request->user()).

Testing Your MCP Server

Laravel MCP provides two ways to test your implementation:

  • MCP Inspector: An interactive command-line tool that allows you to connect to your server, test authentication, and interact with your tools, resources, and prompts. You can run it with php artisan mcp:inspector <server_name_or_uri>.
  • Unit Tests: You can write unit and feature tests for your MCP primitives. The framework provides assertion methods to verify responses, check for errors, and confirm that notifications were sent. You can also simulate requests from an authenticated user using the actingAs() method.

What are the main use cases for Laravel MCP?

Laravel MCP (Model Context Protocol) serves as a bridge, enabling AI assistants to securely and intelligently interact with your Laravel application's functions and data. Its main use cases revolve around automation, enhancing developer productivity, and creating sophisticated, AI-driven business solutions.

Developer Productivity and Codebase Interaction

One of the most immediate applications of Laravel MCP is to augment the software development process itself. By exposing parts of the Laravel framework and application codebase as tools, developers can use AI assistants to perform complex tasks with simple natural language commands.

Common use cases include:

  • Code Generation and Scaffolding: Instructing an AI to create new controllers, models, migrations, or other Laravel components, significantly speeding up development workflows.
  • Database Management: Allowing an AI to run database migrations, query records, or generate reports directly from the chat interface.
  • Running Commands: Triggering artisan commands to manage queues, clear caches, or perform other maintenance tasks without leaving the code editor or a chat client.
  • Automated Testing: Using AI to write or execute tests for specific parts of the application, ensuring code quality and integrity.

Laravel Boost and Laravel Herd are prime examples of this, providing a suite of pre-built tools for AI-assisted coding within the Laravel ecosystem.

Business and Workflow Automation

Laravel MCP allows you to expose your application's core business logic as a set of tools that an AI can use to perform actions on behalf of a user. This turns a conversational AI into an active participant in your business processes.

Examples of business automation include:

  • Automated Invoicing: A user could ask an AI assistant to "create an invoice for client X for $500," and the AI would use an MCP tool to execute this function within the application.
  • Content Management: Instructing an AI to create, update, or publish content, such as blog posts or product descriptions, directly into your application's database.
  • User Management: Performing administrative tasks like creating new user accounts, resetting passwords, or assigning roles through an AI-driven interface.
  • Email and Notifications: Using AI to compose and send emails or trigger notifications based on specific events or user requests.

Enterprise-Level Solutions

For larger organizations, Laravel MCP enables the integration of AI into critical systems, leading to more efficient and intelligent operations.

  • Personalized Customer Support: By connecting an AI to a CRM system (like Salesforce or Zendesk) via an MCP server, the AI can access customer history, provide personalized responses, and even update support tickets automatically. This reduces the workload on human agents and provides faster service.
  • Fraud Detection: In financial applications, an MCP server can trigger advanced fraud detection models in real-time. If a suspicious transaction occurs, the AI can flag the issue, alert the appropriate team, and initiate protective measures without delay.
  • Predictive Maintenance: In IoT environments, MCP can connect sensor data to predictive maintenance models. When a sensor detects a potential issue with a piece of equipment, it can trigger a workflow to schedule maintenance, preventing downtime and costly repairs.

Data Access and Integration

Beyond performing actions, AI assistants can use MCP to securely access and retrieve data from your application, providing them with the necessary context to deliver accurate and relevant information.

  • Dynamic Data Retrieval: An AI can fetch specific data from your application, such as a user's profile, an order's status, or application settings, and use that information in its response.
  • Connecting to External APIs: You can create MCP tools that act as a proxy to third-party services. This allows an AI to interact with external APIs—for things like processing payments or checking stock levels—through the secure and controlled environment of your Laravel application.
  • Data Entry Automation: By combining MCP with technologies like Optical Character Recognition (OCR), you can build systems where an AI can read documents (like invoices or receipts) and automatically enter that data into your application, reducing manual data entry.

Top comments (2)

Collapse
 
trojanmocx profile image
ALI

Laravel MCP is basically giving your AI assistant the keys to your code kingdom. Finally, a bot that can run migrations, create models, and send emails without asking for coffee first. Just hope it doesn’t start changing my variable names to something dramatic like heroOfTheDay… though honestly, that might make debugging more fun!

Some comments may only be visible to logged-in visitors. Sign in to view all comments.