@solidcommerce/mcp-server 2.0.0-alpha.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.
Files changed (268) hide show
  1. package/README.md +74 -0
  2. package/bin/solidcommerce-mcp.js +8 -0
  3. package/dist/audit/auditClient.d.ts +51 -0
  4. package/dist/audit/auditClient.d.ts.map +1 -0
  5. package/dist/audit/auditClient.js +93 -0
  6. package/dist/audit/auditClient.js.map +1 -0
  7. package/dist/auth/apiKey.d.ts +44 -0
  8. package/dist/auth/apiKey.d.ts.map +1 -0
  9. package/dist/auth/apiKey.js +80 -0
  10. package/dist/auth/apiKey.js.map +1 -0
  11. package/dist/auth/oauth.d.ts +108 -0
  12. package/dist/auth/oauth.d.ts.map +1 -0
  13. package/dist/auth/oauth.js +300 -0
  14. package/dist/auth/oauth.js.map +1 -0
  15. package/dist/generator/fromOpenApi.d.ts +54 -0
  16. package/dist/generator/fromOpenApi.d.ts.map +1 -0
  17. package/dist/generator/fromOpenApi.js +411 -0
  18. package/dist/generator/fromOpenApi.js.map +1 -0
  19. package/dist/generator/schemaToZod.d.ts +81 -0
  20. package/dist/generator/schemaToZod.d.ts.map +1 -0
  21. package/dist/generator/schemaToZod.js +277 -0
  22. package/dist/generator/schemaToZod.js.map +1 -0
  23. package/dist/generator/scopeInference.d.ts +26 -0
  24. package/dist/generator/scopeInference.d.ts.map +1 -0
  25. package/dist/generator/scopeInference.js +91 -0
  26. package/dist/generator/scopeInference.js.map +1 -0
  27. package/dist/index.d.ts +2 -0
  28. package/dist/index.d.ts.map +1 -0
  29. package/dist/index.js +106 -0
  30. package/dist/index.js.map +1 -0
  31. package/dist/server/buildServer.d.ts +35 -0
  32. package/dist/server/buildServer.d.ts.map +1 -0
  33. package/dist/server/buildServer.js +104 -0
  34. package/dist/server/buildServer.js.map +1 -0
  35. package/dist/server/dispatcher.d.ts +14 -0
  36. package/dist/server/dispatcher.d.ts.map +1 -0
  37. package/dist/server/dispatcher.js +190 -0
  38. package/dist/server/dispatcher.js.map +1 -0
  39. package/dist/session.d.ts +9 -0
  40. package/dist/session.d.ts.map +1 -0
  41. package/dist/session.js +11 -0
  42. package/dist/session.js.map +1 -0
  43. package/dist/telemetry/hostName.d.ts +26 -0
  44. package/dist/telemetry/hostName.d.ts.map +1 -0
  45. package/dist/telemetry/hostName.js +80 -0
  46. package/dist/telemetry/hostName.js.map +1 -0
  47. package/dist/tools/contract.d.ts +125 -0
  48. package/dist/tools/contract.d.ts.map +1 -0
  49. package/dist/tools/contract.js +101 -0
  50. package/dist/tools/contract.js.map +1 -0
  51. package/dist/tools/foundation/catalog_amazon_items_list.d.ts +4 -0
  52. package/dist/tools/foundation/catalog_amazon_items_list.d.ts.map +1 -0
  53. package/dist/tools/foundation/catalog_amazon_items_list.js +47 -0
  54. package/dist/tools/foundation/catalog_amazon_items_list.js.map +1 -0
  55. package/dist/tools/foundation/catalog_attribute_filters_list.d.ts +4 -0
  56. package/dist/tools/foundation/catalog_attribute_filters_list.d.ts.map +1 -0
  57. package/dist/tools/foundation/catalog_attribute_filters_list.js +47 -0
  58. package/dist/tools/foundation/catalog_attribute_filters_list.js.map +1 -0
  59. package/dist/tools/foundation/catalog_attribute_tags_list.d.ts +4 -0
  60. package/dist/tools/foundation/catalog_attribute_tags_list.d.ts.map +1 -0
  61. package/dist/tools/foundation/catalog_attribute_tags_list.js +47 -0
  62. package/dist/tools/foundation/catalog_attribute_tags_list.js.map +1 -0
  63. package/dist/tools/foundation/catalog_attributes_list.d.ts +4 -0
  64. package/dist/tools/foundation/catalog_attributes_list.d.ts.map +1 -0
  65. package/dist/tools/foundation/catalog_attributes_list.js +57 -0
  66. package/dist/tools/foundation/catalog_attributes_list.js.map +1 -0
  67. package/dist/tools/foundation/catalog_column_views_default_list.d.ts +4 -0
  68. package/dist/tools/foundation/catalog_column_views_default_list.d.ts.map +1 -0
  69. package/dist/tools/foundation/catalog_column_views_default_list.js +47 -0
  70. package/dist/tools/foundation/catalog_column_views_default_list.js.map +1 -0
  71. package/dist/tools/foundation/catalog_column_views_list.d.ts +4 -0
  72. package/dist/tools/foundation/catalog_column_views_list.d.ts.map +1 -0
  73. package/dist/tools/foundation/catalog_column_views_list.js +47 -0
  74. package/dist/tools/foundation/catalog_column_views_list.js.map +1 -0
  75. package/dist/tools/foundation/catalog_ebay_categories_list.d.ts +4 -0
  76. package/dist/tools/foundation/catalog_ebay_categories_list.d.ts.map +1 -0
  77. package/dist/tools/foundation/catalog_ebay_categories_list.js +56 -0
  78. package/dist/tools/foundation/catalog_ebay_categories_list.js.map +1 -0
  79. package/dist/tools/foundation/catalog_ebay_category_specifics_list.d.ts +4 -0
  80. package/dist/tools/foundation/catalog_ebay_category_specifics_list.d.ts.map +1 -0
  81. package/dist/tools/foundation/catalog_ebay_category_specifics_list.js +56 -0
  82. package/dist/tools/foundation/catalog_ebay_category_specifics_list.js.map +1 -0
  83. package/dist/tools/foundation/catalog_ebay_listing_templates_list.d.ts +4 -0
  84. package/dist/tools/foundation/catalog_ebay_listing_templates_list.d.ts.map +1 -0
  85. package/dist/tools/foundation/catalog_ebay_listing_templates_list.js +47 -0
  86. package/dist/tools/foundation/catalog_ebay_listing_templates_list.js.map +1 -0
  87. package/dist/tools/foundation/catalog_ebay_product_search_list.d.ts +4 -0
  88. package/dist/tools/foundation/catalog_ebay_product_search_list.d.ts.map +1 -0
  89. package/dist/tools/foundation/catalog_ebay_product_search_list.js +56 -0
  90. package/dist/tools/foundation/catalog_ebay_product_search_list.js.map +1 -0
  91. package/dist/tools/foundation/catalog_ebay_template_fields_list.d.ts +4 -0
  92. package/dist/tools/foundation/catalog_ebay_template_fields_list.d.ts.map +1 -0
  93. package/dist/tools/foundation/catalog_ebay_template_fields_list.js +47 -0
  94. package/dist/tools/foundation/catalog_ebay_template_fields_list.js.map +1 -0
  95. package/dist/tools/foundation/catalog_ebay_variation_groups_list.d.ts +4 -0
  96. package/dist/tools/foundation/catalog_ebay_variation_groups_list.d.ts.map +1 -0
  97. package/dist/tools/foundation/catalog_ebay_variation_groups_list.js +56 -0
  98. package/dist/tools/foundation/catalog_ebay_variation_groups_list.js.map +1 -0
  99. package/dist/tools/foundation/catalog_inventory_sources_list.d.ts +4 -0
  100. package/dist/tools/foundation/catalog_inventory_sources_list.d.ts.map +1 -0
  101. package/dist/tools/foundation/catalog_inventory_sources_list.js +47 -0
  102. package/dist/tools/foundation/catalog_inventory_sources_list.js.map +1 -0
  103. package/dist/tools/foundation/catalog_listing_rules_list.d.ts +4 -0
  104. package/dist/tools/foundation/catalog_listing_rules_list.d.ts.map +1 -0
  105. package/dist/tools/foundation/catalog_listing_rules_list.js +47 -0
  106. package/dist/tools/foundation/catalog_listing_rules_list.js.map +1 -0
  107. package/dist/tools/foundation/catalog_listing_templates_list.d.ts +4 -0
  108. package/dist/tools/foundation/catalog_listing_templates_list.d.ts.map +1 -0
  109. package/dist/tools/foundation/catalog_listing_templates_list.js +47 -0
  110. package/dist/tools/foundation/catalog_listing_templates_list.js.map +1 -0
  111. package/dist/tools/foundation/catalog_manufacturers_all_list.d.ts +4 -0
  112. package/dist/tools/foundation/catalog_manufacturers_all_list.d.ts.map +1 -0
  113. package/dist/tools/foundation/catalog_manufacturers_all_list.js +47 -0
  114. package/dist/tools/foundation/catalog_manufacturers_all_list.js.map +1 -0
  115. package/dist/tools/foundation/catalog_manufacturers_list.d.ts +4 -0
  116. package/dist/tools/foundation/catalog_manufacturers_list.d.ts.map +1 -0
  117. package/dist/tools/foundation/catalog_manufacturers_list.js +47 -0
  118. package/dist/tools/foundation/catalog_manufacturers_list.js.map +1 -0
  119. package/dist/tools/foundation/catalog_market_lists_list.d.ts +4 -0
  120. package/dist/tools/foundation/catalog_market_lists_list.d.ts.map +1 -0
  121. package/dist/tools/foundation/catalog_market_lists_list.js +47 -0
  122. package/dist/tools/foundation/catalog_market_lists_list.js.map +1 -0
  123. package/dist/tools/foundation/catalog_product_usage_filters_list.d.ts +4 -0
  124. package/dist/tools/foundation/catalog_product_usage_filters_list.d.ts.map +1 -0
  125. package/dist/tools/foundation/catalog_product_usage_filters_list.js +47 -0
  126. package/dist/tools/foundation/catalog_product_usage_filters_list.js.map +1 -0
  127. package/dist/tools/foundation/catalog_product_usage_list.d.ts +4 -0
  128. package/dist/tools/foundation/catalog_product_usage_list.d.ts.map +1 -0
  129. package/dist/tools/foundation/catalog_product_usage_list.js +61 -0
  130. package/dist/tools/foundation/catalog_product_usage_list.js.map +1 -0
  131. package/dist/tools/foundation/catalog_product_usage_totals_list.d.ts +4 -0
  132. package/dist/tools/foundation/catalog_product_usage_totals_list.d.ts.map +1 -0
  133. package/dist/tools/foundation/catalog_product_usage_totals_list.js +58 -0
  134. package/dist/tools/foundation/catalog_product_usage_totals_list.js.map +1 -0
  135. package/dist/tools/foundation/catalog_products_generate_sku_list.d.ts +4 -0
  136. package/dist/tools/foundation/catalog_products_generate_sku_list.d.ts.map +1 -0
  137. package/dist/tools/foundation/catalog_products_generate_sku_list.js +47 -0
  138. package/dist/tools/foundation/catalog_products_generate_sku_list.js.map +1 -0
  139. package/dist/tools/foundation/catalog_products_list.d.ts +4 -0
  140. package/dist/tools/foundation/catalog_products_list.d.ts.map +1 -0
  141. package/dist/tools/foundation/catalog_products_list.js +60 -0
  142. package/dist/tools/foundation/catalog_products_list.js.map +1 -0
  143. package/dist/tools/foundation/catalog_taxonomy_channels_list.d.ts +4 -0
  144. package/dist/tools/foundation/catalog_taxonomy_channels_list.d.ts.map +1 -0
  145. package/dist/tools/foundation/catalog_taxonomy_channels_list.js +47 -0
  146. package/dist/tools/foundation/catalog_taxonomy_channels_list.js.map +1 -0
  147. package/dist/tools/foundation/catalog_taxonomy_mappings_list.d.ts +4 -0
  148. package/dist/tools/foundation/catalog_taxonomy_mappings_list.d.ts.map +1 -0
  149. package/dist/tools/foundation/catalog_taxonomy_mappings_list.js +56 -0
  150. package/dist/tools/foundation/catalog_taxonomy_mappings_list.js.map +1 -0
  151. package/dist/tools/foundation/catalog_taxonomy_product_values_list.d.ts +4 -0
  152. package/dist/tools/foundation/catalog_taxonomy_product_values_list.d.ts.map +1 -0
  153. package/dist/tools/foundation/catalog_taxonomy_product_values_list.js +57 -0
  154. package/dist/tools/foundation/catalog_taxonomy_product_values_list.js.map +1 -0
  155. package/dist/tools/foundation/catalog_tree_list.d.ts +4 -0
  156. package/dist/tools/foundation/catalog_tree_list.d.ts.map +1 -0
  157. package/dist/tools/foundation/catalog_tree_list.js +47 -0
  158. package/dist/tools/foundation/catalog_tree_list.js.map +1 -0
  159. package/dist/tools/foundation/crm_customers_list.d.ts +4 -0
  160. package/dist/tools/foundation/crm_customers_list.d.ts.map +1 -0
  161. package/dist/tools/foundation/crm_customers_list.js +59 -0
  162. package/dist/tools/foundation/crm_customers_list.js.map +1 -0
  163. package/dist/tools/foundation/fulfillment_manifests_list.d.ts +4 -0
  164. package/dist/tools/foundation/fulfillment_manifests_list.d.ts.map +1 -0
  165. package/dist/tools/foundation/fulfillment_manifests_list.js +47 -0
  166. package/dist/tools/foundation/fulfillment_manifests_list.js.map +1 -0
  167. package/dist/tools/foundation/fulfillment_ship_now_addresses_list.d.ts +4 -0
  168. package/dist/tools/foundation/fulfillment_ship_now_addresses_list.d.ts.map +1 -0
  169. package/dist/tools/foundation/fulfillment_ship_now_addresses_list.js +47 -0
  170. package/dist/tools/foundation/fulfillment_ship_now_addresses_list.js.map +1 -0
  171. package/dist/tools/foundation/fulfillment_ship_now_dictionaries_list.d.ts +4 -0
  172. package/dist/tools/foundation/fulfillment_ship_now_dictionaries_list.d.ts.map +1 -0
  173. package/dist/tools/foundation/fulfillment_ship_now_dictionaries_list.js +56 -0
  174. package/dist/tools/foundation/fulfillment_ship_now_dictionaries_list.js.map +1 -0
  175. package/dist/tools/foundation/index.d.ts +8 -0
  176. package/dist/tools/foundation/index.d.ts.map +1 -0
  177. package/dist/tools/foundation/index.js +93 -0
  178. package/dist/tools/foundation/index.js.map +1 -0
  179. package/dist/tools/foundation/inventory_alert_rules_list.d.ts +4 -0
  180. package/dist/tools/foundation/inventory_alert_rules_list.d.ts.map +1 -0
  181. package/dist/tools/foundation/inventory_alert_rules_list.js +47 -0
  182. package/dist/tools/foundation/inventory_alert_rules_list.js.map +1 -0
  183. package/dist/tools/foundation/inventory_alert_settings_list.d.ts +4 -0
  184. package/dist/tools/foundation/inventory_alert_settings_list.d.ts.map +1 -0
  185. package/dist/tools/foundation/inventory_alert_settings_list.js +47 -0
  186. package/dist/tools/foundation/inventory_alert_settings_list.js.map +1 -0
  187. package/dist/tools/foundation/inventory_analytics_alert_count_list.d.ts +4 -0
  188. package/dist/tools/foundation/inventory_analytics_alert_count_list.d.ts.map +1 -0
  189. package/dist/tools/foundation/inventory_analytics_alert_count_list.js +47 -0
  190. package/dist/tools/foundation/inventory_analytics_alert_count_list.js.map +1 -0
  191. package/dist/tools/foundation/inventory_rules_list.d.ts +4 -0
  192. package/dist/tools/foundation/inventory_rules_list.d.ts.map +1 -0
  193. package/dist/tools/foundation/inventory_rules_list.js +47 -0
  194. package/dist/tools/foundation/inventory_rules_list.js.map +1 -0
  195. package/dist/tools/foundation/inventory_rules_periods_list.d.ts +4 -0
  196. package/dist/tools/foundation/inventory_rules_periods_list.d.ts.map +1 -0
  197. package/dist/tools/foundation/inventory_rules_periods_list.js +47 -0
  198. package/dist/tools/foundation/inventory_rules_periods_list.js.map +1 -0
  199. package/dist/tools/foundation/inventory_seasonal_factors_list.d.ts +4 -0
  200. package/dist/tools/foundation/inventory_seasonal_factors_list.d.ts.map +1 -0
  201. package/dist/tools/foundation/inventory_seasonal_factors_list.js +47 -0
  202. package/dist/tools/foundation/inventory_seasonal_factors_list.js.map +1 -0
  203. package/dist/tools/foundation/inventory_warehouses_list.d.ts +4 -0
  204. package/dist/tools/foundation/inventory_warehouses_list.d.ts.map +1 -0
  205. package/dist/tools/foundation/inventory_warehouses_list.js +47 -0
  206. package/dist/tools/foundation/inventory_warehouses_list.js.map +1 -0
  207. package/dist/tools/foundation/listings_dictionary_marketplace_locales_list.d.ts +4 -0
  208. package/dist/tools/foundation/listings_dictionary_marketplace_locales_list.d.ts.map +1 -0
  209. package/dist/tools/foundation/listings_dictionary_marketplace_locales_list.js +56 -0
  210. package/dist/tools/foundation/listings_dictionary_marketplace_locales_list.js.map +1 -0
  211. package/dist/tools/foundation/listings_dictionary_marketplaces_list.d.ts +4 -0
  212. package/dist/tools/foundation/listings_dictionary_marketplaces_list.d.ts.map +1 -0
  213. package/dist/tools/foundation/listings_dictionary_marketplaces_list.js +47 -0
  214. package/dist/tools/foundation/listings_dictionary_marketplaces_list.js.map +1 -0
  215. package/dist/tools/tasks/bulk_update_prices.d.ts +4 -0
  216. package/dist/tools/tasks/bulk_update_prices.d.ts.map +1 -0
  217. package/dist/tools/tasks/bulk_update_prices.js +96 -0
  218. package/dist/tools/tasks/bulk_update_prices.js.map +1 -0
  219. package/dist/tools/tasks/cancel_order_with_reason.d.ts +4 -0
  220. package/dist/tools/tasks/cancel_order_with_reason.d.ts.map +1 -0
  221. package/dist/tools/tasks/cancel_order_with_reason.js +117 -0
  222. package/dist/tools/tasks/cancel_order_with_reason.js.map +1 -0
  223. package/dist/tools/tasks/check_listing_health.d.ts +4 -0
  224. package/dist/tools/tasks/check_listing_health.d.ts.map +1 -0
  225. package/dist/tools/tasks/check_listing_health.js +123 -0
  226. package/dist/tools/tasks/check_listing_health.js.map +1 -0
  227. package/dist/tools/tasks/create_and_submit_purchase_order.d.ts +4 -0
  228. package/dist/tools/tasks/create_and_submit_purchase_order.d.ts.map +1 -0
  229. package/dist/tools/tasks/create_and_submit_purchase_order.js +142 -0
  230. package/dist/tools/tasks/create_and_submit_purchase_order.js.map +1 -0
  231. package/dist/tools/tasks/find_product_by_sku.d.ts +4 -0
  232. package/dist/tools/tasks/find_product_by_sku.d.ts.map +1 -0
  233. package/dist/tools/tasks/find_product_by_sku.js +68 -0
  234. package/dist/tools/tasks/find_product_by_sku.js.map +1 -0
  235. package/dist/tools/tasks/fulfill_order.d.ts +4 -0
  236. package/dist/tools/tasks/fulfill_order.d.ts.map +1 -0
  237. package/dist/tools/tasks/fulfill_order.js +121 -0
  238. package/dist/tools/tasks/fulfill_order.js.map +1 -0
  239. package/dist/tools/tasks/get_inventory_across_warehouses.d.ts +4 -0
  240. package/dist/tools/tasks/get_inventory_across_warehouses.d.ts.map +1 -0
  241. package/dist/tools/tasks/get_inventory_across_warehouses.js +118 -0
  242. package/dist/tools/tasks/get_inventory_across_warehouses.js.map +1 -0
  243. package/dist/tools/tasks/index.d.ts +14 -0
  244. package/dist/tools/tasks/index.d.ts.map +1 -0
  245. package/dist/tools/tasks/index.js +32 -0
  246. package/dist/tools/tasks/index.js.map +1 -0
  247. package/dist/tools/tasks/publish_product_to_channels.d.ts +4 -0
  248. package/dist/tools/tasks/publish_product_to_channels.d.ts.map +1 -0
  249. package/dist/tools/tasks/publish_product_to_channels.js +109 -0
  250. package/dist/tools/tasks/publish_product_to_channels.js.map +1 -0
  251. package/dist/tools/tasks/reply_to_buyer_message.d.ts +4 -0
  252. package/dist/tools/tasks/reply_to_buyer_message.d.ts.map +1 -0
  253. package/dist/tools/tasks/reply_to_buyer_message.js +72 -0
  254. package/dist/tools/tasks/reply_to_buyer_message.js.map +1 -0
  255. package/dist/tools/tasks/reprice_listing.d.ts +4 -0
  256. package/dist/tools/tasks/reprice_listing.d.ts.map +1 -0
  257. package/dist/tools/tasks/reprice_listing.js +74 -0
  258. package/dist/tools/tasks/reprice_listing.js.map +1 -0
  259. package/dist/transports/stdio.d.ts +12 -0
  260. package/dist/transports/stdio.d.ts.map +1 -0
  261. package/dist/transports/stdio.js +30 -0
  262. package/dist/transports/stdio.js.map +1 -0
  263. package/dist/transports/streamableHttp.d.ts +33 -0
  264. package/dist/transports/streamableHttp.d.ts.map +1 -0
  265. package/dist/transports/streamableHttp.js +237 -0
  266. package/dist/transports/streamableHttp.js.map +1 -0
  267. package/package.json +47 -0
  268. package/vendor/openapi.snapshot.json +19887 -0
