Absortio

Email → Summary → Bookmark → Email

Boosting Laravel Boost

Extracto

In the era of AI, LLMs are undeniably part of our workflow. Let's make them suck less with Laravel Boost.

Resumen

Resumen Principal

El autor inicia el artículo reflexionando sobre el impacto de la Inteligencia Artificial en la creación de contenido, expresando una creencia en el valor del material "hecho por humanos" a pesar de la facilidad que ofrece la IA para generar información. El foco principal del texto es la capacidad de la IA para volverse más determinista y menos propensa a la alucinación, abordando dos cuellos de botella fundamentales en el uso diario de los LLMs (Large Language Models): el prompt y el contexto. Para superar la limitación del contexto desactualizado de los datos de entrenamiento, se introduce el concepto de herramientas que permiten a los LLMs acceder a información fresca y específica. Este método es estandarizado por el Model Context Protocol (MCP), una capa que facilita la interacción entre los modelos y estas herramientas externas, permitiendo que la IA obtenga el contexto necesario para tareas específicas. En este marco, se presenta Laravel Boost, un servidor MCP diseñado para el ecosistema Laravel, que equipa a la IA con herramientas para comprender y operar dentro de aplicaciones Laravel, como leer rutas o registros.

Elementos Clave

  • Problemas de los LLMs y la Solución con Herramientas: Los LLMs tienen como principales limitaciones el prompt (cómo se les formula la pregunta) y el contexto (la información que poseen). Para resolver la falta de contexto actualizado, se les "empodera" con herramientas externas, como la capacidad de "buscar en la web", que les permite acceder a datos en tiempo real o a bases de datos específicas de la empresa, superando así los límites de su entrenamiento original.
  • Model Context Protocol (MCP): Se describe como un protocolo estandarizado introducido por Anthropic. El MCP documenta cómo los LLMs invocan herramientas, cómo estas herramientas se integran con los modelos y cómo los modelos obtienen contexto adicional. En esencia, actúa como una capa que permite a los LLMs utilizar cualquier tipo de herramienta (API, llamadas al sistema, etc.) para recopilar la información necesaria y completar una tarea.
  • Laravel Boost como Servidor MCP: Laravel Boost se presenta como una implementación de un servidor MCP que expone un conjunto de herramientas específicas para el ecosistema Laravel. Esto permite que, al interactuar con un LLM (por ejemplo, para depurar código en una aplicación SaaS), el modelo pueda decidir qué herramienta de Laravel utilizar (como leer rutas o consultar logs) para obtener el contexto relevante y responder de manera más efectiva y precisa.
  • Definición del "Propósito" de la Aplicación en Laravel Boost: Una característica clave de Laravel Boost es la capacidad de definir un "propósito" para la aplicación. Esto implica añadir una descripción clara y concisa del producto o servicio que ofrece la aplicación en el archivo de configuración de Boost, proporcionando a la IA un contexto fundamental sobre el dominio de la aplicación para guiar mejor sus respuestas y acciones.

Análisis e Implicaciones

La estandarización a través de MCP y la implementación de herramientas específicas como Laravel Boost marcan un paso significativo hacia una IA más útil y confiable en contextos empresariales y de desarrollo. Esto implica que la IA puede integrarse de forma más profunda y funcional en flujos de trabajo específicos, pasando de ser un generador genérico a un asistente inteligente y contextualizado que opera con datos y lógicas de aplicación específicas.

Contexto Adicional

Este enfoque resalta la evolución de la IA hacia agentes más especializados y conscientes del dominio, donde la personalización del contexto a través del "propósito" y las herramientas se vuelve crucial para maximizar su valor en escenarios del mundo real.

Contenido

August 23, 2025

Hello 👋

cover

It's been a while since I wrote an article. I mean, why would I? You prompt AI about a subject, and it spits out everything you need. That kinda killed the joy for me, I ended up drafting like 10 articles but never publishing any of them. Still, part of me believes people enjoy reading something human-made. Like, an AI wouldn't make you sit through this boring intro, but hey, it's human, crappy, but human. Thanks by the way.

Anyway, I'm writing about AI today (the irony ha). Laravel just dropped a new package, Laravel Boost, which basically makes AI suck less. It makes it more deterministic by giving it rules and extra context to follow. Because yeah, the main bottlenecks of LLMs (at least from my day-to-day usage) are the prompt and the context.

WTF are MCPs

I'm not going to lecture you about prompt engineering, there are tons of resources out there already. Instead, let's talk about the second bottleneck: context.

LLMs are trained on massive datasets, and those datasets are their reference point. For example, if the training data only goes up to 2023 and you ask about today's weather, it won't have a clue. So what do we do?

