@mcpspec/core 1.2.0 → 1.2.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.
Files changed (2) hide show
  1. package/dist/index.js +27 -3
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -3715,6 +3715,20 @@ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"
3715
3715
  import { ListToolsRequestSchema, CallToolRequestSchema } from "@modelcontextprotocol/sdk/types.js";
3716
3716
 
3717
3717
  // src/mock/response-matcher.ts
3718
+ function stableStringify(obj) {
3719
+ if (obj === null || typeof obj !== "object") {
3720
+ return JSON.stringify(obj);
3721
+ }
3722
+ if (Array.isArray(obj)) {
3723
+ return "[" + obj.map(stableStringify).join(",") + "]";
3724
+ }
3725
+ const keys = Object.keys(obj).sort();
3726
+ const parts = keys.map((key) => {
3727
+ const val = obj[key];
3728
+ return JSON.stringify(key) + ":" + stableStringify(val);
3729
+ });
3730
+ return "{" + parts.join(",") + "}";
3731
+ }
3718
3732
  var ResponseMatcher = class {
3719
3733
  config;
3720
3734
  steps;
@@ -3776,7 +3790,7 @@ var ResponseMatcher = class {
3776
3790
  return this.stepToResult(step);
3777
3791
  }
3778
3792
  normalizeInput(input) {
3779
- return JSON.stringify(input, Object.keys(input).sort());
3793
+ return stableStringify(input);
3780
3794
  }
3781
3795
  stepToResult(step) {
3782
3796
  return {
@@ -3888,6 +3902,16 @@ const MODE = '${options.mode}';
3888
3902
  const LATENCY = ${latencyValue};
3889
3903
  const ON_MISSING = '${options.onMissing}';
3890
3904
 
3905
+ // --- Stable stringify (deep key sorting) ---
3906
+
3907
+ function stableStringify(obj) {
3908
+ if (obj === null || typeof obj !== 'object') return JSON.stringify(obj);
3909
+ if (Array.isArray(obj)) return '[' + obj.map(stableStringify).join(',') + ']';
3910
+ const keys = Object.keys(obj).sort();
3911
+ const parts = keys.map((k) => JSON.stringify(k) + ':' + stableStringify(obj[k]));
3912
+ return '{' + parts.join(',') + '}';
3913
+ }
3914
+
3891
3915
  // --- ResponseMatcher (inlined) ---
3892
3916
 
3893
3917
  class ResponseMatcher {
@@ -3929,9 +3953,9 @@ class ResponseMatcher {
3929
3953
  const queue = this.toolQueues.get(toolName);
3930
3954
  if (!queue || queue.length === 0) return null;
3931
3955
 
3932
- const inputKey = JSON.stringify(input, Object.keys(input).sort());
3956
+ const inputKey = stableStringify(input);
3933
3957
  const exactIndex = queue.findIndex(
3934
- (s) => JSON.stringify(s.input, Object.keys(s.input).sort()) === inputKey
3958
+ (s) => stableStringify(s.input) === inputKey
3935
3959
  );
3936
3960
 
3937
3961
  let step;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mcpspec/core",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -31,7 +31,7 @@
31
31
  "expr-eval": "^2.0.2",
32
32
  "handlebars": "^4.7.8",
33
33
  "zod": "^3.22.0",
34
- "@mcpspec/shared": "1.2.0"
34
+ "@mcpspec/shared": "1.2.1"
35
35
  },
36
36
  "devDependencies": {
37
37
  "@types/js-yaml": "^4.0.9",