MCP

Scaffold ships with an MCP server for user accounts, built with laravel/mcp. Claude Desktop, claude.ai connectors and other MCP clients can connect to your app and work with the user's account, authorized with OAuth 2.1 via Laravel Passport.

Setup

Run these once per environment. The Passport keys are gitignored. In production they come from the PASSPORT_PRIVATE_KEY and PASSPORT_PUBLIC_KEY environment variables instead (see Deployment).

php artisan migrate
php artisan passport:keys

Connecting Claude

In Claude, add a custom connector pointing at your app:

https://{your-app}/mcp/users

Claude registers itself, and the user approves access on the app's authorize page (resources/views/mcp/authorize.blade.php).

The Server

App\Mcp\Servers\UsersServer is registered at POST /mcp/users in routes/ai.php, which the package loads itself (it is not in bootstrap/app.php). The server is named after your app, so each project forked from Scaffold shows up under its own name in Claude's connector list.

Mcp::web('/mcp/users', UsersServer::class)
    ->middleware(['auth:api', 'throttle:120,1']);

Tools

get_current_user - Who the client is acting as (name, email, roles).
update_profile - Changes only the fields sent.
search_users - Admin only.
get_user - Admin only.

Authentication

Mcp::oauthRoutes() publishes OAuth discovery and dynamic client registration, so MCP clients can authorize without manual client setup. Registration is unauthenticated by design (RFC 7591), so redirect URIs are limited to the domains in config/mcp.php and the routes are throttled.

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

'custom_schemes' => [
    'claude',
    // 'cursor',
    // 'vscode',
],

Adding Tools

Tools live in app/Mcp/Tools/** and are generated with:

php artisan make:mcp-tool
php artisan make:mcp-server

Then add the tool to the server's $tools. Tools share business logic with the REST API through services (such as App\Services\UserService) rather than duplicating it.

Admin-only tools implement shouldRegister() so they are hidden from tools/list, and re-check the user's role in handle().

public function shouldRegister(Request $request): bool
{
    return $this->isAdmin($request); // from Concerns\FormatsUsers
}

Testing

Test tools directly against the server, and the full HTTP flow with Passport. See tests/Feature/Mcp/ for examples.

UsersServer::actingAs($user)->tool(GetCurrentUserTool::class, []);

Passport::actingAs($user);
$this->postJson('/mcp/users', [...]);