@mcp-use/client 2.4.3 → 2.4.4-canary.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.
@@ -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.3";
131
+ var VERSION = "2.4.4-canary.0";
132
132
  function getPackageVersion() {
133
133
  return VERSION;
134
134
  }
@@ -2146,6 +2146,89 @@ var DialectJsonSchemaValidator = class {
2146
2146
  }
2147
2147
  };
2148
2148
 
2149
+ // src/transport/mcp-param-headers.ts
2150
+ var MCP_PARAM_HEADER_PREFIX = "Mcp-Param-";
2151
+ var X_MCP_HEADER_KEY = "x-mcp-header";
2152
+ var RFC9110_TOKEN = /^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/;
2153
+ var PERMITTED_TYPES = /* @__PURE__ */ new Set(["string", "integer", "boolean", "number"]);
2154
+ var BASE64_SENTINEL_PREFIX = "=?base64?";
2155
+ var BASE64_SENTINEL_SUFFIX = "?=";
2156
+ function sdkMirrorsMcpParamHeaders() {
2157
+ const g = globalThis;
2158
+ return g.window === void 0 || g.document === void 0;
2159
+ }
2160
+ function collectDeclarations(schema, path, seen, out) {
2161
+ if (schema === null || typeof schema !== "object") return;
2162
+ const node = schema;
2163
+ const headerName = node[X_MCP_HEADER_KEY];
2164
+ if (path.length > 0 && typeof headerName === "string" && RFC9110_TOKEN.test(headerName) && typeof node.type === "string" && PERMITTED_TYPES.has(node.type) && !seen.has(headerName.toLowerCase())) {
2165
+ seen.add(headerName.toLowerCase());
2166
+ out.push({ path, headerName });
2167
+ }
2168
+ const properties = node.properties;
2169
+ if (properties !== null && typeof properties === "object") {
2170
+ for (const [key, child] of Object.entries(properties)) {
2171
+ collectDeclarations(child, [...path, key], seen, out);
2172
+ }
2173
+ }
2174
+ }
2175
+ function valueAtPath(root, path) {
2176
+ let node = root;
2177
+ for (const key of path) {
2178
+ if (node === null || typeof node !== "object") return void 0;
2179
+ node = node[key];
2180
+ }
2181
+ return node;
2182
+ }
2183
+ function primitiveToString(value) {
2184
+ if (typeof value === "string") return value;
2185
+ if (typeof value === "boolean") return value ? "true" : "false";
2186
+ if (typeof value === "number") {
2187
+ if (!Number.isFinite(value)) return void 0;
2188
+ if (Number.isInteger(value) && !Number.isSafeInteger(value)) {
2189
+ return void 0;
2190
+ }
2191
+ return String(value);
2192
+ }
2193
+ return void 0;
2194
+ }
2195
+ function needsBase64(value) {
2196
+ if (value.length === 0) return true;
2197
+ if (value.startsWith(BASE64_SENTINEL_PREFIX) && value.endsWith(BASE64_SENTINEL_SUFFIX)) {
2198
+ return true;
2199
+ }
2200
+ if (value !== value.trim()) return true;
2201
+ for (let i = 0; i < value.length; i++) {
2202
+ const code = value.charCodeAt(i);
2203
+ if (code === 9 || code >= 32 && code <= 126) continue;
2204
+ return true;
2205
+ }
2206
+ return false;
2207
+ }
2208
+ function utf8ToBase64(value) {
2209
+ let binary = "";
2210
+ for (const byte of new TextEncoder().encode(value)) {
2211
+ binary += String.fromCharCode(byte);
2212
+ }
2213
+ return btoa(binary);
2214
+ }
2215
+ function encodeValue(value) {
2216
+ return needsBase64(value) ? `${BASE64_SENTINEL_PREFIX}${utf8ToBase64(value)}${BASE64_SENTINEL_SUFFIX}` : value;
2217
+ }
2218
+ function buildMcpParamHeaders(inputSchema, args) {
2219
+ const declarations = [];
2220
+ collectDeclarations(inputSchema, [], /* @__PURE__ */ new Set(), declarations);
2221
+ const headers = {};
2222
+ for (const { path, headerName } of declarations) {
2223
+ const raw = valueAtPath(args, path);
2224
+ if (raw === void 0 || raw === null) continue;
2225
+ const value = primitiveToString(raw);
2226
+ if (value === void 0) continue;
2227
+ headers[`${MCP_PARAM_HEADER_PREFIX}${headerName}`] = encodeValue(value);
2228
+ }
2229
+ return headers;
2230
+ }
2231
+
2149
2232
  // src/transport/base.ts
2150
2233
  var passthroughResultSchema = {
2151
2234
  "~standard": {
@@ -2606,7 +2689,7 @@ var BaseConnector = class {
2606
2689
  if (!this.client) {
2607
2690
  throw new Error("MCP client is not connected");
2608
2691
  }
2609
- const enhancedOptions = options ? { ...options } : void 0;
2692
+ let enhancedOptions = options ? { ...options } : void 0;
2610
2693
  if (enhancedOptions?.resetTimeoutOnProgress && !enhancedOptions.onprogress) {
2611
2694
  enhancedOptions.onprogress = () => {
2612
2695
  };
@@ -2614,6 +2697,16 @@ var BaseConnector = class {
2614
2697
  `[BaseConnector] Added onprogress callback for tool '${name}' to enable progressToken`
2615
2698
  );
2616
2699
  }
2700
+ if (this.protocolEra === "modern" && !sdkMirrorsMcpParamHeaders()) {
2701
+ const tool = this.toolsCache?.find((t) => t.name === name);
2702
+ const paramHeaders = tool ? buildMcpParamHeaders(tool.inputSchema, args) : {};
2703
+ if (Object.keys(paramHeaders).length > 0) {
2704
+ enhancedOptions = {
2705
+ ...enhancedOptions,
2706
+ headers: { ...enhancedOptions?.headers, ...paramHeaders }
2707
+ };
2708
+ }
2709
+ }
2617
2710
  logger.debug(`Calling tool '${name}' with args`, args);
2618
2711
  const res = await this.executeRequest(
2619
2712
  () => this.client.callTool({ name, arguments: args }, enhancedOptions)