@skillsmith/mcp-server 0.1.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 (306) hide show
  1. package/dist/.tsbuildinfo +1 -0
  2. package/dist/src/__tests__/get-skill.test.d.ts +6 -0
  3. package/dist/src/__tests__/get-skill.test.d.ts.map +1 -0
  4. package/dist/src/__tests__/get-skill.test.js +88 -0
  5. package/dist/src/__tests__/get-skill.test.js.map +1 -0
  6. package/dist/src/__tests__/middleware/errorFormatter.test.d.ts +7 -0
  7. package/dist/src/__tests__/middleware/errorFormatter.test.d.ts.map +1 -0
  8. package/dist/src/__tests__/middleware/errorFormatter.test.js +304 -0
  9. package/dist/src/__tests__/middleware/errorFormatter.test.js.map +1 -0
  10. package/dist/src/__tests__/middleware/license.test.d.ts +7 -0
  11. package/dist/src/__tests__/middleware/license.test.d.ts.map +1 -0
  12. package/dist/src/__tests__/middleware/license.test.js +500 -0
  13. package/dist/src/__tests__/middleware/license.test.js.map +1 -0
  14. package/dist/src/__tests__/search.test.d.ts +6 -0
  15. package/dist/src/__tests__/search.test.d.ts.map +1 -0
  16. package/dist/src/__tests__/search.test.js +86 -0
  17. package/dist/src/__tests__/search.test.js.map +1 -0
  18. package/dist/src/__tests__/test-utils.d.ts +19 -0
  19. package/dist/src/__tests__/test-utils.d.ts.map +1 -0
  20. package/dist/src/__tests__/test-utils.js +87 -0
  21. package/dist/src/__tests__/test-utils.js.map +1 -0
  22. package/dist/src/context/index.d.ts +19 -0
  23. package/dist/src/context/index.d.ts.map +1 -0
  24. package/dist/src/context/index.js +25 -0
  25. package/dist/src/context/index.js.map +1 -0
  26. package/dist/src/context/project-detector.d.ts +145 -0
  27. package/dist/src/context/project-detector.d.ts.map +1 -0
  28. package/dist/src/context/project-detector.js +321 -0
  29. package/dist/src/context/project-detector.js.map +1 -0
  30. package/dist/src/context.d.ts +100 -0
  31. package/dist/src/context.d.ts.map +1 -0
  32. package/dist/src/context.js +157 -0
  33. package/dist/src/context.js.map +1 -0
  34. package/dist/src/core-shim.d.ts +7 -0
  35. package/dist/src/core-shim.d.ts.map +1 -0
  36. package/dist/src/core-shim.js +9 -0
  37. package/dist/src/core-shim.js.map +1 -0
  38. package/dist/src/health/healthCheck.d.ts +88 -0
  39. package/dist/src/health/healthCheck.d.ts.map +1 -0
  40. package/dist/src/health/healthCheck.js +117 -0
  41. package/dist/src/health/healthCheck.js.map +1 -0
  42. package/dist/src/health/index.d.ts +21 -0
  43. package/dist/src/health/index.d.ts.map +1 -0
  44. package/dist/src/health/index.js +21 -0
  45. package/dist/src/health/index.js.map +1 -0
  46. package/dist/src/health/readinessCheck.d.ts +139 -0
  47. package/dist/src/health/readinessCheck.d.ts.map +1 -0
  48. package/dist/src/health/readinessCheck.js +266 -0
  49. package/dist/src/health/readinessCheck.js.map +1 -0
  50. package/dist/src/index.d.ts +8 -0
  51. package/dist/src/index.d.ts.map +1 -0
  52. package/dist/src/index.js +178 -0
  53. package/dist/src/index.js.map +1 -0
  54. package/dist/src/index.test.d.ts +2 -0
  55. package/dist/src/index.test.d.ts.map +1 -0
  56. package/dist/src/index.test.js +43 -0
  57. package/dist/src/index.test.js.map +1 -0
  58. package/dist/src/logger.d.ts +26 -0
  59. package/dist/src/logger.d.ts.map +1 -0
  60. package/dist/src/logger.js +179 -0
  61. package/dist/src/logger.js.map +1 -0
  62. package/dist/src/middleware/__tests__/csp.test.d.ts +2 -0
  63. package/dist/src/middleware/__tests__/csp.test.d.ts.map +1 -0
  64. package/dist/src/middleware/__tests__/csp.test.js +389 -0
  65. package/dist/src/middleware/__tests__/csp.test.js.map +1 -0
  66. package/dist/src/middleware/csp.d.ts +87 -0
  67. package/dist/src/middleware/csp.d.ts.map +1 -0
  68. package/dist/src/middleware/csp.js +273 -0
  69. package/dist/src/middleware/csp.js.map +1 -0
  70. package/dist/src/middleware/degradation.d.ts +99 -0
  71. package/dist/src/middleware/degradation.d.ts.map +1 -0
  72. package/dist/src/middleware/degradation.js +315 -0
  73. package/dist/src/middleware/degradation.js.map +1 -0
  74. package/dist/src/middleware/errorFormatter.d.ts +119 -0
  75. package/dist/src/middleware/errorFormatter.d.ts.map +1 -0
  76. package/dist/src/middleware/errorFormatter.js +294 -0
  77. package/dist/src/middleware/errorFormatter.js.map +1 -0
  78. package/dist/src/middleware/index.d.ts +10 -0
  79. package/dist/src/middleware/index.d.ts.map +1 -0
  80. package/dist/src/middleware/index.js +14 -0
  81. package/dist/src/middleware/index.js.map +1 -0
  82. package/dist/src/middleware/license.d.ts +161 -0
  83. package/dist/src/middleware/license.d.ts.map +1 -0
  84. package/dist/src/middleware/license.js +281 -0
  85. package/dist/src/middleware/license.js.map +1 -0
  86. package/dist/src/middleware/toolFeatureMapping.d.ts +36 -0
  87. package/dist/src/middleware/toolFeatureMapping.d.ts.map +1 -0
  88. package/dist/src/middleware/toolFeatureMapping.js +90 -0
  89. package/dist/src/middleware/toolFeatureMapping.js.map +1 -0
  90. package/dist/src/onboarding/first-run.d.ts +64 -0
  91. package/dist/src/onboarding/first-run.d.ts.map +1 -0
  92. package/dist/src/onboarding/first-run.js +77 -0
  93. package/dist/src/onboarding/first-run.js.map +1 -0
  94. package/dist/src/onboarding/index.d.ts +7 -0
  95. package/dist/src/onboarding/index.d.ts.map +1 -0
  96. package/dist/src/onboarding/index.js +7 -0
  97. package/dist/src/onboarding/index.js.map +1 -0
  98. package/dist/src/suggestions/index.d.ts +21 -0
  99. package/dist/src/suggestions/index.d.ts.map +1 -0
  100. package/dist/src/suggestions/index.js +20 -0
  101. package/dist/src/suggestions/index.js.map +1 -0
  102. package/dist/src/suggestions/suggestion-engine.d.ts +185 -0
  103. package/dist/src/suggestions/suggestion-engine.d.ts.map +1 -0
  104. package/dist/src/suggestions/suggestion-engine.js +352 -0
  105. package/dist/src/suggestions/suggestion-engine.js.map +1 -0
  106. package/dist/src/suggestions/types.d.ts +88 -0
  107. package/dist/src/suggestions/types.d.ts.map +1 -0
  108. package/dist/src/suggestions/types.js +21 -0
  109. package/dist/src/suggestions/types.js.map +1 -0
  110. package/dist/src/tools/analyze.d.ts +151 -0
  111. package/dist/src/tools/analyze.d.ts.map +1 -0
  112. package/dist/src/tools/analyze.js +205 -0
  113. package/dist/src/tools/analyze.js.map +1 -0
  114. package/dist/src/tools/compare.d.ts +149 -0
  115. package/dist/src/tools/compare.d.ts.map +1 -0
  116. package/dist/src/tools/compare.js +464 -0
  117. package/dist/src/tools/compare.js.map +1 -0
  118. package/dist/src/tools/get-skill.d.ts +116 -0
  119. package/dist/src/tools/get-skill.d.ts.map +1 -0
  120. package/dist/src/tools/get-skill.js +224 -0
  121. package/dist/src/tools/get-skill.js.map +1 -0
  122. package/dist/src/tools/index.d.ts +20 -0
  123. package/dist/src/tools/index.d.ts.map +1 -0
  124. package/dist/src/tools/index.js +20 -0
  125. package/dist/src/tools/index.js.map +1 -0
  126. package/dist/src/tools/install.d.ts +122 -0
  127. package/dist/src/tools/install.d.ts.map +1 -0
  128. package/dist/src/tools/install.js +314 -0
  129. package/dist/src/tools/install.js.map +1 -0
  130. package/dist/src/tools/recommend.d.ts +171 -0
  131. package/dist/src/tools/recommend.d.ts.map +1 -0
  132. package/dist/src/tools/recommend.js +325 -0
  133. package/dist/src/tools/recommend.js.map +1 -0
  134. package/dist/src/tools/search.d.ts +121 -0
  135. package/dist/src/tools/search.d.ts.map +1 -0
  136. package/dist/src/tools/search.js +249 -0
  137. package/dist/src/tools/search.js.map +1 -0
  138. package/dist/src/tools/suggest.d.ts +181 -0
  139. package/dist/src/tools/suggest.d.ts.map +1 -0
  140. package/dist/src/tools/suggest.js +342 -0
  141. package/dist/src/tools/suggest.js.map +1 -0
  142. package/dist/src/tools/uninstall.d.ts +123 -0
  143. package/dist/src/tools/uninstall.d.ts.map +1 -0
  144. package/dist/src/tools/uninstall.js +250 -0
  145. package/dist/src/tools/uninstall.js.map +1 -0
  146. package/dist/src/tools/validate.d.ts +122 -0
  147. package/dist/src/tools/validate.d.ts.map +1 -0
  148. package/dist/src/tools/validate.js +497 -0
  149. package/dist/src/tools/validate.js.map +1 -0
  150. package/dist/src/utils/installed-skills.d.ts +101 -0
  151. package/dist/src/utils/installed-skills.d.ts.map +1 -0
  152. package/dist/src/utils/installed-skills.js +220 -0
  153. package/dist/src/utils/installed-skills.js.map +1 -0
  154. package/dist/src/utils/validation.d.ts +76 -0
  155. package/dist/src/utils/validation.d.ts.map +1 -0
  156. package/dist/src/utils/validation.js +153 -0
  157. package/dist/src/utils/validation.js.map +1 -0
  158. package/dist/src/webhooks/index.d.ts +8 -0
  159. package/dist/src/webhooks/index.d.ts.map +1 -0
  160. package/dist/src/webhooks/index.js +9 -0
  161. package/dist/src/webhooks/index.js.map +1 -0
  162. package/dist/src/webhooks/webhook-endpoint.d.ts +149 -0
  163. package/dist/src/webhooks/webhook-endpoint.d.ts.map +1 -0
  164. package/dist/src/webhooks/webhook-endpoint.js +339 -0
  165. package/dist/src/webhooks/webhook-endpoint.js.map +1 -0
  166. package/dist/tests/compare.test.d.ts +6 -0
  167. package/dist/tests/compare.test.d.ts.map +1 -0
  168. package/dist/tests/compare.test.js +225 -0
  169. package/dist/tests/compare.test.js.map +1 -0
  170. package/dist/tests/context/project-detector.test.d.ts +6 -0
  171. package/dist/tests/context/project-detector.test.d.ts.map +1 -0
  172. package/dist/tests/context/project-detector.test.js +719 -0
  173. package/dist/tests/context/project-detector.test.js.map +1 -0
  174. package/dist/tests/e2e/compare.e2e.test.d.ts +10 -0
  175. package/dist/tests/e2e/compare.e2e.test.d.ts.map +1 -0
  176. package/dist/tests/e2e/compare.e2e.test.js +286 -0
  177. package/dist/tests/e2e/compare.e2e.test.js.map +1 -0
  178. package/dist/tests/e2e/install-flow.e2e.test.d.ts +10 -0
  179. package/dist/tests/e2e/install-flow.e2e.test.d.ts.map +1 -0
  180. package/dist/tests/e2e/install-flow.e2e.test.js +209 -0
  181. package/dist/tests/e2e/install-flow.e2e.test.js.map +1 -0
  182. package/dist/tests/e2e/recommend.e2e.test.d.ts +12 -0
  183. package/dist/tests/e2e/recommend.e2e.test.d.ts.map +1 -0
  184. package/dist/tests/e2e/recommend.e2e.test.js +347 -0
  185. package/dist/tests/e2e/recommend.e2e.test.js.map +1 -0
  186. package/dist/tests/e2e/skill-flow.e2e.test.d.ts +10 -0
  187. package/dist/tests/e2e/skill-flow.e2e.test.d.ts.map +1 -0
  188. package/dist/tests/e2e/skill-flow.e2e.test.js +280 -0
  189. package/dist/tests/e2e/skill-flow.e2e.test.js.map +1 -0
  190. package/dist/tests/e2e/suggest.e2e.test.d.ts +13 -0
  191. package/dist/tests/e2e/suggest.e2e.test.d.ts.map +1 -0
  192. package/dist/tests/e2e/suggest.e2e.test.js +347 -0
  193. package/dist/tests/e2e/suggest.e2e.test.js.map +1 -0
  194. package/dist/tests/e2e/utils/baseline-collector.d.ts +107 -0
  195. package/dist/tests/e2e/utils/baseline-collector.d.ts.map +1 -0
  196. package/dist/tests/e2e/utils/baseline-collector.js +211 -0
  197. package/dist/tests/e2e/utils/baseline-collector.js.map +1 -0
  198. package/dist/tests/e2e/utils/hardcoded-detector.d.ts +46 -0
  199. package/dist/tests/e2e/utils/hardcoded-detector.d.ts.map +1 -0
  200. package/dist/tests/e2e/utils/hardcoded-detector.js +255 -0
  201. package/dist/tests/e2e/utils/hardcoded-detector.js.map +1 -0
  202. package/dist/tests/e2e/utils/index.d.ts +7 -0
  203. package/dist/tests/e2e/utils/index.d.ts.map +1 -0
  204. package/dist/tests/e2e/utils/index.js +7 -0
  205. package/dist/tests/e2e/utils/index.js.map +1 -0
  206. package/dist/tests/e2e/utils/linear-reporter.d.ts +60 -0
  207. package/dist/tests/e2e/utils/linear-reporter.d.ts.map +1 -0
  208. package/dist/tests/e2e/utils/linear-reporter.js +232 -0
  209. package/dist/tests/e2e/utils/linear-reporter.js.map +1 -0
  210. package/dist/tests/health.test.d.ts +9 -0
  211. package/dist/tests/health.test.d.ts.map +1 -0
  212. package/dist/tests/health.test.js +308 -0
  213. package/dist/tests/health.test.js.map +1 -0
  214. package/dist/tests/integration/analyze.integration.test.d.ts +2 -0
  215. package/dist/tests/integration/analyze.integration.test.d.ts.map +1 -0
  216. package/dist/tests/integration/analyze.integration.test.js +244 -0
  217. package/dist/tests/integration/analyze.integration.test.js.map +1 -0
  218. package/dist/tests/integration/compare.integration.test.d.ts +2 -0
  219. package/dist/tests/integration/compare.integration.test.d.ts.map +1 -0
  220. package/dist/tests/integration/compare.integration.test.js +120 -0
  221. package/dist/tests/integration/compare.integration.test.js.map +1 -0
  222. package/dist/tests/integration/fixtures/test-skills.d.ts +62 -0
  223. package/dist/tests/integration/fixtures/test-skills.d.ts.map +1 -0
  224. package/dist/tests/integration/fixtures/test-skills.js +644 -0
  225. package/dist/tests/integration/fixtures/test-skills.js.map +1 -0
  226. package/dist/tests/integration/get-skill.integration.test.d.ts +6 -0
  227. package/dist/tests/integration/get-skill.integration.test.d.ts.map +1 -0
  228. package/dist/tests/integration/get-skill.integration.test.js +203 -0
  229. package/dist/tests/integration/get-skill.integration.test.js.map +1 -0
  230. package/dist/tests/integration/github-api.integration.test.d.ts +14 -0
  231. package/dist/tests/integration/github-api.integration.test.d.ts.map +1 -0
  232. package/dist/tests/integration/github-api.integration.test.js +190 -0
  233. package/dist/tests/integration/github-api.integration.test.js.map +1 -0
  234. package/dist/tests/integration/install.integration.test.d.ts +6 -0
  235. package/dist/tests/integration/install.integration.test.d.ts.map +1 -0
  236. package/dist/tests/integration/install.integration.test.js +282 -0
  237. package/dist/tests/integration/install.integration.test.js.map +1 -0
  238. package/dist/tests/integration/recommend.integration.test.d.ts +2 -0
  239. package/dist/tests/integration/recommend.integration.test.d.ts.map +1 -0
  240. package/dist/tests/integration/recommend.integration.test.js +215 -0
  241. package/dist/tests/integration/recommend.integration.test.js.map +1 -0
  242. package/dist/tests/integration/search.integration.test.d.ts +6 -0
  243. package/dist/tests/integration/search.integration.test.d.ts.map +1 -0
  244. package/dist/tests/integration/search.integration.test.js +229 -0
  245. package/dist/tests/integration/search.integration.test.js.map +1 -0
  246. package/dist/tests/integration/setup.d.ts +71 -0
  247. package/dist/tests/integration/setup.d.ts.map +1 -0
  248. package/dist/tests/integration/setup.js +124 -0
  249. package/dist/tests/integration/setup.js.map +1 -0
  250. package/dist/tests/integration/uninstall.integration.test.d.ts +6 -0
  251. package/dist/tests/integration/uninstall.integration.test.d.ts.map +1 -0
  252. package/dist/tests/integration/uninstall.integration.test.js +296 -0
  253. package/dist/tests/integration/uninstall.integration.test.js.map +1 -0
  254. package/dist/tests/integration/validate.integration.test.d.ts +2 -0
  255. package/dist/tests/integration/validate.integration.test.d.ts.map +1 -0
  256. package/dist/tests/integration/validate.integration.test.js +181 -0
  257. package/dist/tests/integration/validate.integration.test.js.map +1 -0
  258. package/dist/tests/onboarding/first-run.test.d.ts +7 -0
  259. package/dist/tests/onboarding/first-run.test.d.ts.map +1 -0
  260. package/dist/tests/onboarding/first-run.test.js +258 -0
  261. package/dist/tests/onboarding/first-run.test.js.map +1 -0
  262. package/dist/tests/performance/search-performance.test.d.ts +10 -0
  263. package/dist/tests/performance/search-performance.test.d.ts.map +1 -0
  264. package/dist/tests/performance/search-performance.test.js +218 -0
  265. package/dist/tests/performance/search-performance.test.js.map +1 -0
  266. package/dist/tests/recommend.test.d.ts +6 -0
  267. package/dist/tests/recommend.test.d.ts.map +1 -0
  268. package/dist/tests/recommend.test.js +208 -0
  269. package/dist/tests/recommend.test.js.map +1 -0
  270. package/dist/tests/suggestions/suggestion-engine.test.d.ts +6 -0
  271. package/dist/tests/suggestions/suggestion-engine.test.d.ts.map +1 -0
  272. package/dist/tests/suggestions/suggestion-engine.test.js +448 -0
  273. package/dist/tests/suggestions/suggestion-engine.test.js.map +1 -0
  274. package/dist/tests/test-utils.d.ts +74 -0
  275. package/dist/tests/test-utils.d.ts.map +1 -0
  276. package/dist/tests/test-utils.js +98 -0
  277. package/dist/tests/test-utils.js.map +1 -0
  278. package/dist/tests/tools.test.d.ts +5 -0
  279. package/dist/tests/tools.test.d.ts.map +1 -0
  280. package/dist/tests/tools.test.js +138 -0
  281. package/dist/tests/tools.test.js.map +1 -0
  282. package/dist/tests/unit/installed-skills.test.d.ts +6 -0
  283. package/dist/tests/unit/installed-skills.test.d.ts.map +1 -0
  284. package/dist/tests/unit/installed-skills.test.js +285 -0
  285. package/dist/tests/unit/installed-skills.test.js.map +1 -0
  286. package/dist/tests/unit/logger.test.d.ts +6 -0
  287. package/dist/tests/unit/logger.test.d.ts.map +1 -0
  288. package/dist/tests/unit/logger.test.js +281 -0
  289. package/dist/tests/unit/logger.test.js.map +1 -0
  290. package/dist/tests/validate.test.d.ts +5 -0
  291. package/dist/tests/validate.test.d.ts.map +1 -0
  292. package/dist/tests/validate.test.js +303 -0
  293. package/dist/tests/validate.test.js.map +1 -0
  294. package/dist/tests/webhooks/proxy-trust.security.test.d.ts +8 -0
  295. package/dist/tests/webhooks/proxy-trust.security.test.d.ts.map +1 -0
  296. package/dist/tests/webhooks/proxy-trust.security.test.js +145 -0
  297. package/dist/tests/webhooks/proxy-trust.security.test.js.map +1 -0
  298. package/dist/tests/webhooks/rate-limiter.security.test.d.ts +8 -0
  299. package/dist/tests/webhooks/rate-limiter.security.test.d.ts.map +1 -0
  300. package/dist/tests/webhooks/rate-limiter.security.test.js +122 -0
  301. package/dist/tests/webhooks/rate-limiter.security.test.js.map +1 -0
  302. package/dist/vitest.config.d.ts +6 -0
  303. package/dist/vitest.config.d.ts.map +1 -0
  304. package/dist/vitest.config.js +13 -0
  305. package/dist/vitest.config.js.map +1 -0
  306. package/package.json +63 -0
