File tree Expand file tree Collapse file tree 3 files changed +40
-2
lines changed
Expand file tree Collapse file tree 3 files changed +40
-2
lines changed Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ public function register(): void
2525
2626 public function boot (): void
2727 {
28+ $ this ->registerMcpScope ();
2829 $ this ->registerRoutes ();
2930 $ this ->registerContainerCallbacks ();
3031
@@ -96,4 +97,11 @@ protected function registerCommands(): void
9697 InspectorCommand::class,
9798 ]);
9899 }
100+
101+ protected function registerMcpScope (): void
102+ {
103+ $ this ->app ->booted (function (): void {
104+ Registrar::ensureMcpScope ();
105+ });
106+ }
99107}
Original file line number Diff line number Diff line change @@ -84,7 +84,7 @@ public function servers(): array
8484
8585 public function oauthRoutes (string $ oauthPrefix = 'oauth ' ): void
8686 {
87- $ this -> maybeAddMcpScope ();
87+ static :: ensureMcpScope ();
8888 Router::get ('/.well-known/oauth-protected-resource/{path?} ' , fn (?string $ path = '' ) => response ()->json ([
8989 'resource ' => url ('/ ' .$ path ),
9090 'authorization_servers ' => [url ('/ ' .$ path )],
@@ -108,7 +108,7 @@ public function oauthRoutes(string $oauthPrefix = 'oauth'): void
108108 /**
109109 * @return array<string, string>
110110 */
111- protected function maybeAddMcpScope (): array
111+ public static function ensureMcpScope (): array
112112 {
113113 if (class_exists ('Laravel\Passport\Passport ' ) === false ) {
114114 return [];
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ use Laravel \Mcp \Server \McpServiceProvider ;
6+
7+ it ('registers mcp scope during boot ' , function (): void {
8+ if (! class_exists ('Laravel\Passport\Passport ' )) {
9+ eval ('
10+ namespace Laravel\Passport;
11+ class Passport {
12+ public static $scopes = [];
13+ public static function tokensCan($scopes) {
14+ self::$scopes = $scopes;
15+ }
16+ }
17+ ' );
18+ }
19+
20+ \Laravel \Passport \Passport::$ scopes = ['custom ' => 'Custom scope ' ];
21+
22+ $ provider = new McpServiceProvider ($ this ->app );
23+ $ provider ->register ();
24+ $ provider ->boot ();
25+
26+ $ this ->app ->boot ();
27+
28+ expect (\Laravel \Passport \Passport::$ scopes )->toHaveKey ('mcp:use ' );
29+ expect (\Laravel \Passport \Passport::$ scopes ['custom ' ])->toBe ('Custom scope ' );
30+ });
You can’t perform that action at this time.
0 commit comments