@mcp-use/client 2.4.3 → 2.4.4-canary.1
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/.tsbuildinfo +1 -1
- package/dist/auth/session-store.d.ts.map +1 -1
- package/dist/index-browser.js +117 -12
- package/dist/index-browser.js.map +1 -1
- package/dist/index.js +124 -12
- package/dist/index.js.map +1 -1
- package/dist/react/index.js +117 -12
- package/dist/react/index.js.map +1 -1
- package/dist/transport/base.d.ts.map +1 -1
- package/dist/transport/http.d.ts.map +1 -1
- package/dist/transport/mcp-param-headers.d.ts +23 -0
- package/dist/transport/mcp-param-headers.d.ts.map +1 -0
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-store.d.ts","sourceRoot":"","sources":["../../src/auth/session-store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,sBAAsB,EACtB,6BAA6B,EAC7B,mBAAmB,EACnB,mBAAmB,EACnB,iBAAiB,EAClB,MAAM,8BAA8B,CAAC;AAGtC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE5C;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,aAAa,EAAE,MAAM,CAAC;IACtB,eAAe,EAAE;QACf,SAAS,EAAE,MAAM,CAAC;QAClB,gBAAgB,EAAE,MAAM,CAAC;QACzB,UAAU,EAAE,MAAM,CAAC;QACnB,SAAS,EAAE,MAAM,CAAC;QAClB,WAAW,EAAE,MAAM,CAAC;QACpB,aAAa,CAAC,EAAE,MAAM,CAAC;QACvB,iBAAiB,CAAC,EAAE,MAAM,CAAC;QAC3B,gBAAgB,CAAC,EAAE,sBAAsB,CAAC;QAC1C,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB,CAAC;IACF,QAAQ,CAAC,EAAE,OAAO,GAAG,UAAU,CAAC;IAChC,SAAS,CAAC,EAAE,MAAM,CAAC;C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,cAAc,IAAI,mBAAmB,CAWxC;IAED,OAAO,CAAC,aAAa;YASP,cAAc;IA2DtB,MAAM,CACV,GAAG,CAAC,EAAE,6BAA6B,GAClC,OAAO,CAAC,iBAAiB,GAAG,SAAS,CAAC;IAInC,UAAU,CACd,MAAM,EAAE,iBAAiB,EACzB,GAAG,CAAC,EAAE,6BAA6B,GAClC,OAAO,CAAC,IAAI,CAAC;IAYV,iBAAiB,CACrB,GAAG,CAAC,EAAE,6BAA6B,GAClC,OAAO,CAAC,sBAAsB,GAAG,SAAS,CAAC;IAwDxC,qBAAqB,CACzB,iBAAiB,EAAE,sBAAsB,EACzC,GAAG,CAAC,EAAE,6BAA6B,GAClC,OAAO,CAAC,IAAI,CAAC;IAkCV,gBAAgB,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIrD,YAAY,IAAI,OAAO,CAAC,MAAM,CAAC;IAW/B,qBAAqB,CACzB,KAAK,EACD,KAAK,GACL,cAAc,GACd,QAAQ,GACR,QAAQ,GACR,UAAU,GACV,WAAW,GACd,OAAO,CAAC,IAAI,CAAC;IAoDhB;;;;;OAKG;IACG,kBAAkB,CAAC,KAAK,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC;IAInE,mEAAmE;IAC7D,cAAc,IAAI,OAAO,CAAC,mBAAmB,GAAG,SAAS,CAAC;IAahE;;;;;;OAMG;IACG,uBAAuB,CAC3B,gBAAgB,EAAE,GAAG,EACrB,IAAI,GAAE,8BAAmC,GACxC,OAAO,CAAC,MAAM,CAAC;IAqClB;;;OAGG;IACG,gBAAgB,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAOhD;;;OAGG;IACG,WAAW,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;CAI5C"}
|
package/dist/index-browser.js
CHANGED
|
@@ -128,7 +128,7 @@ var Logger = class {
|
|
|
128
128
|
var logger = Logger.get();
|
|
129
129
|
|
|
130
130
|
// src/utils/version.ts
|
|
131
|
-
var VERSION = "2.4.
|
|
131
|
+
var VERSION = "2.4.4-canary.1";
|
|
132
132
|
function getPackageVersion() {
|
|
133
133
|
return VERSION;
|
|
134
134
|
}
|
|
@@ -913,7 +913,11 @@ var OAuthSessionStore = class _OAuthSessionStore {
|
|
|
913
913
|
if (legacyData) {
|
|
914
914
|
try {
|
|
915
915
|
const legacyValue = JSON.parse(legacyData);
|
|
916
|
-
if (
|
|
916
|
+
if (typeof legacyValue.issuer !== "string" || !legacyValue.issuer.trim()) {
|
|
917
|
+
await this.store.remove(legacyKey);
|
|
918
|
+
return void 0;
|
|
919
|
+
}
|
|
920
|
+
if (legacyValue.issuer === ctx.issuer) {
|
|
917
921
|
const migratedValue = {
|
|
918
922
|
...legacyValue,
|
|
919
923
|
issuer: ctx.issuer
|
|
@@ -931,7 +935,12 @@ var OAuthSessionStore = class _OAuthSessionStore {
|
|
|
931
935
|
}
|
|
932
936
|
if (!data) return void 0;
|
|
933
937
|
try {
|
|
934
|
-
|
|
938
|
+
const value = JSON.parse(data);
|
|
939
|
+
if (typeof value?.issuer !== "string" || !value.issuer.trim() || ctx && value.issuer !== ctx.issuer) {
|
|
940
|
+
await this.store.remove(key);
|
|
941
|
+
return void 0;
|
|
942
|
+
}
|
|
943
|
+
return { key, value };
|
|
935
944
|
} catch (e) {
|
|
936
945
|
console.warn(
|
|
937
946
|
`[${this.storageKeyPrefix}] Failed to parse ${kind.replace("_", " ")}:`,
|
|
@@ -2106,6 +2115,7 @@ import {
|
|
|
2106
2115
|
discoverOAuthProtectedResourceMetadata,
|
|
2107
2116
|
SdkError,
|
|
2108
2117
|
SdkHttpError,
|
|
2118
|
+
selectResourceURL,
|
|
2109
2119
|
StreamableHTTPClientTransport as StreamableHTTPClientTransport2,
|
|
2110
2120
|
UnauthorizedError as UnauthorizedError2
|
|
2111
2121
|
} from "@modelcontextprotocol/client";
|
|
@@ -2146,6 +2156,89 @@ var DialectJsonSchemaValidator = class {
|
|
|
2146
2156
|
}
|
|
2147
2157
|
};
|
|
2148
2158
|
|
|
2159
|
+
// src/transport/mcp-param-headers.ts
|
|
2160
|
+
var MCP_PARAM_HEADER_PREFIX = "Mcp-Param-";
|
|
2161
|
+
var X_MCP_HEADER_KEY = "x-mcp-header";
|
|
2162
|
+
var RFC9110_TOKEN = /^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/;
|
|
2163
|
+
var PERMITTED_TYPES = /* @__PURE__ */ new Set(["string", "integer", "boolean", "number"]);
|
|
2164
|
+
var BASE64_SENTINEL_PREFIX = "=?base64?";
|
|
2165
|
+
var BASE64_SENTINEL_SUFFIX = "?=";
|
|
2166
|
+
function sdkMirrorsMcpParamHeaders() {
|
|
2167
|
+
const g = globalThis;
|
|
2168
|
+
return g.window === void 0 || g.document === void 0;
|
|
2169
|
+
}
|
|
2170
|
+
function collectDeclarations(schema, path, seen, out) {
|
|
2171
|
+
if (schema === null || typeof schema !== "object") return;
|
|
2172
|
+
const node = schema;
|
|
2173
|
+
const headerName = node[X_MCP_HEADER_KEY];
|
|
2174
|
+
if (path.length > 0 && typeof headerName === "string" && RFC9110_TOKEN.test(headerName) && typeof node.type === "string" && PERMITTED_TYPES.has(node.type) && !seen.has(headerName.toLowerCase())) {
|
|
2175
|
+
seen.add(headerName.toLowerCase());
|
|
2176
|
+
out.push({ path, headerName });
|
|
2177
|
+
}
|
|
2178
|
+
const properties = node.properties;
|
|
2179
|
+
if (properties !== null && typeof properties === "object") {
|
|
2180
|
+
for (const [key, child] of Object.entries(properties)) {
|
|
2181
|
+
collectDeclarations(child, [...path, key], seen, out);
|
|
2182
|
+
}
|
|
2183
|
+
}
|
|
2184
|
+
}
|
|
2185
|
+
function valueAtPath(root, path) {
|
|
2186
|
+
let node = root;
|
|
2187
|
+
for (const key of path) {
|
|
2188
|
+
if (node === null || typeof node !== "object") return void 0;
|
|
2189
|
+
node = node[key];
|
|
2190
|
+
}
|
|
2191
|
+
return node;
|
|
2192
|
+
}
|
|
2193
|
+
function primitiveToString(value) {
|
|
2194
|
+
if (typeof value === "string") return value;
|
|
2195
|
+
if (typeof value === "boolean") return value ? "true" : "false";
|
|
2196
|
+
if (typeof value === "number") {
|
|
2197
|
+
if (!Number.isFinite(value)) return void 0;
|
|
2198
|
+
if (Number.isInteger(value) && !Number.isSafeInteger(value)) {
|
|
2199
|
+
return void 0;
|
|
2200
|
+
}
|
|
2201
|
+
return String(value);
|
|
2202
|
+
}
|
|
2203
|
+
return void 0;
|
|
2204
|
+
}
|
|
2205
|
+
function needsBase64(value) {
|
|
2206
|
+
if (value.length === 0) return true;
|
|
2207
|
+
if (value.startsWith(BASE64_SENTINEL_PREFIX) && value.endsWith(BASE64_SENTINEL_SUFFIX)) {
|
|
2208
|
+
return true;
|
|
2209
|
+
}
|
|
2210
|
+
if (value !== value.trim()) return true;
|
|
2211
|
+
for (let i = 0; i < value.length; i++) {
|
|
2212
|
+
const code = value.charCodeAt(i);
|
|
2213
|
+
if (code === 9 || code >= 32 && code <= 126) continue;
|
|
2214
|
+
return true;
|
|
2215
|
+
}
|
|
2216
|
+
return false;
|
|
2217
|
+
}
|
|
2218
|
+
function utf8ToBase64(value) {
|
|
2219
|
+
let binary = "";
|
|
2220
|
+
for (const byte of new TextEncoder().encode(value)) {
|
|
2221
|
+
binary += String.fromCharCode(byte);
|
|
2222
|
+
}
|
|
2223
|
+
return btoa(binary);
|
|
2224
|
+
}
|
|
2225
|
+
function encodeValue(value) {
|
|
2226
|
+
return needsBase64(value) ? `${BASE64_SENTINEL_PREFIX}${utf8ToBase64(value)}${BASE64_SENTINEL_SUFFIX}` : value;
|
|
2227
|
+
}
|
|
2228
|
+
function buildMcpParamHeaders(inputSchema, args) {
|
|
2229
|
+
const declarations = [];
|
|
2230
|
+
collectDeclarations(inputSchema, [], /* @__PURE__ */ new Set(), declarations);
|
|
2231
|
+
const headers = {};
|
|
2232
|
+
for (const { path, headerName } of declarations) {
|
|
2233
|
+
const raw = valueAtPath(args, path);
|
|
2234
|
+
if (raw === void 0 || raw === null) continue;
|
|
2235
|
+
const value = primitiveToString(raw);
|
|
2236
|
+
if (value === void 0) continue;
|
|
2237
|
+
headers[`${MCP_PARAM_HEADER_PREFIX}${headerName}`] = encodeValue(value);
|
|
2238
|
+
}
|
|
2239
|
+
return headers;
|
|
2240
|
+
}
|
|
2241
|
+
|
|
2149
2242
|
// src/transport/base.ts
|
|
2150
2243
|
var passthroughResultSchema = {
|
|
2151
2244
|
"~standard": {
|
|
@@ -2606,7 +2699,7 @@ var BaseConnector = class {
|
|
|
2606
2699
|
if (!this.client) {
|
|
2607
2700
|
throw new Error("MCP client is not connected");
|
|
2608
2701
|
}
|
|
2609
|
-
|
|
2702
|
+
let enhancedOptions = options ? { ...options } : void 0;
|
|
2610
2703
|
if (enhancedOptions?.resetTimeoutOnProgress && !enhancedOptions.onprogress) {
|
|
2611
2704
|
enhancedOptions.onprogress = () => {
|
|
2612
2705
|
};
|
|
@@ -2614,6 +2707,16 @@ var BaseConnector = class {
|
|
|
2614
2707
|
`[BaseConnector] Added onprogress callback for tool '${name}' to enable progressToken`
|
|
2615
2708
|
);
|
|
2616
2709
|
}
|
|
2710
|
+
if (this.protocolEra === "modern" && !sdkMirrorsMcpParamHeaders()) {
|
|
2711
|
+
const tool = this.toolsCache?.find((t) => t.name === name);
|
|
2712
|
+
const paramHeaders = tool ? buildMcpParamHeaders(tool.inputSchema, args) : {};
|
|
2713
|
+
if (Object.keys(paramHeaders).length > 0) {
|
|
2714
|
+
enhancedOptions = {
|
|
2715
|
+
...enhancedOptions,
|
|
2716
|
+
headers: { ...enhancedOptions?.headers, ...paramHeaders }
|
|
2717
|
+
};
|
|
2718
|
+
}
|
|
2719
|
+
}
|
|
2617
2720
|
logger.debug(`Calling tool '${name}' with args`, args);
|
|
2618
2721
|
const res = await this.executeRequest(
|
|
2619
2722
|
() => this.client.callTool({ name, arguments: args }, enhancedOptions)
|
|
@@ -3047,19 +3150,20 @@ var HttpConnector = class extends BaseConnector {
|
|
|
3047
3150
|
await this.completeInteractiveAuthorization();
|
|
3048
3151
|
}
|
|
3049
3152
|
async discoverAuthorization() {
|
|
3050
|
-
|
|
3153
|
+
const provider = this.oauthProvider;
|
|
3154
|
+
if (!this.detectMixedAuth || !provider || this.hadAccessTokenAtConnect) {
|
|
3051
3155
|
return this.authorizationCache;
|
|
3052
3156
|
}
|
|
3053
3157
|
if (this.authorizationDiscovery) return this.authorizationDiscovery;
|
|
3054
|
-
this.authorizationDiscovery = this.discoverMixedAuthorization(
|
|
3055
|
-
|
|
3056
|
-
|
|
3057
|
-
|
|
3058
|
-
|
|
3059
|
-
);
|
|
3158
|
+
this.authorizationDiscovery = this.discoverMixedAuthorization(
|
|
3159
|
+
provider
|
|
3160
|
+
).then((authorization) => {
|
|
3161
|
+
if (!authorization) this.authorizationDiscovery = null;
|
|
3162
|
+
return authorization;
|
|
3163
|
+
});
|
|
3060
3164
|
return this.authorizationDiscovery;
|
|
3061
3165
|
}
|
|
3062
|
-
async discoverMixedAuthorization() {
|
|
3166
|
+
async discoverMixedAuthorization(provider) {
|
|
3063
3167
|
const controller = new AbortController();
|
|
3064
3168
|
let timeout;
|
|
3065
3169
|
const discoveryTimeout = new Promise((_, reject) => {
|
|
@@ -3081,6 +3185,7 @@ var HttpConnector = class extends BaseConnector {
|
|
|
3081
3185
|
),
|
|
3082
3186
|
discoveryTimeout
|
|
3083
3187
|
]);
|
|
3188
|
+
await selectResourceURL(this.baseUrl, provider, metadata);
|
|
3084
3189
|
this.authorizationCache = {
|
|
3085
3190
|
mode: "mixed",
|
|
3086
3191
|
authenticated: false,
|