From 58353309efedda77b65ecead5eee073208fb5a15 Mon Sep 17 00:00:00 2001 From: Pushpak Chhajed Date: Mon, 15 Dec 2025 22:38:10 +0530 Subject: [PATCH 1/2] Implement MCP scope registration in service provider and update route handling --- src/Server/McpServiceProvider.php | 8 ++++++ src/Server/Registrar.php | 12 +++++++-- tests/Unit/Server/McpServiceProviderTest.php | 28 ++++++++++++++++++++ 3 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 tests/Unit/Server/McpServiceProviderTest.php diff --git a/src/Server/McpServiceProvider.php b/src/Server/McpServiceProvider.php index 4bbd9af9..b8023730 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 bbf9fdd2..b80e366e 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 00000000..5f8d56e6 --- /dev/null +++ b/tests/Unit/Server/McpServiceProviderTest.php @@ -0,0 +1,28 @@ + 'Custom scope']; + + $provider = new McpServiceProvider($this->app); + $provider->register(); + $provider->boot(); + + expect(\Laravel\Passport\Passport::$scopes)->toHaveKey('mcp:use'); + expect(\Laravel\Passport\Passport::$scopes['custom'])->toBe('Custom scope'); +}); From bf1abe15fcd6cde2ff912c567efa7e33acbe994a Mon Sep 17 00:00:00 2001 From: Pushpak Chhajed Date: Mon, 15 Dec 2025 22:42:24 +0530 Subject: [PATCH 2/2] Fix test --- tests/Unit/Server/McpServiceProviderTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/Unit/Server/McpServiceProviderTest.php b/tests/Unit/Server/McpServiceProviderTest.php index 5f8d56e6..4741f0de 100644 --- a/tests/Unit/Server/McpServiceProviderTest.php +++ b/tests/Unit/Server/McpServiceProviderTest.php @@ -23,6 +23,8 @@ public static function tokensCan($scopes) { $provider->register(); $provider->boot(); + $this->app->boot(); + expect(\Laravel\Passport\Passport::$scopes)->toHaveKey('mcp:use'); expect(\Laravel\Passport\Passport::$scopes['custom'])->toBe('Custom scope'); });