PHP code example of yoosuf / laravel-mcp-server

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'];
    }
}

MCP::tenantResolver(function () {
    return tenant();
});

use Yoosuf\LaravelMcpServer\Eloquent\Support\HasMcpExposure;

class Customer extends Model
{
    use HasMcpExposure;
}

Customer::mcp()->allow(['list', 'search', 'find']);
bash
php artisan vendor:publish --tag=mcp-config
php artisan vendor:publish --tag=mcp-migrations
php artisan migrate
bash
php artisan make:mcp-tool CreateInvoiceTool
bash
php artisan make:mcp-resource CustomerResource