mlabonne commited on
Commit
3adb53f
·
1 Parent(s): 5ecdefa

Fix MCP SDK build errors

Browse files
Files changed (2) hide show
  1. src/services/mcpClient.ts +2 -6
  2. src/services/oauth.ts +52 -19
src/services/mcpClient.ts CHANGED
@@ -153,9 +153,7 @@ export class MCPClientService {
153
  version: MCP_CLIENT_CONFIG.VERSION,
154
  },
155
  {
156
- capabilities: {
157
- tools: {},
158
- },
159
  }
160
  );
161
 
@@ -324,9 +322,7 @@ export class MCPClientService {
324
  version: MCP_CLIENT_CONFIG.VERSION,
325
  },
326
  {
327
- capabilities: {
328
- tools: {},
329
- },
330
  }
331
  );
332
 
 
153
  version: MCP_CLIENT_CONFIG.VERSION,
154
  },
155
  {
156
+ capabilities: {},
 
 
157
  }
158
  );
159
 
 
322
  version: MCP_CLIENT_CONFIG.VERSION,
323
  },
324
  {
325
+ capabilities: {},
 
 
326
  }
327
  );
328
 
src/services/oauth.ts CHANGED
@@ -5,8 +5,20 @@ import {
5
  exchangeAuthorization,
6
  registerClient,
7
  } from "@modelcontextprotocol/sdk/client/auth.js";
 
 
 
 
8
  import { secureStorage } from "../utils/storage";
9
  import { MCP_CLIENT_CONFIG, STORAGE_KEYS, DEFAULTS } from "../config/constants";
 
 
 
 
 
 
 
 
10
  // Utility to fetch .well-known/modelcontextprotocol for OAuth endpoints
