You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -20,8 +20,16 @@ export type SSEClientTransportOptions = {
20
20
/**
21
21
* An OAuth client provider to use for authentication.
22
22
*
23
-
* If given, the transport will automatically attach an `Authorization` header
24
-
* if an access token is available, or begin the authorization flow if not.
23
+
* When an `authProvider` is specified and the SSE connection is started:
24
+
* 1. The connection is attempted with any existing access token from the `authProvider`.
25
+
* 2. If the access token has expired, the `authProvider` is used to refresh the token.
26
+
* 3. If token refresh fails or no access token exists, and auth is required, `OAuthClientProvider.redirectToAuthorization` is called, and an `UnauthorizedError` will be thrown from `connect`/`start`.
27
+
*
28
+
* After the user has finished authorizing via their user agent, and is redirected back to the MCP client application, call `SSEClientTransport.finishAuth` with the authorization code before retrying the connection.
29
+
*
30
+
* If an `authProvider` is not provided, and auth is required, an `UnauthorizedError` will be thrown.
31
+
*
32
+
* `UnauthorizedError` might also be thrown when sending any message over the SSE transport, indicating that the session has expired, and needs to be re-authed and reconnected.
25
33
*/
26
34
authProvider?: OAuthClientProvider;
27
35
@@ -70,7 +78,7 @@ export class SSEClientTransport implements Transport {
70
78
71
79
privateasync_authThenStart(): Promise<void>{
72
80
if(!this._authProvider){
73
-
thrownewError("No auth provider");
81
+
thrownewUnauthorizedError("No auth provider");
74
82
}
75
83
76
84
letresult: AuthResult;
@@ -82,7 +90,7 @@ export class SSEClientTransport implements Transport {
82
90
}
83
91
84
92
if(result!=="AUTHORIZED"){
85
-
thrownewError("Unauthorized");
93
+
thrownewUnauthorizedError();
86
94
}
87
95
88
96
returnawaitthis._startOrAuth();
@@ -177,6 +185,20 @@ export class SSEClientTransport implements Transport {
177
185
returnawaitthis._startOrAuth();
178
186
}
179
187
188
+
/**
189
+
* Call this method after the user has finished authorizing via their user agent and is redirected back to the MCP client application. This will exchange the authorization code for an access token, enabling the next connection attempt to successfully auth.
0 commit comments