diff --git a/src/Server/McpServiceProvider.php b/src/Server/McpServiceProvider.php index 4bbd9af..b802373 100644 --- a/src/Server/McpServiceProvider.php +++ b/src/Server/McpServiceProvider.php @@ -25,6 +25,7 @@ public function register(): void public function boot(): void { + $this->registerMcpScope(); $this->registerRoutes(); $this->registerContainerCallbacks(); @@ -96,4 +97,11 @@ protected function registerCommands(): void InspectorCommand::class, ]); } + + protected function registerMcpScope(): void + { + $this->app->booted(function (): void { + Registrar::ensureMcpScope(); + }); + } } diff --git a/src/Server/Registrar.php b/src/Server/Registrar.php index c0dbaf3..063d56b 100644 --- a/src/Server/Registrar.php +++ b/src/Server/Registrar.php @@ -84,7 +84,7 @@ public function servers(): array public function oauthRoutes(string $oauthPrefix = 'oauth'): void { - $this->maybeAddMcpScope(); + static::ensureMcpScope(); Router::get('/.well-known/oauth-protected-resource/{path?}', fn (?string $path = '') => response()->json([ 'resource' => url('/'.$path), 'authorization_servers' => [url('/'.$path)], @@ -108,7 +108,7 @@ public function oauthRoutes(string $oauthPrefix = 'oauth'): void /** * @return array */ - protected function maybeAddMcpScope(): array + public static function ensureMcpScope(): array { if (class_exists('Laravel\Passport\Passport') === false) { return []; @@ -124,6 +124,14 @@ protected function maybeAddMcpScope(): array return $current; } + /** + * @return array + */ + protected function maybeAddMcpScope(): array + { + return static::ensureMcpScope(); + } + /** * @param class-string $serverClass * @param callable(): Transport $transportFactory diff --git a/tests/Unit/Server/McpServiceProviderTest.php b/tests/Unit/Server/McpServiceProviderTest.php new file mode 100644 index 0000000..4741f0d --- /dev/null +++ b/tests/Unit/Server/McpServiceProviderTest.php @@ -0,0 +1,30 @@ + 'Custom scope']; + + $provider = new McpServiceProvider($this->app); + $provider->register(); + $provider->boot(); + + $this->app->boot(); + + expect(\Laravel\Passport\Passport::$scopes)->toHaveKey('mcp:use'); + expect(\Laravel\Passport\Passport::$scopes['custom'])->toBe('Custom scope'); +});