11
  export async function discoverOAuthEndpoints(serverUrl: string) {
12
  // ...existing code...
@@ -42,8 +54,34 @@ export async function discoverOAuthEndpoints(serverUrl: string) {
42
  throw new Error("Missing OAuth endpoints in authorization server metadata");
43
  }
44
 
45
- // If client_id is missing, register client dynamically
46
- if (!authMetadata.client_id && authMetadata.registration_endpoint) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
  // Determine token endpoint auth method
48
  let tokenEndpointAuthMethod = "none";
49
  if (
@@ -60,12 +98,7 @@ export async function discoverOAuthEndpoints(serverUrl: string) {
60
  tokenEndpointAuthMethod = "client_secret_basic";
61
  }
62
  const clientMetadata = {
63
- redirect_uris: [
64
- String(
65
- authMetadata.redirect_uri ||
66
- window.location.origin + "/#/oauth/callback"
67
- ),
68
- ],
69
  client_name: MCP_CLIENT_CONFIG.NAME,
70
  grant_types: ["authorization_code"],
71
  response_types: ["code"],
@@ -75,17 +108,14 @@ export async function discoverOAuthEndpoints(serverUrl: string) {
75
  metadata: authMetadata,
76
  clientMetadata,
77
  });
78
- authMetadata.client_id = clientInfo.client_id;
79
- if (clientInfo.client_secret) {
80
- authMetadata.client_secret = clientInfo.client_secret;
81
- }
82
  // Persist client credentials for later use
83
  localStorage.setItem(STORAGE_KEYS.OAUTH_CLIENT_ID, clientInfo.client_id);
84
  if (clientInfo.client_secret) {
85
  await secureStorage.setItem(STORAGE_KEYS.OAUTH_CLIENT_SECRET, clientInfo.client_secret);
86
  }
87
  }
88
- if (!authMetadata.client_id) {
89
  throw new Error(
90
  "Missing client_id and registration not supported by authorization server"
91
  );
@@ -104,7 +134,7 @@ export async function discoverOAuthEndpoints(serverUrl: string) {
104
  localStorage.setItem(STORAGE_KEYS.OAUTH_TOKEN_ENDPOINT, authMetadata.token_endpoint);
105
  localStorage.setItem(
106
  STORAGE_KEYS.OAUTH_REDIRECT_URI,
107
- (authMetadata.redirect_uri ||window.location.origin + "/#" + DEFAULTS.OAUTH_REDIRECT_PATH).toString()
108
  );
109
  localStorage.setItem(STORAGE_KEYS.OAUTH_MCP_SERVER_URL, serverUrl);
110
  localStorage.setItem(
@@ -117,11 +147,14 @@ export async function discoverOAuthEndpoints(serverUrl: string) {
117
  return {
118
  authorizationEndpoint: authMetadata.authorization_endpoint,
119
  tokenEndpoint: authMetadata.token_endpoint,
120
- clientId: authMetadata.client_id,
121
- clientSecret: authMetadata.client_secret,
122
- scopes: authMetadata.scopes || [],
123
- redirectUri:
124
- authMetadata.redirect_uri || window.location.origin + "/#/oauth/callback",
 
 
 
125
  resource,
126
  };
127
  }
 
5
  exchangeAuthorization,
6
  registerClient,
7
  } from "@modelcontextprotocol/sdk/client/auth.js";
8
+ import type {
9
+ AuthorizationServerMetadata,
10
+ OAuthClientInformationMixed,
11
+ } from "@modelcontextprotocol/sdk/shared/auth.js";
12
  import { secureStorage } from "../utils/storage";
13
  import { MCP_CLIENT_CONFIG, STORAGE_KEYS, DEFAULTS } from "../config/constants";
14
+
15
+ type OAuthMetadataOverrides = AuthorizationServerMetadata & {
16
+ client_id?: string;
17
+ client_secret?: string;
18
+ redirect_uri?: string;
19
+ scopes?: string[];
20
+ };
21
+
22
  // Utility to fetch .well-known/modelcontextprotocol for OAuth endpoints
23
  export async function discoverOAuthEndpoints(serverUrl: string) {
24
  // ...existing code...
 
54
  throw new Error("Missing OAuth endpoints in authorization server metadata");
55
  }
56
 
57
+ const metadataOverrides = authMetadata as OAuthMetadataOverrides;
58
+ const redirectUri =
59
+ metadataOverrides.redirect_uri ||
60
+ window.location.origin + "/#" + DEFAULTS.OAUTH_REDIRECT_PATH;
61
+ let clientInformation: OAuthClientInformationMixed | undefined;
62
+ const persistedClientId = localStorage.getItem(STORAGE_KEYS.OAUTH_CLIENT_ID);
63
+ const persistedClientSecret = await secureStorage.getItem(
64
+ STORAGE_KEYS.OAUTH_CLIENT_SECRET
65
+ );
66
+
67
+ if (persistedClientId) {
68
+ clientInformation = {
69
+ client_id: persistedClientId,
70
+ ...(persistedClientSecret
71
+ ? { client_secret: persistedClientSecret }
72
+ : {}),
73
+ };
74
+ } else if (metadataOverrides.client_id) {
75
+ clientInformation = {
76
+ client_id: metadataOverrides.client_id,
77
+ ...(metadataOverrides.client_secret
78
+ ? { client_secret: metadataOverrides.client_secret }
79
+ : {}),
80
+ };
81
+ }
82
+
83
+ // If client credentials are missing, register client dynamically
84
+ if (!clientInformation?.client_id && authMetadata.registration_endpoint) {
85
  // Determine token endpoint auth method
86
  let tokenEndpointAuthMethod = "none";
87
  if (
 
98
  tokenEndpointAuthMethod = "client_secret_basic";
99
  }
100
  const clientMetadata = {
101
+ redirect_uris: [redirectUri],
 
 
 
 
 
102
  client_name: MCP_CLIENT_CONFIG.NAME,
103
  grant_types: ["authorization_code"],
104
  response_types: ["code"],
 
108
  metadata: authMetadata,
109
  clientMetadata,
110
  });
111
+ clientInformation = clientInfo;
 
 
 
112
  // Persist client credentials for later use
113
  localStorage.setItem(STORAGE_KEYS.OAUTH_CLIENT_ID, clientInfo.client_id);
114
  if (clientInfo.client_secret) {
115
  await secureStorage.setItem(STORAGE_KEYS.OAUTH_CLIENT_SECRET, clientInfo.client_secret);
116
  }
117
  }
118
+ if (!clientInformation?.client_id) {
119
  throw new Error(
120
  "Missing client_id and registration not supported by authorization server"
121
  );
 
134
  localStorage.setItem(STORAGE_KEYS.OAUTH_TOKEN_ENDPOINT, authMetadata.token_endpoint);
135
  localStorage.setItem(
136
  STORAGE_KEYS.OAUTH_REDIRECT_URI,
137
+ redirectUri
138
  );
139
  localStorage.setItem(STORAGE_KEYS.OAUTH_MCP_SERVER_URL, serverUrl);
140
  localStorage.setItem(
 
147
  return {
148
  authorizationEndpoint: authMetadata.authorization_endpoint,
149
  tokenEndpoint: authMetadata.token_endpoint,
150
+ clientId: clientInformation.client_id,
151
+ clientSecret: clientInformation.client_secret,
152
+ scopes:
153
+ metadataOverrides.scopes ||
154
+ authMetadata.scopes_supported ||
155
+ resourceMetadata?.scopes_supported ||
156
+ [],
157
+ redirectUri,
158
  resource,
159
  };
160
  }