mcpField
L
Laravel MCP (Model Context Protocol)

Laravel MCP (Model Context Protocol)

ローカル
github.com/InnoGE開発ツール178 週間前に更新

Laravel MCP (Model Context Protocol) について

Laravel MCPは、LaravelでMCPサーバーを構築するための、メンテナンス終了済みの概念実証パッケージです。STDIOトランスポートとリソースプロバイダー、カスタムツールを備え、公式のlaravel/mcpパッケージの利用が推奨されています。

主な機能

  1. 01LaravelでのMCPサーバー構築
  2. 02Eloquentとインメモリリソースの公開
  3. 03カスタムツールの定義
  4. 04STDIOトランスポート

活用シーン

  1. 01LaravelアプリでMCP対応を試作
  2. 02リソースプロバイダー経由でアプリデータを公開
  3. 03MCPクライアント向けの操作を定義

MCP 対応

STDIOトランスポートでMCPサーバーを実装し、設定したリソースとツールをMCPクライアントに公開します。メンテナンスは終了しており、公式のlaravel/mcpパッケージに置き換えられています。

設定

ローカルサーバーの設定はどのクライアントでも共通です。コピーしてクライアントの MCP 設定ファイルに貼り付けてください。

mcp.json · 共通設定
{
"mcpServers": {
"laravel": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/inspector"
]
}
}
}
起動コマンドnpx -y @modelcontextprotocol/inspector

ローカルサーバーにはマシン上の実行環境(Node.js 18 以上など)が必要です。設定ファイルの場所はクライアントごとに異なります。

パッケージ
npm@modelcontextprotocol/inspector

ツール

ツール一覧はまだ取得されていません

ローカルサーバーのツールはマシン上で起動して初めて取得できます。メンテナーはまだツール一覧を提供していません。

詳細

Laravel MCP(Model Context Protocol)

警告

このパッケージはメンテナンスされていません。

このパッケージは概念実証であり、今後開発されることはありません。現在は公式の laravel/mcp パッケージに完全に置き換えられています。代わりにそちらをご利用ください。

Packagist の最新バージョン GitHub テストアクションのステータス GitHub コードスタイルアクションのステータス 合計ダウンロード数

Laravel アプリケーションと AI アシスタントやその他のシステムとの間で、標準化された API を通じてシームレスに通信できるようにする、Model Context Protocol(MCP)を実装した Laravel パッケージです。 このパッケージは現在も開発中であり、本番環境での使用にはまだ対応していませんのでご注意ください。

インストール

composer を使ってパッケージをインストールできます。

composer require innoge/laravel-mcp

基本的な使い方

MCP サーバーのセットアップ

このパッケージは現在、STDIO トランスポートを介した MCP サーバーの作成のみをサポートしています。 HTTP トランスポートにはまだ対応していませんが、今後追加される予定です。

MCP サーバーを提供するコマンドを作成します。

<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use InnoGE\LaravelMcp\Commands\ServesMcpServer;

class McpServerCommand extends Command
{
    use ServesMcpServer;

    protected $signature = 'mcp:serve';
    protected $description = 'Start an MCP server';

    public function handle(): int
    {
        return $this->serveMcp('your-app-name', '1.0.0');
    }

    private function getTools(): array
    {
        return [
            // List your tool classes here
        ];
    }

    private function getResources(): array
    {
        return [
            // List your resource providers here
        ];
    }
}
リソース

リソースを使用すると、MCP プロトコルを通じてアプリケーションのデータモデルを公開できます。このパッケージでは、次の 2 種類のリソースプロバイダーを利用できます。

  1. EloquentResourceProvider:Eloquent モデルを公開します
use InnoGE\LaravelMcp\Resources\EloquentResourceProvider;
use App\Models\User;

// In your getResources() method:
return [
    new EloquentResourceProvider(User::query(), 'users', 'A User of the Application')
];
  1. InMemoryResourceProvider:カスタムデータ構造または Eloquent 以外のデータを公開します
use InnoGE\LaravelMcp\Resources\InMemoryResourceProvider;
use InnoGE\LaravelMcp\Types\Resources\ResourceContent;
use InnoGE\LaravelMcp\Types\Resources\ResourceItem;

// Create a resource provider
$resourceProvider = new InMemoryResourceProvider();

// Add example documents as resources
$resourceProvider->addResource(
    new ResourceItem('doc://example/document1', 'Example Document 1', 'This is an example document', 'text/plain', 1024),
    new ResourceContent('doc://example/document1', 'text/plain', 'This is the content of the document')
);

