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