@workglow/util 0.0.109 → 0.0.111
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/dist/browser.js +480 -10
- package/dist/browser.js.map +8 -6
- package/dist/bun.js +488 -5
- package/dist/bun.js.map +8 -6
- package/dist/common.d.ts +2 -0
- package/dist/common.d.ts.map +1 -1
- package/dist/logging/LoggerRegistry.d.ts.map +1 -1
- package/dist/mcp/McpAuthProvider.d.ts +68 -0
- package/dist/mcp/McpAuthProvider.d.ts.map +1 -0
- package/dist/mcp/McpAuthTypes.d.ts +126 -0
- package/dist/mcp/McpAuthTypes.d.ts.map +1 -0
- package/dist/mcp/McpClientUtil.browser.d.ts +66 -0
- package/dist/mcp/McpClientUtil.browser.d.ts.map +1 -1
- package/dist/mcp/McpClientUtil.node.d.ts +66 -0
- package/dist/mcp/McpClientUtil.node.d.ts.map +1 -1
- package/dist/node.js +488 -5
- package/dist/node.js.map +8 -6
- package/dist/worker/WorkerManager.d.ts.map +1 -1
- package/package.json +3 -1
package/dist/browser.js
CHANGED
|
@@ -372,7 +372,7 @@ function getEnv(name) {
|
|
|
372
372
|
if (typeof process !== "undefined" && process.env) {
|
|
373
373
|
return process.env[name];
|
|
374
374
|
}
|
|
375
|
-
return;
|
|
375
|
+
return import.meta.env[name];
|
|
376
376
|
}
|
|
377
377
|
function isTruthy(value) {
|
|
378
378
|
return value !== undefined && value !== "" && value !== "0" && value !== "false";
|
|
@@ -385,6 +385,12 @@ function createDefaultLogger() {
|
|
|
385
385
|
timings: isTruthy(getEnv("LOGGER_TIMINGS"))
|
|
386
386
|
});
|
|
387
387
|
}
|
|
388
|
+
if (getEnv("DEV")) {
|
|
389
|
+
return new ConsoleLogger({
|
|
390
|
+
level: "debug",
|
|
391
|
+
timings: true
|
|
392
|
+
});
|
|
393
|
+
}
|
|
388
394
|
return new NullLogger;
|
|
389
395
|
}
|
|
390
396
|
if (!globalServiceRegistry.has(LOGGER)) {
|
|
@@ -1984,16 +1990,20 @@ class WorkerManager {
|
|
|
1984
1990
|
return;
|
|
1985
1991
|
if (type === "progress" && options?.onProgress) {
|
|
1986
1992
|
options.onProgress(data.progress, data.message, data.details);
|
|
1993
|
+
getLogger().debug(`Worker ${workerName} function ${functionName} progress: ${data.progress}, `, { data });
|
|
1987
1994
|
} else if (type === "complete") {
|
|
1988
1995
|
cleanup();
|
|
1996
|
+
getLogger().debug(`Worker ${workerName} function ${functionName} complete.`, { data });
|
|
1989
1997
|
resolve(data);
|
|
1990
1998
|
} else if (type === "error") {
|
|
1991
1999
|
cleanup();
|
|
2000
|
+
getLogger().debug(`Worker ${workerName} function ${functionName} error.`, { data });
|
|
1992
2001
|
reject(new Error(data));
|
|
1993
2002
|
}
|
|
1994
2003
|
};
|
|
1995
2004
|
const handleAbort = () => {
|
|
1996
2005
|
worker.postMessage({ id: requestId, type: "abort" });
|
|
2006
|
+
getLogger().info(`Worker ${workerName} function ${functionName} aborted.`);
|
|
1997
2007
|
};
|
|
1998
2008
|
const cleanup = () => {
|
|
1999
2009
|
worker.removeEventListener("message", handleMessage);
|
|
@@ -2005,6 +2015,7 @@ class WorkerManager {
|
|
|
2005
2015
|
}
|
|
2006
2016
|
const message = { id: requestId, type: "call", functionName, args };
|
|
2007
2017
|
worker.postMessage(message);
|
|
2018
|
+
getLogger().info(`Worker ${workerName} function ${functionName} called.`);
|
|
2008
2019
|
});
|
|
2009
2020
|
}
|
|
2010
2021
|
async callWorkerReactiveFunction(workerName, functionName, args) {
|
|
@@ -2035,6 +2046,7 @@ class WorkerManager {
|
|
|
2035
2046
|
worker.addEventListener("message", handleMessage);
|
|
2036
2047
|
const message = { id: requestId, type: "call", functionName, args, reactive: true };
|
|
2037
2048
|
worker.postMessage(message);
|
|
2049
|
+
getLogger().info(`Worker ${workerName} reactive function ${functionName} called.`);
|
|
2038
2050
|
});
|
|
2039
2051
|
}
|
|
2040
2052
|
async* callWorkerStreamFunction(workerName, functionName, args, options) {
|
|
@@ -2074,6 +2086,7 @@ class WorkerManager {
|
|
|
2074
2086
|
};
|
|
2075
2087
|
const handleAbort = () => {
|
|
2076
2088
|
worker.postMessage({ id: requestId, type: "abort" });
|
|
2089
|
+
getLogger().info(`Worker ${workerName} stream function ${functionName} aborted.`);
|
|
2077
2090
|
};
|
|
2078
2091
|
const cleanup = () => {
|
|
2079
2092
|
worker.removeEventListener("message", handleMessage);
|
|
@@ -2089,6 +2102,7 @@ class WorkerManager {
|
|
|
2089
2102
|
}
|
|
2090
2103
|
const message = { id: requestId, type: "call", functionName, args, stream: true };
|
|
2091
2104
|
worker.postMessage(message);
|
|
2105
|
+
getLogger().info(`Worker ${workerName} stream function ${functionName} called.`);
|
|
2092
2106
|
let completedNormally = false;
|
|
2093
2107
|
try {
|
|
2094
2108
|
while (true) {
|
|
@@ -2111,6 +2125,7 @@ class WorkerManager {
|
|
|
2111
2125
|
} finally {
|
|
2112
2126
|
if (!completedNormally) {
|
|
2113
2127
|
worker.postMessage({ id: requestId, type: "abort" });
|
|
2128
|
+
getLogger().info(`Worker ${workerName} stream function ${functionName} aborted.`);
|
|
2114
2129
|
}
|
|
2115
2130
|
cleanup();
|
|
2116
2131
|
}
|
|
@@ -2554,6 +2569,450 @@ function base64ToBuf(b64) {
|
|
|
2554
2569
|
}
|
|
2555
2570
|
return buf;
|
|
2556
2571
|
}
|
|
2572
|
+
// src/mcp/McpAuthTypes.ts
|
|
2573
|
+
var mcpAuthTypes = [
|
|
2574
|
+
"none",
|
|
2575
|
+
"bearer",
|
|
2576
|
+
"client_credentials",
|
|
2577
|
+
"private_key_jwt",
|
|
2578
|
+
"static_private_key_jwt",
|
|
2579
|
+
"authorization_code"
|
|
2580
|
+
];
|
|
2581
|
+
var mcpAuthConfigSchema = {
|
|
2582
|
+
auth_type: {
|
|
2583
|
+
type: "string",
|
|
2584
|
+
enum: mcpAuthTypes,
|
|
2585
|
+
title: "Auth Type",
|
|
2586
|
+
description: "Authentication method for connecting to the MCP server",
|
|
2587
|
+
default: "none"
|
|
2588
|
+
},
|
|
2589
|
+
auth_token: {
|
|
2590
|
+
type: "string",
|
|
2591
|
+
format: "credential",
|
|
2592
|
+
title: "Bearer Token",
|
|
2593
|
+
description: "Static bearer token or API key (for bearer auth)"
|
|
2594
|
+
},
|
|
2595
|
+
auth_client_id: {
|
|
2596
|
+
type: "string",
|
|
2597
|
+
title: "Client ID",
|
|
2598
|
+
description: "OAuth client ID (for OAuth auth types)"
|
|
2599
|
+
},
|
|
2600
|
+
auth_client_secret: {
|
|
2601
|
+
type: "string",
|
|
2602
|
+
format: "credential",
|
|
2603
|
+
title: "Client Secret",
|
|
2604
|
+
description: "OAuth client secret (for client_credentials auth)"
|
|
2605
|
+
},
|
|
2606
|
+
auth_private_key: {
|
|
2607
|
+
type: "string",
|
|
2608
|
+
format: "credential",
|
|
2609
|
+
title: "Private Key",
|
|
2610
|
+
description: "PEM or JWK private key (for private_key_jwt auth)"
|
|
2611
|
+
},
|
|
2612
|
+
auth_algorithm: {
|
|
2613
|
+
type: "string",
|
|
2614
|
+
title: "Algorithm",
|
|
2615
|
+
description: "JWT signing algorithm, e.g. RS256, ES256 (for private_key_jwt auth)"
|
|
2616
|
+
},
|
|
2617
|
+
auth_jwt_bearer_assertion: {
|
|
2618
|
+
type: "string",
|
|
2619
|
+
format: "credential",
|
|
2620
|
+
title: "JWT Assertion",
|
|
2621
|
+
description: "Pre-built JWT assertion (for static_private_key_jwt auth)"
|
|
2622
|
+
},
|
|
2623
|
+
auth_redirect_url: {
|
|
2624
|
+
type: "string",
|
|
2625
|
+
format: "uri",
|
|
2626
|
+
title: "Redirect URL",
|
|
2627
|
+
description: "OAuth redirect URL (for authorization_code auth)"
|
|
2628
|
+
},
|
|
2629
|
+
auth_scope: {
|
|
2630
|
+
type: "string",
|
|
2631
|
+
title: "Scope",
|
|
2632
|
+
description: "OAuth scope (space-separated)"
|
|
2633
|
+
},
|
|
2634
|
+
auth_client_name: {
|
|
2635
|
+
type: "string",
|
|
2636
|
+
title: "Client Name",
|
|
2637
|
+
description: "Optional OAuth client display name"
|
|
2638
|
+
},
|
|
2639
|
+
auth_jwt_lifetime_seconds: {
|
|
2640
|
+
type: "number",
|
|
2641
|
+
title: "JWT Lifetime",
|
|
2642
|
+
description: "JWT lifetime in seconds (default: 300)",
|
|
2643
|
+
minimum: 1
|
|
2644
|
+
}
|
|
2645
|
+
};
|
|
2646
|
+
function isMcpAuthType(value) {
|
|
2647
|
+
return typeof value === "string" && mcpAuthTypes.includes(value);
|
|
2648
|
+
}
|
|
2649
|
+
function asNonEmptyString(value) {
|
|
2650
|
+
if (typeof value !== "string")
|
|
2651
|
+
return;
|
|
2652
|
+
const trimmed = value.trim();
|
|
2653
|
+
return trimmed === "" ? undefined : trimmed;
|
|
2654
|
+
}
|
|
2655
|
+
function asNumber(value) {
|
|
2656
|
+
return typeof value === "number" ? value : undefined;
|
|
2657
|
+
}
|
|
2658
|
+
function buildAuthConfig(flat) {
|
|
2659
|
+
const rawAuthType = flat.auth_type;
|
|
2660
|
+
if (!isMcpAuthType(rawAuthType) || rawAuthType === "none") {
|
|
2661
|
+
return;
|
|
2662
|
+
}
|
|
2663
|
+
const authType = rawAuthType;
|
|
2664
|
+
switch (authType) {
|
|
2665
|
+
case "bearer": {
|
|
2666
|
+
const token = asNonEmptyString(flat.auth_token);
|
|
2667
|
+
if (!token)
|
|
2668
|
+
return;
|
|
2669
|
+
return { type: "bearer", token };
|
|
2670
|
+
}
|
|
2671
|
+
case "client_credentials": {
|
|
2672
|
+
const client_id = asNonEmptyString(flat.auth_client_id);
|
|
2673
|
+
const client_secret = asNonEmptyString(flat.auth_client_secret);
|
|
2674
|
+
if (!client_id || !client_secret)
|
|
2675
|
+
return;
|
|
2676
|
+
return {
|
|
2677
|
+
type: "client_credentials",
|
|
2678
|
+
client_id,
|
|
2679
|
+
client_secret,
|
|
2680
|
+
client_name: asNonEmptyString(flat.auth_client_name),
|
|
2681
|
+
scope: asNonEmptyString(flat.auth_scope)
|
|
2682
|
+
};
|
|
2683
|
+
}
|
|
2684
|
+
case "private_key_jwt": {
|
|
2685
|
+
const client_id = asNonEmptyString(flat.auth_client_id);
|
|
2686
|
+
const private_key = asNonEmptyString(flat.auth_private_key);
|
|
2687
|
+
const algorithm = asNonEmptyString(flat.auth_algorithm);
|
|
2688
|
+
if (!client_id || !private_key || !algorithm)
|
|
2689
|
+
return;
|
|
2690
|
+
return {
|
|
2691
|
+
type: "private_key_jwt",
|
|
2692
|
+
client_id,
|
|
2693
|
+
private_key,
|
|
2694
|
+
algorithm,
|
|
2695
|
+
client_name: asNonEmptyString(flat.auth_client_name),
|
|
2696
|
+
jwt_lifetime_seconds: asNumber(flat.auth_jwt_lifetime_seconds),
|
|
2697
|
+
scope: asNonEmptyString(flat.auth_scope)
|
|
2698
|
+
};
|
|
2699
|
+
}
|
|
2700
|
+
case "static_private_key_jwt": {
|
|
2701
|
+
const client_id = asNonEmptyString(flat.auth_client_id);
|
|
2702
|
+
const jwt_bearer_assertion = asNonEmptyString(flat.auth_jwt_bearer_assertion);
|
|
2703
|
+
if (!client_id || !jwt_bearer_assertion)
|
|
2704
|
+
return;
|
|
2705
|
+
return {
|
|
2706
|
+
type: "static_private_key_jwt",
|
|
2707
|
+
client_id,
|
|
2708
|
+
jwt_bearer_assertion,
|
|
2709
|
+
client_name: asNonEmptyString(flat.auth_client_name),
|
|
2710
|
+
scope: asNonEmptyString(flat.auth_scope)
|
|
2711
|
+
};
|
|
2712
|
+
}
|
|
2713
|
+
case "authorization_code": {
|
|
2714
|
+
const client_id = asNonEmptyString(flat.auth_client_id);
|
|
2715
|
+
const redirect_url = asNonEmptyString(flat.auth_redirect_url);
|
|
2716
|
+
if (!client_id || !redirect_url)
|
|
2717
|
+
return;
|
|
2718
|
+
return {
|
|
2719
|
+
type: "authorization_code",
|
|
2720
|
+
client_id,
|
|
2721
|
+
client_secret: asNonEmptyString(flat.auth_client_secret),
|
|
2722
|
+
redirect_url,
|
|
2723
|
+
scope: asNonEmptyString(flat.auth_scope)
|
|
2724
|
+
};
|
|
2725
|
+
}
|
|
2726
|
+
default:
|
|
2727
|
+
return;
|
|
2728
|
+
}
|
|
2729
|
+
}
|
|
2730
|
+
// src/mcp/McpAuthProvider.ts
|
|
2731
|
+
import {
|
|
2732
|
+
ClientCredentialsProvider,
|
|
2733
|
+
PrivateKeyJwtProvider,
|
|
2734
|
+
StaticPrivateKeyJwtProvider,
|
|
2735
|
+
createPrivateKeyJwtAuth
|
|
2736
|
+
} from "@modelcontextprotocol/sdk/client/auth-extensions.js";
|
|
2737
|
+
function normalizeServerUrl(serverUrl) {
|
|
2738
|
+
try {
|
|
2739
|
+
const u = new URL(serverUrl);
|
|
2740
|
+
return u.origin + u.pathname.replace(/\/+$/, "");
|
|
2741
|
+
} catch {
|
|
2742
|
+
return serverUrl;
|
|
2743
|
+
}
|
|
2744
|
+
}
|
|
2745
|
+
function storeKey(serverUrl, suffix) {
|
|
2746
|
+
return `mcp:oauth:${normalizeServerUrl(serverUrl)}:${suffix}`;
|
|
2747
|
+
}
|
|
2748
|
+
|
|
2749
|
+
class CredentialStoreOAuthProvider {
|
|
2750
|
+
store;
|
|
2751
|
+
serverUrl;
|
|
2752
|
+
_clientMetadata;
|
|
2753
|
+
_redirectUrl;
|
|
2754
|
+
_initialClientInfo;
|
|
2755
|
+
prepareTokenRequest;
|
|
2756
|
+
addClientAuthentication;
|
|
2757
|
+
constructor(options) {
|
|
2758
|
+
this.store = options.store;
|
|
2759
|
+
this.serverUrl = options.serverUrl;
|
|
2760
|
+
this._clientMetadata = options.clientMetadata;
|
|
2761
|
+
this._redirectUrl = options.redirectUrl;
|
|
2762
|
+
this._initialClientInfo = options.initialClientInfo;
|
|
2763
|
+
if (options.prepareTokenRequest) {
|
|
2764
|
+
this.prepareTokenRequest = options.prepareTokenRequest;
|
|
2765
|
+
}
|
|
2766
|
+
if (options.addClientAuthentication) {
|
|
2767
|
+
this.addClientAuthentication = options.addClientAuthentication;
|
|
2768
|
+
}
|
|
2769
|
+
}
|
|
2770
|
+
get redirectUrl() {
|
|
2771
|
+
return this._redirectUrl;
|
|
2772
|
+
}
|
|
2773
|
+
get clientMetadata() {
|
|
2774
|
+
return this._clientMetadata;
|
|
2775
|
+
}
|
|
2776
|
+
async clientInformation() {
|
|
2777
|
+
const raw = await this.store.get(storeKey(this.serverUrl, "client_info"));
|
|
2778
|
+
if (!raw)
|
|
2779
|
+
return this._initialClientInfo;
|
|
2780
|
+
return JSON.parse(raw);
|
|
2781
|
+
}
|
|
2782
|
+
async saveClientInformation(info) {
|
|
2783
|
+
await this.store.put(storeKey(this.serverUrl, "client_info"), JSON.stringify(info));
|
|
2784
|
+
}
|
|
2785
|
+
async tokens() {
|
|
2786
|
+
const raw = await this.store.get(storeKey(this.serverUrl, "tokens"));
|
|
2787
|
+
if (!raw)
|
|
2788
|
+
return;
|
|
2789
|
+
return JSON.parse(raw);
|
|
2790
|
+
}
|
|
2791
|
+
async saveTokens(tokens) {
|
|
2792
|
+
const expiresAt = tokens.expires_in != null ? new Date(Date.now() + tokens.expires_in * 1000) : undefined;
|
|
2793
|
+
await this.store.put(storeKey(this.serverUrl, "tokens"), JSON.stringify(tokens), {
|
|
2794
|
+
expiresAt
|
|
2795
|
+
});
|
|
2796
|
+
}
|
|
2797
|
+
async redirectToAuthorization(authorizationUrl) {
|
|
2798
|
+
throw new Error(`MCP OAuth authorization required. ` + `Open this URL to authorize: ${authorizationUrl.toString()}`);
|
|
2799
|
+
}
|
|
2800
|
+
async saveCodeVerifier(codeVerifier) {
|
|
2801
|
+
await this.store.put(storeKey(this.serverUrl, "code_verifier"), codeVerifier);
|
|
2802
|
+
}
|
|
2803
|
+
async codeVerifier() {
|
|
2804
|
+
const v = await this.store.get(storeKey(this.serverUrl, "code_verifier"));
|
|
2805
|
+
if (!v)
|
|
2806
|
+
throw new Error("No code verifier saved for this session");
|
|
2807
|
+
return v;
|
|
2808
|
+
}
|
|
2809
|
+
async saveDiscoveryState(state) {
|
|
2810
|
+
await this.store.put(storeKey(this.serverUrl, "discovery"), JSON.stringify(state));
|
|
2811
|
+
}
|
|
2812
|
+
async discoveryState() {
|
|
2813
|
+
const raw = await this.store.get(storeKey(this.serverUrl, "discovery"));
|
|
2814
|
+
if (!raw)
|
|
2815
|
+
return;
|
|
2816
|
+
return JSON.parse(raw);
|
|
2817
|
+
}
|
|
2818
|
+
async invalidateCredentials(scope) {
|
|
2819
|
+
const deleteKey = async (suffix) => {
|
|
2820
|
+
await this.store.delete(storeKey(this.serverUrl, suffix));
|
|
2821
|
+
};
|
|
2822
|
+
switch (scope) {
|
|
2823
|
+
case "all":
|
|
2824
|
+
await deleteKey("tokens");
|
|
2825
|
+
await deleteKey("client_info");
|
|
2826
|
+
await deleteKey("code_verifier");
|
|
2827
|
+
await deleteKey("discovery");
|
|
2828
|
+
break;
|
|
2829
|
+
case "client":
|
|
2830
|
+
await deleteKey("client_info");
|
|
2831
|
+
break;
|
|
2832
|
+
case "tokens":
|
|
2833
|
+
await deleteKey("tokens");
|
|
2834
|
+
break;
|
|
2835
|
+
case "verifier":
|
|
2836
|
+
await deleteKey("code_verifier");
|
|
2837
|
+
break;
|
|
2838
|
+
case "discovery":
|
|
2839
|
+
await deleteKey("discovery");
|
|
2840
|
+
break;
|
|
2841
|
+
}
|
|
2842
|
+
}
|
|
2843
|
+
}
|
|
2844
|
+
function createAuthProvider(auth, serverUrl, credentialStore) {
|
|
2845
|
+
switch (auth.type) {
|
|
2846
|
+
case "none":
|
|
2847
|
+
case "bearer":
|
|
2848
|
+
return;
|
|
2849
|
+
case "client_credentials": {
|
|
2850
|
+
if (!credentialStore) {
|
|
2851
|
+
return new ClientCredentialsProvider({
|
|
2852
|
+
clientId: auth.client_id,
|
|
2853
|
+
clientSecret: auth.client_secret,
|
|
2854
|
+
clientName: auth.client_name,
|
|
2855
|
+
scope: auth.scope
|
|
2856
|
+
});
|
|
2857
|
+
}
|
|
2858
|
+
const prepareTokenRequest = (scope) => {
|
|
2859
|
+
const params = new URLSearchParams({ grant_type: "client_credentials" });
|
|
2860
|
+
const effectiveScope = scope ?? auth.scope;
|
|
2861
|
+
if (effectiveScope)
|
|
2862
|
+
params.set("scope", effectiveScope);
|
|
2863
|
+
return params;
|
|
2864
|
+
};
|
|
2865
|
+
return new CredentialStoreOAuthProvider({
|
|
2866
|
+
store: credentialStore,
|
|
2867
|
+
serverUrl,
|
|
2868
|
+
clientMetadata: {
|
|
2869
|
+
redirect_uris: [],
|
|
2870
|
+
grant_types: ["client_credentials"],
|
|
2871
|
+
token_endpoint_auth_method: "client_secret_basic",
|
|
2872
|
+
client_name: auth.client_name
|
|
2873
|
+
},
|
|
2874
|
+
initialClientInfo: {
|
|
2875
|
+
client_id: auth.client_id,
|
|
2876
|
+
client_secret: auth.client_secret
|
|
2877
|
+
},
|
|
2878
|
+
prepareTokenRequest
|
|
2879
|
+
});
|
|
2880
|
+
}
|
|
2881
|
+
case "private_key_jwt": {
|
|
2882
|
+
if (!credentialStore) {
|
|
2883
|
+
return new PrivateKeyJwtProvider({
|
|
2884
|
+
clientId: auth.client_id,
|
|
2885
|
+
privateKey: auth.private_key,
|
|
2886
|
+
algorithm: auth.algorithm,
|
|
2887
|
+
clientName: auth.client_name,
|
|
2888
|
+
jwtLifetimeSeconds: auth.jwt_lifetime_seconds,
|
|
2889
|
+
scope: auth.scope
|
|
2890
|
+
});
|
|
2891
|
+
}
|
|
2892
|
+
const addClientAuth = createPrivateKeyJwtAuth({
|
|
2893
|
+
issuer: auth.client_id,
|
|
2894
|
+
subject: auth.client_id,
|
|
2895
|
+
privateKey: auth.private_key,
|
|
2896
|
+
alg: auth.algorithm,
|
|
2897
|
+
lifetimeSeconds: auth.jwt_lifetime_seconds
|
|
2898
|
+
});
|
|
2899
|
+
const prepareTokenRequest = (scope) => {
|
|
2900
|
+
const params = new URLSearchParams({ grant_type: "client_credentials" });
|
|
2901
|
+
const effectiveScope = scope ?? auth.scope;
|
|
2902
|
+
if (effectiveScope)
|
|
2903
|
+
params.set("scope", effectiveScope);
|
|
2904
|
+
return params;
|
|
2905
|
+
};
|
|
2906
|
+
return new CredentialStoreOAuthProvider({
|
|
2907
|
+
store: credentialStore,
|
|
2908
|
+
serverUrl,
|
|
2909
|
+
clientMetadata: {
|
|
2910
|
+
redirect_uris: [],
|
|
2911
|
+
grant_types: ["client_credentials"],
|
|
2912
|
+
token_endpoint_auth_method: "private_key_jwt",
|
|
2913
|
+
client_name: auth.client_name
|
|
2914
|
+
},
|
|
2915
|
+
initialClientInfo: { client_id: auth.client_id },
|
|
2916
|
+
prepareTokenRequest,
|
|
2917
|
+
addClientAuthentication: addClientAuth
|
|
2918
|
+
});
|
|
2919
|
+
}
|
|
2920
|
+
case "static_private_key_jwt": {
|
|
2921
|
+
if (!credentialStore) {
|
|
2922
|
+
return new StaticPrivateKeyJwtProvider({
|
|
2923
|
+
clientId: auth.client_id,
|
|
2924
|
+
jwtBearerAssertion: auth.jwt_bearer_assertion,
|
|
2925
|
+
clientName: auth.client_name,
|
|
2926
|
+
scope: auth.scope
|
|
2927
|
+
});
|
|
2928
|
+
}
|
|
2929
|
+
const assertion = auth.jwt_bearer_assertion;
|
|
2930
|
+
const addClientAuth = (_headers, params) => {
|
|
2931
|
+
params.set("client_assertion_type", "urn:ietf:params:oauth:client-assertion-type:jwt-bearer");
|
|
2932
|
+
params.set("client_assertion", assertion);
|
|
2933
|
+
};
|
|
2934
|
+
const prepareTokenRequest = (scope) => {
|
|
2935
|
+
const params = new URLSearchParams({ grant_type: "client_credentials" });
|
|
2936
|
+
const effectiveScope = scope ?? auth.scope;
|
|
2937
|
+
if (effectiveScope)
|
|
2938
|
+
params.set("scope", effectiveScope);
|
|
2939
|
+
return params;
|
|
2940
|
+
};
|
|
2941
|
+
return new CredentialStoreOAuthProvider({
|
|
2942
|
+
store: credentialStore,
|
|
2943
|
+
serverUrl,
|
|
2944
|
+
clientMetadata: {
|
|
2945
|
+
redirect_uris: [],
|
|
2946
|
+
grant_types: ["client_credentials"],
|
|
2947
|
+
token_endpoint_auth_method: "private_key_jwt",
|
|
2948
|
+
client_name: auth.client_name
|
|
2949
|
+
},
|
|
2950
|
+
initialClientInfo: { client_id: auth.client_id },
|
|
2951
|
+
prepareTokenRequest,
|
|
2952
|
+
addClientAuthentication: addClientAuth
|
|
2953
|
+
});
|
|
2954
|
+
}
|
|
2955
|
+
case "authorization_code": {
|
|
2956
|
+
if (!credentialStore) {
|
|
2957
|
+
throw new Error("authorization_code auth requires a credential store for token persistence");
|
|
2958
|
+
}
|
|
2959
|
+
return new CredentialStoreOAuthProvider({
|
|
2960
|
+
store: credentialStore,
|
|
2961
|
+
serverUrl,
|
|
2962
|
+
clientMetadata: {
|
|
2963
|
+
redirect_uris: [auth.redirect_url],
|
|
2964
|
+
grant_types: ["authorization_code", "refresh_token"],
|
|
2965
|
+
token_endpoint_auth_method: auth.client_secret ? "client_secret_basic" : "none",
|
|
2966
|
+
scope: auth.scope
|
|
2967
|
+
},
|
|
2968
|
+
initialClientInfo: {
|
|
2969
|
+
client_id: auth.client_id,
|
|
2970
|
+
...auth.client_secret ? { client_secret: auth.client_secret } : {}
|
|
2971
|
+
},
|
|
2972
|
+
redirectUrl: auth.redirect_url
|
|
2973
|
+
});
|
|
2974
|
+
}
|
|
2975
|
+
default:
|
|
2976
|
+
return;
|
|
2977
|
+
}
|
|
2978
|
+
}
|
|
2979
|
+
async function resolveAuthSecrets(auth, credentialStore) {
|
|
2980
|
+
if (auth.type === "none")
|
|
2981
|
+
return auth;
|
|
2982
|
+
const store = credentialStore ?? getGlobalCredentialStore();
|
|
2983
|
+
async function resolve(value) {
|
|
2984
|
+
if (!value)
|
|
2985
|
+
return value;
|
|
2986
|
+
const resolved = await store.get(value);
|
|
2987
|
+
return resolved ?? value;
|
|
2988
|
+
}
|
|
2989
|
+
switch (auth.type) {
|
|
2990
|
+
case "bearer":
|
|
2991
|
+
return { ...auth, token: await resolve(auth.token) ?? auth.token };
|
|
2992
|
+
case "client_credentials":
|
|
2993
|
+
return {
|
|
2994
|
+
...auth,
|
|
2995
|
+
client_secret: await resolve(auth.client_secret) ?? auth.client_secret
|
|
2996
|
+
};
|
|
2997
|
+
case "private_key_jwt":
|
|
2998
|
+
return {
|
|
2999
|
+
...auth,
|
|
3000
|
+
private_key: await resolve(auth.private_key) ?? auth.private_key
|
|
3001
|
+
};
|
|
3002
|
+
case "static_private_key_jwt":
|
|
3003
|
+
return {
|
|
3004
|
+
...auth,
|
|
3005
|
+
jwt_bearer_assertion: await resolve(auth.jwt_bearer_assertion) ?? auth.jwt_bearer_assertion
|
|
3006
|
+
};
|
|
3007
|
+
case "authorization_code":
|
|
3008
|
+
return {
|
|
3009
|
+
...auth,
|
|
3010
|
+
client_secret: await resolve(auth.client_secret)
|
|
3011
|
+
};
|
|
3012
|
+
default:
|
|
3013
|
+
return auth;
|
|
3014
|
+
}
|
|
3015
|
+
}
|
|
2557
3016
|
// src/compress/compress.browser.ts
|
|
2558
3017
|
async function compress(input, algorithm = "gzip") {
|
|
2559
3018
|
const sourceBlob = new Blob([typeof input === "string" ? input : new Uint8Array(input)]);
|
|
@@ -2570,7 +3029,6 @@ async function decompress(input, algorithm = "gzip") {
|
|
|
2570
3029
|
import { Client } from "@modelcontextprotocol/sdk/client";
|
|
2571
3030
|
import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js";
|
|
2572
3031
|
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
2573
|
-
var MCP_PROTOCOL_VERSION_HEADER = "2025-11-25";
|
|
2574
3032
|
var mcpTransportTypes = ["streamable-http", "sse"];
|
|
2575
3033
|
var mcpServerConfigSchema = {
|
|
2576
3034
|
transport: {
|
|
@@ -2584,25 +3042,31 @@ var mcpServerConfigSchema = {
|
|
|
2584
3042
|
format: "uri",
|
|
2585
3043
|
title: "Server URL",
|
|
2586
3044
|
description: "The URL of the MCP server (for streamable-http transport)"
|
|
2587
|
-
}
|
|
3045
|
+
},
|
|
3046
|
+
...mcpAuthConfigSchema
|
|
2588
3047
|
};
|
|
2589
3048
|
async function createMcpClient(config, signal) {
|
|
2590
3049
|
let transport;
|
|
3050
|
+
let auth = config.auth ?? buildAuthConfig({ ...config });
|
|
3051
|
+
if (auth && auth.type !== "none") {
|
|
3052
|
+
auth = await resolveAuthSecrets(auth, getGlobalCredentialStore());
|
|
3053
|
+
}
|
|
3054
|
+
const authProvider = auth && auth.type !== "none" && auth.type !== "bearer" ? createAuthProvider(auth, config.server_url ?? "", getGlobalCredentialStore()) : undefined;
|
|
3055
|
+
const headers = {
|
|
3056
|
+
...auth?.type === "bearer" ? { Authorization: `Bearer ${auth.token}` } : {}
|
|
3057
|
+
};
|
|
3058
|
+
const requestInit = { headers };
|
|
2591
3059
|
switch (config.transport) {
|
|
2592
3060
|
case "sse": {
|
|
2593
|
-
const requestInit = {
|
|
2594
|
-
headers: { "MCP-Protocol-Version": MCP_PROTOCOL_VERSION_HEADER }
|
|
2595
|
-
};
|
|
2596
3061
|
transport = new SSEClientTransport(new URL(config.server_url), {
|
|
3062
|
+
authProvider,
|
|
2597
3063
|
requestInit
|
|
2598
3064
|
});
|
|
2599
3065
|
break;
|
|
2600
3066
|
}
|
|
2601
3067
|
case "streamable-http": {
|
|
2602
|
-
const requestInit = {
|
|
2603
|
-
headers: { "MCP-Protocol-Version": MCP_PROTOCOL_VERSION_HEADER }
|
|
2604
|
-
};
|
|
2605
3068
|
transport = new StreamableHTTPClientTransport(new URL(config.server_url), {
|
|
3069
|
+
authProvider,
|
|
2606
3070
|
requestInit
|
|
2607
3071
|
});
|
|
2608
3072
|
break;
|
|
@@ -2717,6 +3181,7 @@ export {
|
|
|
2717
3181
|
setGlobalCredentialStore,
|
|
2718
3182
|
serialize,
|
|
2719
3183
|
resolveCredential,
|
|
3184
|
+
resolveAuthSecrets,
|
|
2720
3185
|
registerInputResolver,
|
|
2721
3186
|
parsePartialJson,
|
|
2722
3187
|
parseDataUri,
|
|
@@ -2727,6 +3192,8 @@ export {
|
|
|
2727
3192
|
mcpTransportTypes,
|
|
2728
3193
|
mcpServerConfigSchema,
|
|
2729
3194
|
mcpClientFactory,
|
|
3195
|
+
mcpAuthTypes,
|
|
3196
|
+
mcpAuthConfigSchema,
|
|
2730
3197
|
makeFingerprint,
|
|
2731
3198
|
magnitude,
|
|
2732
3199
|
jaccardSimilarity,
|
|
@@ -2748,11 +3215,13 @@ export {
|
|
|
2748
3215
|
createTypedArrayFrom,
|
|
2749
3216
|
createServiceToken,
|
|
2750
3217
|
createMcpClient,
|
|
3218
|
+
createAuthProvider,
|
|
2751
3219
|
cosineSimilarity,
|
|
2752
3220
|
convertImageDataToUseableForm,
|
|
2753
3221
|
compress,
|
|
2754
3222
|
compileSchema,
|
|
2755
3223
|
collectPropertyValues,
|
|
3224
|
+
buildAuthConfig,
|
|
2756
3225
|
bufToBase64,
|
|
2757
3226
|
base64ToBuf,
|
|
2758
3227
|
areSemanticallyCompatible,
|
|
@@ -2779,6 +3248,7 @@ export {
|
|
|
2779
3248
|
DirectedGraph,
|
|
2780
3249
|
DirectedAcyclicGraph,
|
|
2781
3250
|
CycleError,
|
|
3251
|
+
CredentialStoreOAuthProvider,
|
|
2782
3252
|
Container,
|
|
2783
3253
|
ConsoleLogger,
|
|
2784
3254
|
ChainedCredentialStore,
|
|
@@ -2786,4 +3256,4 @@ export {
|
|
|
2786
3256
|
BaseError
|
|
2787
3257
|
};
|
|
2788
3258
|
|
|
2789
|
-
//# debugId=
|
|
3259
|
+
//# debugId=0564D1DAF5A6667164756E2164756E21
|