Skip to content
全部文档

Laravel Boost

简介

Laravel Boost 通过提供必要的指南与 agent skills,加速 AI 辅助开发,帮助 AI agent 编写符合 Laravel 最佳实践的高质量 Laravel 应用。

Boost 还提供强大的 Laravel 生态文档 API,将内置 MCP 工具与包含超过 17,000 条 Laravel 专用信息的知识库相结合,并通过基于嵌入的语义搜索能力增强,以获得精确、具备上下文感知的结果。Boost 会指示 Claude Code、Cursor 等 AI agent 使用该 API,了解最新的 Laravel 特性与最佳实践。

安装

Laravel Boost 可通过 Composer 安装:

shell
composer require laravel/boost --dev

接下来,安装 MCP 服务器与编码指南:

shell
php artisan boost:install

boost:install 命令会为你在安装过程中选择的编码 agent 生成相应的 agent 指南与 skill 文件。

安装好 Laravel Boost 后,就可以开始使用 Cursor、Claude Code 或你选择的 AI agent 进行编码了。

INFO

你可以放心地将生成的 MCP 配置文件(.mcp.json)、指南文件(CLAUDE.mdAGENTS.mdjunie/ 等)以及 boost.json 配置文件加入应用的 .gitignore,因为运行 boost:installboost:update 时这些文件会自动重新生成。

配置你的 Agent

text
1. Open the command palette (`Cmd+Shift+P` or `Ctrl+Shift+P`)
2. Press `enter` on "/open MCP Settings"
3. Turn the toggle on for `laravel-boost`
text
Claude Code support is typically enabled automatically. If you find it isn't, open a shell in the project's directory and run the following command:

claude mcp add -s local -t stdio laravel-boost php artisan boost:mcp
text
Codex support is typically enabled automatically. If you find it isn't, open a shell in the project's directory and run the following command:

codex mcp add laravel-boost -- php "artisan" "boost:mcp"
text
Gemini CLI support is typically enabled automatically. If you find it isn't, open a shell in the project's directory and run the following command:

gemini mcp add -s project -t stdio laravel-boost php artisan boost:mcp
text
1. Open the command palette (`Cmd+Shift+P` or `Ctrl+Shift+P`)
2. Press `enter` on "MCP: List Servers"
3. Arrow to `laravel-boost` and press `enter`
4. Choose "Start server"
text
1. Press `shift` twice to open the command palette
2. Search "MCP Settings" and press `enter`
3. Check the box next to `laravel-boost`
4. Click "Apply" at the bottom right

保持 Boost 资源更新

你可能希望定期更新本地的 Boost 资源(AI 指南与 skills),以确保它们反映你已安装的 Laravel 生态包的最新版本。为此,可以使用 boost:update Artisan 命令。

shell
php artisan boost:update

你也可以通过将其加入 Composer 的「post-update-cmd」脚本中来自动化此过程:

json
{
  "scripts": {
    "post-update-cmd": [
      "@php artisan boost:update --ansi"
    ]
  }
}

MCP 服务器

Laravel Boost 提供一个 MCP(Model Context Protocol)服务器,向 AI agent 暴露用于与 Laravel 应用交互的工具。这些工具使 agent 能够检查应用结构、查询数据库、执行代码等。

可用的 MCP 工具

NameNotes
Application InfoRead PHP & Laravel versions, database engine, list of ecosystem packages with versions, and Eloquent models
Browser LogsRead logs and errors from the browser
Database ConnectionsInspect available database connections, including the default connection
Database QueryExecute a query against the database
Database SchemaRead the database schema
Get Absolute URLConvert relative path URIs to absolute so agents generate valid URLs
Last ErrorRead the last error from the application's log files
Read Log EntriesRead the last N log entries
Search DocsQuery the Laravel hosted documentation API service to retrieve documentation based on installed packages

手动注册 MCP 服务器

有时你可能需要手动将 Laravel Boost MCP 服务器注册到所选编辑器中。应使用以下信息注册 MCP 服务器:

Commandphp
Argsartisan boost:mcp

JSON 示例:

json
{
    "mcpServers": {
        "laravel-boost": {
            "command": "php",
            "args": ["artisan", "boost:mcp"]
        }
    }
}

AI 指南

AI 指南是可组合的指令文件,会预先加载,为 AI agent 提供关于 Laravel 生态包的必要上下文。这些指南包含核心约定、最佳实践以及框架特定模式,帮助 agent 生成一致、高质量的代码。

