Looking to hire Laravel developers? Try LaraJobs

laravel-mcp-oauth maintained by qiick

Description
OAuth authorization server for laravel/mcp endpoints in qiick Laravel products.
Author
Last update
2026/11/26 22:04 (dev-develop)
License
Downloads
0
Tags

Comments
comments powered by Disqus

qiick/laravel-mcp-oauth

In development. Not released and not on Packagist yet: do not depend on it.

OAuth authorization server for laravel/mcp endpoints in qiick Laravel products. Consent plumbing, governed dynamic client registration, redirect URI rules, refresh-token family revocation, RFC 6750 errors, fail-closed Passport keys, and the /mcp Bearer door — built on Passport and laravel/mcp.

Part of the qiick fleet. Binding design: projects/qiick/packages/laravel-mcp-oauth-design.md in the knowledge base (answers: decisions/2026-11-22-mcp-oauth-and-access-design-answers.md).

Status

Pre-0.1.0. Public APIs may change in any 0.x release; see UPGRADING.md. Do not require this package from production apps until a tagged release lands on Packagist (Packagist publish only after Luca’s go). 1.0.0 needs a non-externa adopter and Luca’s go.

Requirements

  • PHP ^8.3 with ext-intl and ext-openssl
  • illuminate/console, contracts, database, http, routing, support ^12.41.1 \|\| ^13.0 (never laravel/framework)
  • laravel/passport ^13.12, laravel/mcp ^1.2, league/uri ^7.8
  • Optional: inertiajs/inertia-laravel ^3.0 (default ConsentView)

Install (when published)

composer require qiick/laravel-mcp-oauth:^0.1
php artisan vendor:publish --tag=mcp-oauth-config
php artisan vendor:publish --tag=passport-migrations
php artisan vendor:publish --tag=mcp-oauth-migrations
php artisan vendor:publish --tag=mcp-oauth-binding-stub
php artisan passport:keys

The service provider is auto-discovered. Products implement the contracts (AdminSwitch, GrantStore, ConsentProvider, …), call McpOAuthRoutes::register() from their MCP routes file, and keep OAuth off until keys exist and the admin switch is flipped.

McpOAuthRoutes::register() serves DCR, authorize, token, revocation (RFC 7009) and the RFC 8414 / RFC 9728 discovery documents. Do not also call Mcp::oauthRoutes(): its documents are built from the request Host and sit outside the off-gate, and its oauth/register would replace the package's.

Browser-based MCP clients (the MCP inspector, for example) call these endpoints cross-origin. The package sets no CORS headers itself: add the paths to the product's config/cors.php, where Laravel's HandleCors answers the preflight before routing:

'paths' => ['api/*', '.well-known/*', 'oauth/register', 'oauth/token', 'oauth/revoke', 'mcp'],

mcp is the MCP endpoint itself (mcp-oauth.mcp_path): a browser client calls it cross-origin with the token it got.

Mount the package's door and challenge on the product's /mcp route. The door replaces the product's own /mcp authentication middleware and sits before its throttle; the challenge replaces laravel/mcp's AddWwwAuthenticateHeader, which would overwrite the RFC 6750 error code:

Mcp::web('/mcp', ProductServer::class)
    ->withoutMiddleware(AddWwwAuthenticateHeader::class)
    ->middleware([McpChallengeMiddleware::class, McpBearerDoorMiddleware::class, 'throttle:mcp']);

The door takes an API key through the product's ApiKeyDoor and an OAuth access token through AccessTokenAuthenticator (audience, client, blocked hosts, bound grant, mcp:use, then the product's GrantAuthorizer, on every call), binds either through McpCredentialBinder, and answers 429 to an address that failed mcp_auth_failures_per_minute times. With OAuth off it behaves as before the package: every Bearer is an API key, and a 401 says Bearer realm="mcp", error="invalid_token". With OAuth on, every 401 and 403 points at the protected resource metadata built from APP_URL.

Schedule the prune of authorization-code exchanges whose grant is gone:

Schedule::command('mcp-oauth:prune-auth-code-exchanges')->daily()->onOneServer();

Threat model (short)

Threat Mitigation
Public DCR flood / phishing Off by default (three gates); per-key and global caps; prune; admin block
Hostile redirect hosts League URI only; ASCII hosts; UTS #46; exact/subdomain block
Host-header discovery poisoning Issuer and resource from APP_URL only
Refresh-token theft / races Atomic rotation; family + grant revocation; live binding required
Code replay One-shot codes; a replay revokes the grant and every token issued with it
A token used after revocation /mcp re-checks token, audience, client, blocked hosts and bound grant on every call; nothing cached
Credential guessing at /mcp Per-address failure brake (429 before the credential is read). Clients behind one shared address (carrier NAT, a corporate egress) share the counter: raise mcp_auth_failures_per_minute or throttle sharper at the edge
Missing Passport keys 503 temporarily_unavailable; switch refuses to turn on

Full table: design §16.

Public API (contracts and data)

Products implement Qiick\McpOAuth\Contracts\* (AdminSwitch, GrantStore, ConsentProvider, GrantAuthorizer, ApiKeyDoor, McpCredentialBinder, AuditLogger, ConsentView, OAuthUserResolver). Wire and consent shapes are the @api DTOs under Qiick\McpOAuth\Data and events under Qiick\McpOAuth\Events. Public ids are UUID strings only.

Config

Publishable config/mcp-oauth.php (tag mcp-oauth-config). Env prefix MCP_OAUTH_*. Redirect allowlists stay in laravel/mcp’s mcp.redirect_domains and mcp.custom_schemes. Issuer is always APP_URL.

Testing

composer test
composer lint
composer analyse
bash scripts/mutate-per-class.sh   # per-class MSI ≥ 95 once targets land

CI: PHP 8.3/8.4/8.5 × Laravel 12/13 × lowest/stable, Pint, PHPStan max, Pest, composer validate --strict, composer audit, database engine jobs, real HTTP (php -S) once the http group exists, and qiick standards drift against app-ui v0.12.0.

License

MIT