We empower LLMs, give them up-to-date context, through tools. You have probably used this without even realizing it. Ask an LLM about the latest news and you will see "searching web". That's a tool in action, feeding the AI fresh data so it can answer you. Neat.

But "searching web" is just a built-in tool. If you asked it about your latest Jira ticket, it wouldn't know. And think about it, providers like OpenAI or Anthropic can't build tools for every possible need. For instance, you might want your LLM to query internal company data. That's where the idea of bringing your own tool comes in. The LLM can call your tool, fetch the data it needs, and then respond. Again, pretty neat.

So neat that Anthropic introduced the Model Context Protocol (MCP) to document this. It standardizes how LLMs call tools, how you plug tools into them, and how they fetch more context. So, if you have never heard of MCPs, well, we just covered them. At the core, they are just a thin layer that lets LLMs use tools (like the "searching web" tool) to grab more context.

MCPs do a bit more too.

And these tools can be anything, API calls, system calls, method calls, whatever. As long as they can provide an answer back to the LLM, the model can use it to finish the task.

Cool. Now you know about MCPs. You can read more about them here.

Hmm, Laravel Boost?

So Laravel Boost is basically an MCP server that exposes a set of tools. These tools revolve around the Laravel ecosystem, things like reading routes, checking logs, or searching the Laravel docs.

So when you prompt an LLM to fix your vibe coded SaaS, it can decide which tool to use. Though, nothing's guaranteed, an LLM can be a bitch and just ignore the tools, making up a method that never existed 🤷🏽.

And then you undo the change, get pissed, prompt again, and deal with a "sorry, you are absolutely right"...

I'm not going to cover how to install it, there's already an official YouTube video, a Laracasts episode, and a bunch of community guides. Besides, I'm a bit late to the party.

Though, I do want to show you how to boost Laravel boost.

What's My Purpose?

Boost lets you give your application a "purpose", basically a description of your product so the AI knows the context. Say you are building a SaaS, you could write something like:

This application is a SaaS that provides X services, etc.

You know your product best buddy.

First, make sure you have published the Boost config:

php artisan vendor:publish --tag=boost-config

At the time of writing, the config file looks like this:

<?php

declare(strict_types=1);

return [
    /*
    |--------------------------------------------------------------------------
    | Boost Master Switch
    |--------------------------------------------------------------------------
    |
    | This option may be used to disable all Boost functionality, which
    | simply provides a single and convenient way to enable or disable
    | Boost's AI development tools.
    |
    */

    'enabled' => env('BOOST_ENABLED', true),

    /*
    |--------------------------------------------------------------------------
    | Boost Browser Logs Watcher
    |--------------------------------------------------------------------------
    |
    | The following option may be used to enable or disable the browser logs
    | watcher feature within Laravel Boost. The log watcher will read any
    | errors within the browser's console to give Boost better context.
    */

    'browser_logs_watcher' => env('BOOST_BROWSER_LOGS_WATCHER', true),

];

To add the application purpose we just talked about, drop a new entry in the config:

// omitted for breivety
'purpose' => 'Describe your application purpose'

For this to take effect, you will need to re-generate the guidelines:

php artisan boost:install

In the published guidelines, for example, if you are using Cursor, you will find your purpose (I hope we all do lol) in .cursor/rules/laravel-boost.mdc, in the "Foundational Context" section.

Less is More

Boost ships with 15+ tools, but depending on your app you might not need them all. If you are building a pure API, you don't need a BrowserLogs tool, you are spared from frontend hell. Personally, I also found GetConfig and ListAvailableConfigKeys kinda useless, the LLM can just read configs directly without jumping through those hoops. So let's exclude them.

Tweak the boost.php config:

<?php

use Laravel\Boost\Mcp\Tools\GetConfig;
use Laravel\Boost\Mcp\Tools\BrowserLogs;
use Laravel\Boost\Mcp\Tools\ListAvailableConfigKeys;

// omitted for breivety
'mcp' => [
    'tools' => [
        'exclude' => [BrowserLogs::class, GetConfig::class, ListAvailableConfigKeys::class],
    ],
],

Boom, 3 tools gone.

And just like excluding tools, you can add your own. For example, I like having a tool that lists all registered events in the app. If you are pulling in third-party packages, this makes it easier for the LLM to spot events it can hook into instead of building extra logic or extending classes.

Under the hood, Boost uses a new first-party package, laravel/mcp, which handles tool creation and all the fun stuff. You can create a new tool with:

php artisan make:mcp-tool ListEvents

The tool code for listing event is something like:

<?php

namespace App\Mcp\Tools;

use Illuminate\Support\Facades\Artisan;
use Laravel\Mcp\Server\Tool;
use Laravel\Mcp\Server\Tools\Annotations\IsReadOnly;
use Laravel\Mcp\Server\Tools\ToolInputSchema;
use Laravel\Mcp\Server\Tools\ToolResult;
use Symfony\Component\Console\Command\Command as CommandAlias;
use Symfony\Component\Console\Output\BufferedOutput;

