Laravel MCP Beta

Share
Laravel MCP Beta
Photo by Olia Budaeva / Unsplash

Recently, the Laravel team launched the beta of the Laravel MCP package. The idea of the package is to aid the development of building MCP servers for your applications. This is the 2nd first party AI focused package that the team has released, the first of which was Laravel Boost

Laravel Boost
This week, I took Laravel Boost for a spin. Boost is a new package by Laravel that, in their own words: “Accelerates AI-assisted development by providing the essential context and structure that AI needs to generate high-quality, Laravel-specific code using any agent.” Essentially, the package exposes a

Laravel MCP provides an intuitive framework for AI agents to interact with your application. Let's take a look at how it works:

namespace App\Mcp\Servers;
 
use Laravel\Mcp\Server;
 
class WeatherServer extends Server
{
    /**
     * The tools registered with this MCP server.
     *
     * @var array<int, class-string<\Laravel\Mcp\Server\Tool>>
     */
    protected array $tools = [
        // ExampleTool::class,
    ];
 
    /**
     * The resources registered with this MCP server.
     *
     * @var array<int, class-string<\Laravel\Mcp\Server\Resource>>
     */
    protected array $resources = [
        // ExampleResource::class,
    ];
 
    /**
     * The prompts registered with this MCP server.
     *
     * @var array<int, class-string<\Laravel\Mcp\Server\Prompt>>
     */
    protected array $prompts = [
        // ExamplePrompt::class,
    ];
}

The above snippet is an example MCP server which allows you to define tools, resources and prompts. For an example tool, you'd do something like the following:


 
use Illuminate\JsonSchema\JsonSchema;
use Laravel\Mcp\Request;
use Laravel\Mcp\Response;
use Laravel\Mcp\Server\Tool;
 
class CurrentWeatherTool extends Tool
{
    protected string $description = 'Fetches the current weather forecast for a specified location.';
 
    public function handle(Request $request): Response
    {
        $location = $request->get('location');
 
        // Get weather...
 
        return Response::text('The weather is...');
    }
 
    public function schema(JsonSchema $schema): array
    {
        return [
            'location' => $schema->string()
                ->description('The location to get the weather for.')
                ->required(),
        ];
    }
}

Admittedly, I've always been put off building an MCP server for my applications because there was never a simple way to do it, or even a great guide on how to do it. With the MCP package, everything I think I would've struggled with seems to be taken care off.

Over the next couple of weeks, I'm going to be taking a deeper look into the MCP beta, to see if I can see it have a place within our Shopify apps at work.