innoge/laravel-mcp
Composer 安装命令:
composer require innoge/laravel-mcp
包简介
A package for developing MCP Servers with Laravel.
README 文档
README
A Laravel package that implements the Model Context Protocol (MCP), enabling seamless communication between your Laravel application and AI assistants or other systems through a standardized API. Please note that this package is still in development and not yet ready for production use.
Installation
You can install the package via composer:
composer require innoge/laravel-mcp
Basic Usage
Setting Up an MCP Server
This package currently only supports creating MCP servers via the STDIO transport. HTTP transport is not supported yet but will be added in the future.
Create a command to serve your MCP server:
<?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 ]; } }
Resources
Resources allow you to expose your application's data models through the MCP protocol. The package provides two types of resource providers:
- EloquentResourceProvider: Expose Eloquent models
use InnoGE\LaravelMcp\Resources\EloquentResourceProvider; use App\Models\User; // In your getResources() method: return [ new EloquentResourceProvider(User::query(), 'users', 'A User of the Application') ];
- InMemoryResourceProvider: Expose custom data structures or non-Eloquent data
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 ];
Tools
Tools define actions that can be performed through the MCP protocol:
-
Built-in Example Tools:
HelloTool: A simple hello world exampleClockTool: Returns the current time
-
Custom Tools: Create your own by implementing the
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, ];
Creating a Tool
Tools are the core functionality of MCP, allowing AI assistants to interact with your Laravel application. They provide a way to execute specific actions in your application through a well-defined interface.
Real-world examples of MCP tools include:
- Database Operations: Create, read, update, or delete records
- External API Integration: Make API calls to third-party services
- File Management: Upload, download, or process files
- Authentication: Verify user credentials or generate tokens
- Reporting: Generate reports or export data
- Email/Notification: Send messages to users
Example Tool:
<?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(); } }
Testing your MCP Server
Use Modelcontext Protocol Inspector to test the MCP server:
npx @modelcontextprotocol/inspector php /path/to/your/app/artisan mcp:serve
Adding your MCP Server to Claude Desktop
Edit your Claude Desktop config file:
~/Library/Application Support/Claude/claude_desktop_config.json
Add your MCP server to the config file:
{
"mcpServers": {
"laravel-mcp": {
"command": "php",
"args": [
"/path/to/your/app/artisan",
"mcp:serve"
]
}
}
}
Now you can use your MCP server in Claude Desktop. Please note that Claude currently does not use MCP resources. If you want to access data of your application you can use tool calls.
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.
innoge/laravel-mcp 适用场景与选型建议
innoge/laravel-mcp 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 561 次下载、GitHub Stars 达 17, 最近一次更新时间为 2025 年 03 月 27 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「mcp」 「innoge」 「model-context-protocol」 「laravel-mcp」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 innoge/laravel-mcp 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 innoge/laravel-mcp 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 innoge/laravel-mcp 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Laravel Mail driver for Microsoft Office 365 using the MSGraph API
This package helps prevent performance problems with frequent Policy calls within your application lifecycle.
Secure HTTP transport wrapper for MCP servers with API key auth, IP/Origin allowlisting, and rate limiting
Standardized event classes for MCP (Model Context Protocol) tool execution lifecycle
JSON Schema builder and validator for MCP tool definitions
A package to generate fake input data for Filament forms.
统计信息
- 总下载量: 561
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 17
- 点击次数: 16
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-03-27