@cyanheads/mcp-ts-core 0.1.0-beta.12

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 (485) hide show
  1. package/CLAUDE.md +583 -0
  2. package/LICENSE +201 -0
  3. package/README.md +287 -0
  4. package/biome.json +103 -0
  5. package/dist/app.d.ts +82 -0
  6. package/dist/app.d.ts.map +1 -0
  7. package/dist/app.js +222 -0
  8. package/dist/app.js.map +1 -0
  9. package/dist/cli/init.d.ts +8 -0
  10. package/dist/cli/init.d.ts.map +1 -0
  11. package/dist/cli/init.js +161 -0
  12. package/dist/cli/init.js.map +1 -0
  13. package/dist/config/index.d.ts +349 -0
  14. package/dist/config/index.d.ts.map +1 -0
  15. package/dist/config/index.js +464 -0
  16. package/dist/config/index.js.map +1 -0
  17. package/dist/context.d.ts +119 -0
  18. package/dist/context.d.ts.map +1 -0
  19. package/dist/context.js +144 -0
  20. package/dist/context.js.map +1 -0
  21. package/dist/index.d.ts +8 -0
  22. package/dist/index.d.ts.map +1 -0
  23. package/dist/index.js +9 -0
  24. package/dist/index.js.map +1 -0
  25. package/dist/mcp-server/prompts/prompt-registration.d.ts +33 -0
  26. package/dist/mcp-server/prompts/prompt-registration.d.ts.map +1 -0
  27. package/dist/mcp-server/prompts/prompt-registration.js +91 -0
  28. package/dist/mcp-server/prompts/prompt-registration.js.map +1 -0
  29. package/dist/mcp-server/prompts/utils/newPromptDefinition.d.ts +49 -0
  30. package/dist/mcp-server/prompts/utils/newPromptDefinition.d.ts.map +1 -0
  31. package/dist/mcp-server/prompts/utils/newPromptDefinition.js +39 -0
  32. package/dist/mcp-server/prompts/utils/newPromptDefinition.js.map +1 -0
  33. package/dist/mcp-server/prompts/utils/promptDefinition.d.ts +37 -0
  34. package/dist/mcp-server/prompts/utils/promptDefinition.d.ts.map +1 -0
  35. package/dist/mcp-server/prompts/utils/promptDefinition.js +2 -0
  36. package/dist/mcp-server/prompts/utils/promptDefinition.js.map +1 -0
  37. package/dist/mcp-server/resources/resource-registration.d.ts +27 -0
  38. package/dist/mcp-server/resources/resource-registration.d.ts.map +1 -0
  39. package/dist/mcp-server/resources/resource-registration.js +85 -0
  40. package/dist/mcp-server/resources/resource-registration.js.map +1 -0
  41. package/dist/mcp-server/resources/utils/newResourceDefinition.d.ts +84 -0
  42. package/dist/mcp-server/resources/utils/newResourceDefinition.d.ts.map +1 -0
  43. package/dist/mcp-server/resources/utils/newResourceDefinition.js +40 -0
  44. package/dist/mcp-server/resources/utils/newResourceDefinition.js.map +1 -0
  45. package/dist/mcp-server/resources/utils/newResourceHandlerFactory.d.ts +32 -0
  46. package/dist/mcp-server/resources/utils/newResourceHandlerFactory.d.ts.map +1 -0
  47. package/dist/mcp-server/resources/utils/newResourceHandlerFactory.js +103 -0
  48. package/dist/mcp-server/resources/utils/newResourceHandlerFactory.js.map +1 -0
  49. package/dist/mcp-server/resources/utils/resourceDefinition.d.ts +94 -0
  50. package/dist/mcp-server/resources/utils/resourceDefinition.d.ts.map +1 -0
  51. package/dist/mcp-server/resources/utils/resourceDefinition.js +2 -0
  52. package/dist/mcp-server/resources/utils/resourceDefinition.js.map +1 -0
  53. package/dist/mcp-server/resources/utils/resourceHandlerFactory.d.ts +14 -0
  54. package/dist/mcp-server/resources/utils/resourceHandlerFactory.d.ts.map +1 -0
  55. package/dist/mcp-server/resources/utils/resourceHandlerFactory.js +111 -0
  56. package/dist/mcp-server/resources/utils/resourceHandlerFactory.js.map +1 -0
  57. package/dist/mcp-server/roots/roots-registration.d.ts +22 -0
  58. package/dist/mcp-server/roots/roots-registration.d.ts.map +1 -0
  59. package/dist/mcp-server/roots/roots-registration.js +25 -0
  60. package/dist/mcp-server/roots/roots-registration.js.map +1 -0
  61. package/dist/mcp-server/server.d.ts +34 -0
  62. package/dist/mcp-server/server.d.ts.map +1 -0
  63. package/dist/mcp-server/server.js +62 -0
  64. package/dist/mcp-server/server.js.map +1 -0
  65. package/dist/mcp-server/tasks/core/sessionAwareTaskStore.d.ts +42 -0
  66. package/dist/mcp-server/tasks/core/sessionAwareTaskStore.d.ts.map +1 -0
  67. package/dist/mcp-server/tasks/core/sessionAwareTaskStore.js +70 -0
  68. package/dist/mcp-server/tasks/core/sessionAwareTaskStore.js.map +1 -0
  69. package/dist/mcp-server/tasks/core/storageBackedTaskStore.d.ts +109 -0
  70. package/dist/mcp-server/tasks/core/storageBackedTaskStore.d.ts.map +1 -0
  71. package/dist/mcp-server/tasks/core/storageBackedTaskStore.js +209 -0
  72. package/dist/mcp-server/tasks/core/storageBackedTaskStore.js.map +1 -0
  73. package/dist/mcp-server/tasks/core/taskManager.d.ts +103 -0
  74. package/dist/mcp-server/tasks/core/taskManager.d.ts.map +1 -0
  75. package/dist/mcp-server/tasks/core/taskManager.js +144 -0
  76. package/dist/mcp-server/tasks/core/taskManager.js.map +1 -0
  77. package/dist/mcp-server/tasks/core/taskTypes.d.ts +11 -0
  78. package/dist/mcp-server/tasks/core/taskTypes.d.ts.map +1 -0
  79. package/dist/mcp-server/tasks/core/taskTypes.js +13 -0
  80. package/dist/mcp-server/tasks/core/taskTypes.js.map +1 -0
  81. package/dist/mcp-server/tasks/utils/taskToolDefinition.d.ts +108 -0
  82. package/dist/mcp-server/tasks/utils/taskToolDefinition.d.ts.map +1 -0
  83. package/dist/mcp-server/tasks/utils/taskToolDefinition.js +14 -0
  84. package/dist/mcp-server/tasks/utils/taskToolDefinition.js.map +1 -0
  85. package/dist/mcp-server/tools/tool-registration.d.ts +49 -0
  86. package/dist/mcp-server/tools/tool-registration.d.ts.map +1 -0
  87. package/dist/mcp-server/tools/tool-registration.js +269 -0
  88. package/dist/mcp-server/tools/tool-registration.js.map +1 -0
  89. package/dist/mcp-server/tools/utils/newToolDefinition.d.ts +73 -0
  90. package/dist/mcp-server/tools/utils/newToolDefinition.d.ts.map +1 -0
  91. package/dist/mcp-server/tools/utils/newToolDefinition.js +45 -0
  92. package/dist/mcp-server/tools/utils/newToolDefinition.js.map +1 -0
  93. package/dist/mcp-server/tools/utils/newToolHandlerFactory.d.ts +33 -0
  94. package/dist/mcp-server/tools/utils/newToolHandlerFactory.d.ts.map +1 -0
  95. package/dist/mcp-server/tools/utils/newToolHandlerFactory.js +107 -0
  96. package/dist/mcp-server/tools/utils/newToolHandlerFactory.js.map +1 -0
  97. package/dist/mcp-server/tools/utils/toolDefinition.d.ts +118 -0
  98. package/dist/mcp-server/tools/utils/toolDefinition.d.ts.map +1 -0
  99. package/dist/mcp-server/tools/utils/toolDefinition.js +2 -0
  100. package/dist/mcp-server/tools/utils/toolDefinition.js.map +1 -0
  101. package/dist/mcp-server/tools/utils/toolHandlerFactory.d.ts +34 -0
  102. package/dist/mcp-server/tools/utils/toolHandlerFactory.d.ts.map +1 -0
  103. package/dist/mcp-server/tools/utils/toolHandlerFactory.js +68 -0
  104. package/dist/mcp-server/tools/utils/toolHandlerFactory.js.map +1 -0
  105. package/dist/mcp-server/transports/ITransport.d.ts +15 -0
  106. package/dist/mcp-server/transports/ITransport.d.ts.map +1 -0
  107. package/dist/mcp-server/transports/ITransport.js +2 -0
  108. package/dist/mcp-server/transports/ITransport.js.map +1 -0
  109. package/dist/mcp-server/transports/auth/authFactory.d.ts +11 -0
  110. package/dist/mcp-server/transports/auth/authFactory.d.ts.map +1 -0
  111. package/dist/mcp-server/transports/auth/authFactory.js +43 -0
  112. package/dist/mcp-server/transports/auth/authFactory.js.map +1 -0
  113. package/dist/mcp-server/transports/auth/authMiddleware.d.ts +24 -0
  114. package/dist/mcp-server/transports/auth/authMiddleware.d.ts.map +1 -0
  115. package/dist/mcp-server/transports/auth/authMiddleware.js +69 -0
  116. package/dist/mcp-server/transports/auth/authMiddleware.js.map +1 -0
  117. package/dist/mcp-server/transports/auth/lib/authContext.d.ts +34 -0
  118. package/dist/mcp-server/transports/auth/lib/authContext.d.ts.map +1 -0
  119. package/dist/mcp-server/transports/auth/lib/authContext.js +25 -0
  120. package/dist/mcp-server/transports/auth/lib/authContext.js.map +1 -0
  121. package/dist/mcp-server/transports/auth/lib/authTypes.d.ts +19 -0
  122. package/dist/mcp-server/transports/auth/lib/authTypes.d.ts.map +1 -0
  123. package/dist/mcp-server/transports/auth/lib/authTypes.js +2 -0
  124. package/dist/mcp-server/transports/auth/lib/authTypes.js.map +1 -0
  125. package/dist/mcp-server/transports/auth/lib/authUtils.d.ts +18 -0
  126. package/dist/mcp-server/transports/auth/lib/authUtils.d.ts.map +1 -0
  127. package/dist/mcp-server/transports/auth/lib/authUtils.js +64 -0
  128. package/dist/mcp-server/transports/auth/lib/authUtils.js.map +1 -0
  129. package/dist/mcp-server/transports/auth/lib/checkScopes.d.ts +25 -0
  130. package/dist/mcp-server/transports/auth/lib/checkScopes.d.ts.map +1 -0
  131. package/dist/mcp-server/transports/auth/lib/checkScopes.js +34 -0
  132. package/dist/mcp-server/transports/auth/lib/checkScopes.js.map +1 -0
  133. package/dist/mcp-server/transports/auth/lib/claimParser.d.ts +34 -0
  134. package/dist/mcp-server/transports/auth/lib/claimParser.d.ts.map +1 -0
  135. package/dist/mcp-server/transports/auth/lib/claimParser.js +58 -0
  136. package/dist/mcp-server/transports/auth/lib/claimParser.js.map +1 -0
  137. package/dist/mcp-server/transports/auth/lib/withAuth.d.ts +25 -0
  138. package/dist/mcp-server/transports/auth/lib/withAuth.d.ts.map +1 -0
  139. package/dist/mcp-server/transports/auth/lib/withAuth.js +30 -0
  140. package/dist/mcp-server/transports/auth/lib/withAuth.js.map +1 -0
  141. package/dist/mcp-server/transports/auth/strategies/authStrategy.d.ts +18 -0
  142. package/dist/mcp-server/transports/auth/strategies/authStrategy.d.ts.map +1 -0
  143. package/dist/mcp-server/transports/auth/strategies/authStrategy.js +2 -0
  144. package/dist/mcp-server/transports/auth/strategies/authStrategy.js.map +1 -0
  145. package/dist/mcp-server/transports/auth/strategies/jwtStrategy.d.ts +14 -0
  146. package/dist/mcp-server/transports/auth/strategies/jwtStrategy.d.ts.map +1 -0
  147. package/dist/mcp-server/transports/auth/strategies/jwtStrategy.js +86 -0
  148. package/dist/mcp-server/transports/auth/strategies/jwtStrategy.js.map +1 -0
  149. package/dist/mcp-server/transports/auth/strategies/oauthStrategy.d.ts +14 -0
  150. package/dist/mcp-server/transports/auth/strategies/oauthStrategy.d.ts.map +1 -0
  151. package/dist/mcp-server/transports/auth/strategies/oauthStrategy.js +113 -0
  152. package/dist/mcp-server/transports/auth/strategies/oauthStrategy.js.map +1 -0
  153. package/dist/mcp-server/transports/http/httpErrorHandler.d.ts +25 -0
  154. package/dist/mcp-server/transports/http/httpErrorHandler.d.ts.map +1 -0
  155. package/dist/mcp-server/transports/http/httpErrorHandler.js +112 -0
  156. package/dist/mcp-server/transports/http/httpErrorHandler.js.map +1 -0
  157. package/dist/mcp-server/transports/http/httpTransport.d.ts +47 -0
  158. package/dist/mcp-server/transports/http/httpTransport.d.ts.map +1 -0
  159. package/dist/mcp-server/transports/http/httpTransport.js +396 -0
  160. package/dist/mcp-server/transports/http/httpTransport.js.map +1 -0
  161. package/dist/mcp-server/transports/http/httpTypes.d.ts +17 -0
  162. package/dist/mcp-server/transports/http/httpTypes.d.ts.map +1 -0
  163. package/dist/mcp-server/transports/http/httpTypes.js +2 -0
  164. package/dist/mcp-server/transports/http/httpTypes.js.map +1 -0
  165. package/dist/mcp-server/transports/http/protectedResourceMetadata.d.ts +21 -0
  166. package/dist/mcp-server/transports/http/protectedResourceMetadata.d.ts.map +1 -0
  167. package/dist/mcp-server/transports/http/protectedResourceMetadata.js +44 -0
  168. package/dist/mcp-server/transports/http/protectedResourceMetadata.js.map +1 -0
  169. package/dist/mcp-server/transports/http/sessionIdUtils.d.ts +33 -0
  170. package/dist/mcp-server/transports/http/sessionIdUtils.d.ts.map +1 -0
  171. package/dist/mcp-server/transports/http/sessionIdUtils.js +54 -0
  172. package/dist/mcp-server/transports/http/sessionIdUtils.js.map +1 -0
  173. package/dist/mcp-server/transports/http/sessionStore.d.ts +87 -0
  174. package/dist/mcp-server/transports/http/sessionStore.d.ts.map +1 -0
  175. package/dist/mcp-server/transports/http/sessionStore.js +209 -0
  176. package/dist/mcp-server/transports/http/sessionStore.js.map +1 -0
  177. package/dist/mcp-server/transports/manager.d.ts +22 -0
  178. package/dist/mcp-server/transports/manager.d.ts.map +1 -0
  179. package/dist/mcp-server/transports/manager.js +62 -0
  180. package/dist/mcp-server/transports/manager.js.map +1 -0
  181. package/dist/mcp-server/transports/stdio/stdioTransport.d.ts +44 -0
  182. package/dist/mcp-server/transports/stdio/stdioTransport.d.ts.map +1 -0
  183. package/dist/mcp-server/transports/stdio/stdioTransport.js +63 -0
  184. package/dist/mcp-server/transports/stdio/stdioTransport.js.map +1 -0
  185. package/dist/services/graph/core/GraphService.d.ts +205 -0
  186. package/dist/services/graph/core/GraphService.d.ts.map +1 -0
  187. package/dist/services/graph/core/GraphService.js +231 -0
  188. package/dist/services/graph/core/GraphService.js.map +1 -0
  189. package/dist/services/graph/core/IGraphProvider.d.ts +295 -0
  190. package/dist/services/graph/core/IGraphProvider.d.ts.map +1 -0
  191. package/dist/services/graph/core/IGraphProvider.js +8 -0
  192. package/dist/services/graph/core/IGraphProvider.js.map +1 -0
  193. package/dist/services/graph/types.d.ts +107 -0
  194. package/dist/services/graph/types.d.ts.map +1 -0
  195. package/dist/services/graph/types.js +8 -0
  196. package/dist/services/graph/types.js.map +1 -0
  197. package/dist/services/llm/core/ILlmProvider.d.ts +86 -0
  198. package/dist/services/llm/core/ILlmProvider.d.ts.map +1 -0
  199. package/dist/services/llm/core/ILlmProvider.js +2 -0
  200. package/dist/services/llm/core/ILlmProvider.js.map +1 -0
  201. package/dist/services/llm/providers/openrouter.provider.d.ts +187 -0
  202. package/dist/services/llm/providers/openrouter.provider.d.ts.map +1 -0
  203. package/dist/services/llm/providers/openrouter.provider.js +302 -0
  204. package/dist/services/llm/providers/openrouter.provider.js.map +1 -0
  205. package/dist/services/llm/types.d.ts +16 -0
  206. package/dist/services/llm/types.d.ts.map +1 -0
  207. package/dist/services/llm/types.js +9 -0
  208. package/dist/services/llm/types.js.map +1 -0
  209. package/dist/services/speech/core/ISpeechProvider.d.ts +92 -0
  210. package/dist/services/speech/core/ISpeechProvider.d.ts.map +1 -0
  211. package/dist/services/speech/core/ISpeechProvider.js +34 -0
  212. package/dist/services/speech/core/ISpeechProvider.js.map +1 -0
  213. package/dist/services/speech/core/SpeechService.d.ts +87 -0
  214. package/dist/services/speech/core/SpeechService.d.ts.map +1 -0
  215. package/dist/services/speech/core/SpeechService.js +135 -0
  216. package/dist/services/speech/core/SpeechService.js.map +1 -0
  217. package/dist/services/speech/providers/elevenlabs.provider.d.ts +77 -0
  218. package/dist/services/speech/providers/elevenlabs.provider.d.ts.map +1 -0
  219. package/dist/services/speech/providers/elevenlabs.provider.js +199 -0
  220. package/dist/services/speech/providers/elevenlabs.provider.js.map +1 -0
  221. package/dist/services/speech/providers/whisper.provider.d.ts +94 -0
  222. package/dist/services/speech/providers/whisper.provider.d.ts.map +1 -0
  223. package/dist/services/speech/providers/whisper.provider.js +240 -0
  224. package/dist/services/speech/providers/whisper.provider.js.map +1 -0
  225. package/dist/services/speech/types.d.ts +173 -0
  226. package/dist/services/speech/types.d.ts.map +1 -0
  227. package/dist/services/speech/types.js +8 -0
  228. package/dist/services/speech/types.js.map +1 -0
  229. package/dist/storage/core/IStorageProvider.d.ts +159 -0
  230. package/dist/storage/core/IStorageProvider.d.ts.map +1 -0
  231. package/dist/storage/core/IStorageProvider.js +2 -0
  232. package/dist/storage/core/IStorageProvider.js.map +1 -0
  233. package/dist/storage/core/StorageService.d.ts +22 -0
  234. package/dist/storage/core/StorageService.d.ts.map +1 -0
  235. package/dist/storage/core/StorageService.js +151 -0
  236. package/dist/storage/core/StorageService.js.map +1 -0
  237. package/dist/storage/core/storageFactory.d.ts +66 -0
  238. package/dist/storage/core/storageFactory.d.ts.map +1 -0
  239. package/dist/storage/core/storageFactory.js +122 -0
  240. package/dist/storage/core/storageFactory.js.map +1 -0
  241. package/dist/storage/core/storageValidation.d.ts +77 -0
  242. package/dist/storage/core/storageValidation.d.ts.map +1 -0
  243. package/dist/storage/core/storageValidation.js +303 -0
  244. package/dist/storage/core/storageValidation.js.map +1 -0
  245. package/dist/storage/providers/cloudflare/d1Provider.d.ts +94 -0
  246. package/dist/storage/providers/cloudflare/d1Provider.d.ts.map +1 -0
  247. package/dist/storage/providers/cloudflare/d1Provider.js +347 -0
  248. package/dist/storage/providers/cloudflare/d1Provider.js.map +1 -0
  249. package/dist/storage/providers/cloudflare/kvProvider.d.ts +21 -0
  250. package/dist/storage/providers/cloudflare/kvProvider.d.ts.map +1 -0
  251. package/dist/storage/providers/cloudflare/kvProvider.js +183 -0
  252. package/dist/storage/providers/cloudflare/kvProvider.js.map +1 -0
  253. package/dist/storage/providers/cloudflare/r2Provider.d.ts +28 -0
  254. package/dist/storage/providers/cloudflare/r2Provider.d.ts.map +1 -0
  255. package/dist/storage/providers/cloudflare/r2Provider.js +222 -0
  256. package/dist/storage/providers/cloudflare/r2Provider.js.map +1 -0
  257. package/dist/storage/providers/fileSystem/fileSystemProvider.d.ts +20 -0
  258. package/dist/storage/providers/fileSystem/fileSystemProvider.d.ts.map +1 -0
  259. package/dist/storage/providers/fileSystem/fileSystemProvider.js +282 -0
  260. package/dist/storage/providers/fileSystem/fileSystemProvider.js.map +1 -0
  261. package/dist/storage/providers/inMemory/inMemoryProvider.d.ts +21 -0
  262. package/dist/storage/providers/inMemory/inMemoryProvider.d.ts.map +1 -0
  263. package/dist/storage/providers/inMemory/inMemoryProvider.js +139 -0
  264. package/dist/storage/providers/inMemory/inMemoryProvider.js.map +1 -0
  265. package/dist/storage/providers/supabase/supabase.types.d.ts +49 -0
  266. package/dist/storage/providers/supabase/supabase.types.d.ts.map +1 -0
  267. package/dist/storage/providers/supabase/supabase.types.js +8 -0
  268. package/dist/storage/providers/supabase/supabase.types.js.map +1 -0
  269. package/dist/storage/providers/supabase/supabaseProvider.d.ts +24 -0
  270. package/dist/storage/providers/supabase/supabaseProvider.d.ts.map +1 -0
  271. package/dist/storage/providers/supabase/supabaseProvider.js +209 -0
  272. package/dist/storage/providers/supabase/supabaseProvider.js.map +1 -0
  273. package/dist/testing/index.d.ts +53 -0
  274. package/dist/testing/index.d.ts.map +1 -0
  275. package/dist/testing/index.js +132 -0
  276. package/dist/testing/index.js.map +1 -0
  277. package/dist/types-global/errors.d.ts +83 -0
  278. package/dist/types-global/errors.d.ts.map +1 -0
  279. package/dist/types-global/errors.js +113 -0
  280. package/dist/types-global/errors.js.map +1 -0
  281. package/dist/utils/formatting/diffFormatter.d.ts +227 -0
  282. package/dist/utils/formatting/diffFormatter.d.ts.map +1 -0
  283. package/dist/utils/formatting/diffFormatter.js +369 -0
  284. package/dist/utils/formatting/diffFormatter.js.map +1 -0
  285. package/dist/utils/formatting/index.d.ts +9 -0
  286. package/dist/utils/formatting/index.d.ts.map +1 -0
  287. package/dist/utils/formatting/index.js +9 -0
  288. package/dist/utils/formatting/index.js.map +1 -0
  289. package/dist/utils/formatting/markdownBuilder.d.ts +543 -0
  290. package/dist/utils/formatting/markdownBuilder.d.ts.map +1 -0
  291. package/dist/utils/formatting/markdownBuilder.js +674 -0
  292. package/dist/utils/formatting/markdownBuilder.js.map +1 -0
  293. package/dist/utils/formatting/tableFormatter.d.ts +261 -0
  294. package/dist/utils/formatting/tableFormatter.d.ts.map +1 -0
  295. package/dist/utils/formatting/tableFormatter.js +456 -0
  296. package/dist/utils/formatting/tableFormatter.js.map +1 -0
  297. package/dist/utils/formatting/treeFormatter.d.ts +344 -0
  298. package/dist/utils/formatting/treeFormatter.d.ts.map +1 -0
  299. package/dist/utils/formatting/treeFormatter.js +400 -0
  300. package/dist/utils/formatting/treeFormatter.js.map +1 -0
  301. package/dist/utils/internal/encoding.d.ts +42 -0
  302. package/dist/utils/internal/encoding.d.ts.map +1 -0
  303. package/dist/utils/internal/encoding.js +87 -0
  304. package/dist/utils/internal/encoding.js.map +1 -0
  305. package/dist/utils/internal/error-handler/errorHandler.d.ts +140 -0
  306. package/dist/utils/internal/error-handler/errorHandler.d.ts.map +1 -0
  307. package/dist/utils/internal/error-handler/errorHandler.js +318 -0
  308. package/dist/utils/internal/error-handler/errorHandler.js.map +1 -0
  309. package/dist/utils/internal/error-handler/helpers.d.ts +98 -0
  310. package/dist/utils/internal/error-handler/helpers.d.ts.map +1 -0
  311. package/dist/utils/internal/error-handler/helpers.js +214 -0
  312. package/dist/utils/internal/error-handler/helpers.js.map +1 -0
  313. package/dist/utils/internal/error-handler/mappings.d.ts +85 -0
  314. package/dist/utils/internal/error-handler/mappings.d.ts.map +1 -0
  315. package/dist/utils/internal/error-handler/mappings.js +234 -0
  316. package/dist/utils/internal/error-handler/mappings.js.map +1 -0
  317. package/dist/utils/internal/error-handler/types.d.ts +160 -0
  318. package/dist/utils/internal/error-handler/types.d.ts.map +1 -0
  319. package/dist/utils/internal/error-handler/types.js +6 -0
  320. package/dist/utils/internal/error-handler/types.js.map +1 -0
  321. package/dist/utils/internal/health.d.ts +60 -0
  322. package/dist/utils/internal/health.d.ts.map +1 -0
  323. package/dist/utils/internal/health.js +46 -0
  324. package/dist/utils/internal/health.js.map +1 -0
  325. package/dist/utils/internal/logger.d.ts +300 -0
  326. package/dist/utils/internal/logger.d.ts.map +1 -0
  327. package/dist/utils/internal/logger.js +573 -0
  328. package/dist/utils/internal/logger.js.map +1 -0
  329. package/dist/utils/internal/performance.d.ts +78 -0
  330. package/dist/utils/internal/performance.d.ts.map +1 -0
  331. package/dist/utils/internal/performance.js +227 -0
  332. package/dist/utils/internal/performance.js.map +1 -0
  333. package/dist/utils/internal/requestContext.d.ts +200 -0
  334. package/dist/utils/internal/requestContext.d.ts.map +1 -0
  335. package/dist/utils/internal/requestContext.js +163 -0
  336. package/dist/utils/internal/requestContext.js.map +1 -0
  337. package/dist/utils/internal/runtime.d.ts +49 -0
  338. package/dist/utils/internal/runtime.d.ts.map +1 -0
  339. package/dist/utils/internal/runtime.js +90 -0
  340. package/dist/utils/internal/runtime.js.map +1 -0
  341. package/dist/utils/internal/startupBanner.d.ts +23 -0
  342. package/dist/utils/internal/startupBanner.d.ts.map +1 -0
  343. package/dist/utils/internal/startupBanner.js +34 -0
  344. package/dist/utils/internal/startupBanner.js.map +1 -0
  345. package/dist/utils/metrics/tokenCounter.d.ts +97 -0
  346. package/dist/utils/metrics/tokenCounter.d.ts.map +1 -0
  347. package/dist/utils/metrics/tokenCounter.js +162 -0
  348. package/dist/utils/metrics/tokenCounter.js.map +1 -0
  349. package/dist/utils/network/fetchWithTimeout.d.ts +91 -0
  350. package/dist/utils/network/fetchWithTimeout.d.ts.map +1 -0
  351. package/dist/utils/network/fetchWithTimeout.js +305 -0
  352. package/dist/utils/network/fetchWithTimeout.js.map +1 -0
  353. package/dist/utils/pagination/pagination.d.ts +157 -0
  354. package/dist/utils/pagination/pagination.d.ts.map +1 -0
  355. package/dist/utils/pagination/pagination.js +191 -0
  356. package/dist/utils/pagination/pagination.js.map +1 -0
  357. package/dist/utils/parsing/csvParser.d.ts +84 -0
  358. package/dist/utils/parsing/csvParser.d.ts.map +1 -0
  359. package/dist/utils/parsing/csvParser.js +132 -0
  360. package/dist/utils/parsing/csvParser.js.map +1 -0
  361. package/dist/utils/parsing/dateParser.d.ts +103 -0
  362. package/dist/utils/parsing/dateParser.d.ts.map +1 -0
  363. package/dist/utils/parsing/dateParser.js +142 -0
  364. package/dist/utils/parsing/dateParser.js.map +1 -0
  365. package/dist/utils/parsing/frontmatterParser.d.ts +91 -0
  366. package/dist/utils/parsing/frontmatterParser.d.ts.map +1 -0
  367. package/dist/utils/parsing/frontmatterParser.js +163 -0
  368. package/dist/utils/parsing/frontmatterParser.js.map +1 -0
  369. package/dist/utils/parsing/index.d.ts +15 -0
  370. package/dist/utils/parsing/index.d.ts.map +1 -0
  371. package/dist/utils/parsing/index.js +15 -0
  372. package/dist/utils/parsing/index.js.map +1 -0
  373. package/dist/utils/parsing/jsonParser.d.ts +115 -0
  374. package/dist/utils/parsing/jsonParser.d.ts.map +1 -0
  375. package/dist/utils/parsing/jsonParser.js +177 -0
  376. package/dist/utils/parsing/jsonParser.js.map +1 -0
  377. package/dist/utils/parsing/pdfParser.d.ts +563 -0
  378. package/dist/utils/parsing/pdfParser.d.ts.map +1 -0
  379. package/dist/utils/parsing/pdfParser.js +775 -0
  380. package/dist/utils/parsing/pdfParser.js.map +1 -0
  381. package/dist/utils/parsing/thinkBlock.d.ts +31 -0
  382. package/dist/utils/parsing/thinkBlock.d.ts.map +1 -0
  383. package/dist/utils/parsing/thinkBlock.js +31 -0
  384. package/dist/utils/parsing/thinkBlock.js.map +1 -0
  385. package/dist/utils/parsing/xmlParser.d.ts +69 -0
  386. package/dist/utils/parsing/xmlParser.d.ts.map +1 -0
  387. package/dist/utils/parsing/xmlParser.js +140 -0
  388. package/dist/utils/parsing/xmlParser.js.map +1 -0
  389. package/dist/utils/parsing/yamlParser.d.ts +64 -0
  390. package/dist/utils/parsing/yamlParser.d.ts.map +1 -0
  391. package/dist/utils/parsing/yamlParser.js +129 -0
  392. package/dist/utils/parsing/yamlParser.js.map +1 -0
  393. package/dist/utils/scheduling/scheduler.d.ts +174 -0
  394. package/dist/utils/scheduling/scheduler.d.ts.map +1 -0
  395. package/dist/utils/scheduling/scheduler.js +248 -0
  396. package/dist/utils/scheduling/scheduler.js.map +1 -0
  397. package/dist/utils/security/idGenerator.d.ts +189 -0
  398. package/dist/utils/security/idGenerator.d.ts.map +1 -0
  399. package/dist/utils/security/idGenerator.js +301 -0
  400. package/dist/utils/security/idGenerator.js.map +1 -0
  401. package/dist/utils/security/index.d.ts +8 -0
  402. package/dist/utils/security/index.d.ts.map +1 -0
  403. package/dist/utils/security/index.js +8 -0
  404. package/dist/utils/security/index.js.map +1 -0
  405. package/dist/utils/security/rateLimiter.d.ts +171 -0
  406. package/dist/utils/security/rateLimiter.d.ts.map +1 -0
  407. package/dist/utils/security/rateLimiter.js +294 -0
  408. package/dist/utils/security/rateLimiter.js.map +1 -0
  409. package/dist/utils/security/sanitization.d.ts +430 -0
  410. package/dist/utils/security/sanitization.d.ts.map +1 -0
  411. package/dist/utils/security/sanitization.js +759 -0
  412. package/dist/utils/security/sanitization.js.map +1 -0
  413. package/dist/utils/telemetry/index.d.ts +12 -0
  414. package/dist/utils/telemetry/index.d.ts.map +1 -0
  415. package/dist/utils/telemetry/index.js +12 -0
  416. package/dist/utils/telemetry/index.js.map +1 -0
  417. package/dist/utils/telemetry/instrumentation.d.ts +62 -0
  418. package/dist/utils/telemetry/instrumentation.d.ts.map +1 -0
  419. package/dist/utils/telemetry/instrumentation.js +223 -0
  420. package/dist/utils/telemetry/instrumentation.js.map +1 -0
  421. package/dist/utils/telemetry/metrics.d.ts +170 -0
  422. package/dist/utils/telemetry/metrics.d.ts.map +1 -0
  423. package/dist/utils/telemetry/metrics.js +205 -0
  424. package/dist/utils/telemetry/metrics.js.map +1 -0
  425. package/dist/utils/telemetry/semconv.d.ts +147 -0
  426. package/dist/utils/telemetry/semconv.d.ts.map +1 -0
  427. package/dist/utils/telemetry/semconv.js +159 -0
  428. package/dist/utils/telemetry/semconv.js.map +1 -0
  429. package/dist/utils/telemetry/trace.d.ts +141 -0
  430. package/dist/utils/telemetry/trace.d.ts.map +1 -0
  431. package/dist/utils/telemetry/trace.js +193 -0
  432. package/dist/utils/telemetry/trace.js.map +1 -0
  433. package/dist/utils/types/guards.d.ts +209 -0
  434. package/dist/utils/types/guards.d.ts.map +1 -0
  435. package/dist/utils/types/guards.js +229 -0
  436. package/dist/utils/types/guards.js.map +1 -0
  437. package/dist/utils/types/index.d.ts +6 -0
  438. package/dist/utils/types/index.d.ts.map +1 -0
  439. package/dist/utils/types/index.js +6 -0
  440. package/dist/utils/types/index.js.map +1 -0
  441. package/dist/worker.d.ts +59 -0
  442. package/dist/worker.d.ts.map +1 -0
  443. package/dist/worker.js +216 -0
  444. package/dist/worker.js.map +1 -0
  445. package/package.json +377 -0
  446. package/skills/README.md +38 -0
  447. package/skills/add-export/SKILL.md +49 -0
  448. package/skills/add-prompt/SKILL.md +97 -0
  449. package/skills/add-provider/SKILL.md +53 -0
  450. package/skills/add-resource/SKILL.md +107 -0
  451. package/skills/add-service/SKILL.md +113 -0
  452. package/skills/add-tool/SKILL.md +110 -0
  453. package/skills/api-auth/SKILL.md +173 -0
  454. package/skills/api-config/SKILL.md +68 -0
  455. package/skills/api-context/SKILL.md +321 -0
  456. package/skills/api-errors/SKILL.md +146 -0
  457. package/skills/api-services/SKILL.md +24 -0
  458. package/skills/api-services/references/graph.md +124 -0
  459. package/skills/api-services/references/llm.md +46 -0
  460. package/skills/api-services/references/speech.md +72 -0
  461. package/skills/api-testing/SKILL.md +263 -0
  462. package/skills/api-utils/SKILL.md +106 -0
  463. package/skills/api-utils/references/formatting.md +237 -0
  464. package/skills/api-utils/references/parsing.md +263 -0
  465. package/skills/api-utils/references/security.md +226 -0
  466. package/skills/api-workers/SKILL.md +165 -0
  467. package/skills/devcheck/SKILL.md +31 -0
  468. package/skills/maintenance/SKILL.md +52 -0
  469. package/skills/migrate-mcp-ts-template/SKILL.md +131 -0
  470. package/skills/release/SKILL.md +67 -0
  471. package/skills/setup/SKILL.md +89 -0
  472. package/skills/walkthrough-init/SKILL.md +50 -0
  473. package/templates/.env.example +17 -0
  474. package/templates/AGENTS.md +113 -0
  475. package/templates/CLAUDE.md +113 -0
  476. package/templates/_tsconfig.json +33 -0
  477. package/templates/biome.template.json +43 -0
  478. package/templates/package.json +26 -0
  479. package/templates/src/index.ts +16 -0
  480. package/templates/src/mcp-server/prompts/definitions/echo.prompt.ts +19 -0
  481. package/templates/src/mcp-server/resources/definitions/echo.resource.ts +30 -0
  482. package/templates/src/mcp-server/tools/definitions/echo.tool.ts +24 -0
  483. package/templates/vitest.config.ts +12 -0
  484. package/tsconfig.base.json +44 -0
  485. package/vitest.config.base.ts +38 -0