可用的 AI 指南

Laravel Boost 为以下包和框架包含了 AI 指南。core 指南为给定包提供通用、概括性的建议,适用于所有版本。

PackageVersions Supported
Core & Boostcore
Laravel Frameworkcore, 10.x, 11.x, 12.x
Livewirecore, 2.x, 3.x, 4.x
Flux UIcore, free, pro
Foliocore
Herdcore
Inertia Laravelcore, 1.x, 2.x, 3.x
Inertia Reactcore, 1.x, 2.x, 3.x
Inertia Vuecore, 1.x, 2.x, 3.x
Inertia Sveltecore, 1.x, 2.x, 3.x
MCPcore
Pennantcore
Pestcore, 3.x, 4.x
PHPUnitcore
Pintcore
Sailcore
Tailwind CSScore, 3.x, 4.x
Livewire Voltcore
Wayfindercore
Enforce Testsconditional

注意: 若要保持 AI 指南为最新,请参阅保持 Boost 资源更新一节。

添加自定义 AI 指南

要用自己的自定义 AI 指南增强 Laravel Boost,请将 .blade.php.md 文件添加到应用的 .ai/guidelines/* 目录。运行 boost:install 时,这些文件会自动与 Laravel Boost 的指南一起包含。

覆盖 Boost AI 指南

你可以通过创建路径匹配的自定义指南来覆盖 Boost 内置的 AI 指南。当你创建的自定义指南与现有 Boost 指南路径匹配时,Boost 会使用你的自定义版本,而不是内置版本。

例如,要覆盖 Boost 的「Inertia React v2 Form Guidance」指南,请在 .ai/guidelines/inertia-react/2/forms.blade.php 创建文件。运行 boost:install 时,Boost 会包含你的自定义指南,而不是默认指南。

第三方包 AI 指南

如果你维护第三方包,并希望 Boost 为其包含 AI 指南,可在包中添加 resources/boost/guidelines/core.blade.php 文件。当你的包用户运行 php artisan boost:install 时,Boost 会自动加载你的指南。

AI 指南应简要概述包的功能,说明所需的文件结构或约定,并解释如何创建或使用其主要功能(附示例命令或代码片段)。保持简洁、可执行,并聚焦最佳实践,以便 AI 能为你的用户生成正确代码。示例如下:

php
## Package Name

This package provides [brief description of functionality].

### Features

- Feature 1: [clear & short description].
- Feature 2: [clear & short description]. Example usage:

@verbatim
<code-snippet name="How to use Feature 2" lang="php">
$result = PackageName::featureTwo($param1, $param2);
</code-snippet>
@endverbatim

Agent Skills

Agent Skills 是轻量、有针对性的知识模块,agent 在处理特定领域时可按需激活。与预先加载的指南不同,skills 允许仅在相关时加载详细模式与最佳实践,从而减少上下文膨胀并提高 AI 生成代码的相关性。

运行 boost:install 并选择 skills 功能时,会根据 composer.json 中检测到的包自动安装 skills。例如,若项目包含 livewire/livewire,会自动安装 livewire-development skill。

可用的 Skills

SkillPackage
fluxui-developmentFlux UI
folio-routingFolio
inertia-react-developmentInertia React
inertia-svelte-developmentInertia Svelte
inertia-vue-developmentInertia Vue
livewire-developmentLivewire
mcp-developmentMCP
pennant-developmentPennant
pest-testingPest
tailwindcss-developmentTailwind CSS
volt-developmentVolt
wayfinder-developmentWayfinder

注意: 若要保持 skills 为最新,请参阅保持 Boost 资源更新一节。

自定义 Skills

要创建自己的自定义 skills,请在应用的 .ai/skills/{skill-name}/ 目录中添加 SKILL.md 文件。运行 boost:update 时,你的自定义 skills 会与 Boost 内置 skills 一起安装。

例如,要为应用的领域逻辑创建自定义 skill:

text
.ai/skills/creating-invoices/SKILL.md

覆盖 Skills

你可以通过创建名称匹配的自定义 skills 来覆盖 Boost 内置的 skills。当你创建的自定义 skill 与现有 Boost skill 名称匹配时,Boost 会使用你的自定义版本,而不是内置版本。

例如,要覆盖 Boost 的 livewire-development skill,请在 .ai/skills/livewire-development/SKILL.md 创建文件。运行 boost:update 时,Boost 会包含你的自定义 skill,而不是默认 skill。

第三方包 Skills

如果你维护第三方包,并希望 Boost 为其包含 skills,可在包中添加 resources/boost/skills/{skill-name}/SKILL.md 文件。当你的包用户运行 php artisan boost:install 时,Boost 会根据用户偏好自动安装你的 skills。

Boost Skills 支持 Agent Skills 格式,应组织为一个包含带 YAML frontmatter 与 Markdown 说明的 SKILL.md 文件的文件夹。SKILL.md 文件必须包含必需的 frontmatter(namedescription),并可选择性地包含脚本、模板和参考材料。

Skills 应说明所需的文件结构或约定,并解释如何创建或使用其主要功能(附示例命令或代码片段)。保持简洁、可执行,并聚焦最佳实践,以便 AI 能为你的用户生成正确代码:

markdown
---
name: package-name-development
description: Build and work with PackageName features, including components and workflows.
---

# Package Name Development

## When to use this skill
Use this skill when working with PackageName features...

## Features

- Feature 1: [clear & short description].
- Feature 2: [clear & short description]. Example usage:

$result = PackageName::featureTwo($param1, $param2);

指南与 Skills 对比

Laravel Boost 提供两种不同的方式,为 AI agent 提供关于应用的上下文:guidelines(指南)skills

指南在 AI agent 启动时预先加载,提供适用于整个代码库的 Laravel 约定与最佳实践等必要上下文。

Skills在处理特定任务时按需激活,包含针对特定领域(如 Livewire 组件或 Pest 测试)的详细模式。仅在相关时加载 skills 可减少上下文膨胀并提高代码质量。

AspectGuidelinesSkills
LoadedUpfront, always presentOn-demand, when relevant
ScopeBroad, foundationalFocused, task-specific
PurposeCore conventions & best practicesDetailed implementation patterns

文档 API

Laravel Boost 包含文档 API,为 AI agent 提供包含超过 17,000 条 Laravel 专用信息的知识库访问能力。该 API 使用基于嵌入的语义搜索,以提供精确、具备上下文感知的结果。

Search Docs MCP 工具允许 agent 查询 Laravel 托管的文档 API 服务,根据已安装的包检索文档。Boost 的 AI 指南与 skills 会自动指示你的编码 agent 使用该 API。

PackageVersions Supported
Laravel Framework10.x, 11.x, 12.x
Filament2.x, 3.x, 4.x, 5.x
Flux UI2.x Free, 2.x Pro
Inertia1.x, 2.x
Livewire1.x, 2.x, 3.x, 4.x
Nova4.x, 5.x
Pest3.x, 4.x
Tailwind CSS3.x, 4.x

扩展 Boost

Boost 开箱即用地支持许多流行的 IDE 与 AI agent。如果尚未支持你的编码工具,你可以创建自己的 agent 并与 Boost 集成。

为其他 IDE / AI Agent 添加支持

要为新的 IDE 或 AI agent 添加支持,请创建一个继承 Laravel\Boost\Install\Agents\Agent 的类,并根据需要实现以下一个或多个契约:

  • `Laravel\Boost\Contracts\SupportsGuidelines` - 添加对 AI 指南的支持。
  • `Laravel\Boost\Contracts\SupportsMcp` - 添加对 MCP 的支持。
  • `Laravel\Boost\Contracts\SupportsSkills` - 添加对 Agent Skills 的支持。

编写 Agent

php
<?php

declare(strict_types=1);

namespace App;

use Laravel\Boost\Contracts\SupportsGuidelines;
use Laravel\Boost\Contracts\SupportsMcp;
use Laravel\Boost\Contracts\SupportsSkills;
use Laravel\Boost\Install\Agents\Agent;

class CustomAgent extends Agent implements SupportsGuidelines, SupportsMcp, SupportsSkills
{
    // Your implementation...
}

示例实现请参阅 ClaudeCode.php

注册 Agent

在应用的 App\Providers\AppServiceProviderboot 方法中注册你的自定义 agent:

php
use Laravel\Boost\Boost;

public function boot(): void
{
    Boost::registerAgent('customagent', CustomAgent::class);
}

注册后,运行 php artisan boost:install 时即可选择你的 agent。