@haikit/mcp 0.32.0 → 0.33.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/transports.ts CHANGED
@@ -1,4 +1,9 @@
1
- import { StreamableHTTPClientTransport, type StreamableHTTPClientTransportOptions, type Transport } from "@modelcontextprotocol/client";
1
+ import {
2
+ StreamableHTTPClientTransport,
3
+ type AuthProvider,
4
+ type StreamableHTTPClientTransportOptions,
5
+ type Transport,
6
+ } from "@modelcontextprotocol/client";
2
7
  import { StdioClientTransport, type StdioServerParameters } from "@modelcontextprotocol/client/stdio";
3
8
 
4
9
  export interface HttpOptions extends StreamableHTTPClientTransportOptions {
@@ -6,12 +11,24 @@ export interface HttpOptions extends StreamableHTTPClientTransportOptions {
6
11
  headers?: Record<string, string>;
7
12
  }
8
13
 
14
+ /** What `mcpServer({ auth })` needs to know of a transport `http()` made. */
15
+ export interface HttpMade {
16
+ /** It was given an `authProvider` of its own. */
17
+ authProvider: boolean;
18
+ /** It sends an `Authorization` header of its own. */
19
+ authorization: boolean;
20
+ }
21
+
22
+ /** The factories `http()` made: only these can carry each user's credential. */
23
+ export const madeByHttp = new WeakMap<object, HttpMade>();
24
+
9
25
  /**
10
26
  * A server at `url`, over Streamable HTTP. Everything but `headers` is the
11
27
  * SDK's own `StreamableHTTPClientTransportOptions`, such as an `authProvider`.
12
- * The URL is checked now, so a bad one fails at startup.
28
+ * The URL is checked now, so a bad one fails at startup. For a server with
29
+ * `auth`, each user's connection is given that user's `authProvider`.
13
30
  */
14
- export function http(url: string | URL, options: HttpOptions = {}): () => Transport {
31
+ export function http(url: string | URL, options: HttpOptions = {}): (authProvider?: AuthProvider) => Transport {
15
32
  const target = new URL(url);
16
33
  const { headers, ...rest } = options;
17
34
  if (headers) {
@@ -19,7 +36,13 @@ export function http(url: string | URL, options: HttpOptions = {}): () => Transp
19
36
  for (const [name, value] of Object.entries(headers)) merged.set(name, value);
20
37
  rest.requestInit = { ...rest.requestInit, headers: merged };
21
38
  }
22
- return () => new StreamableHTTPClientTransport(target, rest);
39
+ const make = (authProvider?: AuthProvider) =>
40
+ new StreamableHTTPClientTransport(target, authProvider ? { ...rest, authProvider } : rest);
41
+ madeByHttp.set(make, {
42
+ authProvider: rest.authProvider !== undefined,
43
+ authorization: new Headers(rest.requestInit?.headers).has("authorization"),
44
+ });
45
+ return make;
23
46
  }
24
47
 
25
48
  /**