@cyanheads/mcp-ts-core 0.12.0 → 0.12.2

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 (129) hide show
  1. package/AGENTS.md +7 -3
  2. package/CLAUDE.md +7 -3
  3. package/README.md +1 -1
  4. package/changelog/0.12.x/0.12.1.md +26 -0
  5. package/changelog/0.12.x/0.12.2.md +29 -0
  6. package/dist/config/index.d.ts +9 -0
  7. package/dist/config/index.d.ts.map +1 -1
  8. package/dist/config/index.js +21 -3
  9. package/dist/config/index.js.map +1 -1
  10. package/dist/core/app.d.ts +45 -1
  11. package/dist/core/app.d.ts.map +1 -1
  12. package/dist/core/app.js +18 -3
  13. package/dist/core/app.js.map +1 -1
  14. package/dist/core/index.d.ts +3 -2
  15. package/dist/core/index.d.ts.map +1 -1
  16. package/dist/core/index.js +1 -1
  17. package/dist/core/index.js.map +1 -1
  18. package/dist/core/serverManifest.d.ts +11 -2
  19. package/dist/core/serverManifest.d.ts.map +1 -1
  20. package/dist/core/serverManifest.js +30 -12
  21. package/dist/core/serverManifest.js.map +1 -1
  22. package/dist/core/worker.d.ts.map +1 -1
  23. package/dist/core/worker.js +2 -2
  24. package/dist/core/worker.js.map +1 -1
  25. package/dist/linter/rules/enrichment-rules.d.ts.map +1 -1
  26. package/dist/linter/rules/enrichment-rules.js +5 -2
  27. package/dist/linter/rules/enrichment-rules.js.map +1 -1
  28. package/dist/linter/rules/portability-rules.d.ts +4 -2
  29. package/dist/linter/rules/portability-rules.d.ts.map +1 -1
  30. package/dist/linter/rules/portability-rules.js +33 -4
  31. package/dist/linter/rules/portability-rules.js.map +1 -1
  32. package/dist/linter/rules/schema-rules.d.ts +28 -3
  33. package/dist/linter/rules/schema-rules.d.ts.map +1 -1
  34. package/dist/linter/rules/schema-rules.js +87 -25
  35. package/dist/linter/rules/schema-rules.js.map +1 -1
  36. package/dist/linter/rules/tool-rules.d.ts.map +1 -1
  37. package/dist/linter/rules/tool-rules.js +9 -3
  38. package/dist/linter/rules/tool-rules.js.map +1 -1
  39. package/dist/linter/types.d.ts +2 -1
  40. package/dist/linter/types.d.ts.map +1 -1
  41. package/dist/logs/combined.log +10 -10
  42. package/dist/logs/error.log +6 -6
  43. package/dist/mcp-server/cacheHints.d.ts +35 -0
  44. package/dist/mcp-server/cacheHints.d.ts.map +1 -0
  45. package/dist/mcp-server/cacheHints.js +43 -0
  46. package/dist/mcp-server/cacheHints.js.map +1 -0
  47. package/dist/mcp-server/notifications.d.ts +68 -1
  48. package/dist/mcp-server/notifications.d.ts.map +1 -1
  49. package/dist/mcp-server/notifications.js +67 -0
  50. package/dist/mcp-server/notifications.js.map +1 -1
  51. package/dist/mcp-server/resources/resource-registration.d.ts +2 -2
  52. package/dist/mcp-server/resources/resource-registration.d.ts.map +1 -1
  53. package/dist/mcp-server/resources/resource-registration.js +6 -2
  54. package/dist/mcp-server/resources/resource-registration.js.map +1 -1
  55. package/dist/mcp-server/resources/utils/resourceDefinition.d.ts +14 -1
  56. package/dist/mcp-server/resources/utils/resourceDefinition.d.ts.map +1 -1
  57. package/dist/mcp-server/resources/utils/resourceDefinition.js.map +1 -1
  58. package/dist/mcp-server/resources/utils/resourceHandlerFactory.d.ts +13 -5
  59. package/dist/mcp-server/resources/utils/resourceHandlerFactory.d.ts.map +1 -1
  60. package/dist/mcp-server/resources/utils/resourceHandlerFactory.js +28 -26
  61. package/dist/mcp-server/resources/utils/resourceHandlerFactory.js.map +1 -1
  62. package/dist/mcp-server/server.d.ts +16 -1
  63. package/dist/mcp-server/server.d.ts.map +1 -1
  64. package/dist/mcp-server/server.js +7 -2
  65. package/dist/mcp-server/server.js.map +1 -1
  66. package/dist/mcp-server/tools/tool-registration.d.ts +2 -2
  67. package/dist/mcp-server/tools/tool-registration.d.ts.map +1 -1
  68. package/dist/mcp-server/tools/tool-registration.js +2 -1
  69. package/dist/mcp-server/tools/tool-registration.js.map +1 -1
  70. package/dist/mcp-server/tools/utils/headerParam.d.ts +113 -0
  71. package/dist/mcp-server/tools/utils/headerParam.d.ts.map +1 -0
  72. package/dist/mcp-server/tools/utils/headerParam.js +280 -0
  73. package/dist/mcp-server/tools/utils/headerParam.js.map +1 -0
  74. package/dist/mcp-server/tools/utils/schemaShape.d.ts +27 -0
  75. package/dist/mcp-server/tools/utils/schemaShape.d.ts.map +1 -0
  76. package/dist/mcp-server/tools/utils/schemaShape.js +43 -0
  77. package/dist/mcp-server/tools/utils/schemaShape.js.map +1 -0
  78. package/dist/mcp-server/tools/utils/toolDefinition.d.ts +28 -5
  79. package/dist/mcp-server/tools/utils/toolDefinition.d.ts.map +1 -1
  80. package/dist/mcp-server/tools/utils/toolDefinition.js +22 -3
  81. package/dist/mcp-server/tools/utils/toolDefinition.js.map +1 -1
  82. package/dist/mcp-server/tools/utils/toolHandlerFactory.d.ts +13 -5
  83. package/dist/mcp-server/tools/utils/toolHandlerFactory.d.ts.map +1 -1
  84. package/dist/mcp-server/tools/utils/toolHandlerFactory.js +35 -28
  85. package/dist/mcp-server/tools/utils/toolHandlerFactory.js.map +1 -1
  86. package/dist/mcp-server/transports/http/eventStore.d.ts +57 -0
  87. package/dist/mcp-server/transports/http/eventStore.d.ts.map +1 -0
  88. package/dist/mcp-server/transports/http/eventStore.js +114 -0
  89. package/dist/mcp-server/transports/http/eventStore.js.map +1 -0
  90. package/dist/mcp-server/transports/http/httpServer.d.ts +2 -1
  91. package/dist/mcp-server/transports/http/httpServer.d.ts.map +1 -1
  92. package/dist/mcp-server/transports/http/httpServer.js +2 -2
  93. package/dist/mcp-server/transports/http/httpServer.js.map +1 -1
  94. package/dist/mcp-server/transports/http/httpTransport.d.ts +8 -3
  95. package/dist/mcp-server/transports/http/httpTransport.d.ts.map +1 -1
  96. package/dist/mcp-server/transports/http/httpTransport.js +30 -5
  97. package/dist/mcp-server/transports/http/httpTransport.js.map +1 -1
  98. package/dist/mcp-server/transports/http/landing-page/sections/tools.js +22 -2
  99. package/dist/mcp-server/transports/http/landing-page/sections/tools.js.map +1 -1
  100. package/dist/mcp-server/transports/manager.d.ts +10 -1
  101. package/dist/mcp-server/transports/manager.d.ts.map +1 -1
  102. package/dist/mcp-server/transports/manager.js +6 -2
  103. package/dist/mcp-server/transports/manager.js.map +1 -1
  104. package/dist/mcp-server/types.d.ts +20 -1
  105. package/dist/mcp-server/types.d.ts.map +1 -1
  106. package/dist/mcp-server/types.js +14 -0
  107. package/dist/mcp-server/types.js.map +1 -1
  108. package/dist/testing/fuzz.d.ts +7 -4
  109. package/dist/testing/fuzz.d.ts.map +1 -1
  110. package/dist/testing/fuzz.js +13 -5
  111. package/dist/testing/fuzz.js.map +1 -1
  112. package/dist/utils/internal/performance.d.ts +12 -4
  113. package/dist/utils/internal/performance.d.ts.map +1 -1
  114. package/dist/utils/internal/performance.js +23 -8
  115. package/dist/utils/internal/performance.js.map +1 -1
  116. package/dist/utils/internal/requestContext.d.ts +13 -0
  117. package/dist/utils/internal/requestContext.d.ts.map +1 -1
  118. package/dist/utils/internal/requestContext.js +43 -8
  119. package/dist/utils/internal/requestContext.js.map +1 -1
  120. package/package.json +2 -2
  121. package/skills/add-resource/SKILL.md +31 -1
  122. package/skills/add-tool/SKILL.md +70 -1
  123. package/skills/api-config/SKILL.md +30 -3
  124. package/skills/api-context/SKILL.md +47 -15
  125. package/skills/api-linter/SKILL.md +39 -3
  126. package/skills/api-telemetry/SKILL.md +3 -1
  127. package/skills/api-workers/SKILL.md +9 -1
  128. package/skills/tool-defs-analysis/SKILL.md +15 -5
  129. package/templates/.env.example +4 -0
