PHP code example of mnapoli / backoffice-mcp

1. Go to this page and download the library: Download mnapoli/backoffice-mcp 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/ */

    

mnapoli / backoffice-mcp example snippets


use BackofficeMcp\Filter;
use BackofficeMcp\McpServer;
use BackofficeMcp\Resource;

class AdminMcpServer extends McpServer
{
    protected string $name = 'Acme Admin';

    protected function resources(): array
    {
        return [
            Resource::for(Team::class)
                ->columns('id', 'name', 'plan', 'owner_id', 'created_at', 'deleted_at')
                ->filter('name', Filter::Partial)
                ->filter('plan', Filter::Exact)
                ->filter('created_at', Filter::Operator)
                ->sorts('id', 'created_at')
                ->

protected string $description = 'The Acme database, for its support team. The application is the acme/app repository.';

return [
    'servers' => [
        'admin' => [
            'server' => App\Mcp\AdminMcpServer::class,
            'path' => 'mcp/admin',
            'auth' => [
                'token' => env('ADMIN_MCP_TOKEN'),
            ],
        ],
    ],
];

'support' => [
    'server' => App\Mcp\SupportMcpServer::class,
    'path' => 'mcp/support',
    'auth' => [
        'oauth' => true,
        'gate' => 'useSupportMcp',
    ],
],

Gate::define('useSupportMcp', fn (User $user) => $user->is_support_agent);

    Passport::authorizationView(fn ($parameters) => view('mcp.authorize', $parameters));
    

    'redirect_domains' => [
        'https://claude.ai',
        'https://chatgpt.com',
        'http://localhost', // Claude Code
    ],
    

class SupportMcpServer extends McpServer
{
    public int $maxLimit = 50;
    public int $queryTimeout = 3;
    // ...
}

use BackofficeMcp\Tools\QueryTool;

AdminMcpServer::tool(QueryTool::class, ['resource' => 'teams', 'filter' => ['plan' => 'pro']])
    ->assertOk()
    ->assertStructuredContent(fn ($json) => $json->where('returned', 1)->etc());
sh
php artisan vendor:publish --tag=backoffice-mcp-config
sh
    php artisan vendor:publish --tag=mcp-views