1. Go to this page and download the library: Download yoosuf/laravel-mcp-server library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
yoosuf / laravel-mcp-server example snippets
use Yoosuf\LaravelMcpServer\Facades\MCP;
MCP::resource(\App\MCP\Resources\CustomerResource::class);
MCP::tool(\App\MCP\Tools\CreateInvoiceTool::class);
MCP::async(\App\MCP\Tools\GenerateReportTool::class);
MCP::tenantResolver(fn () => tenant());
class CreateInvoiceTool extends MCPTool
{
public function name(): string { return 'create_invoice'; }
public function description(): string { return 'Creates customer invoice'; }
public function schema(): array
{
return [
'customer_id' => 'integer',
'items' => 'array',
];
}
public function rules(): array
{
return [
'customer_id' => ['
class CustomerResource extends MCPResource
{
public function name(): string { return 'customers'; }
public function schema(): array
{
return [
'id' => 'integer',
'name' => 'string',
'email' => 'string',
];
}
public function actions(): array
{
return ['list', 'find'];
}
}
use Yoosuf\LaravelMcpServer\Eloquent\Support\HasMcpExposure;
class Customer extends Model
{
use HasMcpExposure;
}
Customer::mcp()->allow(['list', 'search', 'find']);