PHP code example of afiqsazlan / laravel-mcp-safe-sql

1. Go to this page and download the library: Download afiqsazlan/laravel-mcp-safe-sql 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/ */

    

afiqsazlan / laravel-mcp-safe-sql example snippets


'profiles' => [
    'research' => [
        'connection' => 'mysql_replica',
        'anonymize'  => true,
        'tools'      => ['sql', 'schema'],
        'instructions' => resource_path('mcp/research.md'),
    ],
],

namespace App\Mcp\Servers;

use Afiqsazlan\SafeSql\Servers\SqlMcpServer;

class ResearchServer extends SqlMcpServer
{
    protected string $profile = 'research';
}

use Afiqsazlan\SafeSql\Http\OAuthRoutes;

OAuthRoutes::register();

Route::middleware(['auth:oauth', 'scope:mcp:use', 'can:access-research'])
    ->group(fn () => Mcp::web('mcp/research', ResearchServer::class));

'research' => ['label' => 'production', 'anonymize' => true,  ...],
'debug'    => ['label' => 'staging',    'anonymize' => false, ...],

'instructions' => resource_path('mcp/research.md'),

Route::middleware(['auth:oauth', 'scope:mcp:use', 'can:access-research'])
    ->group(fn () => Mcp::web('mcp/research', ResearchServer::class));

// A gate — nothing extra needed
Gate::define('access-research', fn (User $user) => $user->hasRole('analyst'));

// An explicit allowlist, while you are still deciding who should have it
Gate::define('access-research', fn (User $user) => in_array($user->id, [1, 5], true));

// spatie/laravel-permission — swap the middleware instead
->middleware(['auth:oauth', 'scope:mcp:use', 'permission:access-research'])

Event::listen(QueryExecuted::class, function (QueryExecuted $event) {
    Log::channel('audit')->info('safe-sql query', $event->context());
});
bash
php artisan safe-sql:classify --profile=research
php artisan safe-sql:classify --profile=research --write=config/safe-sql-columns.php
bash
php artisan passport:client --public --name="Claude"