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 安装:
composer require laravel/boost --dev接下来,安装 MCP 服务器与编码指南:
php artisan boost:installboost:install 命令会为你在安装过程中选择的编码 agent 生成相应的 agent 指南与 skill 文件。
安装好 Laravel Boost 后,就可以开始使用 Cursor、Claude Code 或你选择的 AI agent 进行编码了。
INFO
你可以放心地将生成的 MCP 配置文件(.mcp.json)、指南文件(CLAUDE.md、AGENTS.md、junie/ 等)以及 boost.json 配置文件加入应用的 .gitignore,因为运行 boost:install 和 boost:update 时这些文件会自动重新生成。
配置你的 Agent
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`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:mcpCodex 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"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:mcp1. 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"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 命令。
php artisan boost:update你也可以通过将其加入 Composer 的「post-update-cmd」脚本中来自动化此过程:
{
"scripts": {
"post-update-cmd": [
"@php artisan boost:update --ansi"
]
}
}默认情况下,boost:update 命令只会更新应用中已发布的现有 Boost 资源。若希望 Boost 扫描应用中新安装的包,并提供发布对应指南与 skills 的选项,可使用 --discover 选项:
php artisan boost:update --discoverMCP 服务器
Laravel Boost 提供一个 MCP(Model Context Protocol)服务器,向 AI agent 暴露用于与 Laravel 应用交互的工具。这些工具使 agent 能够检查应用结构、查询数据库、执行代码等。
可用的 MCP 工具
| Name | Notes |
|---|---|
| Application Info | 读取 PHP 与 Laravel 版本、数据库引擎、带版本的生态包列表,以及 Eloquent 模型 |
| Browser Logs | 读取浏览器中的日志与错误 |
| Database Connections | 检查可用的数据库连接,包括默认连接 |
| Database Query | 对数据库执行查询 |
| Database Schema | 读取数据库结构 |
| Get Absolute URL | 将相对路径 URI 转换为绝对路径,以便 agent 生成有效 URL |
| Last Error | 从应用日志文件中读取最近一次错误 |
| Read Log Entries | 读取最近 N 条日志条目 |
| Record Rule | 将持久的项目规则记录到 .ai/rules,供后续 agent 继承 |
| Search Docs | 查询 Laravel 托管的文档 API 服务,根据已安装的包检索文档 |
手动注册 MCP 服务器
有时你可能需要手动将 Laravel Boost MCP 服务器注册到所选编辑器中。应使用以下信息注册 MCP 服务器:
| Command | php |
| Args | artisan boost:mcp |
JSON 示例:
{
"mcpServers": {
"laravel-boost": {
"command": "php",
"args": ["artisan", "boost:mcp"]
}
}
}AI 指南
AI 指南是可组合的指令文件,会预先加载,为 AI agent 提供关于 Laravel 生态包的必要上下文。这些指南包含核心约定、最佳实践以及框架特定模式,帮助 agent 生成一致、高质量的代码。
可用的 AI 指南
Laravel Boost 为以下包和框架包含了 AI 指南。core 指南为给定包提供通用、概括性的建议,适用于所有版本。
| Package | Versions Supported |
|---|---|
| Core & Boost | core |
| Laravel Framework | core, 10.x, 11.x, 12.x, 13.x |
| Livewire | core, 2.x, 3.x, 4.x |
| Flux UI | core, free, pro |
| Folio | core |
| Herd | core |
| Inertia Laravel | core, 1.x, 2.x, 3.x |
| Inertia React | core, 1.x, 2.x, 3.x |
| Inertia Vue | core, 1.x, 2.x, 3.x |
| Inertia Svelte | core, 1.x, 2.x, 3.x |
| MCP | core |
| Pennant | core |
| Pest | core, 3.x, 4.x |
| PHPUnit | core |
| Pint | core |
| Sail | core |
| Tailwind CSS | core, 3.x, 4.x |
| Livewire Volt | core |
| Wayfinder | core |
| Enforce Tests | conditional |
Note:
要保持 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 能为你的用户生成正确代码。示例如下:
## 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>
@endverbatimAgent Skills
Agent Skills 是轻量、有针对性的知识模块,agent 在处理特定领域时可按需激活。与预先加载的指南不同,skills 允许仅在相关时加载详细模式与最佳实践,从而减少上下文膨胀并提高 AI 生成代码的相关性。
当你运行 boost:install 并选择 skills 作为功能时,会根据 composer.json 中检测到的包自动安装 skills。例如,若项目包含 livewire/livewire,则会自动安装 livewire-development skill。Boost 自带的 skills(如 infer-conventions)无论安装了哪些包都会安装。
可用的 Skills
| Skill | Package |
|---|---|
| fluxui-development | Flux UI |
| folio-routing | Folio |
| infer-conventions | Boost |
| inertia-react-development | Inertia React |
| inertia-svelte-development | Inertia Svelte |
| inertia-vue-development | Inertia Vue |
| livewire-development | Livewire |
| mcp-development | MCP |
| pennant-development | Pennant |
| pest-testing | Pest |
| tailwindcss-development | Tailwind CSS |
| volt-development | Volt |
| wayfinder-development | Wayfinder |
Note:
要保持 skills 为最新,请参阅保持 Boost 资源更新一节。
自定义 Skills
要创建自己的自定义 skills,请在应用的 .ai/skills/{skill-name}/ 目录中添加 SKILL.md 文件。运行 boost:update 时,你的自定义 skills 会与 Boost 内置 skills 一起安装。
例如,要为应用的领域逻辑创建自定义 skill:
.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(name 和 description),并可选择性地包含脚本、模板和参考材料。
Skills 应说明所需的文件结构或约定,并解释如何创建或使用其主要功能(附示例命令或代码片段)。保持简洁、可执行,并聚焦最佳实践,以便 AI 能为你的用户生成正确代码:
---
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 可减少上下文膨胀并提高代码质量。
| Aspect | Guidelines | Skills |
|---|---|---|
加载时机 | 预先加载,始终存在 | 按需,相关时加载 |
范围 | 广泛、基础性 | 聚焦、面向任务 |
目的 | 核心约定与最佳实践 | 详细实现模式 |
指南与 skills 都描述 Laravel 生态。要捕获你自己应用的约定,应使用项目规则。
项目规则
指南与 skills 教 agent 如何编写 Laravel,而项目规则教它们如何编写你的应用。规则是指你原本需要在每个新会话中反复解释的任何内容:
- 你、你的 agent 或队友在过程中做出的决策。
- 难以让 agent 遵循的风格指南与偏好。
- 无法从周围代码推断出的陷阱与约束。
规则以 Markdown 文件形式存储在应用的 .ai/rules 目录中,并应提交到版本控制。与 agent 自身的记忆(个人且限于会话)不同,你的规则会与团队以及处理该应用的每个 agent 共享。
每个规则文件在其 frontmatter 中声明适用的文件 glob:
---
paths:
- app/Http/Controllers/**
---
# Http Controllers
## Extend BaseController for tenant scoping
All controllers must extend `App\Http\Controllers\BaseController`, which applies the
current tenant's query scope. Extending Laravel's base controller directly will leak
data across tenants.此外,Boost 会维护一个 .ai/rules/index.md 文件,将 glob 映射到对应的规则文件。Agent 被指示在规划或编辑任何文件之前查阅该索引,因此规则仅在相关时才会被加载:
# Project Rules Index
Before planning or editing, find the row whose globs match the file's path and read that rule file.
| Applies to | Rule file |
| --- | --- |
| app/Http/Controllers/** | .ai/rules/controllers.md |
| app/Models/** | .ai/rules/models.md |INFO
与 .mcp.json 和生成的指南文件不同,.ai/rules 目录应提交到版本控制,以便与团队共享规则。
记录规则
要记录一条规则,你可以简单地让 agent 记住它:
Remember that all money values are stored as integer cents, never as floats.Agent 会调用 Boost 的 record-rule MCP 工具,并传入 glob、简短的 title 和 note。随后 Boost 会将该规则归入匹配的区域,必要时创建规则文件,并更新索引。
你应始终使用 record-rule 工具记录规则,而不是手动创建规则文件。Boost 在记录规则时会重新生成 .ai/rules/index.md,而 agent 依赖该索引来发现适用于当前文件的规则。手动添加的规则文件在下次重新生成索引之前不会被发现。
推断应用约定
逐条记录规则很适合后续推进;但现有应用往往已沉淀多年约定。infer-conventions skill 会根据你已有的代码引导生成规则。首先,让你的 agent 使用该 skill:
Use the infer-conventions skill该 skill 会按 Laravel 约定维度清单扫描你的应用,包括验证、控制器、授权、模型、架构、测试、前端、数据库与控制台,随后再进行一轮开放式检查,寻找基类、共享 trait、模块布局等模式。
该 skill 记录的是代码实际在做的事,而不是「应该」怎么做。它只记录有充分依据的、非默认约定,会跳过框架默认值以及 Pint 或 Rector 已强制执行的内容,并对真正混杂的模式进行报告而不是直接记录。在写入任何规则之前,该 skill 会展示发现的每条约定及其支持证据,供你确认。若希望该 skill 在无需确认的情况下记录所有已发现约定,可以告诉它「yolo」。
禁用项目规则
项目规则默认启用。要完全禁用,请定义以下环境变量。这会移除 record-rule MCP 工具,并停止 Boost 管理 .ai/rules 目录:
BOOST_RULES_ENABLED=false文档 API
Laravel Boost 包含文档 API,为 AI agent 提供包含超过 17,000 条 Laravel 专用信息的知识库访问能力。该 API 使用基于嵌入的语义搜索,以提供精确、具备上下文感知的结果。
Search Docs MCP 工具允许 agent 查询 Laravel 托管的文档 API 服务,根据已安装的包检索文档。Boost 的 AI 指南与 skills 会自动指示你的编码 agent 使用该 API。
| Package | Versions Supported |
|---|---|
| Laravel Framework | 10.x, 11.x, 12.x, 13.x |
| Filament | 2.x, 3.x, 4.x, 5.x |
| Flux UI | 2.x Free, 2.x Pro |
| Inertia | 1.x, 2.x |
| Livewire | 1.x, 2.x, 3.x, 4.x |
| Nova | 4.x, 5.x |
| Pest | 3.x, 4.x |
| Tailwind CSS | 3.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
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\AppServiceProvider 的 boot 方法中注册你的自定义 agent:
use Laravel\Boost\Boost;
public function boot(): void
{
Boost::registerAgent('customagent', CustomAgent::class);
}注册后,运行 php artisan boost:install 时即可选择你的 agent。