@@ -0,0 +1,301 @@
1
+ /**
2
+ * @fileoverview Provides a utility class `IdGenerator` for creating customizable, prefixed unique identifiers,
3
+ * and a standalone `generateUUID` function for generating standard UUIDs.
4
+ * The `IdGenerator` supports entity-specific prefixes, custom character sets, and lengths.
5
+ *
6
+ * Note: Logging has been removed from this module to prevent circular dependencies
7
+ * with the `requestContextService`, which itself uses `generateUUID` from this module.
8
+ * This was causing `ReferenceError: Cannot access 'generateUUID' before initialization`
9
+ * during application startup.
10
+ * @module src/utils/security/idGenerator
11
+ */
12
+ import { JsonRpcErrorCode, McpError } from '../../types-global/errors.js';
13
+ /**
14
+ * Returns cryptographically secure random bytes using the Web Crypto API (`crypto.getRandomValues`).
15
+ * Available in Node.js 19+, Cloudflare Workers, and browsers — no Node.js-specific imports needed.
16
+ * @param count - Number of random bytes to generate.
17
+ * @returns A `Uint8Array` of `count` random bytes.
18
+ */
19
+ function getRandomBytes(count) {
20
+ const bytes = new Uint8Array(count);
21
+ crypto.getRandomValues(bytes);
22
+ return bytes;
23
+ }
24
+ /**
25
+ * A generic ID Generator class for creating and managing unique, prefixed identifiers.
26
+ * Allows defining custom prefixes, generating random strings, and validating/normalizing IDs.
27
+ */
28
+ export class IdGenerator {
29
+ /**
30
+ * Default character set for the random part of the ID.
31
+ * @private
32
+ */
33
+ static DEFAULT_CHARSET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
34
+ /**
35
+ * Default separator character between prefix and random part.
36
+ * @private
37
+ */
38
+ static DEFAULT_SEPARATOR = '_';
39
+ /**
40
+ * Default length for the random part of the ID.
41
+ * @private
42
+ */
43
+ static DEFAULT_LENGTH = 6;
44
+ /**
45
+ * Stores the mapping of entity types to their prefixes.
46
+ * @private
47
+ */
48
+ entityPrefixes = {};
49
+ /**
50
+ * Stores a reverse mapping from prefixes (case-insensitive) to entity types.
51
+ * @private
52
+ */
53
+ prefixToEntityType = {};
54
+ /**
55
+ * Constructs an `IdGenerator` instance.
56
+ * @param entityPrefixes - An initial map of entity types to their prefixes.
57
+ */
58
+ constructor(entityPrefixes = {}) {
59
+ // Logging removed to prevent circular dependency with requestContextService.
60
+ this.setEntityPrefixes(entityPrefixes);
61
+ }
62
+ /**
63
+ * Sets or updates the entity prefix configuration and rebuilds the internal reverse lookup map.
64
+ * @param entityPrefixes - A map where keys are entity type names and values are their desired ID prefixes.
65
+ */
66
+ setEntityPrefixes(entityPrefixes) {
67
+ // Logging removed.
68
+ this.entityPrefixes = { ...entityPrefixes };
69
+ this.prefixToEntityType = Object.entries(this.entityPrefixes).reduce((acc, [type, prefix]) => {
70
+ acc[prefix.toLowerCase()] = type; // Store lowercase for case-insensitive lookup
71
+ return acc;
72
+ }, {});
73
+ }
74
+ /**
75
+ * Retrieves a copy of the current entity prefix configuration.
76
+ * @returns The current entity prefix configuration.
77
+ */
78
+ getEntityPrefixes() {
79
+ return { ...this.entityPrefixes };
80
+ }
81
+ /**
82
+ * Generates a cryptographically secure random string.
83
+ * @param length - The desired length of the random string. Defaults to `IdGenerator.DEFAULT_LENGTH`.
84
+ * @param charset - The character set to use. Defaults to `IdGenerator.DEFAULT_CHARSET`.
85
+ * @returns The generated random string.
86
+ */
87
+ generateRandomString(length = IdGenerator.DEFAULT_LENGTH, charset = IdGenerator.DEFAULT_CHARSET) {
88
+ let result = '';
89
+ // Determine the largest multiple of charset.length that is less than or equal to 256
90
+ // This is the threshold for rejection sampling to avoid bias.
91
+ const maxValidByteValue = Math.floor(256 / charset.length) * charset.length;
92
+ while (result.length < length) {
93
+ const byteBuffer = getRandomBytes(1);
94
+ const byte = byteBuffer[0];
95
+ // If the byte is within the valid range (i.e., it won't introduce bias),
96
+ // use it to select a character from the charset. Otherwise, discard and try again.
97
+ if (byte !== undefined && byte < maxValidByteValue) {
98
+ const charIndex = byte % charset.length;
99
+ const char = charset[charIndex];
100
+ if (char) {
101
+ result += char;
102
+ }
103
+ }
104
+ }
105
+ return result;
106
+ }
107
+ /**
108
+ * Generates a unique ID, optionally prepended with a prefix.
109
+ * @param prefix - An optional prefix for the ID.
110
+ * @param options - Optional parameters for ID generation (length, separator, charset).
111
+ * @returns A unique identifier string.
112
+ */
113
+ generate(prefix, options = {}) {
114
+ // Logging removed.
115
+ const { length = IdGenerator.DEFAULT_LENGTH, separator = IdGenerator.DEFAULT_SEPARATOR, charset = IdGenerator.DEFAULT_CHARSET, } = options;
116
+ const randomPart = this.generateRandomString(length, charset);
117
+ const generatedId = prefix ? `${prefix}${separator}${randomPart}` : randomPart;
118
+ return generatedId;
119
+ }
120
+ /**
121
+ * Generates a unique ID for a specified entity type, using its configured prefix.
122
+ * @param entityType - The type of entity (must be registered).
123
+ * @param options - Optional parameters for ID generation.
124
+ * @returns A unique identifier string for the entity (e.g., "PROJ_A6B3J0").
125
+ * @throws {McpError} If the `entityType` is not registered.
126
+ */
127
+ generateForEntity(entityType, options = {}) {
128
+ const prefix = this.entityPrefixes[entityType];
129
+ if (!prefix) {
130
+ throw new McpError(JsonRpcErrorCode.ValidationError, `Unknown entity type: ${entityType}. No prefix registered.`);
131
+ }
132
+ return this.generate(prefix, options);
133
+ }
134
+ /**
135
+ * Validates if an ID conforms to the expected format for a specific entity type.
136
+ * @param id - The ID string to validate.
137
+ * @param entityType - The expected entity type of the ID.
138
+ * @param options - Optional parameters used during generation for validation consistency.
139
+ * The `charset` from these options will be used for validation.
140
+ * @returns `true` if the ID is valid, `false` otherwise.
141
+ */
142
+ isValid(id, entityType, options = {}) {
143
+ const prefix = this.entityPrefixes[entityType];
144
+ const { length = IdGenerator.DEFAULT_LENGTH, separator = IdGenerator.DEFAULT_SEPARATOR, charset = IdGenerator.DEFAULT_CHARSET, // Use charset from options or default
145
+ } = options;
146
+ if (!prefix) {
147
+ return false;
148
+ }
149
+ // Build regex character class from the charset
150
+ // Escape characters that have special meaning inside a regex character class `[]`
151
+ const escapedCharsetForClass = charset.replace(/[[\]\\^-]/g, '\\$&');
152
+ const charsetRegexPart = `[${escapedCharsetForClass}]`;
153
+ const pattern = new RegExp(`^${this.escapeRegex(prefix)}${this.escapeRegex(separator)}${charsetRegexPart}{${length}}$`);
154
+ return pattern.test(id);
155
+ }
156
+ /**
157
+ * Escapes special characters in a string for use in a regular expression.
158
+ * @param str - The string to escape.
159
+ * @returns The escaped string.
160
+ * @private
161
+ */
162
+ escapeRegex(str) {
163
+ return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
164
+ }
165
+ /**
166
+ * Strips the prefix and separator from an ID string, returning only the random part.
167
+ * If the separator does not appear in the string, the original ID is returned unchanged.
168
+ * Handles edge cases where the separator character appears in the random part by
169
+ * rejoining all parts after the first split.
170
+ *
171
+ * @param id - The full ID string (e.g., `"PROJ_A6B3J0"`).
172
+ * @param separator - The separator character used in the ID. Defaults to `'_'`.
173
+ * @returns The random part of the ID without the prefix (e.g., `"A6B3J0"`), or the
174
+ * original string if the separator is not present.
175
+ *
176
+ * @example
177
+ * ```ts
178
+ * idGenerator.stripPrefix('PROJ_A6B3J0'); // → 'A6B3J0'
179
+ * idGenerator.stripPrefix('PROJ-A6B3J0', '-'); // → 'A6B3J0'
180
+ * idGenerator.stripPrefix('NOPREFIXID'); // → 'NOPREFIXID'
181
+ * ```
182
+ */
183
+ stripPrefix(id, separator = IdGenerator.DEFAULT_SEPARATOR) {
184
+ const parts = id.split(separator);
185
+ return parts.length > 1 ? parts.slice(1).join(separator) : id; // Handle separators in random part
186
+ }
187
+ /**
188
+ * Determines the entity type from an ID string by its prefix (case-insensitive).
189
+ * @param id - The ID string (e.g., "PROJ_A6B3J0").
190
+ * @param separator - The separator used in the ID. Defaults to `IdGenerator.DEFAULT_SEPARATOR`.
191
+ * @returns The determined entity type.
192
+ * @throws {McpError} If ID format is invalid or prefix is unknown.
193
+ */
194
+ getEntityType(id, separator = IdGenerator.DEFAULT_SEPARATOR) {
195
+ const parts = id.split(separator);
196
+ if (parts.length < 2 || !parts[0]) {
197
+ throw new McpError(JsonRpcErrorCode.ValidationError, `Invalid ID format: ${id}. Expected format like: PREFIX${separator}RANDOMPART`);
198
+ }
199
+ const prefix = parts[0];
200
+ const entityType = this.prefixToEntityType[prefix.toLowerCase()];
201
+ if (!entityType) {
202
+ throw new McpError(JsonRpcErrorCode.ValidationError, `Unknown entity type for prefix: ${prefix}`);
203
+ }
204
+ return entityType;
205
+ }
206
+ /**
207
+ * Normalizes an entity ID so that the prefix matches its registered casing and the random
208
+ * part is uppercased. Delegates to {@link getEntityType} to resolve the canonical prefix.
209
+ *
210
+ * Note: Uppercasing the random part is correct for the default `A-Z0-9` charset. For custom
211
+ * charsets that include lowercase or non-alphabetic characters, `toUpperCase()` may produce
212
+ * unexpected results.
213
+ *
214
+ * @param id - The ID to normalize (e.g., `"proj_a6b3j0"`).
215
+ * @param separator - The separator used in the ID. Defaults to `'_'`.
216
+ * @returns The normalized ID with canonical prefix casing and uppercase random part
217
+ * (e.g., `"PROJ_A6B3J0"`).
218
+ * @throws {McpError} With {@link JsonRpcErrorCode.ValidationError} if the entity type
219
+ * cannot be determined from the ID's prefix.
220
+ *
221
+ * @example
222
+ * ```ts
223
+ * idGenerator.setEntityPrefixes({ project: 'PROJ' });
224
+ * idGenerator.normalize('proj_a6b3j0'); // → 'PROJ_A6B3J0'
225
+ * idGenerator.normalize('PROJ_a6b3j0'); // → 'PROJ_A6B3J0'
226
+ * ```
227
+ */
228
+ normalize(id, separator = IdGenerator.DEFAULT_SEPARATOR) {
229
+ const entityType = this.getEntityType(id, separator);
230
+ const registeredPrefix = this.entityPrefixes[entityType];
231
+ const idParts = id.split(separator);
232
+ const randomPart = idParts.slice(1).join(separator);
233
+ // Consider if randomPart.toUpperCase() is always correct for custom charsets.
234
+ // For now, maintaining existing behavior.
235
+ return `${registeredPrefix}${separator}${randomPart.toUpperCase()}`;
236
+ }
237
+ }
238
+ /**
239
+ * Default singleton instance of {@link IdGenerator}, initialized with no entity prefixes.
240
+ * Call `idGenerator.setEntityPrefixes({ ... })` during application startup to register prefixes
241
+ * before calling `generateForEntity` or `getEntityType`.
242
+ */
243
+ export const idGenerator = new IdGenerator();
244
+ /**
245
+ * Generates a standard Version 4 UUID using the Web Crypto API (`crypto.randomUUID()`).
246
+ * Cross-runtime: works in Node.js 19+, Cloudflare Workers, and browsers.
247
+ *
248
+ * @returns A new UUID v4 string (e.g., `"110e8400-e29b-41d4-a716-446655440000"`).
249
+ *
250
+ * @example
251
+ * ```ts
252
+ * const id = generateUUID(); // → '110e8400-e29b-41d4-a716-446655440000'
253
+ * ```
254
+ */
255
+ export const generateUUID = () => crypto.randomUUID();
256
+ /**
257
+ * Generates a short, human-readable request context ID in the format `XXXXX-XXXXX`
258
+ * (two 5-character alphanumeric segments joined by a hyphen, e.g., `"A3K9Z-BQ72M"`).
259
+ *
260
+ * This function is self-contained — it does not call `IdGenerator` or any other module-level
261
+ * export — specifically to avoid circular dependencies with `requestContextService`, which
262
+ * itself calls this function during initialization.
263
+ *
264
+ * Uses rejection sampling against the Web Crypto API for uniform, bias-free character selection.
265
+ *
266
+ * @returns A 11-character string in `XXXXX-XXXXX` format suitable for request tracing.
267
+ *
268
+ * @example
269
+ * ```ts
270
+ * const reqId = generateRequestContextId(); // → 'A3K9Z-BQ72M'
271
+ * ```
272
+ */
273
+ export const generateRequestContextId = () => {
274
+ /**
275
+ * Generates a cryptographically secure random string of a given length from a given charset.
276
+ * @param length The desired length of the string.
277
+ * @param charset The characters to use for generation.
278
+ * @returns The generated random string.
279
+ */
280
+ const generateSecureRandomString = (length, charset) => {
281
+ let result = '';
282
+ const maxValidByteValue = Math.floor(256 / charset.length) * charset.length;
283
+ while (result.length < length) {
284
+ const byteBuffer = getRandomBytes(1);
285
+ const byte = byteBuffer[0];
286
+ if (byte !== undefined && byte < maxValidByteValue) {
287
+ const charIndex = byte % charset.length;
288
+ const char = charset[charIndex];
289
+ if (char) {
290
+ result += char;
291
+ }
292
+ }
293
+ }
294
+ return result;
295
+ };
296
+ const charset = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
297
+ const part1 = generateSecureRandomString(5, charset);
298
+ const part2 = generateSecureRandomString(5, charset);
299
+ return `${part1}-${part2}`;
300
+ };
301
+ //# sourceMappingURL=idGenerator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"idGenerator.js","sourceRoot":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AE,CAAC;oBACT,MAAM,IAAI,IAAI,CAAC;gBACjB,CAAC;YACH,CAAC;QACH,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC;IAEF,MAAM,OAAO,GAAG,sCAAsC,CAAC;IACvD,MAAM,KAAK,GAAG,0BAA0B,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;IACrD,MAAM,KAAK,GAAG,0BAA0B,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;IACrD,OAAO,GAAG,KAAK,IAAI,KAAK,EAAE,CAAC;AAC7B,CAAC,CAAC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @fileoverview Barrel export for security utilities.
3
+ * @module utils/security
4
+ */
5
+ export { type EntityPrefixConfig, generateRequestContextId, generateUUID, type IdGenerationOptions, IdGenerator, idGenerator, } from './idGenerator.js';
6
+ export { type RateLimitConfig, type RateLimitEntry, RateLimiter } from './rateLimiter.js';
7
+ export { type HtmlSanitizeConfig, type PathSanitizeOptions, Sanitization, type SanitizedPathInfo, type SanitizeStringOptions, sanitization, sanitizeInputForLogging, } from './sanitization.js';
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/security/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACL,KAAK,kBAAkB,EACvB,wBAAwB,EACxB,YAAY,EACZ,KAAK,mBAAmB,EACxB,WAAW,EACX,WAAW,GACZ,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,KAAK,eAAe,EAAE,KAAK,cAAc,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC1F,OAAO,EACL,KAAK,kBAAkB,EACvB,KAAK,mBAAmB,EACxB,YAAY,EACZ,KAAK,iBAAiB,EACtB,KAAK,qBAAqB,EAC1B,YAAY,EACZ,uBAAuB,GACxB,MAAM,mBAAmB,CAAC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @fileoverview Barrel export for security utilities.
3
+ * @module utils/security
4
+ */
5
+ export { generateRequestContextId, generateUUID, IdGenerator, idGenerator, } from './idGenerator.js';
6
+ export { RateLimiter } from './rateLimiter.js';
7
+ export { Sanitization, sanitization, sanitizeInputForLogging, } from './sanitization.js';
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/security/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAEL,wBAAwB,EACxB,YAAY,EAEZ,WAAW,EACX,WAAW,GACZ,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAA6C,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC1F,OAAO,EAGL,YAAY,EAGZ,YAAY,EACZ,uBAAuB,GACxB,MAAM,mBAAmB,CAAC"}
@@ -0,0 +1,171 @@
1
+ import type { config as ConfigType } from '../../config/index.js';
2
+ import type { logger as LoggerType } from '../../utils/internal/logger.js';
3
+ import { type RequestContext } from '../../utils/internal/requestContext.js';
4
+ /**
5
+ * Defines configuration options for the {@link RateLimiter}.
6
+ */
7
+ export interface RateLimitConfig {
8
+ /** How often, in milliseconds, to clean up expired entries. */
9
+ cleanupInterval?: number;
10
+ /** Custom error message template. Can include `{waitTime}` placeholder. */
11
+ errorMessage?: string;
12
+ /** Optional function to generate a custom key for rate limiting. */
13
+ keyGenerator?: (identifier: string, context?: RequestContext) => string;
14
+ /** Maximum number of requests allowed in the window. */
15
+ maxRequests: number;
16
+ /** Maximum number of tracked keys. When exceeded, oldest entries are evicted (LRU). Default: 10000 */
17
+ maxTrackedKeys?: number;
18
+ /** If true, skip rate limiting in development. */
19
+ skipInDevelopment?: boolean;
20
+ /** Time window in milliseconds. */
21
+ windowMs: number;
22
+ }
23
+ /**
24
+ * Represents an individual entry for tracking requests against a rate limit key.
25
+ */
26
+ export interface RateLimitEntry {
27
+ /** Current request count. */
28
+ count: number;
29
+ /** Last access timestamp for LRU eviction. */
30
+ lastAccess: number;
31
+ /** When the window resets (timestamp in milliseconds). */
32
+ resetTime: number;
33
+ }
34
+ /**
35
+ * A configurable, in-process rate limiter that enforces request quotas per key within a sliding
36
+ * time window. Tracks request counts in a `Map`, evicts least-recently-used entries when the
37
+ * tracked-key cap is reached, and periodically cleans up expired windows via a background timer.
38
+ *
39
+ * Throws {@link McpError} with {@link JsonRpcErrorCode.RateLimited} when the limit is exceeded.
40
+ * Integrates with OpenTelemetry by annotating the active span with rate-limit attributes.
41
+ *
42
+ * @example
43
+ * ```ts
44
+ * const limiter = new RateLimiter(config, logger);
45
+ * limiter.configure({ maxRequests: 60, windowMs: 60_000 });
46
+ *
47
+ * // In a request handler:
48
+ * limiter.check(clientId, requestContext); // throws McpError if over limit
49
+ * ```
50
+ */
51
+ export declare class RateLimiter {
52
+ private config;
53
+ private logger;
54
+ private readonly limits;
55
+ private cleanupTimer;
56
+ private readonly effectiveConfig;
57
+ /**
58
+ * Creates a new `RateLimiter` instance with sensible defaults:
59
+ * - 100 requests per 15-minute window
60
+ * - 5-minute cleanup interval
61
+ * - Up to 10,000 tracked keys (LRU eviction beyond that)
62
+ *
63
+ * Call {@link configure} to override any of these defaults before first use.
64
+ *
65
+ * @param config - Application config, used to check `environment` when `skipInDevelopment` is set.
66
+ * @param logger - Logger instance for debug output on cleanup and eviction events.
67
+ */
68
+ constructor(config: typeof ConfigType, logger: typeof LoggerType);
69
+ /**
70
+ * Evicts the least recently used entry from the limits Map.
71
+ * This prevents unbounded memory growth in high-traffic scenarios.
72
+ * @private
73
+ */
74
+ private evictLRUEntry;
75
+ /**
76
+ * Starts (or restarts) the periodic cleanup interval using the current `cleanupInterval` config.
77
+ * Clears any existing timer first. The timer is unref'd so it does not prevent Node.js from exiting.
78
+ * No-ops if `cleanupInterval` is 0 or unset.
79
+ * @private
80
+ */
81
+ private startCleanupTimer;
82
+ /**
83
+ * Iterates all tracked entries and deletes any whose `resetTime` has passed.
84
+ * Called automatically by the cleanup timer. Logs the number of removed entries at debug level.
85
+ * @private
86
+ */
87
+ private cleanupExpiredEntries;
88
+ /**
89
+ * Merges the provided partial config into the current effective configuration.
90
+ * If `cleanupInterval` is included, the background timer is restarted with the new interval.
91
+ *
92
+ * @param config - Partial {@link RateLimitConfig} fields to apply.
93
+ *
94
+ * @example
95
+ * ```ts
96
+ * limiter.configure({ maxRequests: 30, windowMs: 60_000, skipInDevelopment: true });
97
+ * ```
98
+ */
99
+ configure(config: Partial<RateLimitConfig>): void;
100
+ /**
101
+ * Returns a shallow copy of the current effective {@link RateLimitConfig}.
102
+ *
103
+ * @returns A copy of the active rate limit configuration.
104
+ */
105
+ getConfig(): RateLimitConfig;
106
+ /**
107
+ * Clears all tracked rate limit entries, effectively resetting every key's counter.
108
+ * Useful for testing or emergency bypass scenarios.
109
+ */
110
+ reset(): void;
111
+ /**
112
+ * Checks whether the given key has exceeded its rate limit and throws if so.
113
+ *
114
+ * On each call:
115
+ * 1. No-ops if `skipInDevelopment` is `true` and `config.environment === 'development'`.
116
+ * 2. Resolves the effective key via `keyGenerator` if configured, otherwise uses `key` as-is.
117
+ * 3. Creates a new window entry on first call or after the previous window expired.
118
+ * If the tracked-key cap is reached, the least-recently-used entry is evicted first.
119
+ * 4. Increments the count and updates the LRU timestamp.
120
+ * 5. If count exceeds `maxRequests`, throws {@link McpError} with {@link JsonRpcErrorCode.RateLimited}
121
+ * and error data containing `waitTimeSeconds`, `key`, `limit`, and `windowMs`.
122
+ *
123
+ * The active OpenTelemetry span is annotated with rate-limit attributes on every call.
124
+ *
125
+ * @param key - The identifier to rate-limit (e.g., a client ID, IP address, or tool name).
126
+ * @param context - Optional request context passed to the `keyGenerator`, if configured.
127
+ * @throws {McpError} With code {@link JsonRpcErrorCode.RateLimited} when the limit is exceeded.
128
+ *
129
+ * @example
130
+ * ```ts
131
+ * // Basic usage
132
+ * rateLimiter.check('client-abc');
133
+ *
134
+ * // With request context for custom key generation
135
+ * rateLimiter.check('client-abc', requestContext);
136
+ * ```
137
+ */
138
+ check(key: string, context?: RequestContext): void;
139
+ /**
140
+ * Returns the current rate limit status for a given key, or `null` if the key is not tracked
141
+ * (i.e., no requests have been made in the current window).
142
+ *
143
+ * Note: This method does **not** apply the `keyGenerator` — pass the already-resolved key
144
+ * if a custom generator is configured.
145
+ *
146
+ * @param key - The rate limit key to query.
147
+ * @returns An object with `current` count, configured `limit`, `remaining` requests, and
148
+ * `resetTime` (ms epoch when the window resets), or `null` if the key has no active entry.
149
+ *
150
+ * @example
151
+ * ```ts
152
+ * const status = rateLimiter.getStatus('client-abc');
153
+ * if (status) {
154
+ * console.log(`${status.remaining} requests remaining, resets at ${new Date(status.resetTime)}`);
155
+ * }
156
+ * ```
157
+ */
158
+ getStatus(key: string): {
159
+ current: number;
160
+ limit: number;
161
+ remaining: number;
162
+ resetTime: number;
163
+ } | null;
164
+ /**
165
+ * Stops the background cleanup timer and clears all tracked entries.
166
+ * Should be called during application shutdown to allow the process to exit cleanly
167
+ * (even though the timer is unref'd, explicit disposal is good practice).
168
+ */
169
+ dispose(): void;
170
+ }
171
+ //# sourceMappingURL=rateLimiter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rateLimiter.d.ts","sourceRoot":"","sources":["../../../src/utils/security/rateLimiter.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE9D,OAAO,KAAK,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,4BAA4B,CAAC;AACvE,OAAO,EAAE,KAAK,cAAc,EAAyB,MAAM,oCAAoC,CAAC;AAEhG;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,+DAA+D;IAC/D,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,2EAA2E;IAC3E,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,oEAAoE;IACpE,YAAY,CAAC,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,cAAc,KAAK,MAA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