𝗨𝘀𝗲 𝗟𝗮𝗿𝗮𝘃𝗲𝗹 𝘁𝗼 𝗰𝗿𝗲𝗮𝘁𝗲 𝘆𝗼𝘂𝗿 𝗼𝘄𝗻 𝗠𝗖𝗣 𝘀𝗲𝗿𝘃𝗲𝗿

Claude can work with your Laravel app. You do not need to build a REST API or write a custom client. You can expose tools through the Model Context Protocol (MCP).

The laravel/mcp package makes this easy. You can build an MCP server in one afternoon.

An MCP server gives three things to an AI: • Tools: Actions the model calls, like searching orders. • Resources: Read-only data the model pulls for context. • Prompts: Reusable templates.

How to build it:

  1. Setup Install the package via Composer: composer require laravel/mcp

Publish your routes: php artisan vendor:publish --tag=ai-routes

  1. Create a Server A server groups your tools and resources. Generate one with: php artisan make:mcp-server OrdersServer

Register it in routes/ai.php. You can run a web server for remote clients or a local server for tools like Claude Code.

  1. Create Tools Tools do the actual work. Generate a tool with: php artisan make:mcp-tool SearchOrdersTool

A tool needs two methods: • Schema: Defines what arguments the model sends. • Handle: Runs the logic and returns a response.

Write clear descriptions. The model uses these descriptions to decide when to use your tool.

  1. Use Annotations Use attributes to describe tool behavior: • IsReadOnly: The tool does not change data. • IsDestructive: The tool changes or deletes data. • IsIdempotent: Running it twice has the same result as once.

  2. Secure Your Server Web MCP servers are public endpoints. Treat them like any other API. Use middleware to protect them. Laravel Sanctum or Passport works well for authentication.

  3. Test Your Work Use the MCP Inspector to test your server manually: php artisan mcp:inspector orders

You can also write standard PHPUnit tests to ensure your tools work correctly.

You now have a standard interface for AI to interact with your application. You do not need to write any protocol code. Just add tools, describe them clearly, and secure them with middleware.

What have you connected an MCP server to? Let me know in the comments.

Source: https://dev.to/accreditly/use-laravel-to-create-your-own-mcp-server-251g