@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,263 @@
1
+ # Parsing Utilities (`utils/parsing`)
2
+
3
+ ```ts
4
+ import { yamlParser, xmlParser, csvParser, jsonParser, pdfParser, dateParser, frontmatterParser } from '@cyanheads/mcp-ts-core/utils/parsing';
5
+ ```
6
+
7
+ All parsers are **Tier 3** — lazy-load their peer dependency on first call. All methods are **async** unless noted.
8
+
9
+ **Common behavior:**
10
+ - Singleton instances exported alongside classes
11
+ - `<think>...</think>` blocks at the start of input are automatically stripped and logged at `debug` level (except `dateParser` and `pdfParser`)
12
+ - All `context?: RequestContext` parameters are optional (synthetic context created if omitted)
13
+ - Errors throw `McpError` — never return error values
14
+
15
+ ---
16
+
17
+ ## `yamlParser`
18
+
19
+ **Peer dep:** `js-yaml` (`bun add js-yaml`)
20
+
21
+ | Method | Signature |
22
+ |:-------|:----------|
23
+ | `parse` | `<T = unknown>(yamlString, context?) -> Promise<T>` |
24
+
25
+ Uses `js-yaml` `DEFAULT_SCHEMA`. Throws `ConfigurationError` if dep missing, `ValidationError` on empty/malformed input.
26
+
27
+ ```ts
28
+ const config = await yamlParser.parse<ServerConfig>(yamlString);
29
+ ```
30
+
31
+ ---
32
+
33
+ ## `xmlParser`
34
+
35
+ **Peer dep:** `fast-xml-parser` (`bun add fast-xml-parser`)
36
+
37
+ | Method | Signature |
38
+ |:-------|:----------|
39
+ | `parse` | `<T = unknown>(xmlString, context?) -> Promise<T>` |
40
+
41
+ Internal `XMLParser` instance constructed once with `{ processEntities: false, htmlEntities: false }` and cached. Entity refs pass through as-is.
42
+
43
+ ```ts
44
+ const data = await xmlParser.parse<FeedResponse>(xmlString);
45
+ ```
46
+
47
+ ---
48
+
49
+ ## `csvParser`
50
+
51
+ **Peer dep:** `papaparse` (`bun add papaparse`)
52
+
53
+ | Method | Signature |
54
+ |:-------|:----------|
55
+ | `parse` | `<T = unknown>(csvString, options?, context?) -> Promise<Papa.ParseResult<T>>` |
56
+
57
+ `options` is `Papa.ParseConfig` forwarded verbatim — key options: `header`, `delimiter`, `dynamicTyping`. Returns `{ data: T[], errors: ParseError[], meta: ParseMeta }`. Throws `ValidationError` if `result.errors` is non-empty.
58
+
59
+ ```ts
60
+ const result = await csvParser.parse<Row>(csvString, { header: true, dynamicTyping: true });
61
+ for (const row of result.data) { /* ... */ }
62
+ ```
63
+
64
+ ---
65
+
66
+ ## `jsonParser`
67
+
68
+ **Peer dep:** `partial-json` (`bun add partial-json`)
69
+
70
+ | Method | Signature |
71
+ |:-------|:----------|
72
+ | `parse` | `<T = unknown>(jsonString, allowPartial?, context?) -> Promise<T>` |
73
+
74
+ `allowPartial` defaults to `Allow.ALL`. Combine `Allow` flags with bitwise OR for fine-grained control over what partial constructs to accept.
75
+
76
+ ### `Allow` flags
77
+
78
+ | Flag | Value | Meaning |
79
+ |:-----|------:|:--------|
80
+ | `STR` | `0x1` | Partial strings |
81
+ | `NUM` | `0x2` | Partial numbers |
82
+ | `ARR` | `0x4` | Partial arrays |
83
+ | `OBJ` | `0x8` | Partial objects |
84
+ | `NULL` | `0x10` | Partial nulls |
85
+ | `BOOL` | `0x20` | Partial booleans |
86
+ | `NAN` | `0x40` | NaN values |
87
+ | `INFINITY` | `0x80` | Positive Infinity |
88
+ | `_INFINITY` | `0x100` | Negative Infinity |
89
+ | `INF` | `0x180` | Both Infinity variants |
90
+ | `SPECIAL` | `0x1F0` | NULL \| BOOL \| NAN \| INF |
91
+ | `ATOM` | `0x1F3` | All atomic types |
92
+ | `COLLECTION` | `0xC` | ARR \| OBJ |
93
+ | `ALL` | `0x1FF` | Everything (default) |
94
+
95
+ ```ts
96
+ // Parse streaming/partial JSON from LLM output
97
+ const partial = await jsonParser.parse<ToolCall>(chunk, Allow.OBJ | Allow.STR);
98
+
99
+ // Strict parse — no partial constructs
100
+ const strict = await jsonParser.parse<Config>(jsonString, 0);
101
+ ```
102
+
103
+ ---
104
+
105
+ ## `pdfParser`
106
+
107
+ **Peer deps:** `pdf-lib` + `unpdf` (`bun add pdf-lib unpdf`)
108
+
109
+ ### Methods
110
+
111
+ | Method | Sync? | Signature |
112
+ |:-------|:------|:----------|
113
+ | `createDocument` | async | `(context?) -> Promise<PDFDocument>` |
114
+ | `loadDocument` | async | `(pdfBytes, context?) -> Promise<PDFDocument>` |
115
+ | `addPage` | **sync** | `(doc, options?) -> PDFPage` |
116
+ | `embedFont` | async | `(doc, fontName?, context?) -> Promise<PDFFont>` |
117
+ | `embedImage` | async | `(doc, options, context?) -> Promise<PDFImage>` |
118
+ | `drawText` | async | `(page, options) -> Promise<void>` |
119
+ | `drawImage` | async | `(page, options) -> Promise<void>` |
120
+ | `mergePdfs` | async | `(pdfBytesArray, context?) -> Promise<PDFDocument>` |
121
+ | `splitPdf` | async | `(pdfBytes, ranges, context?) -> Promise<PDFDocument[]>` |
122
+ | `fillForm` | **sync** | `(doc, options, context?) -> void` |
123
+ | `extractMetadata` | **sync** | `(doc) -> PdfMetadata` |
124
+ | `setMetadata` | **sync** | `(doc, metadata) -> void` |
125
+ | `extractText` | async | `(doc, options?, context?) -> Promise<ExtractTextResult>` |
126
+ | `saveDocument` | async | `(doc, context?) -> Promise<Uint8Array>` |
127
+
128
+ ### Option types
129
+
130
+ ```ts
131
+ interface AddPageOptions { height?: number; width?: number } // default: 612x792 (US Letter)
132
+
133
+ interface DrawTextOptions {
134
+ text: string; x: number; y: number;
135
+ size?: number; // default 12
136
+ font?: PDFFont; // default Helvetica
137
+ color?: RGB; // default black
138
+ rotate?: number; // degrees, default 0
139
+ maxWidth?: number; // enables word-wrap when set
140
+ lineHeight?: number; // multiplier, default 1.2
141
+ }
142
+
143
+ interface EmbedImageOptions { imageBytes: Uint8Array | ArrayBuffer; format: 'png' | 'jpg' }
144
+
145
+ interface DrawImageOptions {
146
+ image: PDFImage; x: number; y: number;
147
+ width?: number; height?: number; // default: intrinsic dimensions
148
+ rotate?: number; opacity?: number; // default: 0, 1
149
+ }
150
+
151
+ interface PageRange { start: number; end: number } // 0-based, inclusive
152
+
153
+ interface FillFormOptions {
154
+ fields: Record<string, string | boolean | number>;
155
+ flatten?: boolean; // default false — flatten removes form interactivity
156
+ }
157
+
158
+ interface ExtractTextOptions { mergePages?: boolean } // default false
159
+
160
+ interface ExtractTextResult { text: string | string[]; totalPages: number }
161
+ // mergePages=true -> single string; false -> string[] per page
162
+
163
+ interface PdfMetadata {
164
+ pageCount: number;
165
+ title?: string; author?: string; subject?: string; keywords?: string;
166
+ creator?: string; producer?: string;
167
+ creationDate?: string; modificationDate?: string; // ISO 8601
168
+ }
169
+
170
+ interface SetMetadataOptions {
171
+ title?: string; author?: string; subject?: string; keywords?: string;
172
+ creator?: string; producer?: string;
173
+ }
174
+ ```
175
+
176
+ Also re-exports from `pdf-lib`: `PDFDocument`, `PDFFont`, `PDFImage`, `PDFPage`, `RGB`.
177
+
178
+ ### Usage
179
+
180
+ ```ts
181
+ // Create a PDF
182
+ const doc = await pdfParser.createDocument();
183
+ const page = pdfParser.addPage(doc, { width: 612, height: 792 });
184
+ const font = await pdfParser.embedFont(doc, 'Helvetica');
185
+ await pdfParser.drawText(page, { text: 'Hello', x: 50, y: 700, font, size: 24 });
186
+ const bytes = await pdfParser.saveDocument(doc);
187
+
188
+ // Extract text from existing PDF
189
+ const loaded = await pdfParser.loadDocument(existingBytes);
190
+ const result = await pdfParser.extractText(loaded, { mergePages: true });
191
+ // result: { text: 'full document text', totalPages: 5 }
192
+
193
+ // Merge multiple PDFs
194
+ const merged = await pdfParser.mergePdfs([pdf1Bytes, pdf2Bytes]);
195
+
196
+ // Fill form fields
197
+ pdfParser.fillForm(doc, {
198
+ fields: { name: 'Alice', approved: true, score: 95 },
199
+ flatten: true,
200
+ });
201
+ ```
202
+
203
+ ---
204
+
205
+ ## `dateParser`
206
+
207
+ **Peer dep:** `chrono-node` (`bun add chrono-node`)
208
+
209
+ Unlike other parsers, `dateParser` is a plain object (not a class singleton) and `context` is **required**.
210
+
211
+ | Method | Signature | Returns |
212
+ |:-------|:----------|:--------|
213
+ | `parseDate` | `(text, context, refDate?) -> Promise<Date \| null>` | First parsed date, or `null` |
214
+ | `parse` | `(text, context, refDate?) -> Promise<chrono.ParsedResult[]>` | Full chrono results array |
215
+
216
+ Both use `forwardDate: true` — ambiguous relative dates resolve to the next future occurrence.
217
+
218
+ Also exported as standalone functions: `parseDateString` (= `parseDate`) and `parseDateStringDetailed` (= `parse`).
219
+
220
+ ```ts
221
+ const date = await dateParser.parseDate('next Tuesday at 3pm', ctx);
222
+ // Date object for the upcoming Tuesday
223
+
224
+ const results = await dateParser.parse('between March 1 and March 15', ctx);
225
+ // Array of ParsedResult with start/end components
226
+ ```
227
+
228
+ ---
229
+
230
+ ## `frontmatterParser`
231
+
232
+ **Peer dep:** inherits `js-yaml` via `yamlParser` (`bun add js-yaml`)
233
+
234
+ | Method | Signature |
235
+ |:-------|:----------|
236
+ | `parse` | `<T = unknown>(markdown, context?) -> Promise<FrontmatterResult<T>>` |
237
+
238
+ ```ts
239
+ interface FrontmatterResult<T = unknown> {
240
+ frontmatter: T; // parsed YAML object, or {} if none found
241
+ content: string; // markdown body after frontmatter block
242
+ hasFrontmatter: boolean;
243
+ }
244
+ ```
245
+
246
+ Matches `--- ... ---` at the very start of the document. An empty `---\n---` block returns `frontmatter: {}` with `hasFrontmatter: true`. Delegates YAML parsing to `yamlParser`, so `<think>` blocks are also stripped from the YAML content.
247
+
248
+ ```ts
249
+ const { frontmatter, content, hasFrontmatter } = await frontmatterParser.parse<SkillMeta>(markdown);
250
+ if (hasFrontmatter) {
251
+ console.log(frontmatter.name, frontmatter.version);
252
+ }
253
+ ```
254
+
255
+ ---
256
+
257
+ ## `thinkBlockRegex`
258
+
259
+ Exported from the barrel. Regex: `/^<think>([\s\S]*?)<\/think>\s*([\s\S]*)$/`
260
+
261
+ - Group 1: content inside `<think>` tag
262
+ - Group 2: payload after the closing tag
263
+ - Only matches when `<think>` is the very first character of the string
@@ -0,0 +1,226 @@
1
+ # Security Utilities (`utils/security`)
2
+
3
+ ```ts
4
+ import { sanitization, RateLimiter, IdGenerator, idGenerator, generateUUID, generateRequestContextId } from '@cyanheads/mcp-ts-core/utils/security';
5
+ ```
6
+
7
+ ---
8
+
9
+ ## `sanitization`
10
+
11
+ Pre-constructed singleton of `Sanitization`. Tier 3 peers: `sanitize-html`, `validator` (install as needed per method).
12
+
13
+ ### Methods
14
+
15
+ | Method | Async | Peer dep | Signature |
16
+ |:-------|:------|:---------|:----------|
17
+ | `sanitizeHtml` | yes | `sanitize-html` | `(input, config?) -> Promise<string>` |
18
+ | `sanitizeString` | yes | `sanitize-html` / `validator` | `(input, options?) -> Promise<string>` |
19
+ | `sanitizeUrl` | yes | `validator` | `(input, allowedProtocols?) -> Promise<string>` |
20
+ | `sanitizeNumber` | yes | `validator` (string input) | `(input, min?, max?) -> Promise<number>` |
21
+ | `sanitizePath` | **no** | Node.js only | `(input, options?) -> SanitizedPathInfo` |
22
+ | `sanitizeJson` | **no** | none | `<T>(input, maxSize?) -> T` |
23
+ | `sanitizeForLogging` | **no** | none | `(input) -> unknown` |
24
+ | `redactSensitiveFields` | **no** | none | `(data, fields?, ctx?) -> unknown` |
25
+ | `getSensitivePinoFields` | **no** | none | `() -> string[]` |
26
+
27
+ ### Option types
28
+
29
+ ```ts
30
+ interface HtmlSanitizeConfig {
31
+ allowedTags?: string[];
32
+ allowedAttributes?: sanitizeHtml.IOptions['allowedAttributes'];
33
+ preserveComments?: boolean;
34
+ transformTags?: sanitizeHtml.IOptions['transformTags'];
35
+ }
36
+
37
+ interface SanitizeStringOptions {
38
+ context?: 'text' | 'html' | 'attribute' | 'url' | 'javascript'; // default: 'text'
39
+ allowedTags?: string[]; // only used when context: 'html'
40
+ allowedAttributes?: Record<string, string[]>; // only used when context: 'html'
41
+ }
42
+
43
+ interface PathSanitizeOptions {
44
+ allowAbsolute?: boolean; // default: false
45
+ rootDir?: string; // resolved via path.resolve before use
46
+ toPosix?: boolean; // normalize backslashes to /
47
+ }
48
+
49
+ interface SanitizedPathInfo {
50
+ sanitizedPath: string;
51
+ originalInput: string;
52
+ wasAbsolute: boolean;
53
+ convertedToRelative: boolean;
54
+ optionsUsed: PathSanitizeOptions;
55
+ }
56
+ ```
57
+
58
+ ### Behavior notes
59
+
60
+ - `sanitizeHtml`: returns `''` for falsy input; `<a>` tags get `rel="noopener noreferrer"` by default
61
+ - `sanitizeString`: `'javascript'` context always throws `McpError(ValidationError)` — no JavaScript allowed
62
+ - `sanitizeUrl`: default protocols `['http', 'https']`; always blocks `javascript:`, `data:`, `vbscript:`
63
+ - `sanitizePath`: **Node-only** — throws `McpError(InternalError)` in Workers. Throws `McpError(ValidationError)` on path traversal or null bytes.
64
+ - `sanitizeJson`: `maxSize` is bytes (UTF-8); uses `Buffer.byteLength` / `TextEncoder` / `string.length` fallback chain
65
+ - `sanitizeNumber`: `NaN`/`Infinity` always rejected; out-of-range values silently clamped with debug log
66
+ - `sanitizeForLogging`: deep clones via `structuredClone`; returns `'[Log Sanitization Failed]'` on clone error
67
+
68
+ ### Sensitive fields
69
+
70
+ Pre-populated: `password`, `token`, `secret`, `apiKey`, `credential`, `jwt`, `ssn`, `cvv`, `authorization`, `cookie`, `clientsecret`, `client_secret`, `private_key`, `privatekey`.
71
+
72
+ Manage with `setSensitiveFields(fields)` (merges, deduped, lowercased) and `getSensitiveFields()`. `getSensitivePinoFields()` generates 3-depth pino `redact.paths` patterns from the current list.
73
+
74
+ ### Usage
75
+
76
+ ```ts
77
+ // HTML sanitization
78
+ const clean = await sanitization.sanitizeHtml(userHtml, {
79
+ allowedTags: ['p', 'b', 'i', 'a'],
80
+ allowedAttributes: { a: ['href'] },
81
+ });
82
+
83
+ // URL validation
84
+ const safeUrl = await sanitization.sanitizeUrl(userUrl, ['http', 'https', 'mailto']);
85
+
86
+ // Path sanitization (Node-only)
87
+ const info = sanitization.sanitizePath(userPath, { rootDir: '/app/data', allowAbsolute: false });
88
+ // info.sanitizedPath is safe to use in fs operations
89
+
90
+ // JSON with size limit
91
+ const data = sanitization.sanitizeJson<Config>(rawJson, 1024 * 1024); // 1MB max
92
+
93
+ // Logging redaction
94
+ const safe = sanitization.sanitizeForLogging({ password: 'secret', name: 'Alice' });
95
+ // { password: '[REDACTED]', name: 'Alice' }
96
+ ```
97
+
98
+ Also exported: `sanitizeInputForLogging(input)` — convenience wrapper around `sanitization.sanitizeForLogging`.
99
+
100
+ ---
101
+
102
+ ## `RateLimiter`
103
+
104
+ In-process sliding window rate limiter with LRU eviction and OTEL span annotations.
105
+
106
+ ### Constructor
107
+
108
+ ```ts
109
+ new RateLimiter(config: AppConfig, logger: Logger)
110
+ ```
111
+
112
+ Reads initial settings from `AppConfig`. Call `configure()` to override at runtime.
113
+
114
+ ### Configuration
115
+
116
+ ```ts
117
+ interface RateLimitConfig {
118
+ maxRequests: number; // required
119
+ windowMs: number; // required, in milliseconds
120
+ cleanupInterval?: number; // ms between expired entry purges
121
+ maxTrackedKeys?: number; // default 10,000; LRU eviction beyond this
122
+ skipInDevelopment?: boolean; // skips limiting when environment === 'development'
123
+ errorMessage?: string; // supports {waitTime} placeholder
124
+ keyGenerator?: (identifier: string, context?: RequestContext) => string;
125
+ }
126
+ ```
127
+
128
+ Defaults: `windowMs` 15 min, `maxRequests` 100, `cleanupInterval` 5 min, `maxTrackedKeys` 10,000.
129
+
130
+ ### Methods
131
+
132
+ | Method | Signature | Notes |
133
+ |:-------|:----------|:------|
134
+ | `configure` | `(config: Partial<RateLimitConfig>) -> void` | Merges partial config; restarts cleanup timer if `cleanupInterval` changed |
135
+ | `check` | `(key, context?) -> void` | Throws `McpError(RateLimited)` with data `{ waitTimeSeconds, key, limit, windowMs }` when exceeded; annotates active OTEL span |
136
+ | `getStatus` | `(key) -> { current, limit, remaining, resetTime } \| null` | Does NOT apply `keyGenerator` — pass the already-resolved key |
137
+ | `getConfig` | `() -> RateLimitConfig` | Shallow copy of effective config |
138
+ | `reset` | `() -> void` | Clears all tracked entries (no per-key reset) |
139
+ | `dispose` | `() -> void` | Stops cleanup timer and clears all entries; call on shutdown |
140
+
141
+ ### Usage
142
+
143
+ ```ts
144
+ // In a service — check before expensive operation
145
+ rateLimiter.check(`api:${ctx.tenantId}`, ctx);
146
+
147
+ // Check status without consuming a request
148
+ const status = rateLimiter.getStatus('api:tenant-123');
149
+ if (status) {
150
+ console.log(`${status.remaining} requests left, resets at ${new Date(status.resetTime)}`);
151
+ }
152
+
153
+ // Runtime reconfiguration
154
+ rateLimiter.configure({ maxRequests: 200, windowMs: 60_000 });
155
+
156
+ // Cleanup on shutdown
157
+ rateLimiter.dispose();
158
+ ```
159
+
160
+ ---
161
+
162
+ ## `IdGenerator` / `idGenerator`
163
+
164
+ Crypto-random ID generation via Web Crypto API (`crypto.getRandomValues`). Rejection sampling prevents modulo bias.
165
+
166
+ ### Constructor
167
+
168
+ ```ts
169
+ new IdGenerator(entityPrefixes?: EntityPrefixConfig)
170
+ ```
171
+
172
+ `idGenerator` is the pre-constructed singleton (no prefixes registered by default).
173
+
174
+ ### Configuration
175
+
176
+ ```ts
177
+ interface EntityPrefixConfig {
178
+ [key: string]: string; // entityType -> prefix, e.g. { project: 'PROJ', task: 'TASK' }
179
+ }
180
+
181
+ interface IdGenerationOptions {
182
+ charset?: string; // default: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
183
+ length?: number; // default: 6 (random part length)
184
+ separator?: string; // default: '_'
185
+ }
186
+ ```
187
+
188
+ ### Methods
189
+
190
+ | Method | Signature | Notes |
191
+ |:-------|:----------|:------|
192
+ | `generate` | `(prefix?, options?) -> string` | `PREFIX_XXXXXX` or just `XXXXXX` if no prefix |
193
+ | `generateForEntity` | `(entityType, options?) -> string` | Uses registered prefix; throws `McpError(ValidationError)` if type unknown |
194
+ | `generateRandomString` | `(length?, charset?) -> string` | Raw random string; defaults: length 6, charset `A-Z0-9` |
195
+ | `isValid` | `(id, entityType, options?) -> boolean` | Regex-validates format against prefix + separator + charset{length} |
196
+ | `getEntityType` | `(id, separator?) -> string` | Resolves entity type from prefix; throws `McpError(ValidationError)` if unknown |
197
+ | `normalize` | `(id, separator?) -> string` | Canonical prefix casing + uppercase random part |
198
+ | `stripPrefix` | `(id, separator?) -> string` | Returns random part; returns original if separator not found |
199
+ | `setEntityPrefixes` | `(config) -> void` | Replaces all prefixes and rebuilds reverse lookup |
200
+ | `getEntityPrefixes` | `() -> EntityPrefixConfig` | Copy of current config |
201
+
202
+ ### Standalone exports
203
+
204
+ | Export | Returns | Notes |
205
+ |:-------|:--------|:------|
206
+ | `generateUUID()` | `string` | `crypto.randomUUID()` — UUID v4 |
207
+ | `generateRequestContextId()` | `string` | `XXXXX-XXXXX` format (5+5 alphanumeric, hyphen-joined) |
208
+
209
+ ### Usage
210
+
211
+ ```ts
212
+ // Simple ID with prefix
213
+ const id = idGenerator.generate('PROJ'); // 'PROJ_A7K2M9'
214
+
215
+ // Entity-based generation
216
+ const gen = new IdGenerator({ project: 'PROJ', task: 'TASK' });
217
+ const taskId = gen.generateForEntity('task'); // 'TASK_X3B8P1'
218
+ const valid = gen.isValid('TASK_X3B8P1', 'task'); // true
219
+ const type = gen.getEntityType('TASK_X3B8P1'); // 'task'
220
+
221
+ // Raw random string
222
+ const token = idGenerator.generateRandomString(32); // 32-char alphanumeric
223
+
224
+ // UUIDs
225
+ const uuid = generateUUID(); // 'a1b2c3d4-e5f6-...'
226
+ ```
@@ -0,0 +1,165 @@
1
+ ---
2
+ name: api-workers
3
+ description: >
4
+ Cloudflare Workers deployment using `createWorkerHandler` from `@cyanheads/mcp-ts-core/worker`. Covers the full handler signature, binding types, CloudflareBindings extensibility, runtime compatibility guards, and wrangler.toml requirements.
5
+ metadata:
6
+ author: cyanheads
7
+ version: "1.0"
8
+ audience: external
9
+ type: reference
10
+ ---
11
+
12
+ ## Overview
13
+
14
+ `@cyanheads/mcp-ts-core/worker` exports `createWorkerHandler` — the Workers entry point. It wraps tool/resource/prompt registries into a per-request `McpServer` factory that integrates with the Cloudflare Workers runtime.
15
+
16
+ ---
17
+
18
+ ## `createWorkerHandler(options)`
19
+
20
+ ```ts
21
+ import { createWorkerHandler } from '@cyanheads/mcp-ts-core/worker';
22
+ import { allToolDefinitions } from './mcp-server/tools/index.js';
23
+ import { allResourceDefinitions } from './mcp-server/resources/index.js';
24
+ import { allPromptDefinitions } from './mcp-server/prompts/index.js';
25
+ import { initMyService } from './services/my-domain/my-service.js';
26
+
27
+ export default createWorkerHandler({
28
+ tools: allToolDefinitions,
29
+ resources: allResourceDefinitions,
30
+ prompts: allPromptDefinitions,
31
+ setup(core) {
32
+ initMyService(core.config, core.storage);
33
+ },
34
+ extraEnvBindings: [['MY_API_KEY', 'MY_API_KEY']],
35
+ extraObjectBindings: [['MY_CUSTOM_KV', 'MY_CUSTOM_KV']],
36
+ onScheduled: async (controller, env, ctx) => {
37
+ // Cloudflare cron trigger handler
38
+ },
39
+ });
40
+ ```
41
+
42
+ ### Options
43
+
44
+ | Option | Type | Purpose |
45
+ |:-------|:-----|:--------|
46
+ | `tools` | `AnyToolDefinition[]` | Tool definitions to register |
47
+ | `resources` | `AnyResourceDefinition[]` | Resource definitions to register |
48
+ | `prompts` | `PromptDefinition[]` | Prompt definitions to register |
49
+ | `setup` | `(core: CoreServices) => void \| Promise<void>` | Runs after core services are ready, before first request |
50
+ | `extraEnvBindings` | `[bindingKey: string, processEnvKey: string][]` | Maps CF string bindings to `process.env` keys |
51
+ | `extraObjectBindings` | `[bindingKey: string, globalKey: string][]` | Maps CF object bindings (KV, R2, D1, AI) to `globalThis` keys |
52
+ | `onScheduled` | `(controller, env, ctx) => Promise<void>` | Cloudflare cron trigger handler |
53
+
54
+ ### Key design points
55
+
56
+ - **Per-request `McpServer` factory** — a new server instance is created for each request. Required by SDK security advisory GHSA-345p-7cg4-v4c7.
57
+ - **Env bindings refreshed per-request** — Cloudflare may rotate binding object references between requests; the handler re-injects them on every call.
58
+ - **`ctx.waitUntil()` is documented but not yet called by the framework** — the `ExecutionContext` is received and passed through to `app.fetch` and `onScheduled`, but the framework itself does not currently call `ctx.waitUntil()` for telemetry flush. Spans complete synchronously within the request lifecycle.
59
+ - **Singleton app promise with retry-on-failure** — the framework init runs once; if it fails, the next request retries rather than leaving the Worker in a permanently broken state.
60
+
61
+ ---
62
+
63
+ ## Binding types
64
+
65
+ Cloudflare Workers bindings come in two kinds with different injection mechanisms:
66
+
67
+ | Type | Examples | Injection mechanism | Runtime access |
68
+ |:-----|:---------|:--------------------|:---------------|
69
+ | String values | API keys, base URLs, feature flags | `injectEnvVars()` → `process.env` | `process.env.MY_API_KEY` |
70
+ | Object bindings | KV namespace, R2 bucket, D1 database, AI | `storeBindings()` → `globalThis` | `(globalThis as any).MY_CUSTOM_KV` |
71
+
72
+ **`extraEnvBindings`** — array of `[bindingKey, processEnvKey]` tuples. The value of `env[bindingKey]` is assigned to `process.env[processEnvKey]` at request time.
73
+
74
+ **`extraObjectBindings`** — array of `[bindingKey, globalKey]` tuples. The object at `env[bindingKey]` is stored on `globalThis[globalKey]` at request time.
75
+
76
+ Both are refreshed on every request. Never cache binding references between requests.
77
+
78
+ ---
79
+
80
+ ## `CloudflareBindings` extensibility
81
+
82
+ Core defines `CloudflareBindings` without an index signature, so servers extend it via intersection rather than module augmentation:
83
+
84
+ ```ts
85
+ import type { CloudflareBindings as CoreBindings } from '@cyanheads/mcp-ts-core/worker';
86
+
87
+ interface MyBindings extends CoreBindings {
88
+ MY_CUSTOM_KV: KVNamespace;
89
+ MY_R2_BUCKET: R2Bucket;
90
+ }
91
+ ```
92
+
93
+ Pass `MyBindings` as a type parameter where the framework accepts a generic env type (e.g., Hono route handlers, `onScheduled`).
94
+
95
+ ---
96
+
97
+ ## Runtime compatibility
98
+
99
+ ### `runtimeCaps` feature detection
100
+
101
+ ```ts
102
+ import { runtimeCaps } from '@cyanheads/mcp-ts-core/utils/runtime';
103
+
104
+ if (runtimeCaps.isWorkerLike) {
105
+ // Workers-specific path
106
+ }
107
+
108
+ if (runtimeCaps.isNode) {
109
+ // Node.js-specific path (e.g., filesystem access)
110
+ }
111
+ ```
112
+
113
+ `runtimeCaps` is a snapshot taken at import time. Fields: `isNode`, `isBun`, `isWorkerLike`, `isBrowserLike`, `hasProcess`, `hasBuffer`, `hasTextEncoder`, `hasPerformanceNow`. All booleans, never throw.
114
+
115
+ ### Serverless storage whitelist
116
+
117
+ In Workers, only these storage providers are allowed:
118
+
119
+ | Provider | Notes |
120
+ |:---------|:------|
121
+ | `in-memory` | Default — data lost on cold start, no persistence |
122
+ | `cloudflare-kv` | KV namespace binding — eventually consistent |
123
+ | `cloudflare-r2` | R2 bucket binding — object storage |
124
+ | `cloudflare-d1` | D1 database binding — SQLite-compatible |
125
+
126
+ `filesystem` and `supabase` providers are not on the whitelist. In a serverless environment, any non-whitelisted provider type is **silently forced to `in-memory`** (a warning is logged) rather than throwing. Set `STORAGE_PROVIDER_TYPE` to one of the whitelisted values to avoid the fallback.
127
+
128
+ ---
129
+
130
+ ## `wrangler.toml` requirements
131
+
132
+ ```toml
133
+ compatibility_flags = ["nodejs_compat"]
134
+ compatibility_date = "2025-09-01" # must be >= 2025-09-01
135
+
136
+ [[kv_namespaces]]
137
+ binding = "MY_CUSTOM_KV"
138
+ id = "..."
139
+
140
+ [[r2_buckets]]
141
+ binding = "MY_R2_BUCKET"
142
+ bucket_name = "..."
143
+ ```
144
+
145
+ `nodejs_compat` is required for Node.js API shims (e.g., `process.env`, `Buffer`, `crypto`). The minimum `compatibility_date` activates the required shim set.
146
+
147
+ ---
148
+
149
+ ## Workers-specific warnings
150
+
151
+ **Lazy env parsing is mandatory.** Cloudflare injects env bindings at request time via `injectEnvVars()` — after all static module imports complete. Never parse `process.env` at module top-level in Workers:
152
+
153
+ ```ts
154
+ // WRONG — parsed before env is injected
155
+ const apiKey = process.env.MY_API_KEY; // undefined in Workers
156
+
157
+ // CORRECT — lazy parse inside a function or getter
158
+ export function getServerConfig() {
159
+ return ServerConfigSchema.parse({ apiKey: process.env.MY_API_KEY });
160
+ }
161
+ ```
162
+
163
+ **`in-memory` storage is volatile.** Data stored with the `in-memory` provider is lost between cold starts and is not shared across Worker instances. Use `cloudflare-kv`, `cloudflare-r2`, or `cloudflare-d1` for any state that must persist or be shared.
164
+
165
+ **Node-only utilities throw in Workers.** `scheduler` (`node-cron`), `sanitizePath` (fs-based), and `filesystem` storage provider all throw `ConfigurationError` when called from a Worker. Guard with `runtimeCaps.isNode` or avoid entirely.
@@ -0,0 +1,31 @@
1
+ ---
2
+ name: devcheck
3
+ description: >
4
+ Lint, format, typecheck, and audit the project. Use after making changes, before committing, or when the user asks to verify the project is clean.
5
+ metadata:
6
+ author: cyanheads
7
+ version: "1.0"
8
+ audience: external
9
+ type: workflow
10
+ ---
11
+
12
+ ## Steps
13
+
14
+ 1. Run `bun run devcheck`
15
+ 2. Read the output carefully — it runs lint, format check, typecheck, and security audit
16
+ 3. If there are failures, fix the issues in the source files
17
+ 4. Re-run `bun run devcheck` until clean
18
+ 5. Do not consider this skill complete until the command exits successfully with no errors
19
+
20
+ ## Common Issues
21
+
22
+ | Error Type | Typical Fix |
23
+ |:-----------|:------------|
24
+ | Lint errors | Fix code style issues, unused imports, missing types |
25
+ | Format errors | Run `bun run format` or fix manually |
26
+ | Type errors | Fix type mismatches, missing properties, incorrect generics |
27
+ | Security audit | Update vulnerable dependencies with `bun update` |
28
+
29
+ ## Checklist
30
+
31
+ - [ ] `bun run devcheck` exits with no errors