MCPcopy Create free account
hub / github.com/modelcontextprotocol/inspector / discoverScopes

Function discoverScopes

client/src/lib/auth.ts:22–49  ·  view source on GitHub ↗
(
  serverUrl: string,
  resourceMetadata?: OAuthProtectedResourceMetadata,
  fetchFn?: typeof fetch,
)

Source from the content-addressed store, hash-verified

20 * @returns Promise resolving to space-separated scope string or undefined
21 */
22export const discoverScopes = async (
23 serverUrl: string,
24 resourceMetadata?: OAuthProtectedResourceMetadata,
25 fetchFn?: typeof fetch,
26): Promise<string | undefined> => {
27 try {
28 const metadata = await discoverAuthorizationServerMetadata(
29 new URL("/", serverUrl),
30 { fetchFn },
31 );
32
33 // Prefer resource metadata scopes, but fall back to OAuth metadata if empty
34 const resourceScopes = resourceMetadata?.scopes_supported;
35 const oauthScopes = metadata?.scopes_supported;
36
37 const scopesSupported =
38 resourceScopes && resourceScopes.length > 0
39 ? resourceScopes
40 : oauthScopes;
41
42 return scopesSupported && scopesSupported.length > 0
43 ? scopesSupported.join(" ")
44 : undefined;
45 } catch (error) {
46 console.debug("OAuth scope discovery failed:", error);
47 return undefined;
48 }
49};
50
51export const getClientInformationFromSessionStorage = async ({
52 serverUrl,

Callers 3

handleAuthErrorFunction · 0.90
auth.test.tsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected