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
@@ -12,6 +13,42 @@ export class SseError extends Error {
12
13
}
13
14
}
14
15
16
+
/**
17
+
* Configuration options for the `SSEClientTransport`.
18
+
*/
19
+
exporttypeSSEClientTransportOptions={
20
+
/**
21
+
* An OAuth client provider to use for authentication.
22
+
*
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.
33
+
*/
34
+
authProvider?: OAuthClientProvider;
35
+
36
+
/**
37
+
* Customizes the initial SSE request to the server (the request that begins the stream).
38
+
*
39
+
* NOTE: Setting this property will prevent an `Authorization` header from
40
+
* being automatically attached to the SSE request, if an `authProvider` is
41
+
* also given. This can be worked around by setting the `Authorization` header
42
+
* manually.
43
+
*/
44
+
eventSourceInit?: EventSourceInit;
45
+
46
+
/**
47
+
* Customizes recurring POST requests to the server.
48
+
*/
49
+
requestInit?: RequestInit;
50
+
};
51
+
15
52
/**
16
53
* Client transport for SSE: this will connect to a server using Server-Sent Events for receiving
17
54
* messages and make separate POST requests for sending messages.
@@ -23,35 +60,76 @@ export class SSEClientTransport implements Transport {
@@ -97,6 +175,30 @@ export class SSEClientTransport implements Transport {
97
175
});
98
176
}
99
177
178
+
asyncstart(){
179
+
if(this._eventSource){
180
+
thrownewError(
181
+
"SSEClientTransport already started! If using Client class, note that connect() calls start() automatically.",
182
+
);
183
+
}
184
+
185
+
returnawaitthis._startOrAuth();
186
+
}
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