$resourceProvider->addResource(
    new ResourceItem('doc://example/document2', 'Example Document 2', 'This is an example document 2', 'text/plain', 1024),
    new ResourceContent('doc://example/document2', 'text/plain', 'This is the content of the document 2')
);

// In your getResources() method:
return [
    $resourceProvider
];
ツール

ツールは、MCP プロトコルを通じて実行できるアクションを定義します。

  • 組み込みのサンプルツール:

    • HelloTool:シンプルな Hello World のサンプルです
    • ClockTool:現在の時刻を返します
  • カスタムツール:ToolInterface を実装して独自のツールを作成できます

use InnoGE\LaravelMcp\Tools\Examples\HelloTool;
use InnoGE\LaravelMcp\Tools\Examples\ClockTool;
use App\MCP\Tools\YourCustomTool;

// In your getTools() method:
return [
    HelloTool::class,
    ClockTool::class,
    YourCustomTool::class,
];
ツールの作成

ツールは MCP の中核となる機能であり、AI アシスタントが Laravel アプリケーションとやり取りできるようにします。明確に定義されたインターフェースを通じて、アプリケーション内の特定のアクションを実行できます。

実際の MCP ツールの例:

  • データベース操作:レコードの作成、読み取り、更新、削除
  • 外部 API との連携:サードパーティーサービスへの API 呼び出し
  • ファイル管理:ファイルのアップロード、ダウンロード、処理
  • 認証:ユーザーの認証情報の確認やトークンの生成
  • レポート作成:レポートの生成やデータのエクスポート
  • メール/通知:ユーザーへのメッセージ送信

ツールの例:

<?php

namespace App\MCP\Tools;

use Illuminate\Support\Facades\Artisan;
use InnoGE\LaravelMcp\Tools\Tool;
use Symfony\Component\Console\Output\BufferedOutput;

class CallArtisanCommandTool implements Tool
{
    /**
     * Get the tool name
     */
    public function getName(): string
    {
        return 'call-artisan-command';
    }

    /**
     * Get the tool description
     */
    public function getDescription(): string
    {
        return 'Call a Laravel Artisan command';
    }

    /**
     * Get the input schema for the tool
     */
    public function getInputSchema(): array
    {
        return [
            'type' => 'object',
            'properties' => [
                'command' => [
                    'type' => 'string',
                    'description' => 'The Artisan command to call (e.g. "migrate")',
                ],
            ],
            'required' => ['command'],
        ];
    }

    /**
     * Execute the tool with the provided arguments
     */
    public function execute(array $arguments): string
    {
        $command = $arguments['command'];

        $outputBuffer = new BufferedOutput;

        Artisan::call($command, [], $outputBuffer);

        return $outputBuffer->fetch();
    }
}

MCP サーバーのテスト

Modelcontext Protocol Inspector を使用して MCP サーバーをテストします。

npx @modelcontextprotocol/inspector php /path/to/your/app/artisan mcp:serve

Claude Desktop への MCP サーバーの追加

Claude Desktop の設定ファイルを編集します。

~/Library/Application Support/Claude/claude_desktop_config.json

設定ファイルに MCP サーバーを追加します。

{
  "mcpServers": {
    "laravel-mcp": {
      "command": "php",
      "args": [
        "/path/to/your/app/artisan",
        "mcp:serve"
      ]
    }
  }
}

これで Claude Desktop で MCP サーバーを使用できます。現在 Claude は MCP リソースを使用しないことにご注意ください。アプリケーションのデータにアクセスする場合は、ツール呼び出しを利用できます。

テスト

composer test

変更履歴

最近の変更については、CHANGELOGをご覧ください。

貢献

詳細については、CONTRIBUTINGをご覧ください。

セキュリティ脆弱性

セキュリティ脆弱性の報告方法については、セキュリティポリシーをご確認ください。

クレジット

License

The MIT License (MIT). Please see License File for more information.

コメント

MCP は初めてですか?

プロトコルの概要から最初のサーバーの導入まで、よくある疑問にまとめて答えます。

AI アプリケーションが外部のツールやデータソースに統一的な方法で接続するためのオープンなプロトコルです。クライアントはモデルとの対話を担い、MCP サーバーはツール・リソース・プロンプトテンプレートを提供します。標準メッセージでやり取りするため、1 つのサーバーを複数のクライアントで再利用できます。