@unchainedshop/api 3.1.12 → 3.1.13

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 (252) hide show
  1. package/lib/errors.d.ts +1 -0
  2. package/lib/errors.d.ts.map +1 -1
  3. package/lib/errors.js +1 -0
  4. package/lib/errors.js.map +1 -1
  5. package/lib/express/chatRouter.d.ts +3 -0
  6. package/lib/express/chatRouter.d.ts.map +1 -0
  7. package/lib/express/chatRouter.js +86 -0
  8. package/lib/express/chatRouter.js.map +1 -0
  9. package/lib/express/createApolloMiddleware.d.ts +4 -0
  10. package/lib/express/createApolloMiddleware.d.ts.map +1 -0
  11. package/lib/express/createApolloMiddleware.js +36 -0
  12. package/lib/express/createApolloMiddleware.js.map +1 -0
  13. package/lib/express/createSingleSignOnMiddleware.d.ts +5 -0
  14. package/lib/express/createSingleSignOnMiddleware.d.ts.map +1 -0
  15. package/lib/express/createSingleSignOnMiddleware.js +71 -0
  16. package/lib/express/createSingleSignOnMiddleware.js.map +1 -0
  17. package/lib/hashPassword.d.ts +2 -0
  18. package/lib/hashPassword.d.ts.map +1 -0
  19. package/lib/hashPassword.js +5 -0
  20. package/lib/hashPassword.js.map +1 -0
  21. package/lib/loaders/assortmentMediaTextLoader.js +1 -1
  22. package/lib/loaders/assortmentMediaTextLoader.js.map +1 -1
  23. package/lib/loaders/assortmentTextLoader.js +1 -1
  24. package/lib/loaders/assortmentTextLoader.js.map +1 -1
  25. package/lib/loaders/filterTextLoader.js +1 -1
  26. package/lib/loaders/filterTextLoader.js.map +1 -1
  27. package/lib/loaders/index.d.ts.map +1 -1
  28. package/lib/loaders/index.js.map +1 -1
  29. package/lib/loaders/productMediaTextLoader.d.ts.map +1 -1
  30. package/lib/loaders/productMediaTextLoader.js +1 -1
  31. package/lib/loaders/productMediaTextLoader.js.map +1 -1
  32. package/lib/loaders/productTextLoader.d.ts.map +1 -1
  33. package/lib/loaders/productTextLoader.js +1 -1
  34. package/lib/loaders/productTextLoader.js.map +1 -1
  35. package/lib/mcp/index.d.ts.map +1 -1
  36. package/lib/mcp/index.js +1 -1
  37. package/lib/mcp/index.js.map +1 -1
  38. package/lib/mcp/tools/addProductAssignmentHandler.d.ts +52 -0
  39. package/lib/mcp/tools/addProductAssignmentHandler.d.ts.map +1 -0
  40. package/lib/mcp/tools/addProductAssignmentHandler.js +97 -0
  41. package/lib/mcp/tools/addProductAssignmentHandler.js.map +1 -0
  42. package/lib/mcp/tools/countriesHandler.d.ts +60 -0
  43. package/lib/mcp/tools/countriesHandler.d.ts.map +1 -0
  44. package/lib/mcp/tools/countriesHandler.js +48 -0
  45. package/lib/mcp/tools/countriesHandler.js.map +1 -0
  46. package/lib/mcp/tools/countryHandler.d.ts +20 -0
  47. package/lib/mcp/tools/countryHandler.d.ts.map +1 -0
  48. package/lib/mcp/tools/countryHandler.js +34 -0
  49. package/lib/mcp/tools/countryHandler.js.map +1 -0
  50. package/lib/mcp/tools/createProduct.d.ts +138 -0
  51. package/lib/mcp/tools/createProduct.d.ts.map +1 -0
  52. package/lib/mcp/tools/createProduct.js +60 -0
  53. package/lib/mcp/tools/createProduct.js.map +1 -0
  54. package/lib/mcp/tools/createProductVariationHandler.d.ts +84 -0
  55. package/lib/mcp/tools/createProductVariationHandler.d.ts.map +1 -0
  56. package/lib/mcp/tools/createProductVariationHandler.js +67 -0
  57. package/lib/mcp/tools/createProductVariationHandler.js.map +1 -0
  58. package/lib/mcp/tools/currenciesHandler.d.ts +60 -0
  59. package/lib/mcp/tools/currenciesHandler.d.ts.map +1 -0
  60. package/lib/mcp/tools/currenciesHandler.js +50 -0
  61. package/lib/mcp/tools/currenciesHandler.js.map +1 -0
  62. package/lib/mcp/tools/currencyHandler.d.ts +20 -0
  63. package/lib/mcp/tools/currencyHandler.d.ts.map +1 -0
  64. package/lib/mcp/tools/currencyHandler.js +34 -0
  65. package/lib/mcp/tools/currencyHandler.js.map +1 -0
  66. package/lib/mcp/tools/getProduct.d.ts +0 -3
  67. package/lib/mcp/tools/getProduct.d.ts.map +1 -1
  68. package/lib/mcp/tools/getProduct.js +0 -324
  69. package/lib/mcp/tools/getProduct.js.map +1 -1
  70. package/lib/mcp/tools/languageHandler.d.ts +20 -0
  71. package/lib/mcp/tools/languageHandler.d.ts.map +1 -0
  72. package/lib/mcp/tools/languageHandler.js +31 -0
  73. package/lib/mcp/tools/languageHandler.js.map +1 -0
  74. package/lib/mcp/tools/languagesHandler.d.ts +60 -0
  75. package/lib/mcp/tools/languagesHandler.d.ts.map +1 -0
  76. package/lib/mcp/tools/languagesHandler.js +42 -0
  77. package/lib/mcp/tools/languagesHandler.js.map +1 -0
  78. package/lib/mcp/tools/listProducts.d.ts.map +1 -1
  79. package/lib/mcp/tools/listProducts.js +0 -13
  80. package/lib/mcp/tools/listProducts.js.map +1 -1
  81. package/lib/mcp/tools/normalizeMediaUrl.d.ts +3 -0
  82. package/lib/mcp/tools/normalizeMediaUrl.d.ts.map +1 -0
  83. package/lib/mcp/tools/normalizeMediaUrl.js +21 -0
  84. package/lib/mcp/tools/normalizeMediaUrl.js.map +1 -0
  85. package/lib/mcp/tools/productsCountHandler.d.ts +32 -0
  86. package/lib/mcp/tools/productsCountHandler.d.ts.map +1 -0
  87. package/lib/mcp/tools/productsCountHandler.js +33 -0
  88. package/lib/mcp/tools/productsCountHandler.js.map +1 -0
  89. package/lib/mcp/tools/publishProduct.d.ts +20 -0
  90. package/lib/mcp/tools/publishProduct.d.ts.map +1 -0
  91. package/lib/mcp/tools/publishProduct.js +40 -0
  92. package/lib/mcp/tools/publishProduct.js.map +1 -0
  93. package/lib/mcp/tools/removeProduct.d.ts +20 -0
  94. package/lib/mcp/tools/removeProduct.d.ts.map +1 -0
  95. package/lib/mcp/tools/removeProduct.js +34 -0
  96. package/lib/mcp/tools/removeProduct.js.map +1 -0
  97. package/lib/mcp/tools/removeProductVariationHandler.d.ts +20 -0
  98. package/lib/mcp/tools/removeProductVariationHandler.d.ts.map +1 -0
  99. package/lib/mcp/tools/removeProductVariationHandler.js +43 -0
  100. package/lib/mcp/tools/removeProductVariationHandler.js.map +1 -0
  101. package/lib/mcp/tools/unPublishProduct.d.ts +20 -0
  102. package/lib/mcp/tools/unPublishProduct.d.ts.map +1 -0
  103. package/lib/mcp/tools/unPublishProduct.js +40 -0
  104. package/lib/mcp/tools/unPublishProduct.js.map +1 -0
  105. package/lib/mcp/tools/updateProduct.d.ts +56 -0
  106. package/lib/mcp/tools/updateProduct.d.ts.map +1 -0
  107. package/lib/mcp/tools/updateProduct.js +44 -0
  108. package/lib/mcp/tools/updateProduct.js.map +1 -0
  109. package/lib/mcp/tools/updateProductCommerceHandler.d.ts +166 -0
  110. package/lib/mcp/tools/updateProductCommerceHandler.d.ts.map +1 -0
  111. package/lib/mcp/tools/updateProductCommerceHandler.js +64 -0
  112. package/lib/mcp/tools/updateProductCommerceHandler.js.map +1 -0
  113. package/lib/mcp/tools/updateProductPlanHandler.d.ts +72 -0
  114. package/lib/mcp/tools/updateProductPlanHandler.d.ts.map +1 -0
  115. package/lib/mcp/tools/updateProductPlanHandler.js +51 -0
  116. package/lib/mcp/tools/updateProductPlanHandler.js.map +1 -0
  117. package/lib/mcp/tools/updateProductSupplyHandler.d.ts +64 -0
  118. package/lib/mcp/tools/updateProductSupplyHandler.d.ts.map +1 -0
  119. package/lib/mcp/tools/updateProductSupplyHandler.js +52 -0
  120. package/lib/mcp/tools/updateProductSupplyHandler.js.map +1 -0
  121. package/lib/mcp/tools/updateProductTextsHandler.d.ts +114 -0
  122. package/lib/mcp/tools/updateProductTextsHandler.d.ts.map +1 -0
  123. package/lib/mcp/tools/updateProductTextsHandler.js +50 -0
  124. package/lib/mcp/tools/updateProductTextsHandler.js.map +1 -0
  125. package/lib/mcp/tools/updateProductTokenizationHandler.d.ts +72 -0
  126. package/lib/mcp/tools/updateProductTokenizationHandler.d.ts.map +1 -0
  127. package/lib/mcp/tools/updateProductTokenizationHandler.js +49 -0
  128. package/lib/mcp/tools/updateProductTokenizationHandler.js.map +1 -0
  129. package/lib/mcp/tools/updateProductWarehousingHandler.d.ts +48 -0
  130. package/lib/mcp/tools/updateProductWarehousingHandler.d.ts.map +1 -0
  131. package/lib/mcp/tools/updateProductWarehousingHandler.js +45 -0
  132. package/lib/mcp/tools/updateProductWarehousingHandler.js.map +1 -0
  133. package/lib/mcp/utils/getNormalizedProductDetails.d.ts +26 -0
  134. package/lib/mcp/utils/getNormalizedProductDetails.d.ts.map +1 -0
  135. package/lib/mcp/utils/getNormalizedProductDetails.js +36 -0
  136. package/lib/mcp/utils/getNormalizedProductDetails.js.map +1 -0
  137. package/lib/mcp/utils/normalizeMediaUrl.d.ts +3 -0
  138. package/lib/mcp/utils/normalizeMediaUrl.d.ts.map +1 -0
  139. package/lib/mcp/utils/normalizeMediaUrl.js +21 -0
  140. package/lib/mcp/utils/normalizeMediaUrl.js.map +1 -0
  141. package/lib/resolvers/mutations/accounts/buildSecretTOTPAuthURL.d.ts +3 -0
  142. package/lib/resolvers/mutations/accounts/buildSecretTOTPAuthURL.d.ts.map +1 -0
  143. package/lib/resolvers/mutations/accounts/buildSecretTOTPAuthURL.js +6 -0
  144. package/lib/resolvers/mutations/accounts/buildSecretTOTPAuthURL.js.map +1 -0
  145. package/lib/resolvers/mutations/accounts/disableTOTP.d.ts +6 -0
  146. package/lib/resolvers/mutations/accounts/disableTOTP.d.ts.map +1 -0
  147. package/lib/resolvers/mutations/accounts/disableTOTP.js +27 -0
  148. package/lib/resolvers/mutations/accounts/disableTOTP.js.map +1 -0
  149. package/lib/resolvers/mutations/accounts/enableTOTP.d.ts +6 -0
  150. package/lib/resolvers/mutations/accounts/enableTOTP.d.ts.map +1 -0
  151. package/lib/resolvers/mutations/accounts/enableTOTP.js +20 -0
  152. package/lib/resolvers/mutations/accounts/enableTOTP.js.map +1 -0
  153. package/lib/resolvers/mutations/accounts/linkOAuthAccount.d.ts +7 -0
  154. package/lib/resolvers/mutations/accounts/linkOAuthAccount.d.ts.map +1 -0
  155. package/lib/resolvers/mutations/accounts/linkOAuthAccount.js +30 -0
  156. package/lib/resolvers/mutations/accounts/linkOAuthAccount.js.map +1 -0
  157. package/lib/resolvers/mutations/accounts/loginWithOAuth.d.ts +8 -0
  158. package/lib/resolvers/mutations/accounts/loginWithOAuth.d.ts.map +1 -0
  159. package/lib/resolvers/mutations/accounts/loginWithOAuth.js +25 -0
  160. package/lib/resolvers/mutations/accounts/loginWithOAuth.js.map +1 -0
  161. package/lib/resolvers/mutations/accounts/logoutAllSessions.d.ts +5 -0
  162. package/lib/resolvers/mutations/accounts/logoutAllSessions.d.ts.map +1 -0
  163. package/lib/resolvers/mutations/accounts/logoutAllSessions.js +20 -0
  164. package/lib/resolvers/mutations/accounts/logoutAllSessions.js.map +1 -0
  165. package/lib/resolvers/mutations/accounts/unlinkOAuthAccount.d.ts +6 -0
  166. package/lib/resolvers/mutations/accounts/unlinkOAuthAccount.d.ts.map +1 -0
  167. package/lib/resolvers/mutations/accounts/unlinkOAuthAccount.js +13 -0
  168. package/lib/resolvers/mutations/accounts/unlinkOAuthAccount.js.map +1 -0
  169. package/lib/resolvers/mutations/assortments/addAssortmentMedia.d.ts +6 -0
  170. package/lib/resolvers/mutations/assortments/addAssortmentMedia.d.ts.map +1 -0
  171. package/lib/resolvers/mutations/assortments/addAssortmentMedia.js +18 -0
  172. package/lib/resolvers/mutations/assortments/addAssortmentMedia.js.map +1 -0
  173. package/lib/resolvers/mutations/products/addProductAssignment.d.ts.map +1 -1
  174. package/lib/resolvers/mutations/products/addProductAssignment.js +3 -1
  175. package/lib/resolvers/mutations/products/addProductAssignment.js.map +1 -1
  176. package/lib/resolvers/mutations/products/addProductMedia.d.ts +6 -0
  177. package/lib/resolvers/mutations/products/addProductMedia.d.ts.map +1 -0
  178. package/lib/resolvers/mutations/products/addProductMedia.js +18 -0
  179. package/lib/resolvers/mutations/products/addProductMedia.js.map +1 -0
  180. package/lib/resolvers/mutations/users/updateUserAvatar.d.ts +6 -0
  181. package/lib/resolvers/mutations/users/updateUserAvatar.d.ts.map +1 -0
  182. package/lib/resolvers/mutations/users/updateUserAvatar.js +22 -0
  183. package/lib/resolvers/mutations/users/updateUserAvatar.js.map +1 -0
  184. package/lib/resolvers/mutations/utils/getOrderCart.d.ts +7 -0
  185. package/lib/resolvers/mutations/utils/getOrderCart.d.ts.map +1 -0
  186. package/lib/resolvers/mutations/utils/getOrderCart.js +13 -0
  187. package/lib/resolvers/mutations/utils/getOrderCart.js.map +1 -0
  188. package/lib/resolvers/type/dispatch-types.d.ts +15 -0
  189. package/lib/resolvers/type/dispatch-types.d.ts.map +1 -0
  190. package/lib/resolvers/type/dispatch-types.js +16 -0
  191. package/lib/resolvers/type/dispatch-types.js.map +1 -0
  192. package/lib/resolvers/type/oauth-account.d.ts +6 -0
  193. package/lib/resolvers/type/oauth-account.d.ts.map +1 -0
  194. package/lib/resolvers/type/oauth-account.js +7 -0
  195. package/lib/resolvers/type/oauth-account.js.map +1 -0
  196. package/lib/resolvers/type/oauth-provider.d.ts +6 -0
  197. package/lib/resolvers/type/oauth-provider.d.ts.map +1 -0
  198. package/lib/resolvers/type/oauth-provider.js +6 -0
  199. package/lib/resolvers/type/oauth-provider.js.map +1 -0
  200. package/lib/resolvers/type/stock-types.d.ts +14 -0
  201. package/lib/resolvers/type/stock-types.d.ts.map +1 -0
  202. package/lib/resolvers/type/stock-types.js +15 -0
  203. package/lib/resolvers/type/stock-types.js.map +1 -0
  204. package/lib/user-context.d.ts +7 -0
  205. package/lib/user-context.d.ts.map +1 -0
  206. package/lib/user-context.js +76 -0
  207. package/lib/user-context.js.map +1 -0
  208. package/package.json +13 -13
  209. package/src/errors.ts +5 -0
  210. package/src/loaders/buildLocaleMap.test.ts +14 -25
  211. package/src/loaders/buildLocaleMap.ts +1 -1
  212. package/src/loaders/buildTextMap.test.ts +9 -10
  213. package/src/loaders/index.ts +0 -1
  214. package/src/resolvers/mutations/products/addProductAssignment.ts +8 -1
  215. package/lib/express/mcpHandler.d.ts.map +0 -1
  216. package/lib/express/mcpHandler.js +0 -68
  217. package/lib/express/mcpHandler.js.map +0 -1
  218. package/lib/fastify/createMCPMiddleware.d.ts +0 -2
  219. package/lib/fastify/createMCPMiddleware.d.ts.map +0 -1
  220. package/lib/fastify/createMCPMiddleware.js +0 -2
  221. package/lib/fastify/createMCPMiddleware.js.map +0 -1
  222. package/lib/fastify/index copy.d.ts.map +0 -1
  223. package/lib/fastify/index copy.js +0 -157
  224. package/lib/fastify/index copy.js.map +0 -1
  225. package/lib/fastify/mcpHandler.d.ts +0 -8
  226. package/lib/fastify/mcpHandler.d.ts.map +0 -1
  227. package/lib/fastify/mcpHandler.js +0 -46
  228. package/lib/fastify/mcpHandler.js.map +0 -1
  229. package/lib/mcp/server.d.ts +0 -4
  230. package/lib/mcp/server.d.ts.map +0 -1
  231. package/lib/mcp/server.js +0 -60
  232. package/lib/mcp/server.js.map +0 -1
  233. package/lib/mcp/types.d.ts +0 -27
  234. package/lib/mcp/types.d.ts.map +0 -1
  235. package/lib/mcp/types.js +0 -5
  236. package/lib/mcp/types.js.map +0 -1
  237. package/lib/mcp/utils/html.d.ts +0 -16
  238. package/lib/mcp/utils/html.d.ts.map +0 -1
  239. package/lib/mcp/utils/html.js +0 -102
  240. package/lib/mcp/utils/html.js.map +0 -1
  241. package/lib/middleware/accountLockout.d.ts.map +0 -1
  242. package/lib/middleware/accountLockout.js +0 -84
  243. package/lib/middleware/accountLockout.js.map +0 -1
  244. package/lib/middleware/rateLimiter.d.ts.map +0 -1
  245. package/lib/middleware/rateLimiter.js +0 -91
  246. package/lib/middleware/rateLimiter.js.map +0 -1
  247. package/lib/plugins/inputValidation.d.ts.map +0 -1
  248. package/lib/plugins/inputValidation.js +0 -95
  249. package/lib/plugins/inputValidation.js.map +0 -1
  250. package/lib/utils/inputValidation.d.ts.map +0 -1
  251. package/lib/utils/inputValidation.js +0 -51
  252. package/lib/utils/inputValidation.js.map +0 -1