@@ -0,0 +1,294 @@
1
+ /**
2
+ * SMI-1061: MCP Error Formatter for License Errors
3
+ *
4
+ * Formats license errors into MCP protocol-compliant error responses
5
+ * with actionable information for clients.
6
+ */
7
+ // ============================================================================
8
+ // Error Formatting
9
+ // ============================================================================
10
+ /**
11
+ * Format a license error into an MCP-compliant error response
12
+ *
13
+ * @param error - The license error to format
14
+ * @returns MCP-formatted error response
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * import { formatLicenseError } from './middleware/errorFormatter.js';
19
+ *
20
+ * try {
21
+ * await checkFeature('audit_logging');
22
+ * } catch (error) {
23
+ * if (isLicenseError(error)) {
24
+ * return formatLicenseError(error);
25
+ * }
26
+ * throw error;
27
+ * }
28
+ * ```
29
+ */
30
+ export function formatLicenseError(error) {
31
+ const errorDetails = {
32
+ code: error.code || 'LICENSE_ERROR',
33
+ message: error.message,
34
+ feature: error.feature,
35
+ currentTier: error.currentTier,
36
+ requiredTier: error.requiredTier,
37
+ upgradeUrl: error.upgradeUrl || 'https://skillsmith.io/upgrade',
38
+ timestamp: error.timestamp?.toISOString(),
39
+ };
40
+ // Build the error response structure matching MCP protocol
41
+ const errorBody = {
42
+ error: {
43
+ code: errorDetails.code,
44
+ message: errorDetails.message,
45
+ details: {},
46
+ },
47
+ };
48
+ // Add details if present
49
+ const details = errorBody.error;
50
+ if (errorDetails.feature) {
51
+ details.details.feature = errorDetails.feature;
52
+ }
53
+ if (errorDetails.currentTier) {
54
+ details.details.currentTier = errorDetails.currentTier;
55
+ }
56
+ if (errorDetails.requiredTier) {
57
+ details.details.requiredTier = errorDetails.requiredTier;
58
+ }
59
+ if (errorDetails.upgradeUrl) {
60
+ details.details.upgradeUrl = errorDetails.upgradeUrl;
61
+ }
62
+ // Remove empty details object
63
+ if (Object.keys(details.details).length === 0) {
64
+ delete errorBody.error.details;
65
+ }
66
+ return {
67
+ content: [
68
+ {
69
+ type: 'text',
70
+ text: JSON.stringify(errorBody, null, 2),
71
+ },
72
+ ],
73
+ isError: true,
74
+ _meta: {
75
+ upgradeUrl: errorDetails.upgradeUrl,
76
+ errorCode: errorDetails.code,
77
+ recoverable: isRecoverableError(errorDetails.code),
78
+ },
79
+ };
80
+ }
81
+ /**
82
+ * Check if an error code represents a recoverable error
83
+ */
84
+ function isRecoverableError(code) {
85
+ // License not found and invalid are potentially recoverable
86
+ // (by setting the license key or refreshing)
87
+ const recoverableCodes = ['E002', 'E003', 'LICENSE_INVALID', 'LICENSE_NOT_FOUND'];
88
+ return recoverableCodes.includes(code);
89
+ }
90
+ /**
91
+ * Format a generic error for MCP response
92
+ *
93
+ * Use this for non-license errors that still need MCP formatting.
94
+ */
95
+ export function formatGenericError(error, code = 'INTERNAL_ERROR') {
96
+ return {
97
+ content: [
98
+ {
99
+ type: 'text',
100
+ text: JSON.stringify({
101
+ error: {
102
+ code,
103
+ message: error.message,
104
+ },
105
+ }, null, 2),
106
+ },
107
+ ],
108
+ isError: true,
109
+ };
110
+ }
111
+ // ============================================================================
112
+ // Error Code Mapping
113
+ // ============================================================================
114
+ /**
115
+ * Map internal license error codes to user-friendly messages
116
+ */
117
+ const ERROR_MESSAGES = {
118
+ E001: 'Your license has expired. Please renew to continue using premium features.',
119
+ E002: 'Your license key is invalid. Please verify the key format or contact support.',
120
+ E003: 'No license key found. Set SKILLSMITH_LICENSE_KEY environment variable.',
121
+ E004: 'This feature is not available in your current license tier.',
122
+ E005: 'You have exceeded your license quota. Please upgrade or reduce usage.',
123
+ LICENSE_EXPIRED: 'Your license has expired. Please renew to continue using premium features.',
124
+ LICENSE_INVALID: 'Your license key is invalid. Please verify the key format or contact support.',
125
+ LICENSE_NOT_FOUND: 'No license key found. Set SKILLSMITH_LICENSE_KEY environment variable.',
126
+ FEATURE_NOT_AVAILABLE: 'This feature is not available in your current license tier.',
127
+ QUOTA_EXCEEDED: 'You have exceeded your license quota. Please upgrade or reduce usage.',
128
+ };
129
+ /**
130
+ * Get a user-friendly message for an error code
131
+ */
132
+ export function getUserFriendlyMessage(code) {
133
+ return ERROR_MESSAGES[code] || 'An error occurred with your license. Please contact support.';
134
+ }
135
+ const DEFAULT_UPGRADE_URL_CONFIG = {
136
+ baseUrl: 'https://skillsmith.io/upgrade',
137
+ includeFeature: true,
138
+ includeTiers: true,
139
+ includeSource: true,
140
+ };
141
+ /**
142
+ * Generate a customized upgrade URL with tracking parameters
143
+ */
144
+ export function generateUpgradeUrl(error, config = {}) {
145
+ const fullConfig = { ...DEFAULT_UPGRADE_URL_CONFIG, ...config };
146
+ const params = new URLSearchParams();
147
+ if (fullConfig.includeFeature && error.feature) {
148
+ params.set('feature', error.feature);
149
+ }
150
+ if (fullConfig.includeTiers) {
151
+ if (error.currentTier) {
152
+ params.set('from', error.currentTier);
153
+ }
154
+ if (error.requiredTier) {
155
+ params.set('to', error.requiredTier);
156
+ }
157
+ }
158
+ if (fullConfig.includeSource) {
159
+ params.set('source', 'mcp-error');
160
+ if (error.code) {
161
+ params.set('error_code', error.code);
162
+ }
163
+ }
164
+ const queryString = params.toString();
165
+ return queryString ? `${fullConfig.baseUrl}?${queryString}` : fullConfig.baseUrl || '';
166
+ }
167
+ // ============================================================================
168
+ // Response Builders
169
+ // ============================================================================
170
+ /**
171
+ * Build an upgrade required response
172
+ *
173
+ * Use this when a feature requires an upgrade but isn't a full error.
174
+ */
175
+ export function buildUpgradeRequiredResponse(feature, currentTier, requiredTier) {
176
+ const upgradeUrl = `https://skillsmith.io/upgrade?feature=${feature}&from=${currentTier}&to=${requiredTier}`;
177
+ return {
178
+ content: [
179
+ {
180
+ type: 'text',
181
+ text: JSON.stringify({
182
+ error: {
183
+ code: 'E004',
184
+ message: `${feature} requires ${requiredTier} tier`,
185
+ details: {
186
+ feature,
187
+ currentTier,
188
+ requiredTier,
189
+ upgradeUrl,
190
+ },
191
+ },
192
+ }, null, 2),
193
+ },
194
+ ],
195
+ isError: true,
196
+ _meta: {
197
+ upgradeUrl,
198
+ errorCode: 'E004',
199
+ recoverable: false,
200
+ },
201
+ };
202
+ }
203
+ /**
204
+ * Build a license expired response with renewal URL
205
+ */
206
+ export function buildLicenseExpiredResponse(expiredAt) {
207
+ const renewUrl = 'https://skillsmith.io/renew';
208
+ return {
209
+ content: [
210
+ {
211
+ type: 'text',
212
+ text: JSON.stringify({
213
+ error: {
214
+ code: 'E001',
215
+ message: 'Your license has expired',
216
+ details: {
217
+ expiredAt: expiredAt?.toISOString(),
218
+ renewUrl,
219
+ },
220
+ },
221
+ }, null, 2),
222
+ },
223
+ ],
224
+ isError: true,
225
+ _meta: {
226
+ upgradeUrl: renewUrl,
227
+ errorCode: 'E001',
228
+ recoverable: false,
229
+ },
230
+ };
231
+ }
232
+ /**
233
+ * Build a quota exceeded response
234
+ */
235
+ export function buildQuotaExceededResponse(quotaType, current, max) {
236
+ const upgradeUrl = `https://skillsmith.io/upgrade?quota=${quotaType}`;
237
+ return {
238
+ content: [
239
+ {
240
+ type: 'text',
241
+ text: JSON.stringify({
242
+ error: {
243
+ code: 'E005',
244
+ message: `${quotaType} quota exceeded`,
245
+ details: {
246
+ quotaType,
247
+ current,
248
+ max,
249
+ upgradeUrl,
250
+ },
251
+ },
252
+ }, null, 2),
253
+ },
254
+ ],
255
+ isError: true,
256
+ _meta: {
257
+ upgradeUrl,
258
+ errorCode: 'E005',
259
+ recoverable: false,
260
+ },
261
+ };
262
+ }
263
+ // ============================================================================
264
+ // Validation Helpers
265
+ // ============================================================================
266
+ /**
267
+ * Check if an object looks like a license error
268
+ */
269
+ export function isLicenseErrorLike(error) {
270
+ if (!error || typeof error !== 'object') {
271
+ return false;
272
+ }
273
+ const e = error;
274
+ // Must have a message
275
+ if (typeof e.message !== 'string') {
276
+ return false;
277
+ }
278
+ // Should have license-specific properties
279
+ const hasLicenseProps = 'code' in e || 'feature' in e || 'currentTier' in e || 'requiredTier' in e || 'upgradeUrl' in e;
280
+ return hasLicenseProps;
281
+ }
282
+ /**
283
+ * Safely convert any error to MCP format
284
+ */
285
+ export function safeFormatError(error) {
286
+ if (isLicenseErrorLike(error)) {
287
+ return formatLicenseError(error);
288
+ }
289
+ if (error instanceof Error) {
290
+ return formatGenericError(error);
291
+ }
292
+ return formatGenericError(new Error(String(error)));
293
+ }
294
+ //# sourceMappingURL=errorFormatter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errorFormatter.js","sourceRoot":"","sources":["../../../src/middleware/errorFormatter.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAwDH,+EAA+E;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I,cAAc,IAAI,CAAC,IAAI,YAAY,IAAI,CAAC,CAAA;IAEjG,OAAO,eAAe,CAAA;AACxB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,eAAe,CAAC,KAAc;IAC5C,IAAI,kBAAkB,CAAC,KAAK,CAAC,EAAE,CAAC;QAC9B,OAAO,kBAAkB,CAAC,KAAK,CAAC,CAAA;IAClC,CAAC;IAED,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;QAC3B,OAAO,kBAAkB,CAAC,KAAK,CAAC,CAAA;IAClC,CAAC;IAED,OAAO,kBAAkB,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;AACrD,CAAC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * MCP Server Middleware
3
+ *
4
+ * Exports all middleware for the Skillsmith MCP server.
5
+ */
6
+ export { cspMiddleware, buildCspHeader, generateNonce, validateCspHeader, validateCspHeaderDetailed, getCspForEnvironment, DEFAULT_CSP_DIRECTIVES, STRICT_CSP_DIRECTIVES, type CspDirectives, type CspValidationResult, } from './csp.js';
7
+ export { createLicenseMiddleware, requireFeature, isEnterpriseFeature, requiresLicense, getRequiredFeature, createLicenseErrorResponse, type LicenseMiddleware, type LicenseMiddlewareContext, type LicenseValidationResult, type LicenseInfo, type FeatureFlag, TOOL_FEATURES, FEATURE_DISPLAY_NAMES, FEATURE_TIERS, } from './license.js';
8
+ export { createDegradationMiddleware, getTierComparisonMessage, consoleDegradationLogger, type DegradationMiddleware, type DegradationMiddlewareOptions, type DegradationLogger, type DegradationLogEvent, type McpToolRequest, type McpToolResponse, type ToolHandler, } from './degradation.js';
9
+ export { formatLicenseError, formatGenericError, getUserFriendlyMessage, generateUpgradeUrl, buildUpgradeRequiredResponse, buildLicenseExpiredResponse, buildQuotaExceededResponse, isLicenseErrorLike, safeFormatError, type MCPErrorContent, type MCPErrorResponse, type LicenseErrorDetails as MCPLicenseErrorDetails, type LicenseErrorLike, type UpgradeUrlConfig, } from './errorFormatter.js';
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/middleware/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EACL,aAAa,EACb,cAAc,EACd,aAAa,EACb,iBAAiB,EACjB,yBAAyB,EACzB,oBAAoB,EACpB,sBAAsB,EACtB,qBAAqB,EACrB,KAAK,aAAa,EAClB,KAAK,mBAAmB,GACzB,MAAM,UAAU,CAAA;AAGjB,OAAO,EACL,uBAAuB,EACvB,cAAc,EACd,mBAAmB,EACnB,eAAe,EACf,kBAAkB,EAClB,0BAA0B,EAC1B,KAAK,iBAAiB,EACtB,KAAK,wBAAwB,EAC7B,KAAK,uBAAuB,EAC5B,KAAK,WAAW,EAChB,KAAK,WAAW,EAChB,aAAa,EACb,qBAAqB,EACrB,aAAa,GACd,MAAM,cAAc,CAAA;AAGrB,OAAO,EACL,2BAA2B,EAC3B,wBAAwB,EACxB,wBAAwB,EACxB,KAAK,qBAAqB,EAC1B,KAAK,4BAA4B,EACjC,KAAK,iBAAiB,EACtB,KAAK,mBAAmB,EACxB,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,WAAW,GACjB,MAAM,kBAAkB,CAAA;AAGzB,OAAO,EACL,kBAAkB,EAClB,kBAAkB,EAClB,sBAAsB,EACtB,kBAAkB,EAClB,4BAA4B,EAC5B,2BAA2B,EAC3B,0BAA0B,EAC1B,kBAAkB,EAClB,eAAe,EACf,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACrB,KAAK,mBAAmB,IAAI,sBAAsB,EAClD,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,GACtB,MAAM,qBAAqB,CAAA"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * MCP Server Middleware
3
+ *
4
+ * Exports all middleware for the Skillsmith MCP server.
5
+ */
6
+ // CSP middleware
7
+ export { cspMiddleware, buildCspHeader, generateNonce, validateCspHeader, validateCspHeaderDetailed, getCspForEnvironment, DEFAULT_CSP_DIRECTIVES, STRICT_CSP_DIRECTIVES, } from './csp.js';
8
+ // License middleware
9
+ export { createLicenseMiddleware, requireFeature, isEnterpriseFeature, requiresLicense, getRequiredFeature, createLicenseErrorResponse, TOOL_FEATURES, FEATURE_DISPLAY_NAMES, FEATURE_TIERS, } from './license.js';
10
+ // Degradation middleware (SMI-1060)
11
+ export { createDegradationMiddleware, getTierComparisonMessage, consoleDegradationLogger, } from './degradation.js';
12
+ // MCP Error Formatter (SMI-1061)
13
+ export { formatLicenseError, formatGenericError, getUserFriendlyMessage, generateUpgradeUrl, buildUpgradeRequiredResponse, buildLicenseExpiredResponse, buildQuotaExceededResponse, isLicenseErrorLike, safeFormatError, } from './errorFormatter.js';
14
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/middleware/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,iBAAiB;AACjB,OAAO,EACL,aAAa,EACb,cAAc,EACd,aAAa,EACb,iBAAiB,EACjB,yBAAyB,EACzB,oBAAoB,EACpB,sBAAsB,EACtB,qBAAqB,GAGtB,MAAM,UAAU,CAAA;AAEjB,qBAAqB;AACrB,OAAO,EACL,uBAAuB,EACvB,cAAc,EACd,mBAAmB,EACnB,eAAe,EACf,kBAAkB,EAClB,0BAA0B,EAM1B,aAAa,EACb,qBAAqB,EACrB,aAAa,GACd,MAAM,cAAc,CAAA;AAErB,oCAAoC;AACpC,OAAO,EACL,2BAA2B,EAC3B,wBAAwB,EACxB,wBAAwB,GAQzB,MAAM,kBAAkB,CAAA;AAEzB,iCAAiC;AACjC,OAAO,EACL,kBAAkB,EAClB,kBAAkB,EAClB,sBAAsB,EACtB,kBAAkB,EAClB,4BAA4B,EAC5B,2BAA2B,EAC3B,0BAA0B,EAC1B,kBAAkB,EAClB,eAAe,GAMhB,MAAM,qBAAqB,CAAA"}
@@ -0,0 +1,161 @@
1
+ /**
2
+ * License validation middleware for MCP server
3
+ *
4
+ * Validates that the user has the required license features for enterprise tools.
5
+ * Gracefully degrades if @skillsmith/enterprise is not installed.
6
+ *
7
+ * @see SMI-1055: Add license middleware to MCP server
8
+ */
9
+ import { type FeatureFlag } from './toolFeatureMapping.js';
10
+ /**
11
+ * License validation result
12
+ */
13
+ export interface LicenseValidationResult {
14
+ valid: boolean;
15
+ feature?: FeatureFlag;
16
+ message?: string;
17
+ upgradeUrl?: string;
18
+ warning?: string;
19
+ }
20
+ /**
21
+ * License information interface (mirrors @skillsmith/enterprise LicenseInfo)
22
+ */
23
+ export interface LicenseInfo {
24
+ valid: boolean;
25
+ tier: 'community' | 'team' | 'enterprise';
26
+ features: FeatureFlag[];
27
+ expiresAt?: Date;
28
+ organizationId?: string;
29
+ }
30
+ /**
31
+ * License from enterprise package validation
32
+ */
33
+ interface EnterpriseLicense {
34
+ tier: 'community' | 'team' | 'enterprise';
35
+ features: FeatureFlag[];
36
+ customerId: string;
37
+ issuedAt: Date;
38
+ expiresAt: Date;
39
+ }
40
+ /**
41
+ * Validation result from enterprise package
42
+ */
43
+ interface EnterpriseValidationResult {
44
+ valid: boolean;
45
+ license?: EnterpriseLicense;
46
+ error?: {
47
+ code: string;
48
+ message: string;
49
+ };
50
+ }
51
+ /**
52
+ * License validator instance type from enterprise package
53
+ * Uses duck typing to avoid interface drift with the actual implementation
54
+ */
55
+ type EnterpriseValidator = {
56
+ validate(licenseKey: string): Promise<EnterpriseValidationResult>;
57
+ };
58
+ /**
59
+ * Check if a tool name corresponds to an enterprise feature
60
+ *
61
+ * @param toolName - The name of the MCP tool
62
+ * @returns true if the tool requires an enterprise license
63
+ */
64
+ export declare function isEnterpriseFeature(toolName: string): boolean;
65
+ /**
66
+ * Check if a tool name requires any license (team or enterprise)
67
+ *
68
+ * @param toolName - The name of the MCP tool
69
+ * @returns true if the tool requires any license
70
+ */
71
+ export declare function requiresLicense(toolName: string): boolean;
72
+ /**
73
+ * Get the required feature for a tool
74
+ *
75
+ * @param toolName - The name of the MCP tool
76
+ * @returns The feature flag required, or null if community tool
77
+ */
78
+ export declare function getRequiredFeature(toolName: string): FeatureFlag | null;
79
+ /**
80
+ * License middleware context
81
+ */
82
+ export interface LicenseMiddlewareContext {
83
+ validator: EnterpriseValidator | null;
84
+ licenseKey: string | undefined;
85
+ cachedLicense: LicenseInfo | null;
86
+ cacheExpiry: number;
87
+ }
88
+ /**
89
+ * License middleware instance
90
+ */
91
+ export interface LicenseMiddleware {
92
+ /**
93
+ * Check if a specific feature is available
94
+ */
95
+ checkFeature(feature: FeatureFlag): Promise<LicenseValidationResult>;
96
+ /**
97
+ * Check if a tool can be executed
98
+ */
99
+ checkTool(toolName: string): Promise<LicenseValidationResult>;
100
+ /**
101
+ * Get the current license info
102
+ */
103
+ getLicenseInfo(): Promise<LicenseInfo | null>;
104
+ /**
105
+ * Invalidate the cached license
106
+ */
107
+ invalidateCache(): void;
108
+ }
109
+ /**
110
+ * Create a license middleware factory
111
+ *
112
+ * This middleware reads the license key from environment variables and
113
+ * validates tool access based on the license features.
114
+ *
115
+ * @param options - Optional configuration
116
+ * @returns License middleware instance
117
+ */
118
+ export declare function createLicenseMiddleware(options?: {
119
+ licenseKeyEnvVar?: string;
120
+ cacheTtlMs?: number;
121
+ }): LicenseMiddleware;
122
+ /**
123
+ * Higher-order function to create feature requirement middleware
124
+ *
125
+ * Use this to wrap tool handlers that require specific features.
126
+ *
127
+ * @param feature - The feature flag required
128
+ * @returns Middleware function that checks the feature
129
+ *
130
+ * @example
131
+ * ```typescript
132
+ * const middleware = createLicenseMiddleware();
133
+ * const requireAudit = requireFeature('audit_logging');
134
+ *
135
+ * // In tool handler:
136
+ * const validation = await requireAudit(middleware);
137
+ * if (!validation.valid) {
138
+ * return { error: validation.message, upgradeUrl: validation.upgradeUrl };
139
+ * }
140
+ * ```
141
+ */
142
+ export declare function requireFeature(feature: FeatureFlag): (middleware: LicenseMiddleware) => Promise<LicenseValidationResult>;
143
+ /**
144
+ * Create an error response for license validation failures
145
+ *
146
+ * @param result - The license validation result
147
+ * @returns MCP-formatted error response
148
+ */
149
+ export declare function createLicenseErrorResponse(result: LicenseValidationResult): {
150
+ content: Array<{
151
+ type: 'text';
152
+ text: string;
153
+ }>;
154
+ isError: true;
155
+ _meta?: {
156
+ upgradeUrl: string;
157
+ };
158
+ };
159
+ export type { FeatureFlag } from './toolFeatureMapping.js';
160
+ export { TOOL_FEATURES, FEATURE_DISPLAY_NAMES, FEATURE_TIERS } from './toolFeatureMapping.js';
161
+ //# sourceMappingURL=license.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"license.d.ts","sourceRoot":"","sources":["../../../src/middleware/license.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAIL,KAAK,WAAW,EACjB,MAAM,yBAAyB,CAAA;AAOhC;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,KAAK,EAAE,OAAO,CAAA;IACd,OAAO,CAAC,EAAE,WAAW,CAAA;IACrB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,OAAO,CAAA;IACd,IAAI,EAAE,WAAW,GAAG,MAAM,GAAG,YAAY,CAAA;IACzC,QAAQ,EAAE,WAAW,EAAE,CAAA;IACvB,SAAS,CAAC,EAAE,IAAI,CAAA;IAChB,cAAc,CAAC,EAAE,MAAM,CAAA;CACxB;AAED;;GAEG;AACH,UAAU,iBAAiB;IACzB,IAAI,EAAE,WAAW,GAAG,MAAM,GAAG,YAAY,CAAA;IACzC,QAAQ,EAAE,WAAW,EAAE,CAAA;IACvB,UAAU,EAAE,MAAM,CAAA;IAClB,QAAQ,EAAE,IAAI,CAAA;IACd,SAAS,EAAE,IAAI,CAAA;CAChB;AAED;;GAEG;AACH,UAAU,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