@henrylabs/mcp 0.2.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 (315) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +255 -0
  3. package/code-tool-paths.cjs +6 -0
  4. package/code-tool-paths.cjs.map +1 -0
  5. package/code-tool-paths.d.cts +2 -0
  6. package/code-tool-paths.d.cts.map +1 -0
  7. package/code-tool-types.d.mts +14 -0
  8. package/code-tool-types.d.mts.map +1 -0
  9. package/code-tool-types.d.ts +14 -0
  10. package/code-tool-types.d.ts.map +1 -0
  11. package/code-tool-types.js +4 -0
  12. package/code-tool-types.js.map +1 -0
  13. package/code-tool-types.mjs +3 -0
  14. package/code-tool-types.mjs.map +1 -0
  15. package/code-tool-worker.d.mts +5 -0
  16. package/code-tool-worker.d.mts.map +1 -0
  17. package/code-tool-worker.d.ts +5 -0
  18. package/code-tool-worker.d.ts.map +1 -0
  19. package/code-tool-worker.js +45 -0
  20. package/code-tool-worker.js.map +1 -0
  21. package/code-tool-worker.mjs +40 -0
  22. package/code-tool-worker.mjs.map +1 -0
  23. package/code-tool.d.mts +12 -0
  24. package/code-tool.d.mts.map +1 -0
  25. package/code-tool.d.ts +12 -0
  26. package/code-tool.d.ts.map +1 -0
  27. package/code-tool.js +158 -0
  28. package/code-tool.js.map +1 -0
  29. package/code-tool.mjs +122 -0
  30. package/code-tool.mjs.map +1 -0
  31. package/compat.d.mts +58 -0
  32. package/compat.d.mts.map +1 -0
  33. package/compat.d.ts +58 -0
  34. package/compat.d.ts.map +1 -0
  35. package/compat.js +387 -0
  36. package/compat.js.map +1 -0
  37. package/compat.mjs +378 -0
  38. package/compat.mjs.map +1 -0
  39. package/docs-search-tool.d.mts +44 -0
  40. package/docs-search-tool.d.mts.map +1 -0
  41. package/docs-search-tool.d.ts +44 -0
  42. package/docs-search-tool.d.ts.map +1 -0
  43. package/docs-search-tool.js +43 -0
  44. package/docs-search-tool.js.map +1 -0
  45. package/docs-search-tool.mjs +39 -0
  46. package/docs-search-tool.mjs.map +1 -0
  47. package/dynamic-tools.d.mts +12 -0
  48. package/dynamic-tools.d.mts.map +1 -0
  49. package/dynamic-tools.d.ts +12 -0
  50. package/dynamic-tools.d.ts.map +1 -0
  51. package/dynamic-tools.js +135 -0
  52. package/dynamic-tools.js.map +1 -0
  53. package/dynamic-tools.mjs +132 -0
  54. package/dynamic-tools.mjs.map +1 -0
  55. package/filtering.d.mts +2 -0
  56. package/filtering.d.mts.map +1 -0
  57. package/filtering.d.ts +2 -0
  58. package/filtering.d.ts.map +1 -0
  59. package/filtering.js +20 -0
  60. package/filtering.js.map +1 -0
  61. package/filtering.mjs +13 -0
  62. package/filtering.mjs.map +1 -0
  63. package/headers.d.mts +4 -0
  64. package/headers.d.mts.map +1 -0
  65. package/headers.d.ts +4 -0
  66. package/headers.d.ts.map +1 -0
  67. package/headers.js +13 -0
  68. package/headers.js.map +1 -0
  69. package/headers.mjs +9 -0
  70. package/headers.mjs.map +1 -0
  71. package/http.d.mts +9 -0
  72. package/http.d.mts.map +1 -0
  73. package/http.d.ts +9 -0
  74. package/http.d.ts.map +1 -0
  75. package/http.js +108 -0
  76. package/http.js.map +1 -0
  77. package/http.mjs +100 -0
  78. package/http.mjs.map +1 -0
  79. package/index.d.mts +3 -0
  80. package/index.d.mts.map +1 -0
  81. package/index.d.ts +3 -0
  82. package/index.d.ts.map +1 -0
  83. package/index.js +91 -0
  84. package/index.js.map +1 -0
  85. package/index.mjs +89 -0
  86. package/index.mjs.map +1 -0
  87. package/options.d.mts +20 -0
  88. package/options.d.mts.map +1 -0
  89. package/options.d.ts +20 -0
  90. package/options.d.ts.map +1 -0
  91. package/options.js +424 -0
  92. package/options.js.map +1 -0
  93. package/options.mjs +417 -0
  94. package/options.mjs.map +1 -0
  95. package/package.json +216 -0
  96. package/server.d.mts +35 -0
  97. package/server.d.mts.map +1 -0
  98. package/server.d.ts +35 -0
  99. package/server.d.ts.map +1 -0
  100. package/server.js +175 -0
  101. package/server.js.map +1 -0
  102. package/server.mjs +161 -0
  103. package/server.mjs.map +1 -0
  104. package/src/code-tool-paths.cts +3 -0
  105. package/src/code-tool-types.ts +14 -0
  106. package/src/code-tool-worker.ts +46 -0
  107. package/src/code-tool.ts +147 -0
  108. package/src/compat.ts +483 -0
  109. package/src/docs-search-tool.ts +48 -0
  110. package/src/dynamic-tools.ts +153 -0
  111. package/src/filtering.ts +14 -0
  112. package/src/headers.ts +14 -0
  113. package/src/http.ts +127 -0
  114. package/src/index.ts +108 -0
  115. package/src/options.ts +466 -0
  116. package/src/server.ts +208 -0
  117. package/src/stdio.ts +13 -0
  118. package/src/tools/cart/create-checkout-cart.ts +49 -0
  119. package/src/tools/cart/items/add-cart-items.ts +93 -0
  120. package/src/tools/cart/items/clear-cart-items.ts +47 -0
  121. package/src/tools/cart/items/list-cart-items.ts +47 -0
  122. package/src/tools/cart/items/remove-cart-items.ts +50 -0
  123. package/src/tools/checkout/session/confirm-checkout-checkout-session.ts +101 -0
  124. package/src/tools/checkout/session/create-quote-checkout-session.ts +96 -0
  125. package/src/tools/checkout/session/list-products-checkout-session.ts +47 -0
  126. package/src/tools/checkout/session/retrieve-shipping-info-checkout-session.ts +49 -0
  127. package/src/tools/index.ts +105 -0
  128. package/src/tools/merchants/check-status-merchants.ts +56 -0
  129. package/src/tools/merchants/get-shipping-info-merchants.ts +60 -0
  130. package/src/tools/merchants/list-supported-merchants.ts +52 -0
  131. package/src/tools/orders/retrieve-status-orders.ts +47 -0
  132. package/src/tools/products/retrieve-details-products.ts +48 -0
  133. package/src/tools/products/search-products.ts +78 -0
  134. package/src/tools/products/variant-check/create-products-variant-check.ts +85 -0
  135. package/src/tools/products/variant-check/retrieve-status-products-variant-check.ts +50 -0
  136. package/src/tools/types.ts +103 -0
  137. package/src/tools/wallet/create-card-collection-wallet.ts +49 -0
  138. package/src/tools.ts +1 -0
  139. package/src/tsconfig.json +11 -0
  140. package/stdio.d.mts +3 -0
  141. package/stdio.d.mts.map +1 -0
  142. package/stdio.d.ts +3 -0
  143. package/stdio.d.ts.map +1 -0
  144. package/stdio.js +14 -0
  145. package/stdio.js.map +1 -0
  146. package/stdio.mjs +10 -0
  147. package/stdio.mjs.map +1 -0
  148. package/tools/cart/create-checkout-cart.d.mts +45 -0
  149. package/tools/cart/create-checkout-cart.d.mts.map +1 -0
  150. package/tools/cart/create-checkout-cart.d.ts +45 -0
  151. package/tools/cart/create-checkout-cart.d.ts.map +1 -0
  152. package/tools/cart/create-checkout-cart.js +44 -0
  153. package/tools/cart/create-checkout-cart.js.map +1 -0
  154. package/tools/cart/create-checkout-cart.mjs +40 -0
  155. package/tools/cart/create-checkout-cart.mjs.map +1 -0
  156. package/tools/cart/items/add-cart-items.d.mts +45 -0
  157. package/tools/cart/items/add-cart-items.d.mts.map +1 -0
  158. package/tools/cart/items/add-cart-items.d.ts +45 -0
  159. package/tools/cart/items/add-cart-items.d.ts.map +1 -0
  160. package/tools/cart/items/add-cart-items.js +86 -0
  161. package/tools/cart/items/add-cart-items.js.map +1 -0
  162. package/tools/cart/items/add-cart-items.mjs +82 -0
  163. package/tools/cart/items/add-cart-items.mjs.map +1 -0
  164. package/tools/cart/items/clear-cart-items.d.mts +45 -0
  165. package/tools/cart/items/clear-cart-items.d.mts.map +1 -0
  166. package/tools/cart/items/clear-cart-items.d.ts +45 -0
  167. package/tools/cart/items/clear-cart-items.d.ts.map +1 -0
  168. package/tools/cart/items/clear-cart-items.js +42 -0
  169. package/tools/cart/items/clear-cart-items.js.map +1 -0
  170. package/tools/cart/items/clear-cart-items.mjs +38 -0
  171. package/tools/cart/items/clear-cart-items.mjs.map +1 -0
  172. package/tools/cart/items/list-cart-items.d.mts +45 -0
  173. package/tools/cart/items/list-cart-items.d.mts.map +1 -0
  174. package/tools/cart/items/list-cart-items.d.ts +45 -0
  175. package/tools/cart/items/list-cart-items.d.ts.map +1 -0
  176. package/tools/cart/items/list-cart-items.js +42 -0
  177. package/tools/cart/items/list-cart-items.js.map +1 -0
  178. package/tools/cart/items/list-cart-items.mjs +38 -0
  179. package/tools/cart/items/list-cart-items.mjs.map +1 -0
  180. package/tools/cart/items/remove-cart-items.d.mts +45 -0
  181. package/tools/cart/items/remove-cart-items.d.mts.map +1 -0
  182. package/tools/cart/items/remove-cart-items.d.ts +45 -0
  183. package/tools/cart/items/remove-cart-items.d.ts.map +1 -0
  184. package/tools/cart/items/remove-cart-items.js +45 -0
  185. package/tools/cart/items/remove-cart-items.js.map +1 -0
  186. package/tools/cart/items/remove-cart-items.mjs +41 -0
  187. package/tools/cart/items/remove-cart-items.mjs.map +1 -0
  188. package/tools/checkout/session/confirm-checkout-checkout-session.d.mts +45 -0
  189. package/tools/checkout/session/confirm-checkout-checkout-session.d.mts.map +1 -0
  190. package/tools/checkout/session/confirm-checkout-checkout-session.d.ts +45 -0
  191. package/tools/checkout/session/confirm-checkout-checkout-session.d.ts.map +1 -0
  192. package/tools/checkout/session/confirm-checkout-checkout-session.js +94 -0
  193. package/tools/checkout/session/confirm-checkout-checkout-session.js.map +1 -0
  194. package/tools/checkout/session/confirm-checkout-checkout-session.mjs +90 -0
  195. package/tools/checkout/session/confirm-checkout-checkout-session.mjs.map +1 -0
  196. package/tools/checkout/session/create-quote-checkout-session.d.mts +45 -0
  197. package/tools/checkout/session/create-quote-checkout-session.d.mts.map +1 -0
  198. package/tools/checkout/session/create-quote-checkout-session.d.ts +45 -0
  199. package/tools/checkout/session/create-quote-checkout-session.d.ts.map +1 -0
  200. package/tools/checkout/session/create-quote-checkout-session.js +91 -0
  201. package/tools/checkout/session/create-quote-checkout-session.js.map +1 -0
  202. package/tools/checkout/session/create-quote-checkout-session.mjs +87 -0
  203. package/tools/checkout/session/create-quote-checkout-session.mjs.map +1 -0
  204. package/tools/checkout/session/list-products-checkout-session.d.mts +45 -0
  205. package/tools/checkout/session/list-products-checkout-session.d.mts.map +1 -0
  206. package/tools/checkout/session/list-products-checkout-session.d.ts +45 -0
  207. package/tools/checkout/session/list-products-checkout-session.d.ts.map +1 -0
  208. package/tools/checkout/session/list-products-checkout-session.js +42 -0
  209. package/tools/checkout/session/list-products-checkout-session.js.map +1 -0
  210. package/tools/checkout/session/list-products-checkout-session.mjs +38 -0
  211. package/tools/checkout/session/list-products-checkout-session.mjs.map +1 -0
  212. package/tools/checkout/session/retrieve-shipping-info-checkout-session.d.mts +45 -0
  213. package/tools/checkout/session/retrieve-shipping-info-checkout-session.d.mts.map +1 -0
  214. package/tools/checkout/session/retrieve-shipping-info-checkout-session.d.ts +45 -0
  215. package/tools/checkout/session/retrieve-shipping-info-checkout-session.d.ts.map +1 -0
  216. package/tools/checkout/session/retrieve-shipping-info-checkout-session.js +42 -0
  217. package/tools/checkout/session/retrieve-shipping-info-checkout-session.js.map +1 -0
  218. package/tools/checkout/session/retrieve-shipping-info-checkout-session.mjs +38 -0
  219. package/tools/checkout/session/retrieve-shipping-info-checkout-session.mjs.map +1 -0
  220. package/tools/index.d.mts +10 -0
  221. package/tools/index.d.mts.map +1 -0
  222. package/tools/index.d.ts +10 -0
  223. package/tools/index.d.ts.map +1 -0
  224. package/tools/index.js +89 -0
  225. package/tools/index.js.map +1 -0
  226. package/tools/index.mjs +82 -0
  227. package/tools/index.mjs.map +1 -0
  228. package/tools/merchants/check-status-merchants.d.mts +45 -0
  229. package/tools/merchants/check-status-merchants.d.mts.map +1 -0
  230. package/tools/merchants/check-status-merchants.d.ts +45 -0
  231. package/tools/merchants/check-status-merchants.d.ts.map +1 -0
  232. package/tools/merchants/check-status-merchants.js +48 -0
  233. package/tools/merchants/check-status-merchants.js.map +1 -0
  234. package/tools/merchants/check-status-merchants.mjs +44 -0
  235. package/tools/merchants/check-status-merchants.mjs.map +1 -0
  236. package/tools/merchants/get-shipping-info-merchants.d.mts +45 -0
  237. package/tools/merchants/get-shipping-info-merchants.d.mts.map +1 -0
  238. package/tools/merchants/get-shipping-info-merchants.d.ts +45 -0
  239. package/tools/merchants/get-shipping-info-merchants.d.ts.map +1 -0
  240. package/tools/merchants/get-shipping-info-merchants.js +55 -0
  241. package/tools/merchants/get-shipping-info-merchants.js.map +1 -0
  242. package/tools/merchants/get-shipping-info-merchants.mjs +51 -0
  243. package/tools/merchants/get-shipping-info-merchants.mjs.map +1 -0
  244. package/tools/merchants/list-supported-merchants.d.mts +45 -0
  245. package/tools/merchants/list-supported-merchants.d.mts.map +1 -0
  246. package/tools/merchants/list-supported-merchants.d.ts +45 -0
  247. package/tools/merchants/list-supported-merchants.d.ts.map +1 -0
  248. package/tools/merchants/list-supported-merchants.js +47 -0
  249. package/tools/merchants/list-supported-merchants.js.map +1 -0
  250. package/tools/merchants/list-supported-merchants.mjs +43 -0
  251. package/tools/merchants/list-supported-merchants.mjs.map +1 -0
  252. package/tools/orders/retrieve-status-orders.d.mts +45 -0
  253. package/tools/orders/retrieve-status-orders.d.mts.map +1 -0
  254. package/tools/orders/retrieve-status-orders.d.ts +45 -0
  255. package/tools/orders/retrieve-status-orders.d.ts.map +1 -0
  256. package/tools/orders/retrieve-status-orders.js +42 -0
  257. package/tools/orders/retrieve-status-orders.js.map +1 -0
  258. package/tools/orders/retrieve-status-orders.mjs +38 -0
  259. package/tools/orders/retrieve-status-orders.mjs.map +1 -0
  260. package/tools/products/retrieve-details-products.d.mts +45 -0
  261. package/tools/products/retrieve-details-products.d.mts.map +1 -0
  262. package/tools/products/retrieve-details-products.d.ts +45 -0
  263. package/tools/products/retrieve-details-products.d.ts.map +1 -0
  264. package/tools/products/retrieve-details-products.js +43 -0
  265. package/tools/products/retrieve-details-products.js.map +1 -0
  266. package/tools/products/retrieve-details-products.mjs +39 -0
  267. package/tools/products/retrieve-details-products.mjs.map +1 -0
  268. package/tools/products/search-products.d.mts +45 -0
  269. package/tools/products/search-products.d.mts.map +1 -0
  270. package/tools/products/search-products.d.ts +45 -0
  271. package/tools/products/search-products.d.ts.map +1 -0
  272. package/tools/products/search-products.js +73 -0
  273. package/tools/products/search-products.js.map +1 -0
  274. package/tools/products/search-products.mjs +69 -0
  275. package/tools/products/search-products.mjs.map +1 -0
  276. package/tools/products/variant-check/create-products-variant-check.d.mts +45 -0
  277. package/tools/products/variant-check/create-products-variant-check.d.mts.map +1 -0
  278. package/tools/products/variant-check/create-products-variant-check.d.ts +45 -0
  279. package/tools/products/variant-check/create-products-variant-check.d.ts.map +1 -0
  280. package/tools/products/variant-check/create-products-variant-check.js +79 -0
  281. package/tools/products/variant-check/create-products-variant-check.js.map +1 -0
  282. package/tools/products/variant-check/create-products-variant-check.mjs +75 -0
  283. package/tools/products/variant-check/create-products-variant-check.mjs.map +1 -0
  284. package/tools/products/variant-check/retrieve-status-products-variant-check.d.mts +45 -0
  285. package/tools/products/variant-check/retrieve-status-products-variant-check.d.mts.map +1 -0
  286. package/tools/products/variant-check/retrieve-status-products-variant-check.d.ts +45 -0
  287. package/tools/products/variant-check/retrieve-status-products-variant-check.d.ts.map +1 -0
  288. package/tools/products/variant-check/retrieve-status-products-variant-check.js +43 -0
  289. package/tools/products/variant-check/retrieve-status-products-variant-check.js.map +1 -0
  290. package/tools/products/variant-check/retrieve-status-products-variant-check.mjs +39 -0
  291. package/tools/products/variant-check/retrieve-status-products-variant-check.mjs.map +1 -0
  292. package/tools/types.d.mts +51 -0
  293. package/tools/types.d.mts.map +1 -0
  294. package/tools/types.d.ts +51 -0
  295. package/tools/types.d.ts.map +1 -0
  296. package/tools/types.js +46 -0
  297. package/tools/types.js.map +1 -0
  298. package/tools/types.mjs +42 -0
  299. package/tools/types.mjs.map +1 -0
  300. package/tools/wallet/create-card-collection-wallet.d.mts +45 -0
  301. package/tools/wallet/create-card-collection-wallet.d.mts.map +1 -0
  302. package/tools/wallet/create-card-collection-wallet.d.ts +45 -0
  303. package/tools/wallet/create-card-collection-wallet.d.ts.map +1 -0
  304. package/tools/wallet/create-card-collection-wallet.js +44 -0
  305. package/tools/wallet/create-card-collection-wallet.js.map +1 -0
  306. package/tools/wallet/create-card-collection-wallet.mjs +40 -0
  307. package/tools/wallet/create-card-collection-wallet.mjs.map +1 -0
  308. package/tools.d.mts +2 -0
  309. package/tools.d.mts.map +1 -0
  310. package/tools.d.ts +2 -0
  311. package/tools.d.ts.map +1 -0
  312. package/tools.js +18 -0
  313. package/tools.js.map +1 -0
  314. package/tools.mjs +2 -0
  315. package/tools.mjs.map +1 -0
