@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,73 @@
1
+ /**
2
+ * @fileoverview New-style tool definition types and `tool()` builder function.
3
+ * Uses the Phase 3 field names: `handler`, `input`, `output`, `format`, `auth`, `task`.
4
+ * Coexists with the legacy `ToolDefinition` during migration.
5
+ * @module src/mcp-server/tools/utils/newToolDefinition
6
+ */
7
+ import type { ContentBlock } from '@modelcontextprotocol/sdk/types.js';
8
+ import type { ZodObject, ZodRawShape, z } from 'zod';
9
+ import type { Context } from '../../../context.js';
10
+ import type { ToolAnnotations } from '../../../mcp-server/tools/utils/toolDefinition.js';
11
+ export type { ToolAnnotations };
12
+ /**
13
+ * New-style tool definition with simplified field names.
14
+ * Produced by the `tool()` builder or constructed directly.
15
+ */
16
+ export interface NewToolDefinition<TInput extends ZodObject<ZodRawShape> = ZodObject<ZodRawShape>, TOutput extends ZodObject<ZodRawShape> = ZodObject<ZodRawShape>> {
17
+ /** Protocol-level metadata (e.g., MCP Apps extension). */
18
+ _meta?: Record<string, unknown>;
19
+ /** UI/behavior hints for clients. */
20
+ annotations?: ToolAnnotations;
21
+ /** Required auth scopes. Checked by handler factory before calling handler. */
22
+ auth?: string[];
23
+ /** LLM-facing description. */
24
+ description: string;
25
+ /**
26
+ * Optional formatter mapping output to ContentBlock[].
27
+ * If omitted, the handler factory JSON-stringifies the output.
28
+ */
29
+ format?: (result: z.infer<TOutput>) => ContentBlock[];
30
+ /**
31
+ * The core handler function. Receives validated input and unified Context.
32
+ * Throw McpError on failure — no try/catch needed.
33
+ */
34
+ handler: (input: z.infer<TInput>, ctx: Context) => Promise<z.infer<TOutput>> | z.infer<TOutput>;
35
+ /** Zod schema for input validation. All fields need `.describe()`. */
36
+ input: TInput;
37
+ /** Programmatic unique name (snake_case). */
38
+ name: string;
39
+ /** Zod schema for output validation. */
40
+ output?: TOutput;
41
+ /** When true, the framework manages task lifecycle automatically. */
42
+ task?: boolean;
43
+ /** Human-readable title for UI display. */
44
+ title?: string;
45
+ }
46
+ /** Type-erased union for mixed arrays passed to createApp(). */
47
+ export type AnyNewToolDefinition = NewToolDefinition<ZodObject<ZodRawShape>, ZodObject<ZodRawShape>>;
48
+ /**
49
+ * Type guard: is this a new-style tool definition?
50
+ * Distinguishes from legacy ToolDefinition (which has `logic` + `inputSchema`)
51
+ * and TaskToolDefinition (which has `taskHandlers`).
52
+ */
53
+ export declare function isNewToolDefinition(def: unknown): def is AnyNewToolDefinition;
54
+ /**
55
+ * Creates a new-style tool definition with full type inference from Zod schemas.
56
+ *
57
+ * @example
58
+ * ```ts
59
+ * const myTool = tool('my_tool', {
60
+ * description: 'Does something useful.',
61
+ * input: z.object({ query: z.string().describe('Search query') }),
62
+ * output: z.object({ result: z.string().describe('Search result') }),
63
+ * auth: ['tool:my_tool:read'],
64
+ * annotations: { readOnlyHint: true },
65
+ * async handler(input, ctx) {
66
+ * ctx.log.info('Processing', { query: input.query });
67
+ * return { result: `Found: ${input.query}` };
68
+ * },
69
+ * });
70
+ * ```
71
+ */
72
+ export declare function tool<TInput extends ZodObject<ZodRawShape>, TOutput extends ZodObject<ZodRawShape> = ZodObject<ZodRawShape>>(name: string, options: Omit<NewToolDefinition<TInput, TOutput>, 'name'>): NewToolDefinition<TInput, TOutput>;
73
+ //# sourceMappingURL=newToolDefinition.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"newToolDefinition.d.ts","sourceRoot":"","sources":["../../../../src/mcp-server/tools/utils/newToolDefinition.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AACvE,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAErD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4CAA4C,CAAC;AAGlF,YAAY,EAAE,eAAe,EAAE,CAAC;AAEhC;;;GAGG;AACH,MAAM,WAAW,iBAAiB,CAChC,MAAM,SAAS,SAAS,CAAC,WAAW,CAAC,GAAG,SAAS,CAAC,WAAW,CAAC,EAC9D,OAAO,SAAS,SAAS,CAAC,WAAW,CAAC,GAAG,SAAS,CAAC,WAAW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AAM,EACZ,OAAO,EAAE,IAAI,CAAC,iBAAiB,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,GACxD,iBAAiB,CAAC,MAAM,EAAE,OAAO,CAAC,CAEpC"}
@@ -0,0 +1,45 @@
1
+ /**
2
+ * @fileoverview New-style tool definition types and `tool()` builder function.
3
+ * Uses the Phase 3 field names: `handler`, `input`, `output`, `format`, `auth`, `task`.
4
+ * Coexists with the legacy `ToolDefinition` during migration.
5
+ * @module src/mcp-server/tools/utils/newToolDefinition
6
+ */
7
+ /**
8
+ * Type guard: is this a new-style tool definition?
9
+ * Distinguishes from legacy ToolDefinition (which has `logic` + `inputSchema`)
10
+ * and TaskToolDefinition (which has `taskHandlers`).
11
+ */
12
+ export function isNewToolDefinition(def) {
13
+ return (def !== null &&
14
+ typeof def === 'object' &&
15
+ 'handler' in def &&
16
+ typeof def.handler === 'function' &&
17
+ 'input' in def &&
18
+ !('taskHandlers' in def) &&
19
+ !('logic' in def));
20
+ }
21
+ // ---------------------------------------------------------------------------
22
+ // Builder
23
+ // ---------------------------------------------------------------------------
24
+ /**
25
+ * Creates a new-style tool definition with full type inference from Zod schemas.
26
+ *
27
+ * @example
28
+ * ```ts
29
+ * const myTool = tool('my_tool', {
30
+ * description: 'Does something useful.',
31
+ * input: z.object({ query: z.string().describe('Search query') }),
32
+ * output: z.object({ result: z.string().describe('Search result') }),
33
+ * auth: ['tool:my_tool:read'],
34
+ * annotations: { readOnlyHint: true },
35
+ * async handler(input, ctx) {
36
+ * ctx.log.info('Processing', { query: input.query });
37
+ * return { result: `Found: ${input.query}` };
38
+ * },
39
+ * });
40
+ * ```
41
+ */
42
+ export function tool(name, options) {
43
+ return { name, ...options };
44
+ }
45
+ //# sourceMappingURL=newToolDefinition.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"newToolDefinition.js","sourceRoot":"","sources":["../../../../src/mcp-server/tools/utils/newToolDefinition.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAuDH;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CAAC,GAAY;IAC9C,OAAO,CACL,GAAG,KAAK,IAAI;QACZ,OAAO,GAAG,KAAK,QAAQ;QACvB,SAAS,IAAI,GAAG;QAChB,OAAQ,GAA+B,CAAC,OAAO,KAAK,UAAU;QAC9D,OAAO,IAAI,GAAG;QACd,CAAC,CAAC,cAAc,IAAI,GAAG,CAAC;QACxB,CAAC,CAAC,OAAO,IAAI,GAAG,CAAC,CAClB,CAAC;AACJ,CAAC;AAED,8EAA8E;AAC9E,UAAU;AACV,8EAA8E;AAE9E;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,IAAI,CAIlB,IAAY,EACZ,OAAyD;IAEzD,OAAO,EAAE,IAAI,EAAE,GAAG,OAAO,EAAE,CAAC;AAC9B,CAAC"}
@@ -0,0 +1,33 @@
1
+ /**
2
+ * @fileoverview Handler factory for new-style tool definitions.
3
+ * Constructs Context, checks inline auth, measures execution, formats response.
4
+ * @module src/mcp-server/tools/utils/newToolHandlerFactory
5
+ */
6
+ import type { RequestHandlerExtra } from '@modelcontextprotocol/sdk/shared/protocol.js';
7
+ import type { CallToolResult, ServerNotification, ServerRequest } from '@modelcontextprotocol/sdk/types.js';
8
+ import type { z } from 'zod';
9
+ import type { StorageService } from '../../../storage/core/StorageService.js';
10
+ import type { Logger } from '../../../utils/internal/logger.js';
11
+ import type { AnyNewToolDefinition } from './newToolDefinition.js';
12
+ type SdkExtra = RequestHandlerExtra<ServerRequest, ServerNotification>;
13
+ /** Services required by the handler factory to construct Context. */
14
+ export interface HandlerFactoryServices {
15
+ logger: Logger;
16
+ storage: StorageService;
17
+ }
18
+ /**
19
+ * Creates an MCP tool handler from a new-style tool definition.
20
+ * The returned function is compatible with the MCP SDK's ToolCallback type.
21
+ *
22
+ * Responsibilities:
23
+ * - Creates RequestContext from SDK context (for tracing)
24
+ * - Creates unified Context (for the handler)
25
+ * - Checks inline `auth` scopes if defined
26
+ * - Validates input via Zod schema
27
+ * - Measures execution time
28
+ * - Formats response via `format` or JSON default
29
+ * - Catches errors and returns `isError: true`
30
+ */
31
+ export declare function createNewToolHandler(def: AnyNewToolDefinition, services: HandlerFactoryServices): (input: z.input<typeof def.input>, extra: SdkExtra) => Promise<CallToolResult>;
32
+ export {};
33
+ //# sourceMappingURL=newToolHandlerFactory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"newToolHandlerFactory.d.ts","sourceRoot":"","sources":["../../../../src/mcp-server/tools/utils/newToolHandlerFactory.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,8CAA8C,CAAC;AACxF,OAAO,KAAK,EACV,cAAc,EAEd,kBAAkB,EAClB,aAAa,EACd,MAAM,oCAAoC,CAAC;AAC5C,OAAO,KAAK,EAA0B,CAAC,EAAE,MAAM,KAAK,CAAC;AAKrD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAC;AAGvE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AAGzD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAMnE,KAAK,QAAQ,GAAG,mBAAmB,CAAC,aAAa,EAAE,kBAAkB,CAAC,CAAC;AAWvE,qEAAqE;AACrE,MAAM,WAAW,sBAAsB;IACrC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,cAAc,CAAC;CACzB;AAgCD;;;;;;;;;;;;GAYG;AACH,wBAAgB,oBAAoB,CAClC,GAAG,EAAE,oBAAoB,EACzB,QAAQ,EAAE,sBAAsB,GAC/B,CAAC,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,GAAG,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,QAAQ,KAAK,OAAO,CAAC,cAAc,CAAC,CAsEhF"}
@@ -0,0 +1,107 @@
1
+ /**
2
+ * @fileoverview Handler factory for new-style tool definitions.
3
+ * Constructs Context, checks inline auth, measures execution, formats response.
4
+ * @module src/mcp-server/tools/utils/newToolHandlerFactory
5
+ */
6
+ import { createContext } from '../../../context.js';
7
+ import { withRequiredScopes } from '../../../mcp-server/transports/auth/lib/authUtils.js';
8
+ import { JsonRpcErrorCode, McpError } from '../../../types-global/errors.js';
9
+ import { ErrorHandler } from '../../../utils/internal/error-handler/errorHandler.js';
10
+ import { measureToolExecution } from '../../../utils/internal/performance.js';
11
+ import { requestContextService } from '../../../utils/internal/requestContext.js';
12
+ // ---------------------------------------------------------------------------
13
+ // Default formatter
14
+ // ---------------------------------------------------------------------------
15
+ const defaultResponseFormatter = (result) => [
16
+ { type: 'text', text: JSON.stringify(result, null, 2) },
17
+ ];
18
+ // ---------------------------------------------------------------------------
19
+ // Capability detection helpers
20
+ // ---------------------------------------------------------------------------
21
+ function wrapElicit(sdkContext) {
22
+ if (typeof sdkContext.elicitInput !== 'function')
23
+ return;
24
+ const fn = sdkContext.elicitInput;
25
+ return (msg, schema) => fn({ message: msg, requestedSchema: schema });
26
+ }
27
+ function wrapSample(sdkContext) {
28
+ if (typeof sdkContext.createMessage !== 'function')
29
+ return;
30
+ const fn = sdkContext.createMessage;
31
+ return (msgs, opts) => fn({ messages: msgs, ...opts });
32
+ }
33
+ // ---------------------------------------------------------------------------
34
+ // Factory
35
+ // ---------------------------------------------------------------------------
36
+ /**
37
+ * Creates an MCP tool handler from a new-style tool definition.
38
+ * The returned function is compatible with the MCP SDK's ToolCallback type.
39
+ *
40
+ * Responsibilities:
41
+ * - Creates RequestContext from SDK context (for tracing)
42
+ * - Creates unified Context (for the handler)
43
+ * - Checks inline `auth` scopes if defined
44
+ * - Validates input via Zod schema
45
+ * - Measures execution time
46
+ * - Formats response via `format` or JSON default
47
+ * - Catches errors and returns `isError: true`
48
+ */
49
+ export function createNewToolHandler(def, services) {
50
+ const formatter = def.format ?? defaultResponseFormatter;
51
+ return async (input, callContext) => {
52
+ // The SDK types `extra` as Record<string, unknown> at the boundary
53
+ const sdkContext = callContext;
54
+ const sdkCaps = callContext;
55
+ const sessionId = typeof sdkContext?.sessionId === 'string' ? sdkContext.sessionId : undefined;
56
+ // Create internal RequestContext for tracing
57
+ const appContext = requestContextService.createRequestContext({
58
+ parentContext: {
59
+ ...(typeof sdkContext?.requestId === 'string' ? { requestId: sdkContext.requestId } : {}),
60
+ ...(sessionId ? { sessionId } : {}),
61
+ },
62
+ operation: 'HandleToolRequest',
63
+ additionalContext: { toolName: def.name, sessionId, input },
64
+ });
65
+ try {
66
+ // Check inline auth scopes
67
+ if (def.auth && def.auth.length > 0) {
68
+ withRequiredScopes(def.auth, appContext);
69
+ }
70
+ // Validate input
71
+ const validatedInput = def.input.parse(input);
72
+ // Construct Context with detected capabilities
73
+ const ctx = createContext({
74
+ appContext,
75
+ logger: services.logger,
76
+ storage: services.storage,
77
+ signal: sdkContext.signal,
78
+ elicit: wrapElicit(sdkCaps),
79
+ sample: wrapSample(sdkCaps),
80
+ });
81
+ // Execute handler with performance measurement.
82
+ // Wrap with Promise.resolve — handler may return sync or async.
83
+ const result = await measureToolExecution(() => Promise.resolve(def.handler(validatedInput, ctx)), { ...appContext, toolName: def.name }, validatedInput);
84
+ return {
85
+ structuredContent: result,
86
+ content: formatter(result),
87
+ };
88
+ }
89
+ catch (error) {
90
+ const handled = ErrorHandler.handleError(error, {
91
+ operation: `tool:${def.name}`,
92
+ context: appContext,
93
+ input,
94
+ });
95
+ const mcpError = handled instanceof McpError
96
+ ? handled
97
+ : new McpError(JsonRpcErrorCode.InternalError, handled.message, {
98
+ originalError: handled.name,
99
+ });
100
+ return {
101
+ isError: true,
102
+ content: [{ type: 'text', text: `Error: ${mcpError.message}` }],
103
+ };
104
+ }
105
+ };
106
+ }
107
+ //# sourceMappingURL=newToolHandlerFactory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"newToolHandlerFactory.js","sourceRoot":"","sources":["../../../../src/mcp-server/tools/utils/newToolHandlerFactory.ts"],"names":[],"mappings":"AAAA;;;;G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fileoverview Defines the standard structure for a declarative tool definition.
3
+ * This interface ensures that all tools provide the necessary metadata (name, schemas)
4
+ * and logic in a consistent, self-contained format, aligned with MCP specifications.
5
+ * @module mcp-server/tools/utils/toolDefinition
6
+ */
7
+ import type { RequestHandlerExtra } from '@modelcontextprotocol/sdk/shared/protocol.js';
8
+ import type { ContentBlock, ServerNotification, ServerRequest } from '@modelcontextprotocol/sdk/types.js';
9
+ import type { ZodObject, ZodRawShape, z } from 'zod';
10
+ import type { RequestContext } from '../../../utils/internal/requestContext.js';
11
+ /**
12
+ * Defines the annotations that provide hints about a tool's behavior.
13
+ * These are not guarantees but are useful for client-side rendering and decision-making.
14
+ * The index signature `[key: string]: unknown;` ensures compatibility with the MCP SDK.
15
+ */
16
+ export interface ToolAnnotations {
17
+ /**
18
+ * A hint indicating that the tool may destroy or modify data in a way that cannot
19
+ * be undone. Only meaningful when `readOnlyHint` is false (the default).
20
+ * Defaults to `true` when unset.
21
+ */
22
+ destructiveHint?: boolean;
23
+ /**
24
+ * A hint indicating that repeated calls with the same arguments have no additional
25
+ * effect beyond the first call. Only meaningful when `readOnlyHint` is false.
26
+ * Defaults to `false` when unset.
27
+ */
28
+ idempotentHint?: boolean;
29
+ /**
30
+ * A hint indicating that the tool may interact with external, unpredictable,
31
+ * or dynamic systems (e.g., fetching from a live API, web search).
32
+ */
33
+ openWorldHint?: boolean;
34
+ /**
35
+ * A hint indicating that the tool does not modify any state.
36
+ * For example, a "read" operation.
37
+ */
38
+ readOnlyHint?: boolean;
39
+ /**
40
+ * An optional human-readable name for the tool, optimized for UI display.
41
+ * If provided, it may be used by clients instead of the programmatic `name`.
42
+ */
43
+ title?: string;
44
+ [key: string]: unknown;
45
+ }
46
+ /**
47
+ * A type alias for the SDK's `RequestHandlerExtra` context, making it more
48
+ * specific and easier to reference in our tool logic signatures.
49
+ */
50
+ export type SdkContext = RequestHandlerExtra<ServerRequest, ServerNotification>;
51
+ /**
52
+ * Represents the complete, self-contained definition of an MCP tool.
53
+ */
54
+ export interface ToolDefinition<TInputSchema extends ZodObject<ZodRawShape>, TOutputSchema extends ZodObject<ZodRawShape>> {
55
+ /**
56
+ * Optional protocol-level metadata passed alongside the tool registration.
57
+ * Extensions use namespaced keys within `_meta` to attach additional semantics.
58
+ *
59
+ * Currently used by the MCP Apps extension (`io.modelcontextprotocol/ui`)
60
+ * to link a tool to an interactive UI resource.
61
+ */
62
+ _meta?: Record<string, unknown>;
63
+ /**
64
+ * Optional metadata providing hints about the tool's behavior.
65
+ */
66
+ annotations?: ToolAnnotations;
67
+ /**
68
+ * A clear, concise description of what the tool does.
69
+ * This is sent to the LLM to help it decide when to use the tool.
70
+ */
71
+ description: string;
72
+ /**
73
+ * The Zod schema for validating the tool's input parameters.
74
+ */
75
+ inputSchema: TInputSchema;
76
+ /**
77
+ * The core business logic function for the tool. It receives the validated
78
+ * input and two context objects, and returns a structured output or throws an McpError.
79
+ *
80
+ * @param input The validated tool input, conforming to `inputSchema`.
81
+ *
82
+ * @param appContext The application's internal `RequestContext`. This should be
83
+ * passed to any internal services (like the logger) for consistent tracing and
84
+ * session management. It contains IDs (`requestId`, `sessionId`, `traceId`)
85
+ * and scoping information (`clientId`, `tenantId`, `scopes`).
86
+ *
87
+ * @param sdkContext The raw `SdkContext` (`RequestHandlerExtra`) from the MCP
88
+ * SDK. This provides access to lower-level protocol capabilities:
89
+ * - `signal`: An `AbortSignal` for handling request cancellation.
90
+ * - `sendNotification`: Send a notification back to the client.
91
+ * - `sendRequest`: Send a new request to the client (e.g., for elicitation).
92
+ * - `authInfo`: Raw, validated authentication information.
93
+ *
94
+ * @returns A promise that resolves with the structured output, conforming to `outputSchema`.
95
+ */
96
+ logic: (input: z.infer<TInputSchema>, appContext: RequestContext, sdkContext: SdkContext) => Promise<z.infer<TOutputSchema>>;
97
+ /**
98
+ * The programmatic, unique name for the tool (e.g., 'echo_message').
99
+ */
100
+ name: string;
101
+ /**
102
+ * The Zod schema for validating the tool's successful output structure.
103
+ */
104
+ outputSchema: TOutputSchema;
105
+ /**
106
+ * An optional function to format the successful output into an array of ContentBlocks
107
+ * for the `CallToolResult`. If not provided, a default JSON stringifier is used.
108
+ * @param result The successful output from the logic function.
109
+ * @returns An array of ContentBlocks to be sent to the client.
110
+ */
111
+ responseFormatter?: (result: z.infer<TOutputSchema>) => ContentBlock[];
112
+ /**
113
+ * An optional, human-readable title for the tool. This is preferred for display in UIs.
114
+ * If not provided, the `name` or `annotations.title` may be used as a fallback.
115
+ */
116
+ title?: string;
117
+ }
118
+ //# sourceMappingURL=toolDefinition.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toolDefinition.d.ts","sourceRoot":"","sources":["../../../../src/mcp-server/tools/utils/toolDefinition.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,8CAA8C,CAAC;AACxF,OAAO,KAAK,EACV,YAAY,EACZ,kBAAkB,EAClB,aAAa,EACd,MAAM,oCAAoC,CAAC;AAC5C,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAErD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AAEzE;;;;GAIG;AACH,MAAM,WAAW,eAAe;IAC9B;;;;OAIG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B;;;;OAIG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB;;;OAGG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB;;;OAGG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED;;;GAGG;AACH,MAAM,MAAM,UAAU,GAAG,mBAAmB,CAAC,aAAa,EAAE,kBAAkB,CAAC,CAAC;AAEhF;;GAEG;AACH,MAAM,WAAW,cAAc,CAC7B,YAAY,SAAS,SAAS,CAAC,WAAW,CAAC,EAC3C,aAAa,SAAS,SAAS,CAAC,WAAW,CAAC;IAE5C;;;;;;OAMG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC;;OAEG;IACH,WAAW,CAAC,EAAE,eAAe,CAAC;IAC9B;;;OAGG;IACH,WAAW,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,WAAW,EAAE,YAAY,CAAC;IAC1B;;;;;;;;;;;;;;;;;;;OAmBG;IACH,KAAK,EAAE,CACL,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,YAAY,CAAC,EAC5B,UAAU,EAAE,cAAc,EAC1B,UAAU,EAAE,UAAU,KACnB,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC;IACrC;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,YAAY,EAAE,aAAa,CAAC;IAC5B;;;;;OAKG;IACH,iBAAiB,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,CAAC,KAAK,CAAC,aAAa,CAAC,KAAK,YAAY,EAAE,CAAC;IACvE;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=toolDefinition.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toolDefinition.js","sourceRoot":"","sources":["../../../../src/mcp-server/tools/utils/toolDefinition.ts"],"names":[],"mappings":""}
@@ -0,0 +1,34 @@
1
+ /**
2
+ * @fileoverview A factory for creating standardized MCP tool handlers.
3
+ * This module abstracts away the boilerplate of error handling, context creation,
4
+ * performance measurement, and response formatting for tool handlers.
5
+ * @module mcp-server/tools/utils/toolHandlerFactory
6
+ */
7
+ import type { AnySchema } from '@modelcontextprotocol/sdk/server/zod-compat.js';
8
+ import type { RequestHandlerExtra } from '@modelcontextprotocol/sdk/shared/protocol.js';
9
+ import type { CallToolResult, ContentBlock, ServerNotification, ServerRequest } from '@modelcontextprotocol/sdk/types.js';
10
+ import type { z } from 'zod';
11
+ import type { RequestContext } from '../../../utils/internal/requestContext.js';
12
+ import type { SdkContext } from './toolDefinition.js';
13
+ /**
14
+ * Options for creating an MCP tool handler via the factory.
15
+ * Uses `AnySchema` from the SDK for Zod 3/4 compatibility.
16
+ */
17
+ export type ToolHandlerFactoryOptions<TInputSchema extends AnySchema, TOutput extends Record<string, unknown>> = {
18
+ toolName: string;
19
+ /** The input schema, captured for type inference (not used at runtime). */
20
+ inputSchema: TInputSchema;
21
+ logic: (input: z.infer<TInputSchema>, appContext: RequestContext, sdkContext: SdkContext) => Promise<TOutput>;
22
+ responseFormatter?: (result: TOutput) => ContentBlock[];
23
+ };
24
+ /**
25
+ * Creates a standardized MCP tool handler.
26
+ * This factory encapsulates context creation, performance measurement,
27
+ * error handling, and response formatting. It separates the app's internal
28
+ * RequestContext from the SDK's `callContext` (which we type as `SdkContext`).
29
+ *
30
+ * @param options - Factory options including toolName, inputSchema, logic, and optional responseFormatter
31
+ * @returns A handler function compatible with the MCP SDK's ToolCallback type
32
+ */
33
+ export declare function createMcpToolHandler<TInputSchema extends AnySchema, TOutput extends Record<string, unknown>>({ toolName, inputSchema, logic, responseFormatter, }: ToolHandlerFactoryOptions<TInputSchema, TOutput>): (input: z.infer<TInputSchema>, extra: RequestHandlerExtra<ServerRequest, ServerNotification>) => Promise<CallToolResult>;
34
+ //# sourceMappingURL=toolHandlerFactory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toolHandlerFactory.d.ts","sourceRoot":"","sources":["../../../../src/mcp-server/tools/utils/toolHandlerFactory.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gDAAgD,CAAC;AAChF,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,8CAA8C,CAAC;AACxF,OAAO,KAAK,EACV,cAAc,EACd,YAAY,EACZ,kBAAkB,EAClB,aAAa,EACd,MAAM,oCAAoC,CAAC;AAC5C,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAI7B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AAEzE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAOtD;;;GAGG;AACH,MAAM,MAAM,yBAAyB,CACnC,YAAY,SAAS,SAAS,EAC9B,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IACrC;IACF,QAAQ,EAAE,MAAM,CAAC;IACjB,2EAA2E;IAC3E,WAAW,EAAE,YAAY,CAAC;IAC1B,KAAK,EAAE,CACL,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,YAAY,CAAC,EAC5B,UAAU,EAAE,cAAc,EAC1B,UAAU,EAAE,UAAU,KACnB,OAAO,CAAC,OAAO,CAAC,CAAC;IACtB,iBAAiB,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,YAAY,EAAE,CAAC;CACzD,CAAC;AAEF;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAClC,YAAY,SAAS,SAAS,EAC9B,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACvC,EACA,QAAQ,EACR,WAAW,EACX,KAAK,EACL,iBAA4C,GAC7C,EAAE,yBAAyB,CAAC,YAAY,EAAE,OAAO,CAAC,GAAG,CACpD,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,YAAY,CAAC,EAC5B,KAAK,EAAE,mBAAmB,CAAC,aAAa,EAAE,kBAAkB,CAAC,KAC1D,OAAO,CAAC,cAAc,CAAC,CA+D3B"}
@@ -0,0 +1,68 @@
1
+ import { JsonRpcErrorCode, McpError } from '../../../types-global/errors.js';
2
+ import { ErrorHandler } from '../../../utils/internal/error-handler/errorHandler.js';
3
+ import { measureToolExecution } from '../../../utils/internal/performance.js';
4
+ import { requestContextService } from '../../../utils/internal/requestContext.js';
5
+ // Default formatter for successful responses
6
+ const defaultResponseFormatter = (result) => [
7
+ { type: 'text', text: JSON.stringify(result, null, 2) },
8
+ ];
9
+ /**
10
+ * Creates a standardized MCP tool handler.
11
+ * This factory encapsulates context creation, performance measurement,
12
+ * error handling, and response formatting. It separates the app's internal
13
+ * RequestContext from the SDK's `callContext` (which we type as `SdkContext`).
14
+ *
15
+ * @param options - Factory options including toolName, inputSchema, logic, and optional responseFormatter
16
+ * @returns A handler function compatible with the MCP SDK's ToolCallback type
17
+ */
18
+ export function createMcpToolHandler({ toolName, inputSchema, logic, responseFormatter = defaultResponseFormatter, }) {
19
+ return async (input, callContext) => {
20
+ // The SDK types `extra` as `Record<string, unknown>` at this boundary, but the
21
+ // runtime object always carries the full SdkContext shape (signal, sendNotification,
22
+ // sendRequest, authInfo, and optional capabilities like elicitInput/createMessage).
23
+ // This cast is unavoidable at the SDK/app type boundary.
24
+ const sdkContext = callContext;
25
+ const sessionId = typeof sdkContext?.sessionId === 'string' ? sdkContext.sessionId : undefined;
26
+ // Extract only plain-data fields from sdkContext — spreading the raw SDK
27
+ // object copies native objects (AbortSignal) that crash Pino serialization.
28
+ const appContext = requestContextService.createRequestContext({
29
+ parentContext: {
30
+ ...(typeof sdkContext?.requestId === 'string' ? { requestId: sdkContext.requestId } : {}),
31
+ ...(sessionId ? { sessionId } : {}),
32
+ },
33
+ operation: 'HandleToolRequest',
34
+ additionalContext: { toolName, sessionId, input },
35
+ });
36
+ try {
37
+ // Defense-in-depth: validate input even though the SDK should have already parsed it.
38
+ // AnySchema is the SDK's Zod 3/4 compat type — cast to access .parse() at runtime.
39
+ const validatedInput = inputSchema.parse(input);
40
+ const result = await measureToolExecution(
41
+ // Pass both the app's internal context and the full SDK context to the logic.
42
+ () => logic(validatedInput, appContext, sdkContext), { ...appContext, toolName }, validatedInput);
43
+ return {
44
+ structuredContent: result,
45
+ content: responseFormatter(result),
46
+ };
47
+ }
48
+ catch (error) {
49
+ // handleError always returns McpError when no errorMapper is provided,
50
+ // but its declared return type is the broader Error. Narrow with instanceof.
51
+ const handled = ErrorHandler.handleError(error, {
52
+ operation: `tool:${toolName}`,
53
+ context: appContext,
54
+ input,
55
+ });
56
+ const mcpError = handled instanceof McpError
57
+ ? handled
58
+ : new McpError(JsonRpcErrorCode.InternalError, handled.message, {
59
+ originalError: handled.name,
60
+ });
61
+ return {
62
+ isError: true,
63
+ content: [{ type: 'text', text: `Error: ${mcpError.message}` }],
64
+ };
65
+ }
66
+ };
67
+ }
68
+ //# sourceMappingURL=toolHandlerFactory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toolHandlerFactory.js","sourceRoot":"","sources":["../../../../src/mcp-server/tools/utils/toolHandlerFactory.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACtE,OAAO,EAAE,YAAY,EAAE,MAAM,gDAAgD,CAAC;AAC9E,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAEvE,OAAO,EAAE,qBAAqB,EAAE,MAAM,oCAAoC,CAAC;AAG3E,6CAA6C;AAC7C,MAAM,wBAAwB,GAAG,CAAC,MAAe,EAAkB,EAAE,CAAC;IACpE,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE;CACxD,CAAC;AAqBF;;;;;;;;GAQG;AACH,MAAM,UAAU,oBAAoB,CAGlC,EACA,QAAQ,EACR,WAAW,EACX,KAAK,EACL,iBAAiB,GAAG,wBAAwB,GACK;IAIjD,OAAO,KAAK,EACV,KAA4B,EAC5B,WAAoC,EACX,EAAE;QAC3B,+EAA+E;QAC/E,qFAAqF;QACrF,oFAAoF;QACpF,yDAAyD;QACzD,MAAM,UAAU,GAAG,WAAyB,CAAC;QAE7C,MAAM,SAAS,GAAG,OAAO,UAAU,EAAE,SAAS,KAAK,QA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T,CAAC,CAAC,IAAI,QAAQ,CAAC,gBAAgB,CAAC,aAAa,EAAE,OAAO,CAAC,OAAO,EAAE;oBAC5D,aAAa,EAAE,OAAO,CAAC,IAAI;iBAC5B,CAAC,CAAC;YAET,OAAO;gBACL,OAAO,EAAE,IAAI;gBACb,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,QAAQ,CAAC,OAAO,EAAE,EAAE,CAAC;aAChE,CAAC;QACJ,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * @fileoverview Defines transport-related types.
3
+ * @module src/mcp-server/transports/ITransport
4
+ */
5
+ import type { ServerType } from '@hono/node-server';
6
+ import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
7
+ export type TransportServer = ServerType | McpServer;
8
+ /**
9
+ * Transport lifecycle contract for HTTP and stdio transports.
10
+ */
11
+ export interface ITransport {
12
+ start(): Promise<TransportServer>;
13
+ stop(): Promise<void>;
14
+ }
15
+ //# sourceMappingURL=ITransport.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ITransport.d.ts","sourceRoot":"","sources":["../../../src/mcp-server/transports/ITransport.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAEzE,MAAM,MAAM,eAAe,GAAG,UAAU,GAAG,SAAS,CAAC;AAErD;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,KAAK,IAAI,OAAO,CAAC,eAAe,CAAC,CAAC;IAClC,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACvB"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=ITransport.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ITransport.js","sourceRoot":"","sources":["../../../src/mcp-server/transports/ITransport.ts"],"names":[],"mappings":""}
@@ -0,0 +1,11 @@
1
+ import type { AuthStrategy } from '../../../mcp-server/transports/auth/strategies/authStrategy.js';
2
+ /**
3
+ * Creates and returns an authentication strategy instance based on the
4
+ * application's configuration (`config.mcpAuthMode`).
5
+ *
6
+ * @returns An instance of a class that implements the `AuthStrategy` interface,
7
+ * or `null` if authentication is disabled (`none`).
8
+ * @throws {Error} If the auth mode is unknown or misconfigured.
9
+ */
10
+ export declare function createAuthStrategy(): AuthStrategy | null;
11
+ //# sourceMappingURL=authFactory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authFactory.d.ts","sourceRoot":"","sources":["../../../../src/mcp-server/transports/auth/authFactory.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yDAAyD,CAAC;AAM5F;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,IAAI,YAAY,GAAG,IAAI,CAuBxD"}
@@ -0,0 +1,43 @@
1
+ /**
2
+ * @fileoverview Factory for creating an authentication strategy based on configuration.
3
+ * This module centralizes the logic for selecting and instantiating the correct
4
+ * authentication strategy, promoting loose coupling and easy extensibility.
5
+ * @module src/mcp-server/transports/auth/authFactory
6
+ */
7
+ import { config } from '../../../config/index.js';
8
+ import { JwtStrategy } from '../../../mcp-server/transports/auth/strategies/jwtStrategy.js';
9
+ import { OauthStrategy } from '../../../mcp-server/transports/auth/strategies/oauthStrategy.js';
10
+ import { logger } from '../../../utils/internal/logger.js';
11
+ import { requestContextService } from '../../../utils/internal/requestContext.js';
12
+ /**
13
+ * Creates and returns an authentication strategy instance based on the
14
+ * application's configuration (`config.mcpAuthMode`).
15
+ *
16
+ * @returns An instance of a class that implements the `AuthStrategy` interface,
17
+ * or `null` if authentication is disabled (`none`).
18
+ * @throws {Error} If the auth mode is unknown or misconfigured.
19
+ */
20
+ export function createAuthStrategy() {
21
+ const context = requestContextService.createRequestContext({
22
+ operation: 'createAuthStrategy',
23
+ authMode: config.mcpAuthMode,
24
+ });
25
+ logger.info('Creating authentication strategy...', context);
26
+ switch (config.mcpAuthMode) {
27
+ case 'jwt':
28
+ logger.debug('Creating JWT strategy.', context);
29
+ return new JwtStrategy(config, logger);
30
+ case 'oauth':
31
+ logger.debug('Creating OAuth strategy.', context);
32
+ return new OauthStrategy(config, logger);
33
+ case 'none':
34
+ logger.info("Authentication is disabled ('none' mode).", context);
35
+ return null; // No authentication
36
+ default:
37
+ // This ensures that if a new auth mode is added to the config type
38
+ // but not to this factory, we get a compile-time or runtime error.
39
+ logger.error(`Unknown authentication mode: ${String(config.mcpAuthMode)}`, context);
40
+ throw new Error(`Unknown authentication mode: ${String(config.mcpAuthMode)}`);
41
+ }
42
+ }
43
+ //# sourceMappingURL=authFactory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authFactory.js","sourceRoot":"","sources":["../../../../src/mcp-server/transports/auth/authFactory.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAE3C,OAAO,EAAE,WAAW,EAAE,MAAM,wDAAwD,CAAC;AACrF,OAAO,EAAE,aAAa,EAAE,MAAM,0DAA0D,CAAC;AACzF,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AACpD,OAAO,EAAE,qBAAqB,EAAE,MAAM,oCAAoC,CAAC;AAE3E;;;;;;;GAOG;AACH,MAAM,UAAU,kBAAkB;IAChC,MAAM,OAAO,GAAG,qBAAqB,CAAC,oBAAoB,CAAC;QACzD,SAAS,EAAE,oBAAoB;QAC/B,QAAQ,EAAE,MAAM,CAAC,WAAW;KAC7B,CAAC,CAAC;IACH,MAAM,CAAC,IAAI,CAAC,qCAAqC,EAAE,OAAO,CAAC,CAAC;IAE5D,QAAQ,MAAM,CAAC,WAAW,EAAE,CAAC;QAC3B,KAAK,KAAK;YACR,MAAM,CAAC,KAAK,CAAC,wBAAwB,EAAE,OAAO,CAAC,CAAC;YAChD,OAA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