@@ -6,7 +6,7 @@ const testTexts = [
6
6
  // 1 has translations in French and German
7
7
  { locale: 'fr', _id: 'french-1', entityId: '1' },
8
8
  { locale: 'de', _id: 'german-1', entityId: '1' },
9
-
9
+
10
10
  // 2 only has Ialien translations
11
11
  { locale: 'it', _id: 'italian-2', entityId: '2' },
12
12
 
@@ -20,30 +20,30 @@ const testTexts = [
20
20
  describe('buildTextMap', () => {
21
21
  it('Generate a correct text map for all fallbacks', () => {
22
22
  const localeMap = {
23
- 'de': ['de-CH', 'fr', 'it'],
24
- 'fr': ['fr'],
25
- 'it': ['it'],
23
+ de: ['de-CH', 'fr', 'it'],
24
+ fr: ['fr'],
25
+ it: ['it'],
26
26
  };
27
27
  const expected = {
28
28
  'de-CH1': {
29
29
  _id: 'german-1',
30
30
  },
31
- 'fr1': {
31
+ fr1: {
32
32
  _id: 'french-1',
33
33
  },
34
- 'it1': {
34
+ it1: {
35
35
  _id: 'german-1',
36
36
  },
37
37
  'de-CH4': {
38
38
  _id: 'german-4',
39
39
  },
40
- 'fr4': {
40
+ fr4: {
41
41
  _id: 'german-4',
42
42
  },
43
- 'it4': {
43
+ it4: {
44
44
  _id: 'german-4',
45
45
  },
46
- 'it2': {
46
+ it2: {
47
47
  _id: 'italian-2',
48
48
  },
49
49
  };
@@ -51,5 +51,4 @@ describe('buildTextMap', () => {
51
51
 
52
52
  assert.partialDeepStrictEqual(result, expected);
53
53
  });
54
-
55
54
  });
@@ -14,7 +14,6 @@ import { File } from '@unchainedshop/core-files';
14
14
  import buildTextMap from './buildTextMap.js';
15
15
  import buildLocaleMap from './buildLocaleMap.js';
16
16
 
17
-
18
17
  const loaders = async (unchainedAPI: UnchainedCore) => {
19
18
  return {
20
19
  assortmentLoader: new DataLoader<{ assortmentId: string }, Assortment>(async (queries) => {
@@ -3,7 +3,12 @@ import { ProductTypes } from '@unchainedshop/core-products';
3
3
 
4
4
  import { Context } from '../../../context.js';
5
5
  import { ProductConfiguration } from '@unchainedshop/core-products';
6
- import { ProductNotFoundError, InvalidIdError, ProductWrongTypeError } from '../../../errors.js';
6
+ import {
7
+ ProductNotFoundError,
8
+ InvalidIdError,
9
+ ProductWrongTypeError,
10
+ ProductVariationInfinityLoop,
11
+ } from '../../../errors.js';
7
12
 
8
13
  export default async function addProductAssignment(
9
14
  root: never,
@@ -29,6 +34,8 @@ export default async function addProductAssignment(
29
34
  });
30
35
  if (!proxyProduct) throw new ProductNotFoundError({ proxyId });
31
36
 
37
+ if (productId === proxyId) throw new ProductVariationInfinityLoop({ productId });
38
+
32
39
  if (proxyProduct.type !== ProductTypes.ConfigurableProduct)
33
40
  throw new ProductWrongTypeError({
34
41
  proxyId,
@@ -1 +0,0 @@
1
- {"version":3,"file":"mcpHandler.d.ts","sourceRoot":"","sources":["../../src/express/mcpHandler.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AA4DzC,QAAA,MAAM,UAAU,EAAE,cAOjB,CAAC;AAEF,eAAe,UAAU,CAAC"}
@@ -1,68 +0,0 @@
1
- import { randomUUID } from 'node:crypto';
2
- import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
3
- import { isInitializeRequest } from '@modelcontextprotocol/sdk/types.js';
4
- import createMcpServer from '../mcp/index.js';
5
- // Map to store transports by session ID
6
- const transports = {};
7
- const handlePostRequest = async (req, res) => {
8
- // Check for existing session ID
9
- const sessionId = req.headers['mcp-session-id'];
10
- let transport;
11
- if (sessionId && transports[sessionId]) {
12
- // Reuse existing transport
13
- transport = transports[sessionId];
14
- }
15
- else if (!sessionId && isInitializeRequest(req.body)) {
16
- // New initialization request
17
- transport = new StreamableHTTPServerTransport({
18
- sessionIdGenerator: () => randomUUID(),
19
- onsessioninitialized: (sessionId) => {
20
- // Store the transport by session ID
21
- transports[sessionId] = transport;
22
- },
23
- });
24
- // Clean up transport when closed
25
- transport.onclose = () => {
26
- if (transport.sessionId) {
27
- delete transports[transport.sessionId];
28
- }
29
- };
30
- const server = createMcpServer();
31
- await server.connect(transport);
32
- }
33
- else {
34
- // Invalid request
35
- res.status(400).json({
36
- jsonrpc: '2.0',
37
- error: {
38
- code: -32000,
39
- message: 'Bad Request: No valid session ID provided',
40
- },
41
- id: null,
42
- });
43
- return;
44
- }
45
- // Handle the request
46
- await transport.handleRequest(req, res, req.body);
47
- };
48
- // Reusable handler for GET and DELETE requests
49
- const handleSessionRequest = async (req, res) => {
50
- const sessionId = req.headers['mcp-session-id'];
51
- if (!sessionId || !transports[sessionId]) {
52
- res.status(400).send('Invalid or missing session ID');
53
- return;
54
- }
55
- const transport = transports[sessionId];
56
- await transport.handleRequest(req, res);
57
- };
58
- const mcpHandler = (req, res, next) => {
59
- if (req.method === 'POST') {
60
- return handlePostRequest(req, res, next);
61
- }
62
- else if (req.method === 'GET' || req.method === 'DELETE') {
63
- return handleSessionRequest(req, res, next);
64
- }
65
- res.status(405).send('Method Not Allowed');
66
- };
67
- export default mcpHandler;
68
- //# sourceMappingURL=mcpHandler.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mcpHandler.js","sourceRoot":"","sources":["../../src/express/mcpHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,6BAA6B,EAAE,MAAM,oDAAoD,CAAC;AACnG,OAAO,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AACzE,OAAO,eAAe,MAAM,iBAAiB,CAAC;AAG9C,wCAAwC;AACxC,MAAM,UAAU,GAAkD,EAAE,CAAC;AAErE,MAAM,iBAAiB,GAAmB,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE;IAC3D,gCAAgC;IAChC,MAAM,SAAS,GAAG,GAAG,CAAC,OAAO,CAAC,gBAAgB,CAAuB,CAAC;IACtE,IAAI,SAAwC,CAAC;IAE7C,IAAI,SAAS,IAAI,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;QACvC,2BAA2B;QAC3B,SAAS,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC;I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,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,+BAA+B,CAAC,CAAC;QACtD,OAAO;IACT,CAAC;IAED,MAAM,SAAS,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC;IACxC,MAAM,SAAS,CAAC,aAAa,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;AAC1C,CAAC,CAAC;AAEF,MAAM,UAAU,GAAmB,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;IACpD,IAAI,GAAG,CAAC,MAAM,KAAK,MAAM,EAAE,CAAC;QAC1B,OAAO,iBAAiB,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;IAC3C,CAAC;SAAM,IAAI,GAAG,CAAC,MAAM,KAAK,KAAK,IAAI,GAAG,CAAC,MAAM,KAAK,QAAQ,EAAE,CAAC;QAC3D,OAAO,oBAAoB,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;IAC9C,CAAC;IACD,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC;AAC7C,CAAC,CAAC;AAEF,eAAe,UAAU,CAAC"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=createMCPMiddleware.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createMCPMiddleware.d.ts","sourceRoot":"","sources":["../../src/fastify/createMCPMiddleware.ts"],"names":[],"mappings":""}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=createMCPMiddleware.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createMCPMiddleware.js","sourceRoot":"","sources":["../../src/fastify/createMCPMiddleware.ts"],"names":[],"mappings":""}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index copy.d.ts","sourceRoot":"","sources":["../../src/fastify/index copy.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAMpD,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAkB,MAAM,SAAS,CAAC;AAgF7E,eAAO,MAAM,eAAe,GAAI,QAAQ,MAAM,KAAG,iBAehD,CAAC;AAEF,eAAO,MAAM,OAAO,GAClB,SAAS,eAAe,EACxB,yBAGG;IAAE,cAAc,EAAE,kBAAkB,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IAAC,EAAE,EAAE,OAAO,CAAC,EAAE,CAAC;IAAC,YAAY,EAAE,aAAa,CAAA;CAAE,EAChG,2CAEG;IAAE,mCAAmC,CAAC,EAAE,OAAO,CAAA;CAAO,SAwF1D,CAAC"}
@@ -1,157 +0,0 @@
1
- import { getCurrentContextResolver } from '../context.js';
2
- import bulkImportHandler from './bulkImportHandler.js';
3
- import ercMetadataHandler from './ercMetadataHandler.js';
4
- import MongoStore from 'connect-mongo';
5
- import { emit } from '@unchainedshop/events';
6
- import { API_EVENTS } from '../events.js';
7
- import fastifySession from '@fastify/session';
8
- import fastifyCookie from '@fastify/cookie';
9
- import { createLogger } from '@unchainedshop/logger';
10
- const resolveUserRemoteAddress = (req) => {
11
- const remoteAddress = req.headers['x-real-ip'] ||
12
- req.headers['x-forwarded-for'] ||
13
- req.socket?.remoteAddress;
14
- const remotePort = req.socket?.remotePort;
15
- return { remoteAddress, remotePort };
16
- };
17
- const { GRAPHQL_API_PATH = '/graphql', BULK_IMPORT_API_PATH = '/bulk-import', ERC_METADATA_API_PATH = '/erc-metadata/:productId/:localeOrTokenFilename/:tokenFileName?', UNCHAINED_COOKIE_NAME = 'unchained_token', UNCHAINED_COOKIE_PATH = '/', UNCHAINED_COOKIE_DOMAIN, UNCHAINED_COOKIE_SAMESITE, UNCHAINED_COOKIE_INSECURE, } = process.env;
18
- const middlewareHook = async function middlewareHook(req, reply) {
19
- const setHeader = (key, value) => reply.header(key, value);
20
- const getHeader = (key) => req.headers[key];
21
- const { remoteAddress, remotePort } = resolveUserRemoteAddress(req);
22
- const context = getCurrentContextResolver();
23
- const login = async function (user, options = {}) {
24
- const { impersonator } = options;
25
- req.session.userId = user._id;
26
- req.session.impersonatorId = impersonator?._id;
27
- const tokenObject = {
28
- _id: req.session.sessionId,
29
- userId: user._id,
30
- tokenExpires: new Date(req.session.cookie._expires),
31
- };
32
- await emit(API_EVENTS.API_LOGIN_TOKEN_CREATED, tokenObject);
33
- user._inLoginMethodResponse = true;
34
- return { user, ...tokenObject };
35
- };
36
- const logout = async function logout() {
37
- const tokenObject = {
38
- _id: req.session.sessionId,
39
- userId: req.session?.userId,
40
- };
41
- req.session.userId = null;
42
- req.session.impersonatorId = null;
43
- await emit(API_EVENTS.API_LOGOUT, tokenObject);
44
- return true;
45
- };
46
- const [, accessToken] = req.headers.authorization?.split(' ') || [];
47
- req.unchainedContext = await context({
48
- setHeader,
49
- getHeader,
50
- remoteAddress,
51
- remotePort,
52
- login,
53
- logout,
54
- accessToken,
55
- userId: req.session.userId,
56
- impersonatorId: req.session.impersonatorId,
57
- }, req, reply);
58
- };
59
- export const unchainedLogger = (prefix) => {
60
- const logger = createLogger(prefix);
61
- function Logger(...args) {
62
- this.args = args;
63
- }
64
- Logger.prototype.info = logger.info;
65
- Logger.prototype.error = logger.error;
66
- Logger.prototype.debug = logger.debug;
67
- Logger.prototype.fatal = logger.error;
68
- Logger.prototype.warn = logger.warn;
69
- Logger.prototype.trace = logger.trace;
70
- Logger.prototype.child = function () {
71
- return new Logger();
72
- };
73
- return new Logger();
74
- };
75
- export const connect = (fastify, { graphqlHandler, db, }, { allowRemoteToLocalhostSecureCookies = false, } = {}) => {
76
- if (allowRemoteToLocalhostSecureCookies) {
77
- // Workaround: Allow to use sandbox with localhost
78
- // https://github.com/fastify/fastify-cookie/issues/308
79
- fastify.addHook('preHandler', async function (request) {
80
- request.headers['x-forwarded-proto'] = 'https';
81
- });
82
- fastify.addHook('onSend', async function (_, reply) {
83
- reply.headers({
84
- 'Access-Control-Allow-Private-Network': 'true',
85
- });
86
- });
87
- }
88
- const cookieName = UNCHAINED_COOKIE_NAME;
89
- const domain = UNCHAINED_COOKIE_DOMAIN;
90
- const path = UNCHAINED_COOKIE_PATH;
91
- const secure = UNCHAINED_COOKIE_INSECURE ? false : true;
92
- const sameSite = ({
93
- none: 'none',
94
- lax: 'lax',
95
- strict: 'strict',
96
- '1': true,
97
- '0': false,
98
- }[UNCHAINED_COOKIE_SAMESITE?.trim()?.toLowerCase()] || false);
99
- if (!fastify.hasPlugin('@fastify/cookie')) {
100
- fastify.register(fastifyCookie);
101
- }
102
- fastify.register(fastifySession, {
103
- secret: process.env.UNCHAINED_TOKEN_SECRET,
104
- cookieName,
105
- store: MongoStore.create({
106
- client: db.client,
107
- dbName: db.databaseName,
108
- collectionName: 'sessions',
109
- }),
110
- cookie: {
111
- domain,
112
- httpOnly: true,
113
- path,
114
- secure,
115
- sameSite,
116
- maxAge: 1000 * 60 * 60 * 24 * 7,
117
- },
118
- });
119
- fastify.decorateRequest('unchainedContext');
120
- fastify.addHook('onRequest', middlewareHook);
121
- fastify.route({
122
- url: GRAPHQL_API_PATH,
123
- method: ['GET', 'POST', 'OPTIONS'],
124
- handler: async (req, reply) => {
125
- // Second parameter adds Fastify's `req` and `reply` to the GraphQL Context
126
- const response = await graphqlHandler.handleNodeRequestAndResponse(req, reply, {
127
- req,
128
- reply,
129
- });
130
- response.headers.forEach((value, key) => {
131
- reply.header(key, value);
132
- });
133
- reply.status(response.status);
134
- reply.send(response.body);
135
- return reply;
136
- },
137
- });
138
- fastify.route({
139
- url: ERC_METADATA_API_PATH,
140
- method: ['GET'],
141
- handler: ercMetadataHandler,
142
- });
143
- fastify.register((s, opts, registered) => {
144
- s.removeAllContentTypeParsers();
145
- s.addContentTypeParser('*', function (req, payload, done) {
146
- done(null);
147
- });
148
- s.route({
149
- url: BULK_IMPORT_API_PATH,
150
- method: ['POST'],
151
- bodyLimit: 1024 * 1024 * 1024 * 5, // 5GB
152
- handler: bulkImportHandler,
153
- });
154
- registered();
155
- });
156
- };
157
- //# sourceMappingURL=index%20copy.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index copy.js","sourceRoot":"","sources":["../../src/fastify/index copy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAqB,MAAM,eAAe,CAAC;AAC7E,OAAO,iBAAiB,MAAM,wBAAwB,CAAC;AACvD,OAAO,kBAAkB,MAAM,yBAAyB,CAAC;AACzD,OAAO,UAAU,MAAM,eAAe,CAAC;AAIvC,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,OAAO,cAAc,MAAM,kBAAkB,CAAC;AAC9C,OAAO,aAAa,MAAM,iBAAiB,CAAC;AAE5C,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAErD,MAAM,wBAAwB,GAAG,CAAC,GAAmB,EAAE,EAAE;IACvD,MAAM,aAAa,GAChB,GAAG,CAAC,OAAO,CAAC,WAAW,CAAY;QACnC,GAAG,CAAC,OAAO,CAAC,iBAAiB,CAAY;QAC1C,GAAG,CAAC,MAAM,EAAE,aAAa,CAAC;IAE5B,MAAM,UAAU,GAAG,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC;IAE1C,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,CAAC;AACvC,CAAC,CAAC;AAEF,MAAM,EACJ,gBAAgB,GAAG,UAAU,EAC7B,oBAAoB,GAAG,cAAc,EACrC,qBAAqB,GAAG,iEAAiE,EACzF,qBAAqB,GAAG,iBAAiB,EACzC,qBAAqB,GAAG,GAAG,EAC3B,uBAAuB,EACvB,yBAAyB,EACzB,yBAAyB,GAC1B,GAAG,OAAO,CAAC,GAAG,CAAC;AAEhB,MAAM,cAAc,GAAG,KAAK,UAAU,cAAc,CAAC,GAAQ,EAAE,KAA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CAAC,KAAK,CAAC;QACf,OAAO,EAAE,kBAAkB;KAC5B,CAAC,CAAC;IAEH,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,EAAE;QACvC,CAAC,CAAC,2BAA2B,EAAE,CAAC;QAChC,CAAC,CAAC,oBAAoB,CAAC,GAAG,EAAE,UAAU,GAAG,EAAE,OAAO,EAAE,IAAI;YACtD,IAAI,CAAC,IAAI,CAAC,CAAC;QACb,CAAC,CAAC,CAAC;QACH,CAAC,CAAC,KAAK,CAAC;YACN,GAAG,EAAE,oBAAoB;YACzB,MAAM,EAAE,CAAC,MAAM,CAAC;YAChB,SAAS,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,CAAC,EAAE,MAAM;YACzC,OAAO,EAAE,iBAAiB;SAC3B,CAAC,CAAC;QACH,UAAU,EAAE,CAAC;IACf,CAAC,CAAC,CAAC;AACL,CAAC,CAAC"}
@@ -1,8 +0,0 @@
1
- import { FastifyRequest, FastifyReply } from 'fastify';
2
- import { UnchainedCore } from '@unchainedshop/core';
3
- export interface MCPHandlerOptions {
4
- unchainedAPI: UnchainedCore;
5
- }
6
- declare const createMCPHandler: ({ unchainedAPI }: MCPHandlerOptions) => (request: FastifyRequest, reply: FastifyReply) => Promise<void>;
7
- export default createMCPHandler;
8
- //# sourceMappingURL=mcpHandler.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mcpHandler.d.ts","sourceRoot":"","sources":["../../src/fastify/mcpHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAGpD,MAAM,WAAW,iBAAiB;IAChC,YAAY,EAAE,aAAa,CAAC;CAC7B;AAED,QAAA,MAAM,gBAAgB,GAAI,kBAAkB,iBAAiB,MAC7C,SAAS,cAAc,EAAE,OAAO,YAAY,kBA6C3D,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
@@ -1,46 +0,0 @@
1
- import { searchProductsWithCore, renderProductList, searchProductsTool } from '../mcp/index.js';
2
- const createMCPHandler = ({ unchainedAPI }) => {
3
- return async (request, reply) => {
4
- if (request.method !== 'POST') {
5
- reply.code(405).send({ error: 'Method not allowed' });
6
- return;
7
- }
8
- try {
9
- const { method, params } = request.body;
10
- if (method === 'tools/list') {
11
- reply.send({
12
- tools: [searchProductsTool],
13
- });
14
- return;
15
- }
16
- if (method === 'tools/call' && params?.name === 'searchProducts') {
17
- const args = params.arguments || {};
18
- const result = await searchProductsWithCore(unchainedAPI, args);
19
- reply.send({
20
- content: [
21
- {
22
- type: 'text',
23
- text: renderProductList(result),
24
- },
25
- ],
26
- });
27
- return;
28
- }
29
- reply.code(400).send({ error: 'Unknown method' });
30
- }
31
- catch (error) {
32
- console.error('MCP handler error:', error);
33
- reply.code(500).send({
34
- content: [
35
- {
36
- type: 'text',
37
- text: `Error: ${error.message}`,
38
- },
39
- ],
40
- isError: true,
41
- });
42
- }
43
- };
44
- };
45
- export default createMCPHandler;
46
- //# sourceMappingURL=mcpHandler.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mcpHandler.js","sourceRoot":"","sources":["../../src/fastify/mcpHandler.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAMhG,MAAM,gBAAgB,GAAG,CAAC,EAAE,YAAY,EAAqB,EAAE,EAAE;IAC/D,OAAO,KAAK,EAAE,OAAuB,EAAE,KAAmB,EAAE,EAAE;QAC5D,IAAI,OAAO,CAAC,MAAM,KAAK,MAAM,EAAE,CAAC;YAC9B,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,oBAAoB,EAAE,CAAC,CAAC;YACtD,OAAO;QACT,CAAC;QAED,IAAI,CAAC;YACH,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAW,CAAC;YAE/C,IAAI,MAAM,KAAK,YAAY,EAAE,CAAC;gBAC5B,KAAK,CAAC,IAAI,CAAC;oBACT,KAAK,EAAE,CAAC,kBAAkB,CAAC;iBAC5B,CAAC,CAAC;gBACH,OAAO;YACT,CAAC;YAED,IAAI,MAAM,KAAK,YAAY,IAAI,MAAM,EAAE,IAAI,KAAK,gBAAgB,EAAE,CAAC;gBACjE,MAAM,IAAI,GAAG,MAAM,CAAC,SAAS,IAAI,EAAE,CAAC;gBACpC,MAAM,MAAM,GAAG,MAAM,sBAAsB,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC;gBAEhE,KAAK,CAAC,IAAI,CAAC;oBACT,OAAO,EAAE;wBACP;4BACE,IAAI,EAAE,MAAM;4BACZ,IAAI,EAAE,iBAAiB,CAAC,MAAM,CAAC;yBAChC;qBACF;iBACF,CAAC,CAAC;gBACH,OAAO;YACT,CAAC;YAED,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,gBAAgB,EAAE,CAAC,CAAC;QACpD,CAAC;QAAC,OAAO,KAAU,EAAE,CAAC;YACpB,OAAO,CAAC,KAAK,CAAC,oBAAoB,EAAE,KAAK,CAAC,CAAC;YAC3C,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;gBACnB,OAAO,EAAE;oBACP;wBACE,IAAI,EAAE,MAAM;wBACZ,IAAI,EAAE,UAAU,KAAK,CAAC,OAAO,EAAE;qBAChC;iBACF;gBACD,OAAO,EAAE,IAAI;aACd,CAAC,CAAC;QACL,CAAC;IACH,CAAC,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
@@ -1,4 +0,0 @@
1
- import { UnchainedCore } from '@unchainedshop/core';
2
- export declare function createMCPServer(unchainedAPI: UnchainedCore): Promise<import("./types.js").MCPServer>;
3
- export declare function startMCPServer(unchainedAPI: UnchainedCore): Promise<import("./types.js").MCPServer>;
4
- //# sourceMappingURL=server.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/mcp/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAIpD,wBAAsB,eAAe,CAAC,YAAY,EAAE,aAAa,2CAyDhE;AAGD,wBAAsB,cAAc,CAAC,YAAY,EAAE,aAAa,2CAQ/D"}
package/lib/mcp/server.js DELETED
@@ -1,60 +0,0 @@
1
- import { searchProductsWithCore, renderProductList, searchProductsTool } from './index.js';
2
- export async function createMCPServer(unchainedAPI) {
3
- // Dynamically import MCP SDK
4
- const { Server } = (await eval('import("@modelcontextprotocol/sdk/server/index.js")'));
5
- const { CallToolRequestSchema, ListToolsRequestSchema } = (await eval('import("@modelcontextprotocol/sdk/types.js")'));
6
- const server = new Server({
7
- name: 'unchained',
8
- version: '1.0.0',
9
- }, {
10
- capabilities: {
11
- tools: {},
12
- },
13
- });
14
- // Handle list tools request
15
- server.setRequestHandler(ListToolsRequestSchema, async () => {
16
- return {
17
- tools: [searchProductsTool],
18
- };
19
- });
20
- // Handle tool calls
21
- server.setRequestHandler(CallToolRequestSchema, async (request) => {
22
- if (request.params.name === 'searchProducts') {
23
- const args = request.params.arguments;
24
- try {
25
- const result = await searchProductsWithCore(unchainedAPI, args);
26
- return {
27
- content: [
28
- {
29
- type: 'text',
30
- text: renderProductList(result),
31
- },
32
- ],
33
- };
34
- }
35
- catch (error) {
36
- return {
37
- content: [
38
- {
39
- type: 'text',
40
- text: `Error searching products: ${error.message}`,
41
- },
42
- ],
43
- isError: true,
44
- };
45
- }
46
- }
47
- throw new Error(`Unknown tool: ${request.params.name}`);
48
- });
49
- return server;
50
- }
51
- // For standalone server usage - export a function that can be called from project examples
52
- export async function startMCPServer(unchainedAPI) {
53
- const { StdioServerTransport } = (await eval('import("@modelcontextprotocol/sdk/server/stdio.js")'));
54
- const server = await createMCPServer(unchainedAPI);
55
- const transport = new StdioServerTransport();
56
- await server.connect(transport);
57
- console.error('Unchained MCP server started');
58
- return server;
59
- }
60
- //# sourceMappingURL=server.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/mcp/server.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAG3F,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,YAA2B;IAC/D,6BAA6B;IAC7B,MAAM,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,IAAI,CAAC,qDAAqD,CAAC,CAAoB,CAAC;IAC1G,MAAM,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,GAAG,CAAC,MAAM,IAAI,CAAC,8CAA8C,CAAC,CAAa,CAAC;IAEnI,MAAM,MAAM,GAAG,IAAI,MAAM,CACvB;QACE,IAAI,EAAE,WAAW;QACjB,OAAO,EAAE,OAAO;KACjB,EACD;QACE,YAAY,EAAE;YACZ,KAAK,EAAE,EAAE;SACV;KACF,CACF,CAAC;IAEF,4BAA4B;IAC5B,MAAM,CAAC,iBAAiB,CAAC,sBAAsB,EAAE,KAAK,IAAI,EAAE;QAC1D,OAAO;YACL,KAAK,EAAE,CAAC,kBAAkB,CAAC;SAC5B,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,oBAAoB;IACpB,MAAM,CAAC,iBAAiB,CAAC,qBAAqB,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE;QAChE,IAAI,OAAO,CAAC,MAAM,CAAC,IAAI,KAAK,gBAAgB,EAAE,CAAC;YAC7C,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,SAAgB,CAAC;YAE7C,IAAI,CAAC;gBACH,MAAM,MAAM,GAAG,MAAM,sBAAsB,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC;gBAEhE,OAAO;oBACL,OAAO,EAAE;wBACP;4BACE,IAAI,EAAE,MAAM;4BACZ,IAAI,EAAE,iBAAiB,CAAC,MAAM,CAAC;yBAChC;qBACF;iBACF,CAAC;YACJ,CAAC;YAAC,OAAO,KAAU,EAAE,CAAC;gBACpB,OAAO;oBACL,OAAO,EAAE;wBACP;4BACE,IAAI,EAAE,MAAM;4BACZ,IAAI,EAAE,6BAA6B,KAAK,CAAC,OAAO,EAAE;yBACnD;qBACF;oBACD,OAAO,EAAE,IAAI;iBACd,CAAC;YACJ,CAAC;QACH,CAAC;QAED,MAAM,IAAI,KAAK,CAAC,iBAAiB,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;IAC1D,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,2FAA2F;AAC3F,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,YAA2B;IAC9D,MAAM,EAAE,oBAAoB,EAAE,GAAG,CAAC,MAAM,IAAI,CAAC,qDAAqD,CAAC,CAAmB,CAAC;IAEvH,MAAM,MAAM,GAAG,MAAM,eAAe,CAAC,YAAY,CAAC,CAAC;IACnD,MAAM,SAAS,GAAG,IAAI,oBAAoB,EAAE,CAAC;IAC7C,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAChC,OAAO,CAAC,KAAK,CAAC,8BAA8B,CAAC,CAAC;IAC9C,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -1,27 +0,0 @@
1
- /**
2
- * Shared types for MCP tools
3
- */
4
- /**
5
- * Base tool response type
6
- */
7
- export interface ToolResponse {
8
- content: {
9
- type: 'text' | 'resource';
10
- text?: string;
11
- resource?: {
12
- text: string;
13
- uri: string;
14
- mimeType: string;
15
- };
16
- }[];
17
- }
18
- /**
19
- * Error response type
20
- */
21
- export interface ErrorResponse {
22
- content: {
23
- type: 'text';
24
- text: string;
25
- }[];
26
- }
27
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/mcp/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE;QACP,IAAI,EAAE,MAAM,GAAG,UAAU,CAAC;QAC1B,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,QAAQ,CAAC,EAAE;YACT,IAAI,EAAE,MAAM,CAAC;YACb,GAAG,EAAE,MAAM,CAAC;YACZ,QAAQ,EAAE,MAAM,CAAC;SAClB,CAAC;KACH,EAAE,CAAC;CACL;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE;QACP,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,EAAE,MAAM,CAAC;KACd,EAAE,CAAC;CACL"}
package/lib/mcp/types.js DELETED
@@ -1,5 +0,0 @@
1
- /**
2
- * Shared types for MCP tools
3
- */
4
- export {};
5
- //# sourceMappingURL=types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/mcp/types.ts"],"names":[],"mappings":"AAAA;;GAEG"}
@@ -1,16 +0,0 @@
1
- /**
2
- * HTML generation utilities for MCP server responses
3
- */
4
- /**
5
- * Escape HTML special characters to prevent XSS
6
- */
7
- export declare function escapeHtml(text: string): string;
8
- /**
9
- * Generate HTML output for products list with Unchained styling
10
- */
11
- export declare function generateProductsHTML(products: any[], productTexts: any[], pagination: {
12
- offset: number;
13
- limit: number;
14
- total: number;
15
- }): string;
16
- //# sourceMappingURL=html.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"html.d.ts","sourceRoot":"","sources":["../../../src/mcp/utils/html.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAQ/C;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,GAAG,EAAE,EACf,YAAY,EAAE,GAAG,EAAE,EACnB,UAAU,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAC3D,MAAM,CAuCR"}