package/src/http.ts ADDED
@@ -0,0 +1,127 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp';
4
+ import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
5
+
6
+ import express from 'express';
7
+ import { fromError } from 'zod-validation-error/v3';
8
+ import { McpOptions, parseQueryOptions } from './options';
9
+ import { ClientOptions, initMcpServer, newMcpServer } from './server';
10
+ import { parseAuthHeaders } from './headers';
11
+
12
+ const newServer = ({
13
+ clientOptions,
14
+ mcpOptions: defaultMcpOptions,
15
+ req,
16
+ res,
17
+ }: {
18
+ clientOptions: ClientOptions;
19
+ mcpOptions: McpOptions;
20
+ req: express.Request;
21
+ res: express.Response;
22
+ }): McpServer | null => {
23
+ const server = newMcpServer();
24
+
25
+ let mcpOptions: McpOptions;
26
+ try {
27
+ mcpOptions = parseQueryOptions(defaultMcpOptions, req.query);
28
+ } catch (error) {
29
+ res.status(400).json({
30
+ jsonrpc: '2.0',
31
+ error: {
32
+ code: -32000,
33
+ message: `Invalid request: ${fromError(error)}`,
34
+ },
35
+ });
36
+ return null;
37
+ }
38
+
39
+ try {
40
+ const authOptions = parseAuthHeaders(req);
41
+ initMcpServer({
42
+ server: server,
43
+ clientOptions: {
44
+ ...clientOptions,
45
+ ...authOptions,
46
+ },
47
+ mcpOptions,
48
+ });
49
+ } catch {
50
+ res.status(401).json({
51
+ jsonrpc: '2.0',
52
+ error: {
53
+ code: -32000,
54
+ message: 'Unauthorized',
55
+ },
56
+ });
57
+ return null;
58
+ }
59
+
60
+ return server;
61
+ };
62
+
63
+ const post =
64
+ (options: { clientOptions: ClientOptions; mcpOptions: McpOptions }) =>
65
+ async (req: express.Request, res: express.Response) => {
66
+ const server = newServer({ ...options, req, res });
67
+ // If we return null, we already set the authorization error.
68
+ if (server === null) return;
69
+ const transport = new StreamableHTTPServerTransport({
70
+ // Stateless server
71
+ sessionIdGenerator: undefined,
72
+ });
73
+ await server.connect(transport);
74
+ await transport.handleRequest(req, res, req.body);
75
+ };
76
+
77
+ const get = async (req: express.Request, res: express.Response) => {
78
+ res.status(405).json({
79
+ jsonrpc: '2.0',
80
+ error: {
81
+ code: -32000,
82
+ message: 'Method not supported',
83
+ },
84
+ });
85
+ };
86
+
87
+ const del = async (req: express.Request, res: express.Response) => {
88
+ res.status(405).json({
89
+ jsonrpc: '2.0',
90
+ error: {
91
+ code: -32000,
92
+ message: 'Method not supported',
93
+ },
94
+ });
95
+ };
96
+
97
+ export const streamableHTTPApp = ({
98
+ clientOptions = {},
99
+ mcpOptions = {},
100
+ }: {
101
+ clientOptions?: ClientOptions;
102
+ mcpOptions?: McpOptions;
103
+ }): express.Express => {
104
+ const app = express();
105
+ app.set('query parser', 'extended');
106
+ app.use(express.json());
107
+
108
+ app.get('/', get);
109
+ app.post('/', post({ clientOptions, mcpOptions }));
110
+ app.delete('/', del);
111
+
112
+ return app;
113
+ };
114
+
115
+ export const launchStreamableHTTPServer = async (options: McpOptions, port: number | string | undefined) => {
116
+ const app = streamableHTTPApp({ mcpOptions: options });
117
+ const server = app.listen(port);
118
+ const address = server.address();
119
+
120
+ if (typeof address === 'string') {
121
+ console.error(`MCP Server running on streamable HTTP at ${address}`);
122
+ } else if (address !== null) {
123
+ console.error(`MCP Server running on streamable HTTP on port ${address.port}`);
124
+ } else {
125
+ console.error(`MCP Server running on streamable HTTP on port ${port}`);
126
+ }
127
+ };
package/src/index.ts ADDED
@@ -0,0 +1,108 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { selectTools } from './server';
4
+ import { Endpoint, endpoints } from './tools';
5
+ import { McpOptions, parseCLIOptions } from './options';
6
+ import { launchStdioServer } from './stdio';
7
+ import { launchStreamableHTTPServer } from './http';
8
+
9
+ async function main() {
10
+ const options = parseOptionsOrError();
11
+
12
+ if (options.list) {
13
+ listAllTools();
14
+ return;
15
+ }
16
+
17
+ const selectedTools = await selectToolsOrError(endpoints, options);
18
+
19
+ console.error(
20
+ `MCP Server starting with ${selectedTools.length} tools:`,
21
+ selectedTools.map((e) => e.tool.name),
22
+ );
23
+
24
+ switch (options.transport) {
25
+ case 'stdio':
26
+ await launchStdioServer(options);
27
+ break;
28
+ case 'http':
29
+ await launchStreamableHTTPServer(options, options.port ?? options.socket);
30
+ break;
31
+ }
32
+ }
33
+
34
+ if (require.main === module) {
35
+ main().catch((error) => {
36
+ console.error('Fatal error in main():', error);
37
+ process.exit(1);
38
+ });
39
+ }
40
+
41
+ function parseOptionsOrError() {
42
+ try {
43
+ return parseCLIOptions();
44
+ } catch (error) {
45
+ console.error('Error parsing options:', error);
46
+ process.exit(1);
47
+ }
48
+ }
49
+
50
+ async function selectToolsOrError(endpoints: Endpoint[], options: McpOptions): Promise<Endpoint[]> {
51
+ try {
52
+ const includedTools = await selectTools(endpoints, options);
53
+ if (includedTools.length === 0) {
54
+ console.error('No tools match the provided filters.');
55
+ process.exit(1);
56
+ }
57
+ return includedTools;
58
+ } catch (error) {
59
+ if (error instanceof Error) {
60
+ console.error('Error filtering tools:', error.message);
61
+ } else {
62
+ console.error('Error filtering tools:', error);
63
+ }
64
+ process.exit(1);
65
+ }
66
+ }
67
+
68
+ function listAllTools() {
69
+ if (endpoints.length === 0) {
70
+ console.log('No tools available.');
71
+ return;
72
+ }
73
+ console.log('Available tools:\n');
74
+
75
+ // Group endpoints by resource
76
+ const resourceGroups = new Map<string, typeof endpoints>();
77
+
78
+ for (const endpoint of endpoints) {
79
+ const resource = endpoint.metadata.resource;
80
+ if (!resourceGroups.has(resource)) {
81
+ resourceGroups.set(resource, []);
82
+ }
83
+ resourceGroups.get(resource)!.push(endpoint);
84
+ }
85
+
86
+ // Sort resources alphabetically
87
+ const sortedResources = Array.from(resourceGroups.keys()).sort();
88
+
89
+ // Display hierarchically by resource
90
+ for (const resource of sortedResources) {
91
+ console.log(`Resource: ${resource}`);
92
+
93
+ const resourceEndpoints = resourceGroups.get(resource)!;
94
+ // Sort endpoints by tool name
95
+ resourceEndpoints.sort((a, b) => a.tool.name.localeCompare(b.tool.name));
96
+
97
+ for (const endpoint of resourceEndpoints) {
98
+ const {
99
+ tool,
100
+ metadata: { operation, tags },
101
+ } = endpoint;
102
+
103
+ console.log(` - ${tool.name} (${operation}) ${tags.length > 0 ? `tags: ${tags.join(', ')}` : ''}`);
104
+ console.log(` Description: ${tool.description}`);
105
+ }
106
+ console.log('');
107
+ }
108
+ }
package/src/options.ts ADDED
@@ -0,0 +1,466 @@
1
+ import qs from 'qs';
2
+ import yargs from 'yargs';
3
+ import { hideBin } from 'yargs/helpers';
4
+ import z from 'zod';
5
+ import { endpoints, Filter } from './tools';
6
+ import { ClientCapabilities, knownClients, ClientType } from './compat';
7
+
8
+ export type CLIOptions = McpOptions & {
9
+ list: boolean;
10
+ transport: 'stdio' | 'http';
11
+ port: number | undefined;
12
+ socket: string | undefined;
13
+ };
14
+
15
+ export type McpOptions = {
16
+ client?: ClientType | undefined;
17
+ includeDynamicTools?: boolean | undefined;
18
+ includeAllTools?: boolean | undefined;
19
+ includeCodeTools?: boolean | undefined;
20
+ includeDocsTools?: boolean | undefined;
21
+ filters?: Filter[] | undefined;
22
+ capabilities?: Partial<ClientCapabilities> | undefined;
23
+ };
24
+
25
+ const CAPABILITY_CHOICES = [
26
+ 'top-level-unions',
27
+ 'valid-json',
28
+ 'refs',
29
+ 'unions',
30
+ 'formats',
31
+ 'tool-name-length',
32
+ ] as const;
33
+
34
+ type Capability = (typeof CAPABILITY_CHOICES)[number];
35
+
36
+ function parseCapabilityValue(cap: string): { name: Capability; value?: number } {
37
+ if (cap.startsWith('tool-name-length=')) {
38
+ const parts = cap.split('=');
39
+ if (parts.length === 2) {
40
+ const length = parseInt(parts[1]!, 10);
41
+ if (!isNaN(length)) {
42
+ return { name: 'tool-name-length', value: length };
43
+ }
44
+ throw new Error(`Invalid tool-name-length value: ${parts[1]}. Expected a number.`);
45
+ }
46
+ throw new Error(`Invalid format for tool-name-length. Expected tool-name-length=N.`);
47
+ }
48
+ if (!CAPABILITY_CHOICES.includes(cap as Capability)) {
49
+ throw new Error(`Unknown capability: ${cap}. Valid capabilities are: ${CAPABILITY_CHOICES.join(', ')}`);
50
+ }
51
+ return { name: cap as Capability };
52
+ }
53
+
54
+ export function parseCLIOptions(): CLIOptions {
55
+ const opts = yargs(hideBin(process.argv))
56
+ .option('tools', {
57
+ type: 'string',
58
+ array: true,
59
+ choices: ['dynamic', 'all', 'code', 'docs'],
60
+ description: 'Use dynamic tools or all tools',
61
+ })
62
+ .option('no-tools', {
63
+ type: 'string',
64
+ array: true,
65
+ choices: ['dynamic', 'all', 'code', 'docs'],
66
+ description: 'Do not use any dynamic or all tools',
67
+ })
68
+ .option('tool', {
69
+ type: 'string',
70
+ array: true,
71
+ description: 'Include tools matching the specified names',
72
+ })
73
+ .option('resource', {
74
+ type: 'string',
75
+ array: true,
76
+ description: 'Include tools matching the specified resources',
77
+ })
78
+ .option('operation', {
79
+ type: 'string',
80
+ array: true,
81
+ choices: ['read', 'write'],
82
+ description: 'Include tools matching the specified operations',
83
+ })
84
+ .option('tag', {
85
+ type: 'string',
86
+ array: true,
87
+ description: 'Include tools with the specified tags',
88
+ })
89
+ .option('no-tool', {
90
+ type: 'string',
91
+ array: true,
92
+ description: 'Exclude tools matching the specified names',
93
+ })
94
+ .option('no-resource', {
95
+ type: 'string',
96
+ array: true,
97
+ description: 'Exclude tools matching the specified resources',
98
+ })
99
+ .option('no-operation', {
100
+ type: 'string',
101
+ array: true,
102
+ description: 'Exclude tools matching the specified operations',
103
+ })
104
+ .option('no-tag', {
105
+ type: 'string',
106
+ array: true,
107
+ description: 'Exclude tools with the specified tags',
108
+ })
109
+ .option('list', {
110
+ type: 'boolean',
111
+ description: 'List all tools and exit',
112
+ })
113
+ .option('client', {
114
+ type: 'string',
115
+ choices: Object.keys(knownClients),
116
+ description: 'Specify the MCP client being used',
117
+ })
118
+ .option('capability', {
119
+ type: 'string',
120
+ array: true,
121
+ description: 'Specify client capabilities',
122
+ coerce: (values: string[]) => {
123
+ return values.flatMap((v) => v.split(','));
124
+ },
125
+ })
126
+ .option('no-capability', {
127
+ type: 'string',
128
+ array: true,
129
+ description: 'Unset client capabilities',
130
+ choices: CAPABILITY_CHOICES,
131
+ coerce: (values: string[]) => {
132
+ return values.flatMap((v) => v.split(','));
133
+ },
134
+ })
135
+ .option('describe-capabilities', {
136
+ type: 'boolean',
137
+ description: 'Print detailed explanation of client capabilities and exit',
138
+ })
139
+ .option('transport', {
140
+ type: 'string',
141
+ choices: ['stdio', 'http'],
142
+ default: 'stdio',
143
+ description: 'What transport to use; stdio for local servers or http for remote servers',
144
+ })
145
+ .option('port', {
146
+ type: 'number',
147
+ description: 'Port to serve on if using http transport',
148
+ })
149
+ .option('socket', {
150
+ type: 'string',
151
+ description: 'Unix socket to serve on if using http transport',
152
+ })
153
+ .help();
154
+
155
+ for (const [command, desc] of examples()) {
156
+ opts.example(command, desc);
157
+ }
158
+
159
+ const argv = opts.parseSync();
160
+
161
+ // Handle describe-capabilities flag
162
+ if (argv.describeCapabilities) {
163
+ console.log(getCapabilitiesExplanation());
164
+ process.exit(0);
165
+ }
166
+
167
+ const filters: Filter[] = [];
168
+
169
+ // Helper function to support comma-separated values
170
+ const splitValues = (values: string[] | undefined): string[] => {
171
+ if (!values) return [];
172
+ return values.flatMap((v) => v.split(','));
173
+ };
174
+
175
+ for (const tag of splitValues(argv.tag)) {
176
+ filters.push({ type: 'tag', op: 'include', value: tag });
177
+ }
178
+
179
+ for (const tag of splitValues(argv.noTag)) {
180
+ filters.push({ type: 'tag', op: 'exclude', value: tag });
181
+ }
182
+
183
+ for (const resource of splitValues(argv.resource)) {
184
+ filters.push({ type: 'resource', op: 'include', value: resource });
185
+ }
186
+
187
+ for (const resource of splitValues(argv.noResource)) {
188
+ filters.push({ type: 'resource', op: 'exclude', value: resource });
189
+ }
190
+
191
+ for (const tool of splitValues(argv.tool)) {
192
+ filters.push({ type: 'tool', op: 'include', value: tool });
193
+ }
194
+
195
+ for (const tool of splitValues(argv.noTool)) {
196
+ filters.push({ type: 'tool', op: 'exclude', value: tool });
197
+ }
198
+
199
+ for (const operation of splitValues(argv.operation)) {
200
+ filters.push({ type: 'operation', op: 'include', value: operation });
201
+ }
202
+
203
+ for (const operation of splitValues(argv.noOperation)) {
204
+ filters.push({ type: 'operation', op: 'exclude', value: operation });
205
+ }
206
+
207
+ // Parse client capabilities
208
+ const clientCapabilities: Partial<ClientCapabilities> = {};
209
+
210
+ // Apply individual capability overrides
211
+ if (Array.isArray(argv.capability)) {
212
+ for (const cap of argv.capability) {
213
+ const parsedCap = parseCapabilityValue(cap);
214
+ if (parsedCap.name === 'top-level-unions') {
215
+ clientCapabilities.topLevelUnions = true;
216
+ } else if (parsedCap.name === 'valid-json') {
217
+ clientCapabilities.validJson = true;
218
+ } else if (parsedCap.name === 'refs') {
219
+ clientCapabilities.refs = true;
220
+ } else if (parsedCap.name === 'unions') {
221
+ clientCapabilities.unions = true;
222
+ } else if (parsedCap.name === 'formats') {
223
+ clientCapabilities.formats = true;
224
+ } else if (parsedCap.name === 'tool-name-length') {
225
+ clientCapabilities.toolNameLength = parsedCap.value;
226
+ }
227
+ }
228
+ }
229
+
230
+ // Handle no-capability options to unset capabilities
231
+ if (Array.isArray(argv.noCapability)) {
232
+ for (const cap of argv.noCapability) {
233
+ if (cap === 'top-level-unions') {
234
+ clientCapabilities.topLevelUnions = false;
235
+ } else if (cap === 'valid-json') {
236
+ clientCapabilities.validJson = false;
237
+ } else if (cap === 'refs') {
238
+ clientCapabilities.refs = false;
239
+ } else if (cap === 'unions') {
240
+ clientCapabilities.unions = false;
241
+ } else if (cap === 'formats') {
242
+ clientCapabilities.formats = false;
243
+ } else if (cap === 'tool-name-length') {
244
+ clientCapabilities.toolNameLength = undefined;
245
+ }
246
+ }
247
+ }
248
+
249
+ const shouldIncludeToolType = (toolType: 'dynamic' | 'all' | 'code' | 'docs') =>
250
+ argv.noTools?.includes(toolType) ? false
251
+ : argv.tools?.includes(toolType) ? true
252
+ : undefined;
253
+
254
+ const includeDynamicTools = shouldIncludeToolType('dynamic');
255
+ const includeAllTools = shouldIncludeToolType('all');
256
+ const includeCodeTools = shouldIncludeToolType('code');
257
+ const includeDocsTools = shouldIncludeToolType('docs');
258
+
259
+ const transport = argv.transport as 'stdio' | 'http';
260
+
261
+ const client = argv.client as ClientType;
262
+ return {
263
+ client: client && client !== 'infer' && knownClients[client] ? client : undefined,
264
+ includeDynamicTools,
265
+ includeAllTools,
266
+ includeCodeTools,
267
+ includeDocsTools,
268
+ filters,
269
+ capabilities: clientCapabilities,
270
+ list: argv.list || false,
271
+ transport,
272
+ port: argv.port,
273
+ socket: argv.socket,
274
+ };
275
+ }
276
+
277
+ const coerceArray = <T extends z.ZodTypeAny>(zodType: T) =>
278
+ z.preprocess(
279
+ (val) =>
280
+ Array.isArray(val) ? val
281
+ : val ? [val]
282
+ : val,
283
+ z.array(zodType).optional(),
284
+ );
285
+
286
+ const QueryOptions = z.object({
287
+ tools: coerceArray(z.enum(['dynamic', 'all', 'docs'])).describe('Use dynamic tools or all tools'),
288
+ no_tools: coerceArray(z.enum(['dynamic', 'all', 'docs'])).describe('Do not use dynamic tools or all tools'),
289
+ tool: coerceArray(z.string()).describe('Include tools matching the specified names'),
290
+ resource: coerceArray(z.string()).describe('Include tools matching the specified resources'),
291
+ operation: coerceArray(z.enum(['read', 'write'])).describe(
292
+ 'Include tools matching the specified operations',
293
+ ),
294
+ tag: coerceArray(z.string()).describe('Include tools with the specified tags'),
295
+ no_tool: coerceArray(z.string()).describe('Exclude tools matching the specified names'),
296
+ no_resource: coerceArray(z.string()).describe('Exclude tools matching the specified resources'),
297
+ no_operation: coerceArray(z.enum(['read', 'write'])).describe(
298
+ 'Exclude tools matching the specified operations',
299
+ ),
300
+ no_tag: coerceArray(z.string()).describe('Exclude tools with the specified tags'),
301
+ client: ClientType.optional().describe('Specify the MCP client being used'),
302
+ capability: coerceArray(z.string()).describe('Specify client capabilities'),
303
+ no_capability: coerceArray(z.enum(CAPABILITY_CHOICES)).describe('Unset client capabilities'),
304
+ });
305
+
306
+ export function parseQueryOptions(defaultOptions: McpOptions, query: unknown): McpOptions {
307
+ const queryObject = typeof query === 'string' ? qs.parse(query) : query;
308
+ const queryOptions = QueryOptions.parse(queryObject);
309
+
310
+ const filters: Filter[] = [...(defaultOptions.filters ?? [])];
311
+
312
+ for (const resource of queryOptions.resource || []) {
313
+ filters.push({ type: 'resource', op: 'include', value: resource });
314
+ }
315
+ for (const operation of queryOptions.operation || []) {
316
+ filters.push({ type: 'operation', op: 'include', value: operation });
317
+ }
318
+ for (const tag of queryOptions.tag || []) {
319
+ filters.push({ type: 'tag', op: 'include', value: tag });
320
+ }
321
+ for (const tool of queryOptions.tool || []) {
322
+ filters.push({ type: 'tool', op: 'include', value: tool });
323
+ }
324
+ for (const resource of queryOptions.no_resource || []) {
325
+ filters.push({ type: 'resource', op: 'exclude', value: resource });
326
+ }
327
+ for (const operation of queryOptions.no_operation || []) {
328
+ filters.push({ type: 'operation', op: 'exclude', value: operation });
329
+ }
330
+ for (const tag of queryOptions.no_tag || []) {
331
+ filters.push({ type: 'tag', op: 'exclude', value: tag });
332
+ }
333
+ for (const tool of queryOptions.no_tool || []) {
334
+ filters.push({ type: 'tool', op: 'exclude', value: tool });
335
+ }
336
+
337
+ // Parse client capabilities
338
+ const clientCapabilities: Partial<ClientCapabilities> = { ...defaultOptions.capabilities };
339
+
340
+ for (const cap of queryOptions.capability || []) {
341
+ const parsed = parseCapabilityValue(cap);
342
+ if (parsed.name === 'top-level-unions') {
343
+ clientCapabilities.topLevelUnions = true;
344
+ } else if (parsed.name === 'valid-json') {
345
+ clientCapabilities.validJson = true;
346
+ } else if (parsed.name === 'refs') {
347
+ clientCapabilities.refs = true;
348
+ } else if (parsed.name === 'unions') {
349
+ clientCapabilities.unions = true;
350
+ } else if (parsed.name === 'formats') {
351
+ clientCapabilities.formats = true;
352
+ } else if (parsed.name === 'tool-name-length') {
353
+ clientCapabilities.toolNameLength = parsed.value;
354
+ }
355
+ }
356
+
357
+ for (const cap of queryOptions.no_capability || []) {
358
+ if (cap === 'top-level-unions') {
359
+ clientCapabilities.topLevelUnions = false;
360
+ } else if (cap === 'valid-json') {
361
+ clientCapabilities.validJson = false;
362
+ } else if (cap === 'refs') {
363
+ clientCapabilities.refs = false;
364
+ } else if (cap === 'unions') {
365
+ clientCapabilities.unions = false;
366
+ } else if (cap === 'formats') {
367
+ clientCapabilities.formats = false;
368
+ } else if (cap === 'tool-name-length') {
369
+ clientCapabilities.toolNameLength = undefined;
370
+ }
371
+ }
372
+
373
+ let dynamicTools: boolean | undefined =
374
+ queryOptions.no_tools && queryOptions.no_tools?.includes('dynamic') ? false
375
+ : queryOptions.tools?.includes('dynamic') ? true
376
+ : defaultOptions.includeDynamicTools;
377
+
378
+ let allTools: boolean | undefined =
379
+ queryOptions.no_tools && queryOptions.no_tools?.includes('all') ? false
380
+ : queryOptions.tools?.includes('all') ? true
381
+ : defaultOptions.includeAllTools;
382
+
383
+ let docsTools: boolean | undefined =
384
+ queryOptions.no_tools && queryOptions.no_tools?.includes('docs') ? false
385
+ : queryOptions.tools?.includes('docs') ? true
386
+ : defaultOptions.includeDocsTools;
387
+
388
+ return {
389
+ client: queryOptions.client ?? defaultOptions.client,
390
+ includeDynamicTools: dynamicTools,
391
+ includeAllTools: allTools,
392
+ includeCodeTools: undefined,
393
+ includeDocsTools: docsTools,
394
+ filters,
395
+ capabilities: clientCapabilities,
396
+ };
397
+ }
398
+
399
+ function getCapabilitiesExplanation(): string {
400
+ return `
401
+ Client Capabilities Explanation:
402
+
403
+ Different Language Models (LLMs) and the MCP clients that use them have varying limitations in how they handle tool schemas. Capability flags allow you to inform the MCP server about these limitations.
404
+
405
+ When a capability flag is set to false, the MCP server will automatically adjust the tool schemas to work around that limitation, ensuring broader compatibility.
406
+
407
+ Available Capabilities:
408
+
409
+ # top-level-unions
410
+ Some clients/LLMs do not support JSON schemas with a union type (anyOf) at the root level. If a client lacks this capability, the MCP server splits tools with top-level unions into multiple separate tools, one for each variant in the union.
411
+
412
+ # refs
413
+ Some clients/LLMs do not support $ref pointers for schema reuse. If a client lacks this capability, the MCP server automatically inlines all references ($defs) directly into the schema. Properties that would cause circular references are removed during this process.
414
+
415
+ # valid-json
416
+ Some clients/LLMs may incorrectly send arguments as a JSON-encoded string instead of a proper JSON object. If a client *has* this capability, the MCP server will attempt to parse string values as JSON if the initial validation against the schema fails.
417
+
418
+ # unions
419
+ Some clients/LLMs do not support union types (anyOf) in JSON schemas. If a client lacks this capability, the MCP server removes all anyOf fields and uses only the first variant as the schema.
420
+
421
+ # formats
422
+ Some clients/LLMs do not support the 'format' keyword in JSON Schema specifications. If a client lacks this capability, the MCP server removes all format fields and appends the format information to the field's description in parentheses.
423
+
424
+ # tool-name-length=N
425
+ Some clients/LLMs impose a maximum length on tool names. If this capability is set, the MCP server will automatically truncate tool names exceeding the specified length (N), ensuring uniqueness by appending numbers if necessary.
426
+
427
+ Client Presets (--client):
428
+ Presets like '--client=openai-agents' or '--client=cursor' automatically configure these capabilities based on current known limitations of those clients, simplifying setup.
429
+
430
+ Current presets:
431
+ ${JSON.stringify(knownClients, null, 2)}
432
+ `;
433
+ }
434
+
435
+ function examples(): [string, string][] {
436
+ const firstEndpoint = endpoints[0]!;
437
+ const secondEndpoint =
438
+ endpoints.find((e) => e.metadata.resource !== firstEndpoint.metadata.resource) || endpoints[1];
439
+ const tag = endpoints.find((e) => e.metadata.tags.length > 0)?.metadata.tags[0];
440
+ const otherEndpoint = secondEndpoint || firstEndpoint;
441
+
442
+ return [
443
+ [
444
+ `--tool="${firstEndpoint.tool.name}" ${secondEndpoint ? `--tool="${secondEndpoint.tool.name}"` : ''}`,
445
+ 'Include tools by name',
446
+ ],
447
+ [
448
+ `--resource="${firstEndpoint.metadata.resource}" --operation="read"`,
449
+ 'Filter by resource and operation',
450
+ ],
451
+ [
452
+ `--resource="${otherEndpoint.metadata.resource}*" --no-tool="${otherEndpoint.tool.name}"`,
453
+ 'Use resource wildcards and exclusions',
454
+ ],
455
+ [`--client="cursor"`, 'Adjust schemas to be more compatible with Cursor'],
456
+ [
457
+ `--capability="top-level-unions" --capability="tool-name-length=40"`,
458
+ 'Specify individual client capabilities',
459
+ ],
460
+ [
461
+ `--client="cursor" --no-capability="tool-name-length"`,
462
+ 'Use cursor client preset but remove tool name length limit',
463
+ ],
464
+ ...(tag ? [[`--tag="${tag}"`, 'Filter based on tags'] as [string, string]] : []),
465
+ ];
466
+ }