#[IsReadOnly]
class ListEvents extends Tool
{
    public function description(): string
    {
        return 'List all available events defined in the application';
    }

    public function schema(ToolInputSchema $schema): ToolInputSchema
    {
        return $schema;
    }

    /**
     * @param array<string> $arguments
     */
    public function handle(array $arguments): ToolResult
    {
        $eventsOutput = $this->artisan('event:list');

        return ToolResult::text($eventsOutput);
    }

    /**
     * @param array<string|bool> $options
     */
    private function artisan(string $command, array $options = []): string
    {
        $output = new BufferedOutput;
        $result = Artisan::call($command, $options, $output);

        if ($result !== CommandAlias::SUCCESS) {
            return 'Failed to list routes: '.$output->fetch();
        }

        return trim($output->fetch());
    }
}

Then register it in, you guessed it, the config file:

<?php

use App\Mcp\Tools\ListEvents;
use Laravel\Boost\Mcp\Tools\GetConfig;
use Laravel\Boost\Mcp\Tools\BrowserLogs;
use Laravel\Boost\Mcp\Tools\ListAvailableConfigKeys;

// omitted for breivty
'mcp' => [
    'tools' => [
        'exclude' => [BrowserLogs::class, GetConfig::class, ListAvailableConfigKeys::class],
        'include' => [ListEvents::class], // include the tool
    ],
],

And just like that, you added a custom tool.

Bonus tip: The MCP server Boost uses comes with an inspector, so you can test new tools right away. Just run:

php artisan mcp:inspector laravel-boost

You will see all available tools, test them, etc.

Don't call me, Don't come by my house

If you are using a modular monolith architecture with a modules/ directory... bad news: Boost only checks enums, models, and controllers inside app/.

Would be nice if there was a native way to customize this, but until then, we do it ourselves.

All you need to do is rebind Laravel\Boost\Install\GuidelineAssist to your own custom GuidelineAssist, which scans modules/ (or wherever).

Your custom guideline might look like:

<?php

declare(strict_types=1);

namespace App\Support;

use Illuminate\Database\Eloquent\Model;
use Laravel\Boost\Install\GuidelineAssist;
use ReflectionClass;
use Symfony\Component\Finder\Finder;

class CustomGuidelineAssist extends GuidelineAssist
{
    public function __construct()
    {
        $this->modelPaths = $this->discover(fn ($reflection) => ($reflection->isSubclassOf(Model::class) && ! $reflection->isAbstract()));
        $this->controllerPaths = $this->discover(fn (ReflectionClass $reflection) => (stripos($reflection->getName(), 'controller') !== false || stripos($reflection->getNamespaceName(), 'controller') !== false));
        $this->enumPaths = $this->discover(fn ($reflection) => $reflection->isEnum());
    }

    private function discover(callable $cb): array
    {
        $classes = [];

        if (empty(self::$classes)) {
            $finder = Finder::create()
                ->in([app_path(), base_path('modules')])
                ->files()
                ->name('/[A-Z].*\.php$/');

            foreach ($finder as $file) {
                $relativePath = $file->getRelativePathname();
                $isModule = str_starts_with($file->getRealPath(), base_path('modules'));

                $className = $isModule
                    ? 'Modules\\'.str_replace(['/', '.php'], ['\\', ''], $relativePath)
                    : app()->getNamespace().str_replace(['/', '.php'], ['\\', ''], $relativePath);

                try {
                    if ($this->fileHasClassLike($file->getRealPath()) && class_exists($className)) {
                        self::$classes[$className] = $file->getRealPath();
                    }
                } catch (\Throwable) {
                    // Ignore exceptions from class loading
                }
            }
        }

        foreach (self::$classes as $className => $path) {
            if ($cb(new ReflectionClass($className))) {
                $classes[$className] = $path;
            }
        }

        return $classes;
    }
}

It's mostly the parent discover() with minor tweaks.

Don't forget to rebind it in a service provider. Once you do, testing the "application-info" tool from the inspector should show all your models listed correctly.

That's it

AI sucks? Maybe. But it sucks a lot less with the right tool, something like Boost.

But don't stop there. There are MCPs for everything, Github, Sentry, Linear. They add tons of value. You can even build your own MCP for fun, I had one that turned on my air fryer (yes, it cooked fries), and another that played a Spotify playlist based on how shitty the code was.

Fun fact: even though I'm shitting on AI a bit here, I used AI to correct my poor grammar. Fixing grammar while getting insulted, cool lol. Sorry AI, you do push me over the line sometimes.