@@ -2,7 +2,7 @@
2
2
  * @fileoverview Encapsulates the registration of all tool definitions with an McpServer.
3
3
  * @module src/mcp-server/tools/tool-registration
4
4
  */
5
- import type { McpServer } from '@modelcontextprotocol/server';
5
+ import type { McpServer, ServerNotifier } from '@modelcontextprotocol/server';
6
6
  import type { ResourceSubscriptions } from '../../mcp-server/notifications.js';
7
7
  import type { AnyToolDefinition } from '../../mcp-server/tools/utils/toolDefinition.js';
8
8
  import { type HandlerFactoryServices } from '../../mcp-server/tools/utils/toolHandlerFactory.js';
@@ -20,7 +20,7 @@ export declare class ToolRegistry {
20
20
  private readonly registeredNames;
21
21
  constructor(toolDefs: AnyToolDef[], services?: HandlerFactoryServices | undefined);
22
22
  /** Registers all tool definitions with the provided McpServer instance. */
23
- registerAll(server: McpServer, subscriptions?: ResourceSubscriptions): Promise<void>;
23
+ registerAll(server: McpServer, subscriptions?: ResourceSubscriptions, bus?: ServerNotifier): Promise<void>;
24
24
  /** Throws at startup if a tool with the same name was already registered. */
25
25
  private assertUniqueName;
26
26
  private deriveTitleFromName;
@@ -1 +1 @@
1
- {"version":3,"file":"tool-registration.d.ts","sourceRoot":"","sources":["../../../src/mcp-server/tools/tool-registration.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAE,SAAS,EAAgB,MAAM,8BAA8B,CAAC;AAE5E,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AAE3E,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,4CAA4C,CAAC;AACpF,OAAO,EAGL,KAAK,sBAAsB,EAE5B,MAAM,gDAAgD,CAAC;AAMxD;;;;;GAKG;AACH,MAAM,MAAM,UAAU,GAAG,iBAAiB,CAAC;AAE3C,qBAAa,YAAY;IAKrB,OAAO,CAAC,QAAQ;IAChB,OAAO,CAAC,QAAQ,CAAC;IALnB,oEAAoE;IACpE,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAqB;IAErD,YACU,QAAQ,EAAE,UAAU,EAAE,EACtB,QAAQ,CAAC,EAAE,sBAAsB,YAAA,EACvC;IAEJ,2EAA2E;IAC9D,WAAW,CACtB,MAAM,EAAE,SAAS,EACjB,aAAa,CAAC,EAAE,qBAAqB,GACpC,OAAO,CAAC,IAAI,CAAC,CA6Cf;IAED,6EAA6E;IAC7E,OAAO,CAAC,gBAAgB;IAUxB,OAAO,CAAC,mBAAmB;IAI3B;;;OAGG;YACW,YAAY;CAiD3B"}
1
+ {"version":3,"file":"tool-registration.d.ts","sourceRoot":"","sources":["../../../src/mcp-server/tools/tool-registration.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAgB,MAAM,8BAA8B,CAAC;AAE5F,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AAE3E,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,4CAA4C,CAAC;AACpF,OAAO,EAGL,KAAK,sBAAsB,EAE5B,MAAM,gDAAgD,CAAC;AAMxD;;;;;GAKG;AACH,MAAM,MAAM,UAAU,GAAG,iBAAiB,CAAC;AAE3C,qBAAa,YAAY;IAKrB,OAAO,CAAC,QAAQ;IAChB,OAAO,CAAC,QAAQ,CAAC;IALnB,oEAAoE;IACpE,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAqB;IAErD,YACU,QAAQ,EAAE,UAAU,EAAE,EACtB,QAAQ,CAAC,EAAE,sBAAsB,YAAA,EACvC;IAEJ,2EAA2E;IAC9D,WAAW,CACtB,MAAM,EAAE,SAAS,EACjB,aAAa,CAAC,EAAE,qBAAqB,EACrC,GAAG,CAAC,EAAE,cAAc,GACnB,OAAO,CAAC,IAAI,CAAC,CA8Cf;IAED,6EAA6E;IAC7E,OAAO,CAAC,gBAAgB;IAUxB,OAAO,CAAC,mBAAmB;IAI3B;;;OAGG;YACW,YAAY;CAiD3B"}
@@ -14,7 +14,7 @@ export class ToolRegistry {
14
14
  this.services = services;
15
15
  }
16
16
  /** Registers all tool definitions with the provided McpServer instance. */
17
- async registerAll(server, subscriptions) {
17
+ async registerAll(server, subscriptions, bus) {
18
18
  // Reset per-server uniqueness tracking — registries are shared across
19
19
  // per-request McpServer instances under HTTP serving.
20
20
  this.registeredNames.clear();
@@ -27,6 +27,7 @@ export class ToolRegistry {
27
27
  notifyResourceListChanged: () => server.sendResourceListChanged(),
28
28
  notifyToolListChanged: () => server.sendToolListChanged(),
29
29
  ...(subscriptions && { subscriptions }),
30
+ ...(bus && { bus }),
30
31
  };
31
32
  const context = requestContextService.createRequestContext({
32
33
  operation: 'ToolRegistry.registerAll',
@@ -1 +1 @@
1
- {"version":3,"file":"tool-registration.js","sourceRoot":"","sources":["../../../src/mcp-server/tools/tool-registration.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,mBAAmB,EAAE,MAAM,2CAA2C,CAAC;AAEhF,OAAO,EACL,sBAAsB,EACtB,iBAAiB,GAGlB,MAAM,gDAAgD,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,gDAAgD,CAAC;AAC9E,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AACpD,OAAO,EAAE,qBAAqB,EAAE,MAAM,oCAAoC,CAAC;AAU3E,MAAM,OAAO,YAAY;IAKb,QAAQ;IACR,QAAQ;IALlB,oEAAoE;IACnD,eAAe,GAAG,IAAI,GAAG,EAAU,CAAC;IAErD,YACU,QAAsB,EACtB,QAAiC;wBADjC,QAAQ;wBACR,QAAQ;IACf,CAAC;IAEJ,2EAA2E;IACpE,KAAK,CAAC,WAAW,CACtB,MAAiB,EACjB,aAAqC;QAErC,sEAAsE;QACtE,sDAAsD;QACtD,IAAI,CAAC,eAAe,CAAC,KAAK,EAAE,CAAC;QAE7B,4EAA4E;QAC5E,0EAA0E;QAC1E,yEAAyE;QACzE,mEAAmE;QACnE,MAAM,SAAS,GAAqB;YAClC,uBAAuB,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,qBAAqB,EAAE;YAC7D,yBAAyB,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,uBAAuB,EAAE;YACjE,qBAAqB,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,mBAAmB,EAAE;YACzD,GAAG,CAAC,aAAa,IAAI,EAAE,aAAa,EAAE,CAAC;SACxC,CAAC;QAEF,MAAM,OAAO,GAAG,q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AAE,IAAI,CAAC,WAAW,EAAE,CAAC;gBAC1D,GAAG,CAAC,IAAI,CAAC,KAAK,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC;aACzC,EACD,OAA0C,CAC3C,CAAC;YAEF,MAAM,CAAC,KAAK,CAAC,SAAS,IAAI,CAAC,IAAI,4BAA4B,EAAE,mBAAmB,CAAC,CAAC;QACpF,CAAC,EACD;YACE,SAAS,EAAE,mBAAmB,IAAI,CAAC,IAAI,EAAE;YACzC,OAAO,EAAE,mBAAmB;YAC5B,SAAS,EAAE,gBAAgB,CAAC,oBAAoB;YAChD,QAAQ,EAAE,IAAI;SACf,CACF,CAAC;IACJ,CAAC;CACF"}
1
+ {"version":3,"file":"tool-registration.js","sourceRoot":"","sources":["../../../src/mcp-server/tools/tool-registration.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,mBAAmB,EAAE,MAAM,2CAA2C,CAAC;AAEhF,OAAO,EACL,sBAAsB,EACtB,iBAAiB,GAGlB,MAAM,gDAAgD,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,gDAAgD,CAAC;AAC9E,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AACpD,OAAO,EAAE,qBAAqB,EAAE,MAAM,oCAAoC,CAAC;AAU3E,MAAM,OAAO,YAAY;IAKb,QAAQ;IACR,QAAQ;IALlB,oEAAoE;IACnD,eAAe,GAAG,IAAI,GAAG,EAAU,CAAC;IAErD,YACU,QAAsB,EACtB,QAAiC;wBADjC,QAAQ;wBACR,QAAQ;IACf,CAAC;IAEJ,2EAA2E;IACpE,KAAK,CAAC,WAAW,CACtB,MAAiB,EACjB,aAAqC,EACrC,GAAoB;QAEpB,sEAAsE;QACtE,sDAAsD;QACtD,IAAI,CAAC,eAAe,CAAC,KAAK,EAAE,CAAC;QAE7B,4EAA4E;QAC5E,0EAA0E;QAC1E,y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,KAAK,GAAG,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,WAAW,EAAE,KAAK,IAAI,IAAI,CAAC,mBAAmB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAE3F,sFAAsF;YACtF,MAAM,CAAC,YAAY,CACjB,IAAI,CAAC,IAAI,EACT;gBACE,KAAK;gBACL,WAAW,EAAE,IAAI,CAAC,WAAW;gBAC7B,WAAW,EAAE,IAAI,CAAC,KAAK;gBACvB,YAAY,EAAE,sBAAsB,CAAC,IAAI,CAAC;gBAC1C,GAAG,CAAC,IAAI,CAAC,WAAW,IAAI,EAAE,WAAW,EAAE,IAAI,CAAC,WAAW,EAAE,CAAC;gBAC1D,GAAG,CAAC,IAAI,CAAC,KAAK,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC;aACzC,EACD,OAA0C,CAC3C,CAAC;YAEF,MAAM,CAAC,KAAK,CAAC,SAAS,IAAI,CAAC,IAAI,4BAA4B,EAAE,mBAAmB,CAAC,CAAC;QACpF,CAAC,EACD;YACE,SAAS,EAAE,mBAAmB,IAAI,CAAC,IAAI,EAAE;YACzC,OAAO,EAAE,mBAAmB;YAC5B,SAAS,EAAE,gBAAgB,CAAC,oBAAoB;YAChD,QAAQ,EAAE,IAAI;SACf,CACF,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,113 @@
1
+ /**
2
+ * @fileoverview `x-mcp-header` input designation (protocol revision 2026-07-28).
3
+ *
4
+ * A tool may designate an input property with `x-mcp-header: "<Name>"`, which
5
+ * makes the value ride an `Mcp-Param-<Name>` request header alongside the
6
+ * JSON-RPC body so an intermediary can read it without parsing the body. It is
7
+ * a mirroring/attestation mechanism, not a relocation: when the body carries a
8
+ * value for a designated property the matching header MUST be present and
9
+ * decode equal, and the handler still reads its argument from the body.
10
+ *
11
+ * `headerParam()` attaches the annotation via Zod `.meta()`, which passes
12
+ * through to the emitted JSON Schema verbatim — the emission seam needs no
13
+ * interception.
14
+ *
15
+ * The spec places five constraints on a declaration, and the SDK enforces them
16
+ * with a `console.warn` rather than a rejection: an invalid declaration still
17
+ * registers and the tool is then silently dropped by conforming Streamable HTTP
18
+ * clients. {@link assertHeaderDesignations} runs the same scan at definition
19
+ * time so the failure is a loud startup error instead. To stay in lockstep with
20
+ * the runtime it targets, the scan here evaluates the *emitted JSON Schema*
21
+ * — the same bytes the SDK scans — rather than Zod internals, and mirrors the
22
+ * SDK's checks, their order, and its first-fault-wins short-circuit.
23
+ *
24
+ * @module src/mcp-server/tools/utils/headerParam
25
+ */
26
+ import type { ZodType } from 'zod';
27
+ /** The JSON Schema extension key a designated input property carries. */
28
+ export declare const X_MCP_HEADER_KEY = "x-mcp-header";
29
+ /**
30
+ * One step of the walk from the schema root to a designation: a `properties`
31
+ * key, or a descent through a subschema keyword (`label` names the branch when
32
+ * the keyword carries several).
33
+ */
34
+ export type DesignationStep = {
35
+ readonly key: string;
36
+ readonly kind: 'property';
37
+ } | {
38
+ readonly keyword: string;
39
+ readonly kind: 'branch';
40
+ readonly label?: number | string;
41
+ };
42
+ /** A validated `x-mcp-header` designation found on an emitted input schema. */
43
+ export interface HeaderDesignation {
44
+ /** The declared header name — the wire header is `Mcp-Param-<headerName>`. */
45
+ readonly headerName: string;
46
+ /** Path from the schema root to the designated property. */
47
+ readonly path: readonly DesignationStep[];
48
+ /** The property's emitted JSON Schema `type`. */
49
+ readonly type: string;
50
+ }
51
+ /**
52
+ * Outcome of scanning an emitted input schema. Invalid carries the first
53
+ * violated constraint and where it was found — the SDK stops at the first
54
+ * fault too, so reporting more would be a divergence, not a courtesy.
55
+ */
56
+ export type HeaderDesignationScan = {
57
+ readonly designations: readonly HeaderDesignation[];
58
+ readonly valid: true;
59
+ } | {
60
+ readonly path: readonly DesignationStep[];
61
+ readonly reason: string;
62
+ readonly valid: false;
63
+ };
64
+ /**
65
+ * Designates a tool input property as an `x-mcp-header` parameter.
66
+ *
67
+ * The emitted property carries `"x-mcp-header": "<headerName>"` and nothing
68
+ * else about the field changes — description, type, validation, and
69
+ * requiredness are untouched. The wire header is `Mcp-Param-<headerName>`.
70
+ *
71
+ * Returns the same schema type, so it composes in either direction:
72
+ * `headerParam(z.string(), 'Region').describe('…')` and
73
+ * `headerParam(z.string().describe('…'), 'Region')` are equivalent.
74
+ *
75
+ * Only a primitive-typed property statically reachable through a chain of
76
+ * `properties` keys may be designated; {@link assertHeaderDesignations} — run
77
+ * by `tool()` — rejects anything else at definition time.
78
+ *
79
+ * @example
80
+ * ```ts
81
+ * input: z.object({
82
+ * region: headerParam(z.string(), 'Region').describe('Deployment region.'),
83
+ * })
84
+ * ```
85
+ */
86
+ export declare function headerParam<TSchema extends ZodType>(schema: TSchema, headerName: string): TSchema;
87
+ /**
88
+ * Scans a tool's input root for `x-mcp-header` declarations and validates every
89
+ * constraint the spec places on them.
90
+ *
91
+ * Evaluates the *emitted JSON Schema* — the same bytes the SDK scans — so a
92
+ * verdict here is the SDK's verdict. Returns `undefined` when the schema cannot
93
+ * be converted to JSON Schema at all: that is `schema-serializable`'s finding
94
+ * and a hard SDK failure at registration, and the SDK swallows the same
95
+ * conversion error around its own scan rather than reporting it twice.
96
+ *
97
+ * The walk descends `properties` at any depth (the spec's "any nesting depth"
98
+ * clause) and visits every excluded position too, with reachability cleared, so
99
+ * a designation found there fails rather than being missed.
100
+ */
101
+ export declare function scanHeaderDesignations(input: unknown): HeaderDesignationScan | undefined;
102
+ /**
103
+ * Renders a designation path in the linter's path vocabulary — `.key` for a
104
+ * property, `[]`/`[i]` for array positions, `|i` for a composition branch,
105
+ * `.<key>` for an `additionalProperties` value, `.<keyword>` for anything else.
106
+ */
107
+ export declare function formatDesignationPath(path: readonly DesignationStep[], root: string): string;
108
+ /**
109
+ * Throws when a tool's input schema carries an invalid `x-mcp-header`
110
+ * designation, naming the field path and the violated constraint.
111
+ */
112
+ export declare function assertHeaderDesignations(toolName: string, input: unknown): void;
113
+ //# sourceMappingURL=headerParam.d.ts.map
@@ -0,0 +1 @@
1
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AG,OAAO,CAEjG;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,OAAO,GAAG,qBAAqB,GAAG,SAAS,CAIxF;AAqGD;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,SAAS,eAAe,EAAE,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAE5F;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,IAAI,CAe/E"}
@@ -0,0 +1,280 @@
1
+ /**
2
+ * @fileoverview `x-mcp-header` input designation (protocol revision 2026-07-28).
3
+ *
4
+ * A tool may designate an input property with `x-mcp-header: "<Name>"`, which
5
+ * makes the value ride an `Mcp-Param-<Name>` request header alongside the
6
+ * JSON-RPC body so an intermediary can read it without parsing the body. It is
7
+ * a mirroring/attestation mechanism, not a relocation: when the body carries a
8
+ * value for a designated property the matching header MUST be present and
9
+ * decode equal, and the handler still reads its argument from the body.
10
+ *
11
+ * `headerParam()` attaches the annotation via Zod `.meta()`, which passes
12
+ * through to the emitted JSON Schema verbatim — the emission seam needs no
13
+ * interception.
14
+ *
15
+ * The spec places five constraints on a declaration, and the SDK enforces them
16
+ * with a `console.warn` rather than a rejection: an invalid declaration still
17
+ * registers and the tool is then silently dropped by conforming Streamable HTTP
18
+ * clients. {@link assertHeaderDesignations} runs the same scan at definition
19
+ * time so the failure is a loud startup error instead. To stay in lockstep with
20
+ * the runtime it targets, the scan here evaluates the *emitted JSON Schema*
21
+ * — the same bytes the SDK scans — rather than Zod internals, and mirrors the
22
+ * SDK's checks, their order, and its first-fault-wins short-circuit.
23
+ *
24
+ * @module src/mcp-server/tools/utils/headerParam
25
+ */
26
+ import { toJSONSchema } from 'zod/v4/core';
27
+ import { isDiscriminatedUnionSchema } from './schemaShape.js';
28
+ /** The JSON Schema extension key a designated input property carries. */
29
+ export const X_MCP_HEADER_KEY = 'x-mcp-header';
30
+ /**
31
+ * RFC 9110 §5.1 `token` syntax (`1*tchar`). Rejects empty, space, control
32
+ * characters (including CR/LF), and the HTTP delimiters.
33
+ */
34
+ const RFC9110_TOKEN = /^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/;
35
+ /**
36
+ * Emitted `type` values a designation may sit on.
37
+ *
38
+ * The spec names `string`, `integer`, and `boolean`; the SDK release this
39
+ * framework targets also accepts `number` (its own source comment tracks the
40
+ * discrepancy against the conformance referee). Matching the runtime is the
41
+ * point of this scan — a rule that hard-rejected `number` would fail a
42
+ * declaration the SDK accepts.
43
+ */
44
+ const PERMITTED_TYPES = new Set(['boolean', 'integer', 'number', 'string']);
45
+ /**
46
+ * JSON Schema keywords the static-reachability constraint excludes from the
47
+ * `properties`-only chain. A designation found under any of them invalidates
48
+ * the whole tool definition, so the walk visits them specifically to fail them.
49
+ */
50
+ const NON_REACHABLE_SUBSCHEMA_KEYWORDS = [
51
+ 'items',
52
+ 'prefixItems',
53
+ 'contains',
54
+ 'additionalProperties',
55
+ 'unevaluatedProperties',
56
+ 'unevaluatedItems',
57
+ 'propertyNames',
58
+ 'patternProperties',
59
+ 'dependentSchemas',
60
+ 'oneOf',
61
+ 'anyOf',
62
+ 'allOf',
63
+ 'not',
64
+ 'if',
65
+ 'then',
66
+ 'else',
67
+ '$defs',
68
+ 'definitions',
69
+ ];
70
+ /**
71
+ * Subschema-carrying keywords whose value is a `name → subschema` map rather
72
+ * than a single subschema or an array of them.
73
+ */
74
+ const OBJECT_VALUED_SUBSCHEMA_KEYWORDS = new Set([
75
+ 'patternProperties',
76
+ 'dependentSchemas',
77
+ '$defs',
78
+ 'definitions',
79
+ ]);
80
+ /**
81
+ * Designates a tool input property as an `x-mcp-header` parameter.
82
+ *
83
+ * The emitted property carries `"x-mcp-header": "<headerName>"` and nothing
84
+ * else about the field changes — description, type, validation, and
85
+ * requiredness are untouched. The wire header is `Mcp-Param-<headerName>`.
86
+ *
87
+ * Returns the same schema type, so it composes in either direction:
88
+ * `headerParam(z.string(), 'Region').describe('…')` and
89
+ * `headerParam(z.string().describe('…'), 'Region')` are equivalent.
90
+ *
91
+ * Only a primitive-typed property statically reachable through a chain of
92
+ * `properties` keys may be designated; {@link assertHeaderDesignations} — run
93
+ * by `tool()` — rejects anything else at definition time.
94
+ *
95
+ * @example
96
+ * ```ts
97
+ * input: z.object({
98
+ * region: headerParam(z.string(), 'Region').describe('Deployment region.'),
99
+ * })
100
+ * ```
101
+ */
102
+ export function headerParam(schema, headerName) {
103
+ return schema.meta({ [X_MCP_HEADER_KEY]: headerName });
104
+ }
105
+ /**
106
+ * Scans a tool's input root for `x-mcp-header` declarations and validates every
107
+ * constraint the spec places on them.
108
+ *
109
+ * Evaluates the *emitted JSON Schema* — the same bytes the SDK scans — so a
110
+ * verdict here is the SDK's verdict. Returns `undefined` when the schema cannot
111
+ * be converted to JSON Schema at all: that is `schema-serializable`'s finding
112
+ * and a hard SDK failure at registration, and the SDK swallows the same
113
+ * conversion error around its own scan rather than reporting it twice.
114
+ *
115
+ * The walk descends `properties` at any depth (the spec's "any nesting depth"
116
+ * clause) and visits every excluded position too, with reachability cleared, so
117
+ * a designation found there fails rather than being missed.
118
+ */
119
+ export function scanHeaderDesignations(input) {
120
+ const inputSchema = emitInputJsonSchema(input);
121
+ if (inputSchema === undefined)
122
+ return undefined;
123
+ return scanEmitted(inputSchema);
124
+ }
125
+ /** The constraint walk itself, over an already-emitted JSON Schema. */
126
+ function scanEmitted(inputSchema) {
127
+ const designations = [];
128
+ const seenLower = new Map();
129
+ const validateDeclaration = (schema, path, reachable) => {
130
+ if (!reachable || path.length === 0) {
131
+ return {
132
+ path,
133
+ reason: 'x-mcp-header is only permitted on a property statically reachable through a chain of ' +
134
+ "'properties' keys — never on the schema root, and never under items, " +
135
+ 'additionalProperties, oneOf/anyOf/allOf/not, if/then/else, patternProperties, ' +
136
+ 'dependentSchemas, propertyNames, or a $defs target.',
137
+ };
138
+ }
139
+ const raw = schema[X_MCP_HEADER_KEY];
140
+ if (typeof raw !== 'string' || raw.length === 0) {
141
+ return { path, reason: 'x-mcp-header must be a non-empty string.' };
142
+ }
143
+ if (!RFC9110_TOKEN.test(raw)) {
144
+ return {
145
+ path,
146
+ reason: `x-mcp-header '${raw}' is not a valid RFC 9110 token — no spaces, control ` +
147
+ 'characters, or HTTP delimiters.',
148
+ };
149
+ }
150
+ const type = typeof schema.type === 'string' ? schema.type : undefined;
151
+ if (type === undefined || !PERMITTED_TYPES.has(type)) {
152
+ return {
153
+ path,
154
+ reason: 'x-mcp-header is only permitted on a primitive-typed property (string, integer, ' +
155
+ `number, boolean); this property emits type ${type ?? '<none>'}.`,
156
+ };
157
+ }
158
+ const lower = raw.toLowerCase();
159
+ const prior = seenLower.get(lower);
160
+ if (prior !== undefined) {
161
+ return {
162
+ path,
163
+ reason: `x-mcp-header '${raw}' is not case-insensitively unique — '${prior}' is already ` +
164
+ 'declared elsewhere in this schema.',
165
+ };
166
+ }
167
+ seenLower.set(lower, raw);
168
+ designations.push({ headerName: raw, path, type });
169
+ return undefined;
170
+ };
171
+ const visit = (node, path, reachable) => {
172
+ if (node === null || typeof node !== 'object')
173
+ return undefined;
174
+ const schema = node;
175
+ if (X_MCP_HEADER_KEY in schema) {
176
+ const fault = validateDeclaration(schema, path, reachable);
177
+ if (fault)
178
+ return fault;
179
+ }
180
+ const properties = schema.properties;
181
+ if (properties !== null && typeof properties === 'object') {
182
+ for (const [key, child] of Object.entries(properties)) {
183
+ const fault = visit(child, [...path, { key, kind: 'property' }], reachable);
184
+ if (fault)
185
+ return fault;
186
+ }
187
+ }
188
+ for (const keyword of NON_REACHABLE_SUBSCHEMA_KEYWORDS) {
189
+ const sub = schema[keyword];
190
+ if (sub === undefined)
191
+ continue;
192
+ for (const [label, branch] of branchesOf(keyword, sub)) {
193
+ const step = label === undefined ? { keyword, kind: 'branch' } : { keyword, kind: 'branch', label };
194
+ const fault = visit(branch, [...path, step], false);
195
+ if (fault)
196
+ return fault;
197
+ }
198
+ }
199
+ return undefined;
200
+ };
201
+ const fault = visit(inputSchema, [], true);
202
+ return fault ? { ...fault, valid: false } : { designations, valid: true };
203
+ }
204
+ /**
205
+ * Renders a designation path in the linter's path vocabulary — `.key` for a
206
+ * property, `[]`/`[i]` for array positions, `|i` for a composition branch,
207
+ * `.<key>` for an `additionalProperties` value, `.<keyword>` for anything else.
208
+ */
209
+ export function formatDesignationPath(path, root) {
210
+ return path.reduce((rendered, step) => rendered + formatStep(step), root);
211
+ }
212
+ /**
213
+ * Throws when a tool's input schema carries an invalid `x-mcp-header`
214
+ * designation, naming the field path and the violated constraint.
215
+ */
216
+ export function assertHeaderDesignations(toolName, input) {
217
+ const scan = scanHeaderDesignations(input);
218
+ if (scan === undefined || scan.valid)
219
+ return;
220
+ const unionNote = isDiscriminatedUnionSchema(input)
221
+ ? " A discriminated-union input root advertises 'oneOf' at the schema root, so every field " +
222
+ 'lives inside a branch — no field of a union-input tool can be designated.'
223
+ : '';
224
+ throw new Error(`Tool '${toolName}' declares an invalid x-mcp-header designation at ` +
225
+ `${formatDesignationPath(scan.path, 'input')}: ${scan.reason}${unionNote} ` +
226
+ 'The MCP SDK only warns about this and registers the tool anyway, leaving conforming ' +
227
+ 'Streamable HTTP clients to drop it from tools/list — so it is rejected here instead.');
228
+ }
229
+ /**
230
+ * The JSON Schema the SDK scans for a tool's input: the `io: 'input'`
231
+ * draft-2020-12 conversion with `type: 'object'` stamped on the root (a
232
+ * discriminated union emits `oneOf` with no root `type`). Reproduced verbatim
233
+ * so the scanned bytes are the SDK's rather than a near-copy.
234
+ */
235
+ function emitInputJsonSchema(input) {
236
+ try {
237
+ const emitted = toJSONSchema(input, {
238
+ io: 'input',
239
+ target: 'draft-2020-12',
240
+ });
241
+ return { type: 'object', ...emitted };
242
+ }
243
+ catch {
244
+ return undefined;
245
+ }
246
+ }
247
+ /**
248
+ * The subschemas a non-reachable keyword carries, each paired with the label
249
+ * that names it: an index for an array-valued keyword, a key for a map-valued
250
+ * one, `undefined` for a single subschema.
251
+ */
252
+ function branchesOf(keyword, sub) {
253
+ if (Array.isArray(sub))
254
+ return sub.map((branch, index) => [index, branch]);
255
+ if (sub !== null && typeof sub === 'object' && OBJECT_VALUED_SUBSCHEMA_KEYWORDS.has(keyword)) {
256
+ return Object.entries(sub);
257
+ }
258
+ return [[undefined, sub]];
259
+ }
260
+ /** Renders one path step. See {@link formatDesignationPath}. */
261
+ function formatStep(step) {
262
+ if (step.kind === 'property')
263
+ return `.${step.key}`;
264
+ switch (step.keyword) {
265
+ case 'allOf':
266
+ case 'anyOf':
267
+ case 'oneOf':
268
+ return `|${step.label}`;
269
+ case 'items':
270
+ return step.label === undefined ? '[]' : `[${step.label}]`;
271
+ case 'prefixItems':
272
+ return `[${step.label}]`;
273
+ case 'additionalProperties':
274
+ case 'unevaluatedProperties':
275
+ return '.<key>';
276
+ default:
277
+ return step.label === undefined ? `.<${step.keyword}>` : `.<${step.keyword}:${step.label}>`;
278
+ }
279
+ }
280
+ //# sourceMappingURL=headerParam.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"headerParam.js","sourceRoot":"","sources":["../../../../src/mcp-server/tools/utils/headerParam.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAGH,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,OAAO,EAAE,0BAA0B,EAAE,MAAM,kBAAkB,CAAC;AAE9D,yEAAyE;AACzE,MAAM,CAAC,MAAM,gBAAgB,GAAG,cAAc,CAAC;AAE/C;;;GAGG;AACH,MAAM,aAAa,GAAG,gCAAgC,CAAC;AAEvD;;;;;;;;GAQG;AACH,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC,CAAC,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC;AAE5E;;;;GAIG;AACH,MAAM,gCAAgC,GAAG;IACvC,OAAO;IACP,aAAa;IACb,UAAU;IACV,sBAAsB;IACtB,uBAAuB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;YACE,OAAO,IAAI,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,OAAO,GAAG,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,KAAK,GAAG,CAAC;IAChG,CAAC;AACH,CAAC"}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * @fileoverview Runtime shape checks for the Zod roots a tool definition may
3
+ * declare. Zod 4 tags every schema with `_zod.def.type`, and a discriminated
4
+ * union tags as `'union'` like any other — the discriminator on its `def` is
5
+ * what separates the two. Kept in one place so the definition builder, the
6
+ * server manifest, and the linter agree on what a union root is.
7
+ * @module src/mcp-server/tools/utils/schemaShape
8
+ */
9
+ import type { ZodDiscriminatedUnion, ZodObject, ZodRawShape } from 'zod';
10
+ /** True when `value` is a `z.object()`. */
11
+ export declare function isZodObjectSchema(value: unknown): value is ZodObject<ZodRawShape>;
12
+ /**
13
+ * True when `value` is a `z.discriminatedUnion()`.
14
+ *
15
+ * A plain `z.union()` also tags as `'union'` but carries no `discriminator`, so
16
+ * the discriminator string is the distinguishing field. Only the discriminated
17
+ * form is accepted as a tool input root: a bare union gives the model no key to
18
+ * choose a branch by, and every variant's `required` list would apply at once.
19
+ */
20
+ export declare function isDiscriminatedUnionSchema(value: unknown): value is ZodDiscriminatedUnion<readonly ZodObject<ZodRawShape>[]>;
21
+ /**
22
+ * The object variants of a tool input root: the union's options, or the single
23
+ * object itself. Empty when the schema is neither — callers that lint or read
24
+ * shapes then have nothing to walk rather than a partial view.
25
+ */
26
+ export declare function inputVariants(schema: unknown): readonly ZodObject<ZodRawShape>[];
27
+ //# sourceMappingURL=schemaShape.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schemaShape.d.ts","sourceRoot":"","sources":["../../../../src/mcp-server/tools/utils/schemaShape.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,qBAAqB,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,KAAK,CAAC;AAOzE,2CAA2C;AAC3C,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,SAAS,CAAC,WAAW,CAAC,CAGjF;AAED;;;;;;;GAOG;AACH,wBAAgB,0BAA0B,CACxC,KAAK,EAAE,OAAO,GACb,KAAK,IAAI,qBAAqB,CAAC,SAAS,SAAS,CAAC,WAAW,CAAC,EAAE,CAAC,CAInE;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,OAAO,GAAG,SAAS,SAAS,CAAC,WAAW,CAAC,EAAE,CAQhF"}
@@ -0,0 +1,43 @@
1
+ /**
2
+ * @fileoverview Runtime shape checks for the Zod roots a tool definition may
3
+ * declare. Zod 4 tags every schema with `_zod.def.type`, and a discriminated
4
+ * union tags as `'union'` like any other — the discriminator on its `def` is
5
+ * what separates the two. Kept in one place so the definition builder, the
6
+ * server manifest, and the linter agree on what a union root is.
7
+ * @module src/mcp-server/tools/utils/schemaShape
8
+ */
9
+ /** True when `value` is a `z.object()`. */
10
+ export function isZodObjectSchema(value) {
11
+ if (!value || typeof value !== 'object')
12
+ return false;
13
+ return value._zod?.def?.type === 'object';
14
+ }
15
+ /**
16
+ * True when `value` is a `z.discriminatedUnion()`.
17
+ *
18
+ * A plain `z.union()` also tags as `'union'` but carries no `discriminator`, so
19
+ * the discriminator string is the distinguishing field. Only the discriminated
20
+ * form is accepted as a tool input root: a bare union gives the model no key to
21
+ * choose a branch by, and every variant's `required` list would apply at once.
22
+ */
23
+ export function isDiscriminatedUnionSchema(value) {
24
+ if (!value || typeof value !== 'object')
25
+ return false;
26
+ const def = value._zod?.def;
27
+ return def?.type === 'union' && typeof def.discriminator === 'string';
28
+ }
29
+ /**
30
+ * The object variants of a tool input root: the union's options, or the single
31
+ * object itself. Empty when the schema is neither — callers that lint or read
32
+ * shapes then have nothing to walk rather than a partial view.
33
+ */
34
+ export function inputVariants(schema) {
35
+ if (isDiscriminatedUnionSchema(schema)) {
36
+ const options = schema.options;
37
+ return Array.isArray(options)
38
+ ? options.filter(isZodObjectSchema)
39
+ : [];
40
+ }
41
+ return isZodObjectSchema(schema) ? [schema] : [];
42
+ }
43
+ //# sourceMappingURL=schemaShape.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schemaShape.js","sourceRoot":"","sources":["../../../../src/mcp-server/tools/utils/schemaShape.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AASH,2CAA2C;AAC3C,MAAM,UAAU,iBAAiB,CAAC,KAAc;IAC9C,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IACtD,OAAQ,KAAsB,CAAC,IAAI,EAAE,GAAG,EAAE,IAAI,KAAK,QAAQ,CAAC;AAC9D,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,0BAA0B,CACxC,KAAc;IAEd,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IACtD,MAAM,GAAG,GAAI,KAAsB,CAAC,IAAI,EAAE,GAAG,CAAC;IAC9C,OAAO,GAAG,EAAE,IAAI,KAAK,OAAO,IAAI,OAAO,GAAG,CAAC,aAAa,KAAK,QAAQ,CAAC;AACxE,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,MAAe;IAC3C,IAAI,0BAA0B,CAAC,MAAM,CAAC,EAAE,CAAC;QACvC,MAAM,OAAO,GAAI,MAAgC,CAAC,OAAO,CAAC;QAC1D,OAAO,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC;YAC3B,CAAC,CAAE,OAAO,CAAC,MAAM,CAAC,iBAAiB,CAA8B;YACjE,CAAC,CAAC,EAAE,CAAC;IACT,CAAC;IACD,OAAO,iBAAiB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AACnD,CAAC"}
@@ -8,10 +8,11 @@
8
8
  * @module src/mcp-server/tools/utils/toolDefinition
9
9
  */
10
10
  import type { ContentBlock } from '@modelcontextprotocol/server';
11
- import type { ZodObject, ZodRawShape, z } from 'zod';
11
+ import { type ZodDiscriminatedUnion, type ZodObject, type ZodRawShape, z } from 'zod';
12
12
  import type { HandlerContext, ReasonOf } from '../../../core/context.js';
13
13
  import type { ErrorContract } from '../../../types-global/errors.js';
14
14
  export { type DisabledMetadata, disabledTool } from './disabled-tool.js';
15
+ export { headerParam } from './headerParam.js';
15
16
  /**
16
17
  * Defines the annotations that provide hints about a tool's behavior.
17
18
  * These are not guarantees but are useful for client-side rendering and decision-making.
@@ -82,6 +83,23 @@ export type EnrichmentTrailerConfig<TEnrich extends ZodRawShape | undefined> = T
82
83
  render?(value: z.infer<TEnrich[K]>): string;
83
84
  };
84
85
  } : never;
86
+ /**
87
+ * What a tool may declare as its `input` root.
88
+ *
89
+ * A `z.object()` is the common shape. A `z.discriminatedUnion()` is the
90
+ * multi-mode shape: mutually exclusive argument sets with a literal
91
+ * discriminator and per-variant required fields. It advertises as
92
+ * `{"type":"object","oneOf":[<branch>, …]}` — branches intact, each carrying
93
+ * its own `required` and `const`-tagged discriminator — with identical bytes on
94
+ * a 2025-11-25 and a 2026-07-28 connection, since the legacy projection
95
+ * inspects `outputSchema` alone.
96
+ *
97
+ * Input roots may be unions; **output roots may not**. The 2025-era projection
98
+ * rewrites a non-object output root to `{ result: <natural> }` and wraps
99
+ * `structuredContent` to match, which would break the success path for every
100
+ * current client. `output` and `enrichment` stay `ZodObject`-only.
101
+ */
102
+ export type ToolInputSchema = ZodDiscriminatedUnion<readonly ZodObject<ZodRawShape>[]> | ZodObject<ZodRawShape>;
85
103
  /**
86
104
  * Represents the complete, self-contained definition of an MCP tool.
87
105
  *
@@ -94,7 +112,7 @@ export type EnrichmentTrailerConfig<TEnrich extends ZodRawShape | undefined> = T
94
112
  * none is declared). Its inferred fields type `ctx.enrich(...)` and are advertised
95
113
  * to clients as part of `outputSchema`.
96
114
  */
97
- export interface ToolDefinition<TInput extends ZodObject<ZodRawShape> = ZodObject<ZodRawShape>, TOutput extends ZodObject<ZodRawShape> = ZodObject<ZodRawShape>, TErrors extends readonly ErrorContract[] | undefined = undefined, TEnrich extends ZodRawShape | undefined = undefined> {
115
+ export interface ToolDefinition<TInput extends ToolInputSchema = ZodObject<ZodRawShape>, TOutput extends ZodObject<ZodRawShape> = ZodObject<ZodRawShape>, TErrors extends readonly ErrorContract[] | undefined = undefined, TEnrich extends ZodRawShape | undefined = undefined> {
98
116
  /** Protocol-level metadata (e.g., MCP Apps extension). */
99
117
  _meta?: Record<string, unknown>;
100
118
  /** UI/behavior hints for clients. */
@@ -193,7 +211,12 @@ export interface ToolDefinition<TInput extends ZodObject<ZodRawShape> = ZodObjec
193
211
  * types remain assignable to the type-erased `AnyToolDefinition` array.
194
212
  */
195
213
  handler(input: z.infer<TInput>, ctx: HandlerContext<ReasonOf<TErrors>, TEnrich>): Promise<z.infer<TOutput>> | z.infer<TOutput>;
196
- /** Zod schema for input validation. All fields need `.describe()`. */
214
+ /**
215
+ * Zod schema for input validation. All fields need `.describe()`.
216
+ *
217
+ * A `z.object()` root, or a `z.discriminatedUnion()` of object variants for a
218
+ * multi-mode tool — see {@link ToolInputSchema}.
219
+ */
197
220
  input: TInput;
198
221
  /** Programmatic unique name (snake_case). */
199
222
  name: string;
@@ -211,7 +234,7 @@ export interface ToolDefinition<TInput extends ZodObject<ZodRawShape> = ZodObjec
211
234
  title?: string;
212
235
  }
213
236
  /** Type-erased union for mixed arrays passed to createApp(). */
214
- export type AnyToolDefinition = ToolDefinition<ZodObject<ZodRawShape>, ZodObject<ZodRawShape>, readonly ErrorContract[] | undefined, ZodRawShape | undefined>;
237
+ export type AnyToolDefinition = ToolDefinition<ToolInputSchema, ZodObject<ZodRawShape>, readonly ErrorContract[] | undefined, ZodRawShape | undefined>;
215
238
  /**
216
239
  * Creates a tool definition with full type inference from Zod schemas.
217
240
  *
@@ -259,5 +282,5 @@ export type AnyToolDefinition = ToolDefinition<ZodObject<ZodRawShape>, ZodObject
259
282
  * });
260
283
  * ```
261
284
  */
262
- export declare function tool<TInput extends ZodObject<ZodRawShape>, TOutput extends ZodObject<ZodRawShape>, const TErrors extends readonly ErrorContract[] | undefined = undefined, const TEnrich extends ZodRawShape | undefined = undefined>(name: string, options: Omit<ToolDefinition<TInput, TOutput, TErrors, TEnrich>, 'name'>): ToolDefinition<TInput, TOutput, TErrors, TEnrich>;
285
+ export declare function tool<TInput extends ToolInputSchema, TOutput extends ZodObject<ZodRawShape>, const TErrors extends readonly ErrorContract[] | undefined = undefined, const TEnrich extends ZodRawShape | undefined = undefined>(name: string, options: Omit<ToolDefinition<TInput, TOutput, TErrors, TEnrich>, 'name'>): ToolDefinition<TInput, TOutput, TErrors, TEnrich>;
263
286
  //# sourceMappingURL=toolDefinition.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"toolDefinition.d.ts","sourceRoot":"","sources":["../../../../src/mcp-server/tools/utils/toolDefinition.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAErD,OAAO,KAAK,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAClE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAE9D,OAAO,EAAE,KAAK,gBAAgB,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEzE;;;;GAIG;AACH,MAAM,WAAW,eAAe;IAC9B;;;;OAIG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B;;;;OAIG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB;;;OAGG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB;;;OAGG;IACH,YAAY,CAAC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