@@ -0,0 +1,277 @@
1
+ // =============================================================================
2
+ // src/generator/schemaToZod.ts
3
+ // Wave: W6 — Stream A
4
+ //
5
+ // Converts a (subset of) OpenAPI 3.0 schema into Zod, in two complementary
6
+ // modes:
7
+ //
8
+ // 1. `schemaToZodSource(...)` — emits a TypeScript source-code string
9
+ // like `z.object({ id: z.number().int(), label: z.string().optional() })`
10
+ // that gets baked into the generated foundation tool file. This is the
11
+ // hot path: 40 tools × N params each.
12
+ //
13
+ // 2. `paramsToZodObject(...)` / `requestBodyToZodSource(...)` —
14
+ // higher-level helpers that combine path + query + body into the
15
+ // single object schema each tool's `inputSchema` exposes.
16
+ //
17
+ // Design decisions:
18
+ // - We do NOT execute Zod here. We *emit* code that does. This keeps the
19
+ // generator pure (just string assembly) and the runtime tool files
20
+ // self-contained — the SDK schema stays as plain JSON in vendor/.
21
+ // - Unsupported features (oneOf, anyOf, allOf with complex composition,
22
+ // $refs to circular schemas) emit `z.unknown()` with a `// TODO` comment
23
+ // pointing at the schema name. The brief explicitly requests this.
24
+ // - Path parameters are always required (per OpenAPI 3.0 spec), even when
25
+ // the operation forgets the `required: true` flag. We force them.
26
+ // =============================================================================
27
+ const MAX_REF_DEPTH = 6;
28
+ // -----------------------------------------------------------------------------
29
+ // Identifier escaping — we render `z.object({ "weird.key": z.string() })`
30
+ // when the property name isn't a valid JS identifier.
31
+ // -----------------------------------------------------------------------------
32
+ const SAFE_IDENT_RE = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
33
+ function quoteKey(key) {
34
+ if (SAFE_IDENT_RE.test(key))
35
+ return key;
36
+ return JSON.stringify(key);
37
+ }
38
+ function jsLiteral(value) {
39
+ // We only call this on enum values, so primitive types are sufficient.
40
+ if (typeof value === "string")
41
+ return JSON.stringify(value);
42
+ if (typeof value === "number" || typeof value === "boolean")
43
+ return String(value);
44
+ if (value === null)
45
+ return "null";
46
+ return JSON.stringify(value);
47
+ }
48
+ // -----------------------------------------------------------------------------
49
+ // Core: schema → Zod source code
50
+ // -----------------------------------------------------------------------------
51
+ /**
52
+ * Emit a Zod source-code expression for a single OpenAPI schema.
53
+ * Returns just the expression — no leading whitespace, no trailing semicolon.
54
+ *
55
+ * `nullable` and `optional` modifiers are NOT applied here — callers (notably
56
+ * `objectFromProperties`) decide per-field whether to chain `.optional()` /
57
+ * `.nullable()` based on the parent's `required[]` array.
58
+ */
59
+ export function schemaToZodSource(schema, ctx) {
60
+ if (!schema)
61
+ return "z.unknown()";
62
+ const visiting = ctx.visiting ?? [];
63
+ // 1. $ref — resolve once, with cycle protection.
64
+ if (schema.$ref) {
65
+ const refName = stripRefPrefix(schema.$ref);
66
+ if (refName === null) {
67
+ return `z.unknown() /* unresolved ref ${JSON.stringify(schema.$ref)} */`;
68
+ }
69
+ if (visiting.includes(refName) || visiting.length >= MAX_REF_DEPTH) {
70
+ return `z.unknown() /* circular or deep ref: ${refName} */`;
71
+ }
72
+ const target = ctx.components[refName];
73
+ if (!target) {
74
+ return `z.unknown() /* missing schema: ${refName} */`;
75
+ }
76
+ return schemaToZodSource(target, {
77
+ components: ctx.components,
78
+ visiting: [...visiting, refName],
79
+ });
80
+ }
81
+ // 2. Composition keywords — only allOf with simple object merges is
82
+ // supported. oneOf/anyOf with non-trivial branches degrade to unknown.
83
+ if (schema.oneOf && schema.oneOf.length > 0) {
84
+ return `z.unknown() /* oneOf with ${schema.oneOf.length} branches not supported */`;
85
+ }
86
+ if (schema.anyOf && schema.anyOf.length > 0) {
87
+ return `z.unknown() /* anyOf with ${schema.anyOf.length} branches not supported */`;
88
+ }
89
+ if (schema.allOf && schema.allOf.length > 0) {
90
+ // Best-effort: if every branch is an object, merge their properties.
91
+ const merged = mergeAllOfObjects(schema.allOf, ctx);
92
+ if (merged) {
93
+ return schemaToZodSource(merged, ctx);
94
+ }
95
+ return `z.unknown() /* allOf with non-object branches not supported */`;
96
+ }
97
+ // 3. Enum — type-aware string/number enums; bool enums collapse to z.boolean().
98
+ if (schema.enum && schema.enum.length > 0) {
99
+ if (schema.enum.every((v) => typeof v === "string")) {
100
+ const literals = schema.enum.map((v) => JSON.stringify(v)).join(", ");
101
+ return `z.enum([${literals}] as const)`;
102
+ }
103
+ // Mixed / numeric enum — fall back to a union of literals.
104
+ const literals = schema.enum.map((v) => `z.literal(${jsLiteral(v)})`).join(", ");
105
+ return `z.union([${literals}])`;
106
+ }
107
+ // 4. Primitives + arrays + objects.
108
+ switch (schema.type) {
109
+ case "string":
110
+ return stringExpr(schema);
111
+ case "integer":
112
+ return "z.number().int()";
113
+ case "number":
114
+ return "z.number()";
115
+ case "boolean":
116
+ return "z.boolean()";
117
+ case "array":
118
+ return `z.array(${schemaToZodSource(schema.items, ctx)})`;
119
+ case "object":
120
+ if (schema.properties) {
121
+ return objectFromProperties(schema.properties, schema.required ?? [], ctx);
122
+ }
123
+ return "z.record(z.unknown())";
124
+ default:
125
+ // Untyped / freeform — common when a body is `any`.
126
+ if (schema.properties) {
127
+ return objectFromProperties(schema.properties, schema.required ?? [], ctx);
128
+ }
129
+ return "z.unknown()";
130
+ }
131
+ }
132
+ function stringExpr(schema) {
133
+ // Light format hints — date-time gets z.string().datetime(), uuid gets uuid.
134
+ if (schema.format === "date-time")
135
+ return "z.string().datetime()";
136
+ if (schema.format === "uuid")
137
+ return "z.string().uuid()";
138
+ if (schema.format === "email")
139
+ return "z.string().email()";
140
+ if (schema.format === "uri" || schema.format === "url")
141
+ return "z.string().url()";
142
+ return "z.string()";
143
+ }
144
+ function objectFromProperties(properties, required, ctx) {
145
+ const keys = Object.keys(properties);
146
+ if (keys.length === 0)
147
+ return "z.object({})";
148
+ const lines = [];
149
+ for (const key of keys) {
150
+ const propSchema = properties[key];
151
+ let expr = schemaToZodSource(propSchema, ctx);
152
+ if (propSchema.nullable === true)
153
+ expr = `${expr}.nullable()`;
154
+ if (!required.includes(key))
155
+ expr = `${expr}.optional()`;
156
+ if (propSchema.description) {
157
+ expr = `${expr}.describe(${JSON.stringify(propSchema.description)})`;
158
+ }
159
+ lines.push(` ${quoteKey(key)}: ${expr}`);
160
+ }
161
+ return `z.object({\n${lines.join(",\n")}\n})`;
162
+ }
163
+ function mergeAllOfObjects(branches, ctx) {
164
+ const properties = {};
165
+ const required = new Set();
166
+ for (const branch of branches) {
167
+ let resolved = branch;
168
+ if (branch.$ref) {
169
+ const refName = stripRefPrefix(branch.$ref);
170
+ if (refName === null)
171
+ return null;
172
+ const target = ctx.components[refName];
173
+ if (!target)
174
+ return null;
175
+ resolved = target;
176
+ }
177
+ if (resolved.type !== "object" && resolved.type !== undefined)
178
+ return null;
179
+ if (!resolved.properties)
180
+ return null;
181
+ for (const [k, v] of Object.entries(resolved.properties)) {
182
+ properties[k] = v;
183
+ }
184
+ for (const r of resolved.required ?? [])
185
+ required.add(r);
186
+ }
187
+ return { type: "object", properties, required: [...required] };
188
+ }
189
+ function stripRefPrefix(ref) {
190
+ const prefix = "#/components/schemas/";
191
+ if (!ref.startsWith(prefix))
192
+ return null;
193
+ return ref.slice(prefix.length);
194
+ }
195
+ /**
196
+ * Build the per-tool inputSchema source. Output shape is always:
197
+ *
198
+ * z.object({
199
+ * path?: z.object({ ... }), // only if op has any path params
200
+ * query?: z.object({ ... }), // only if op has any query params
201
+ * body?: <body schema>, // only if op declares a requestBody
202
+ * })
203
+ *
204
+ * `.optional()` is chained on `path` only when ALL path params are
205
+ * non-required (rare); on `query` when no query param is required;
206
+ * on `body` when the requestBody is not declared as required.
207
+ */
208
+ export function buildToolInputSchema(parameters, requestBody, ctx) {
209
+ const pathParams = parameters.filter((p) => p.in === "path");
210
+ const queryParams = parameters.filter((p) => p.in === "query");
211
+ const pathProperties = {};
212
+ const pathRequired = [];
213
+ for (const p of pathParams) {
214
+ const annotated = p.description
215
+ ? { ...(p.schema ?? {}), description: p.description }
216
+ : (p.schema ?? {});
217
+ pathProperties[p.name] = annotated;
218
+ // Per OpenAPI 3.0, path params are always required even if `required` is
219
+ // missing on the parameter object. We force them.
220
+ pathRequired.push(p.name);
221
+ }
222
+ const queryProperties = {};
223
+ const queryRequired = [];
224
+ for (const p of queryParams) {
225
+ const annotated = p.description
226
+ ? { ...(p.schema ?? {}), description: p.description }
227
+ : (p.schema ?? {});
228
+ queryProperties[p.name] = annotated;
229
+ if (p.required === true)
230
+ queryRequired.push(p.name);
231
+ }
232
+ const pathExpr = pathParams.length === 0
233
+ ? null
234
+ : objectFromProperties(pathProperties, pathRequired, ctx);
235
+ const queryExpr = queryParams.length === 0
236
+ ? null
237
+ : objectFromProperties(queryProperties, queryRequired, ctx);
238
+ let bodyExpr = null;
239
+ let bodyRequired = false;
240
+ if (requestBody && requestBody.content) {
241
+ const json = requestBody.content["application/json"] ??
242
+ requestBody.content["text/json"] ??
243
+ requestBody.content["application/*+json"];
244
+ if (json && json.schema) {
245
+ bodyExpr = schemaToZodSource(json.schema, ctx);
246
+ bodyRequired = requestBody.required === true;
247
+ }
248
+ }
249
+ // Assemble the top-level object schema source.
250
+ const fields = [];
251
+ if (pathExpr) {
252
+ // Path block is required iff at least one path param exists.
253
+ fields.push(` path: ${pathExpr}`);
254
+ }
255
+ if (queryExpr) {
256
+ const allOptional = queryRequired.length === 0;
257
+ fields.push(` query: ${queryExpr}${allOptional ? ".optional()" : ""}`);
258
+ }
259
+ if (bodyExpr !== null) {
260
+ fields.push(` body: ${bodyExpr}${bodyRequired ? "" : ".optional()"}`);
261
+ }
262
+ const source = fields.length === 0 ? "z.object({})" : `z.object({\n${fields.join(",\n")}\n})`;
263
+ return {
264
+ source,
265
+ shape: {
266
+ pathExpr,
267
+ queryExpr,
268
+ bodyExpr,
269
+ hasBody: bodyExpr !== null,
270
+ bodyRequired,
271
+ hasRequiredQuery: queryRequired.length > 0,
272
+ pathParamNames: pathParams.map((p) => p.name),
273
+ queryParamNames: queryParams.map((p) => p.name),
274
+ },
275
+ };
276
+ }
277
+ //# sourceMappingURL=schemaToZod.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schemaToZod.js","sourceRoot":"","sources":["../../src/generator/schemaToZod.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,+BA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EAAE,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;YAC7C,eAAe,EAAE,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;SAChD;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,26 @@
1
+ export type HttpMethodLc = "get" | "post" | "put" | "patch" | "delete";
2
+ interface ScopeAwareOperation {
3
+ readonly "x-required-scope"?: unknown;
4
+ readonly "x-required-scopes"?: unknown;
5
+ readonly "x-scopes"?: unknown;
6
+ }
7
+ /**
8
+ * Derive a single `<segment>:<resource>:<verb>` scope string from a path
9
+ * + HTTP method when the OpenAPI operation has no scope extension.
10
+ *
11
+ * Conventions:
12
+ * - GET, HEAD → :read
13
+ * - DELETE → :delete
14
+ * - POST, PUT, PATCH → :write
15
+ *
16
+ * Resource is the first non-parameter segment after the segment, falling
17
+ * back to the segment itself if there's no second token.
18
+ */
19
+ export declare function inferScopeFromPath(path: string, method: HttpMethodLc): string;
20
+ /**
21
+ * Top-level entry: returns a single canonical scope string for an operation.
22
+ * Never throws; falls back to inference when no extension is present.
23
+ */
24
+ export declare function resolveRequiredScope(operation: ScopeAwareOperation | null | undefined, path: string, method: HttpMethodLc): string;
25
+ export {};
26
+ //# sourceMappingURL=scopeInference.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scopeInference.d.ts","sourceRoot":"","sources":["../../src/generator/scopeInference.ts"],"names":[],"mappings":"AAsBA,MAAM,MAAM,YAAY,GAAG,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,OAAO,GAAG,QAAQ,CAAC;AAEvE,UAAU,mBAAmB;IAC3B,QAAQ,CAAC,kBAAkB,CAAC,EAAE,OAAO,CAAC;IACtC,QAAQ,CAAC,mBAAmB,CAAC,EAAE,OAAO,CAAC;IACvC,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,CAAC;CAC/B;AAmBD;;;;;;;;;;;GAWG;AACH,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,YAAY,GACnB,MAAM,CAgBR;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAClC,SAAS,EAAE,mBAAmB,GAAG,IAAI,GAAG,SAAS,EACjD,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,YAAY,GACnB,MAAM,CAaR"}
@@ -0,0 +1,91 @@
1
+ // =============================================================================
2
+ // src/generator/scopeInference.ts
3
+ // Wave: W6 — Stream A
4
+ //
5
+ // Derives the `required_scope` string for one OpenAPI operation, in priority
6
+ // order:
7
+ //
8
+ // 1. `operation['x-required-scope']` (singular, from W6 brief)
9
+ // 2. `operation['x-required-scopes']` (plural — what the W4 snapshot
10
+ // actually emits; pick the first)
11
+ // 3. `operation['x-scopes']` (alternative spelling — pick the first)
12
+ // 4. Inferred from path + method as `<segment>:<resource>:<verb>` where:
13
+ // - segment = first path token after `/v1/`
14
+ // - resource = next non-param token (or "self" if none)
15
+ // - verb = read|write|delete (delete) | write (POST/PUT/PATCH) | read (GET)
16
+ //
17
+ // We export the *string* form because that's what the MCP tool surface
18
+ // expects (one canonical scope per tool). When an operation declares multiple
19
+ // scopes (e.g. read+write), we pick the first since W4's auth pipeline
20
+ // authenticates with `any-of` semantics on declared scopes.
21
+ // =============================================================================
22
+ /** Internal helper: coerce extension value to a non-empty trimmed string. */
23
+ function pickFirstScope(value) {
24
+ if (typeof value === "string") {
25
+ const t = value.trim();
26
+ return t.length > 0 ? t : null;
27
+ }
28
+ if (Array.isArray(value)) {
29
+ for (const entry of value) {
30
+ if (typeof entry === "string") {
31
+ const t = entry.trim();
32
+ if (t.length > 0)
33
+ return t;
34
+ }
35
+ }
36
+ }
37
+ return null;
38
+ }
39
+ /**
40
+ * Derive a single `<segment>:<resource>:<verb>` scope string from a path
41
+ * + HTTP method when the OpenAPI operation has no scope extension.
42
+ *
43
+ * Conventions:
44
+ * - GET, HEAD → :read
45
+ * - DELETE → :delete
46
+ * - POST, PUT, PATCH → :write
47
+ *
48
+ * Resource is the first non-parameter segment after the segment, falling
49
+ * back to the segment itself if there's no second token.
50
+ */
51
+ export function inferScopeFromPath(path, method) {
52
+ const stripped = path.replace(/^\/+/, "").replace(/^v1\//, "");
53
+ const tokens = stripped
54
+ .split("/")
55
+ .filter((t) => t.length > 0 && !(t.startsWith("{") && t.endsWith("}")));
56
+ const segment = tokens[0] ?? "platform";
57
+ const resource = tokens[1] ?? segment;
58
+ let verb;
59
+ if (method === "delete") {
60
+ verb = "delete";
61
+ }
62
+ else if (method === "get") {
63
+ verb = "read";
64
+ }
65
+ else {
66
+ verb = "write";
67
+ }
68
+ return `${segment}:${resource}:${verb}`;
69
+ }
70
+ /**
71
+ * Top-level entry: returns a single canonical scope string for an operation.
72
+ * Never throws; falls back to inference when no extension is present.
73
+ */
74
+ export function resolveRequiredScope(operation, path, method) {
75
+ if (operation) {
76
+ // Priority 1: x-required-scope (singular — brief's preferred extension).
77
+ const single = pickFirstScope(operation["x-required-scope"]);
78
+ if (single !== null)
79
+ return single;
80
+ // Priority 2: x-required-scopes (plural — what the W4 snapshot uses).
81
+ const plural = pickFirstScope(operation["x-required-scopes"]);
82
+ if (plural !== null)
83
+ return plural;
84
+ // Priority 3: x-scopes (alternate form).
85
+ const xScopes = pickFirstScope(operation["x-scopes"]);
86
+ if (xScopes !== null)
87
+ return xScopes;
88
+ }
89
+ return inferScopeFromPath(path, method);
90
+ }
91
+ //# sourceMappingURL=scopeInference.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scopeInference.js","sourceRoot":"","sources":["../../src/generator/scopeInference.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,kCAAkC;AAClC,sBAAsB;AACtB,EAAE;AACF,6EAA6E;AAC7E,SAAS;AACT,EAAE;AACF,iEAAiE;AACjE,uEAAuE;AACvE,uCAAuC;AACvC,uEAAuE;AACvE,2EAA2E;AAC3E,mDAAmD;AACnD,+DAA+D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IACxC,MAAM,QAAQ,GAAG,MAAM,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC;IACtC,IAAI,IAAiC,CAAC;IACtC,IAAI,MAAM,KAAK,QAAQ,EAAE,CAAC;QACxB,IAAI,GAAG,QAAQ,CAAC;IAClB,CAAC;SAAM,IAAI,MAAM,KAAK,KAAK,EAAE,CAAC;QAC5B,IAAI,GAAG,MAAM,CAAC;IAChB,CAAC;SAAM,CAAC;QACN,IAAI,GAAG,OAAO,CAAC;IACjB,CAAC;IACD,OAAO,GAAG,OAAO,IAAI,QAAQ,IAAI,IAAI,EAAE,CAAC;AAC1C,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,oBAAoB,CAClC,SAAiD,EACjD,IAAY,EACZ,MAAoB;IAEpB,IAAI,SAAS,EAAE,CAAC;QACd,yEAAyE;QACzE,MAAM,MAAM,GAAG,cAAc,CAAC,SAAS,CAAC,kBAAkB,CAAC,CAAC,CAAC;QAC7D,IAAI,MAAM,KAAK,IAAI;YAAE,OAAO,MAAM,CAAC;QACnC,sEAAsE;QACtE,MAAM,MAAM,GAAG,cAAc,CAAC,SAAS,CAAC,mBAAmB,CAAC,CAAC,CAAC;QAC9D,IAAI,MAAM,KAAK,IAAI;YAAE,OAAO,MAAM,CAAC;QACnC,yCAAyC;QACzC,MAAM,OAAO,GAAG,cAAc,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC;QACtD,IAAI,OAAO,KAAK,IAAI;YAAE,OAAO,OAAO,CAAC;IACvC,CAAC;IACD,OAAO,kBAAkB,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;AAC1C,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
package/dist/index.js ADDED
@@ -0,0 +1,106 @@
1
+ // =============================================================================
2
+ // src/index.ts
3
+ // Wave: W6 — MCP Server entrypoint.
4
+ // Phase 0 / E-A1 — SSE replaced by Streamable HTTP; per-session Server factory.
5
+ //
6
+ // Boots the MCP server:
7
+ // 1. Defines makeServer(): builds a fresh per-session SolidCommerceClient
8
+ // (apiKey auth) + audit hook + dispatcher-wired MCP Server.
9
+ // 2. Selects transport (--http / SC_MCP_TRANSPORT=http → Streamable HTTP;
10
+ // else stdio). The legacy "sse" value is accepted as a deprecated alias
11
+ // so existing App Service config boots Streamable HTTP instead of crashing.
12
+ // 3. stdio → one Server for the single local session.
13
+ // http → makeServer is handed to the transport, which calls it ONCE PER
14
+ // SESSION so each remote client gets isolated state (prerequisite
15
+ // for per-user OAuth context in E-A3).
16
+ //
17
+ // Stream A overwrites src/tools/foundation/index.ts; Stream B overwrites
18
+ // src/tools/tasks/index.ts. The merge takes their versions; this file is
19
+ // stable across all three streams.
20
+ // =============================================================================
21
+ import { attachAuditHook } from "./audit/auditClient.js";
22
+ import { buildClient, buildBearerClient, ENV_API_KEY } from "./auth/apiKey.js";
23
+ import { createIntrospector, createSessionAuthResolver, loadOAuthConfigFromEnv, } from "./auth/oauth.js";
24
+ import { buildMcpServer } from "./server/buildServer.js";
25
+ import { ENV_HOST_NAME_OVERRIDE, resolveHostName } from "./telemetry/hostName.js";
26
+ import { foundationTools } from "./tools/foundation/index.js";
27
+ import { taskTools } from "./tools/tasks/index.js";
28
+ import { startStreamableHttpServer } from "./transports/streamableHttp.js";
29
+ import { startStdioServer } from "./transports/stdio.js";
30
+ function pickTransport(argv) {
31
+ const explicit = process.env["SC_MCP_TRANSPORT"]?.toLowerCase();
32
+ if (explicit === "http" || argv.includes("--http"))
33
+ return "http";
34
+ // Deprecated alias: SSE was removed in E-A1. Accept the old value so existing
35
+ // App Service config (SC_MCP_TRANSPORT=sse) still boots — on Streamable HTTP.
36
+ if (explicit === "sse" || argv.includes("--sse")) {
37
+ console.error("[mcp-server] WARNING: 'sse' transport was removed (E-A1); booting Streamable HTTP. " +
38
+ "Update SC_MCP_TRANSPORT to 'http'.");
39
+ return "http";
40
+ }
41
+ return "stdio";
42
+ }
43
+ /**
44
+ * Build a fresh, fully-wired MCP Server bound to a session's auth identity.
45
+ * Called once for stdio, and once PER SESSION for Streamable HTTP. Each
46
+ * invocation mints its own SDK client + audit ref-cell, so concurrent remote
47
+ * sessions never share a tool-name ref, an auth context, or a token.
48
+ *
49
+ * * oauth → SDK client carries the user's bearer token (Platform validates).
50
+ * * apiKey → SDK client uses the env API key (stdio / Scotty / internal).
51
+ */
52
+ function makeServer(session) {
53
+ const { auth, hostName } = session;
54
+ // For oauth sessions, forward the user's bearer; otherwise the env API key.
55
+ // buildClient() / buildBearerClient() throw on missing creds — fail fast.
56
+ const client = auth.mode === "oauth" && auth.token !== undefined
57
+ ? buildBearerClient(auth.token)
58
+ : buildClient();
59
+ // setCurrentToolName is a closure over a ref-cell; the dispatcher (via
60
+ // buildMcpServer's ctxFactory) flips it on every call. The audit hook also
61
+ // stamps auth_mode + install_id (E-A3) and host_name (E-A4) on every call.
62
+ const audit = attachAuditHook(client, { auth, hostName });
63
+ // Order foundation first (stable, generated) → tasks (curated). Duplicate
64
+ // names → buildMcpServer throws.
65
+ const tools = [...foundationTools, ...taskTools];
66
+ return buildMcpServer({
67
+ tools,
68
+ client,
69
+ setCurrentToolName: audit.setCurrentToolName,
70
+ auth,
71
+ });
72
+ }
73
+ async function main() {
74
+ const transport = pickTransport(process.argv.slice(2));
75
+ if (transport === "http") {
76
+ // Wire the per-user OAuth resolver (Phase 0 / E-A3). One introspector
77
+ // (shared cache + circuit breaker) serves every session.
78
+ const oauthConfig = loadOAuthConfigFromEnv();
79
+ const introspector = createIntrospector(oauthConfig);
80
+ const apiKeyAvailable = (process.env[ENV_API_KEY] ?? "").trim().length > 0;
81
+ const authResolver = createSessionAuthResolver({
82
+ config: oauthConfig,
83
+ introspector,
84
+ apiKeyAvailable,
85
+ });
86
+ console.error(`[mcp-server] oauth ${oauthConfig.enabled ? "enabled" : "disabled"}; ` +
87
+ `apiKey fallback ${apiKeyAvailable ? "available" : "absent"}`);
88
+ // The factory is called per-session inside the transport, after auth resolves.
89
+ await startStreamableHttpServer(makeServer, { authResolver });
90
+ }
91
+ else {
92
+ // stdio: no inbound Authorization header; always service/internal identity.
93
+ // hostName comes only from an explicit override (clientInfo isn't known
94
+ // until the post-connect `initialize` over the stdio pipe).
95
+ const stdioSession = {
96
+ auth: { mode: "apiKey", scopes: [], introspectionDegraded: false },
97
+ hostName: resolveHostName({ override: process.env[ENV_HOST_NAME_OVERRIDE] }),
98
+ };
99
+ await startStdioServer(makeServer(stdioSession));
100
+ }
101
+ }
102
+ main().catch((err) => {
103
+ console.error("[mcp-server] fatal:", err instanceof Error ? err.message : err);
104
+ process.exit(1);
105
+ });
106
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,eAAe;AACf,oCAAoC;AACpC,gFAAgF;AAChF,EAAE;AACF,wBAAwB;AACxB,4EAA4E;AAC5E,iEAAiE;AACjE,4EAA4E;AAC5E,6EAA6E;AAC7E,iFAAiF;AACjF,yDAAyD;AACzD,+EAA+E;AAC/E,gFAAgF;AAChF,qDAAqD;AACrD,EAAE;AACF,yEAAyE;AACzE,yEAAyE;AACzE,mCAAmC;AACnC,gFAAgF;AAEhF,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/E,OAAO,EACL,kBAAkB,EAClB,yBAAyB,EACzB,sBAAsB,GACvB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAEzD,OAAO,EAAE,sBAAsB,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAClF,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC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AAC,UAAU,CAAC,YAAY,CAAC,CAAC,CAAC;IACnD,CAAC;AACH,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;IACnB,OAAO,CAAC,KAAK,CAAC,qBAAqB,EAAE,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;IAC/E,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
@@ -0,0 +1,35 @@
1
+ import { Server } from "@modelcontextprotocol/sdk/server/index.js";
2
+ import type { SolidCommerceClient } from "@solidcommerce/sdk";
3
+ import type { SessionAuthContext } from "../auth/oauth.js";
4
+ import type { ToolModule } from "../tools/contract.js";
5
+ export declare const SERVER_NAME = "@solidcommerce/mcp-server";
6
+ export interface BuildServerOptions {
7
+ readonly tools: ReadonlyArray<ToolModule>;
8
+ readonly client: SolidCommerceClient;
9
+ /**
10
+ * Hook into the audit ref-cell. The dispatcher calls this with the tool
11
+ * name just before invoking `tool.handle`, and again with `null` after.
12
+ * See src/audit/auditClient.ts.
13
+ */
14
+ readonly setCurrentToolName: (name: string | null) => void;
15
+ /**
16
+ * Resolved per-session auth identity (Phase 0 / E-A3). Surfaced to every tool
17
+ * via `ToolContext.auth`. Omit for stdio unit tests → defaults to apiKey.
18
+ */
19
+ readonly auth?: SessionAuthContext;
20
+ /** Override for tests. */
21
+ readonly version?: string;
22
+ }
23
+ /**
24
+ * Wire a fully-configured MCP `Server`. Caller is responsible for `connect()`.
25
+ *
26
+ * The dispatcher's `ctxFactory` is closed over `client` + `setCurrentToolName`
27
+ * so each tool invocation:
28
+ *
29
+ * 1. Sets the audit ref to the tool name.
30
+ * 2. Receives a ToolContext { client, toolName }.
31
+ * 3. The SDK fires onRequest hooks → audit headers go on the wire.
32
+ * 4. After tool.handle resolves (or throws), the ref is cleared.
33
+ */
34
+ export declare function buildMcpServer(opts: BuildServerOptions): Server;
35
+ //# sourceMappingURL=buildServer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buildServer.d.ts","sourceRoot":"","sources":["../../src/server/buildServer.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AACnE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAG9D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,KAAK,EAAE,UAAU,EAA6B,MAAM,sBAAsB,CAAC;AAkBlF,eAAO,MAAM,WAAW,8BAA8B,CAAC;AA4BvD,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC,UAAU,CAAC,CAAC;IAC1C,QAAQ,CAAC,MAAM,EAAE,mBAAmB,CAAC;IACrC;;;;OAIG;IACH,QAAQ,CAAC,kBAAkB,EAAE,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,CAAC;IAC3D;;;OAGG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE,kBAAkB,CAAC;IACnC,0BAA0B;IAC1B,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,kBAAkB,GAAG,MAAM,CAqC/D"}