@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.
@@ -632,6 +632,89 @@ function trackConnectorTelemetry(data) {
632
632
  void tracker?.(data);
633
633
  }
634
634
 
635
+ // src/transport/mcp-param-headers.ts
636
+ var MCP_PARAM_HEADER_PREFIX = "Mcp-Param-";
637
+ var X_MCP_HEADER_KEY = "x-mcp-header";
638
+ var RFC9110_TOKEN = /^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/;
639
+ var PERMITTED_TYPES = /* @__PURE__ */ new Set(["string", "integer", "boolean", "number"]);
640
+ var BASE64_SENTINEL_PREFIX = "=?base64?";
641
+ var BASE64_SENTINEL_SUFFIX = "?=";
642
+ function sdkMirrorsMcpParamHeaders() {
643
+ const g = globalThis;
644
+ return g.window === void 0 || g.document === void 0;
645
+ }
646
+ function collectDeclarations(schema, path, seen, out) {
647
+ if (schema === null || typeof schema !== "object") return;
648
+ const node = schema;
649
+ const headerName = node[X_MCP_HEADER_KEY];
650
+ if (path.length > 0 && typeof headerName === "string" && RFC9110_TOKEN.test(headerName) && typeof node.type === "string" && PERMITTED_TYPES.has(node.type) && !seen.has(headerName.toLowerCase())) {
651
+ seen.add(headerName.toLowerCase());
652
+ out.push({ path, headerName });
653
+ }
654
+ const properties = node.properties;
655
+ if (properties !== null && typeof properties === "object") {
656
+ for (const [key, child] of Object.entries(properties)) {
657
+ collectDeclarations(child, [...path, key], seen, out);
658
+ }
659
+ }
660
+ }
661
+ function valueAtPath(root, path) {
662
+ let node = root;
663
+ for (const key of path) {
664
+ if (node === null || typeof node !== "object") return void 0;
665
+ node = node[key];
666
+ }
667
+ return node;
668
+ }
669
+ function primitiveToString(value) {
670
+ if (typeof value === "string") return value;
671
+ if (typeof value === "boolean") return value ? "true" : "false";
672
+ if (typeof value === "number") {
673
+ if (!Number.isFinite(value)) return void 0;
674
+ if (Number.isInteger(value) && !Number.isSafeInteger(value)) {
675
+ return void 0;
676
+ }
677
+ return String(value);
678
+ }
679
+ return void 0;
680
+ }
681
+ function needsBase64(value) {
682
+ if (value.length === 0) return true;
683
+ if (value.startsWith(BASE64_SENTINEL_PREFIX) && value.endsWith(BASE64_SENTINEL_SUFFIX)) {
684
+ return true;
685
+ }
686
+ if (value !== value.trim()) return true;
687
+ for (let i = 0; i < value.length; i++) {
688
+ const code = value.charCodeAt(i);
689
+ if (code === 9 || code >= 32 && code <= 126) continue;
690
+ return true;
691
+ }
692
+ return false;
693
+ }
694
+ function utf8ToBase64(value) {
695
+ let binary = "";
696
+ for (const byte of new TextEncoder().encode(value)) {
697
+ binary += String.fromCharCode(byte);
698
+ }
699
+ return btoa(binary);
700
+ }
701
+ function encodeValue(value) {
702
+ return needsBase64(value) ? `${BASE64_SENTINEL_PREFIX}${utf8ToBase64(value)}${BASE64_SENTINEL_SUFFIX}` : value;
703
+ }
704
+ function buildMcpParamHeaders(inputSchema, args) {
705
+ const declarations = [];
706
+ collectDeclarations(inputSchema, [], /* @__PURE__ */ new Set(), declarations);
707
+ const headers = {};
708
+ for (const { path, headerName } of declarations) {
709
+ const raw = valueAtPath(args, path);
710
+ if (raw === void 0 || raw === null) continue;
711
+ const value = primitiveToString(raw);
712
+ if (value === void 0) continue;
713
+ headers[`${MCP_PARAM_HEADER_PREFIX}${headerName}`] = encodeValue(value);
714
+ }
715
+ return headers;
716
+ }
717
+
635
718
  // src/transport/base.ts
636
719
  var passthroughResultSchema = {
637
720
  "~standard": {
@@ -1092,7 +1175,7 @@ var BaseConnector = class {
1092
1175
  if (!this.client) {
1093
1176
  throw new Error("MCP client is not connected");
1094
1177
  }
1095
- const enhancedOptions = options ? { ...options } : void 0;
1178
+ let enhancedOptions = options ? { ...options } : void 0;
1096
1179
  if (enhancedOptions?.resetTimeoutOnProgress && !enhancedOptions.onprogress) {
1097
1180
  enhancedOptions.onprogress = () => {
1098
1181
  };
@@ -1100,6 +1183,16 @@ var BaseConnector = class {
1100
1183
  `[BaseConnector] Added onprogress callback for tool '${name}' to enable progressToken`
1101
1184
  );
1102
1185
  }
1186
+ if (this.protocolEra === "modern" && !sdkMirrorsMcpParamHeaders()) {
1187
+ const tool = this.toolsCache?.find((t) => t.name === name);
1188
+ const paramHeaders = tool ? buildMcpParamHeaders(tool.inputSchema, args) : {};
1189
+ if (Object.keys(paramHeaders).length > 0) {
1190
+ enhancedOptions = {
1191
+ ...enhancedOptions,
1192
+ headers: { ...enhancedOptions?.headers, ...paramHeaders }
1193
+ };
1194
+ }
1195
+ }
1103
1196
  logger.debug(`Calling tool '${name}' with args`, args);
1104
1197
  const res = await this.executeRequest(
1105
1198
  () => this.client.callTool({ name, arguments: args }, enhancedOptions)
@@ -1883,7 +1976,7 @@ var HttpConnector = class extends BaseConnector {
1883
1976
  };
1884
1977
 
1885
1978
  // src/utils/version.ts
1886
- var VERSION = "2.4.3";
1979
+ var VERSION = "2.4.4-canary.0";
1887
1980
  function getPackageVersion() {
1888
1981
  return VERSION;
1889
1982
  }