/ 目錄 / 演練場 / Laravel MCP
● 官方 laravel ⚡ 即開即用

Laravel MCP

作者 laravel · laravel/mcp

Laravel's official MCP package — define MCP tools as classes, expose Eloquent models and Artisan commands to Claude with first-party auth/middleware.

Laravel MCP turns any Laravel app into an MCP server. Tools are PHP classes you register in a service provider; the package handles JSON-RPC, schema generation, and transport. You get to reuse your auth, policies, and middleware.

為什麼要用

核心特性

即時演示

實際使用效果

就緒

安裝

選擇你的客戶端

~/Library/Application Support/Claude/claude_desktop_config.json  · Windows: %APPDATA%\Claude\claude_desktop_config.json
{
  "mcpServers": {
    "laravel-mcp": {
      "command": "php",
      "args": [
        "artisan",
        "mcp:start"
      ],
      "_doc": "Run inside a Laravel project after `composer require laravel/mcp` and `php artisan mcp:install`."
    }
  }
}

開啟 Claude Desktop → Settings → Developer → Edit Config。儲存後重啟應用。

~/.cursor/mcp.json · .cursor/mcp.json
{
  "mcpServers": {
    "laravel-mcp": {
      "command": "php",
      "args": [
        "artisan",
        "mcp:start"
      ],
      "_doc": "Run inside a Laravel project after `composer require laravel/mcp` and `php artisan mcp:install`."
    }
  }
}

Cursor 使用與 Claude Desktop 相同的 mcpServers 格式。專案級設定優先於全域。

VS Code → Cline → MCP Servers → Edit
{
  "mcpServers": {
    "laravel-mcp": {
      "command": "php",
      "args": [
        "artisan",
        "mcp:start"
      ],
      "_doc": "Run inside a Laravel project after `composer require laravel/mcp` and `php artisan mcp:install`."
    }
  }
}

點擊 Cline 側欄中的 MCP Servers 圖示,然後選 "Edit Configuration"。

~/.codeium/windsurf/mcp_config.json
{
  "mcpServers": {
    "laravel-mcp": {
      "command": "php",
      "args": [
        "artisan",
        "mcp:start"
      ],
      "_doc": "Run inside a Laravel project after `composer require laravel/mcp` and `php artisan mcp:install`."
    }
  }
}

格式與 Claude Desktop 相同。重啟 Windsurf 生效。

~/.continue/config.json
{
  "mcpServers": [
    {
      "name": "laravel-mcp",
      "command": "php",
      "args": [
        "artisan",
        "mcp:start"
      ]
    }
  ]
}

Continue 使用伺服器物件陣列,而非映射。

~/.config/zed/settings.json
{
  "context_servers": {
    "laravel-mcp": {
      "command": {
        "path": "php",
        "args": [
          "artisan",
          "mcp:start"
        ]
      }
    }
  }
}

加入 context_servers。Zed 儲存後熱重載。

claude mcp add laravel-mcp -- php artisan mcp:start

一行命令搞定。用 claude mcp list 驗證,claude mcp remove 移除。

使用場景

實戰用法: Laravel MCP

Expose Eloquent models as MCP tools

👤 Developers ⏱ ~15 min intermediate

何時使用: You want Claude to query/update your domain data through your existing policies.

步驟
  1. Install
    composer require laravel/mcp; php artisan mcp:install✓ 已複製
    → Service provider + config published
  2. Define tool
    Create OrderLookupTool extends McpTool, type-hint $orderId; return Order::findOrFail($orderId).✓ 已複製
    → Tool registered
  3. Run
    php artisan mcp:start; connect Claude.✓ 已複製
    → Claude lists your tool and can call it

結果: Claude reads/writes your domain data via your existing authorization.

Wrap Artisan commands as MCP tools

👤 Developers ⏱ ~15 min intermediate

何時使用: You want Claude to run safe maintenance tasks (cache clear, queue retry).

步驟
  1. Whitelist
    In config/mcp.php, list the Artisan commands you allow.✓ 已複製
    → Whitelist saved
  2. Call
    From Claude: "Run artisan queue:retry all".✓ 已複製
    → Command runs; output streamed back

結果: Operational tasks become Claude-callable, scoped to a whitelist.

組合

與其他 MCP 搭配,撬動十倍槓桿

laravel-mcp + github

Deploy MCP server alongside your Laravel app via Forge/Vapor

Combine laravel-mcp with github: Deploy MCP server alongside your Laravel app via Forge/Vapor✓ 已複製
laravel-mcp + sentry

Errors raised inside tools surface in your existing Sentry pipeline

Combine laravel-mcp with sentry: Errors raised inside tools surface in your existing Sentry pipeline✓ 已複製

工具

此 MCP 暴露的能力

工具輸入參數何時呼叫成本
php-class tools (see docs) Each tool you register is dispatched via Laravel container with normal middleware 1 call

成本與限制

運行它的成本

API 配額
Bound by your DB and rate limits
每次呼叫 Token 數
Whatever your tool returns
費用
Free package; your hosting costs apply
提示
Paginate model returns; large Eloquent dumps blow tokens fast

安全

權限、密鑰、影響範圍

最小權限: app-defined gates/policies
憑證儲存: Sanctum/Passport tokens via Laravel auth
資料出站: Local app only
切勿授予: skip your normal authorization checks in tools

故障排查

常見錯誤與修復

Tool not appearing in client

Restart mcp:start; tools register at boot. Check service provider is loaded.

JSON Schema wrong

Ensure PHP type hints — int $id, not $id. Use attributes for descriptions.

替代方案

Laravel MCP 對比其他方案

替代方案何時用它替代權衡
fastmcp (Python)Stack is PythonNo Eloquent integration
csharp-sdkStack is .NETDifferent ecosystem

更多

資源

📖 閱讀 GitHub 上的官方 README

🐙 查看未解決的 issue

🔍 瀏覽全部 400+ MCP 伺服器和 Skills