@syrin/cli 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (438) hide show
  1. package/LICENSE +15 -0
  2. package/README.md +302 -0
  3. package/dist/cli/commands/analyse.d.ts +16 -0
  4. package/dist/cli/commands/analyse.js +61 -0
  5. package/dist/cli/commands/dev.d.ts +23 -0
  6. package/dist/cli/commands/dev.js +419 -0
  7. package/dist/cli/commands/doctor.d.ts +10 -0
  8. package/dist/cli/commands/doctor.js +195 -0
  9. package/dist/cli/commands/index.d.ts +12 -0
  10. package/dist/cli/commands/index.js +12 -0
  11. package/dist/cli/commands/init.d.ts +16 -0
  12. package/dist/cli/commands/init.js +90 -0
  13. package/dist/cli/commands/list.d.ts +15 -0
  14. package/dist/cli/commands/list.js +50 -0
  15. package/dist/cli/commands/rollback.d.ts +12 -0
  16. package/dist/cli/commands/rollback.js +101 -0
  17. package/dist/cli/commands/test.d.ts +31 -0
  18. package/dist/cli/commands/test.js +88 -0
  19. package/dist/cli/commands/update.d.ts +9 -0
  20. package/dist/cli/commands/update.js +76 -0
  21. package/dist/cli/index.d.ts +13 -0
  22. package/dist/cli/index.js +342 -0
  23. package/dist/cli/prompts/index.d.ts +5 -0
  24. package/dist/cli/prompts/index.js +5 -0
  25. package/dist/cli/prompts/init-prompt.d.ts +17 -0
  26. package/dist/cli/prompts/init-prompt.js +263 -0
  27. package/dist/cli/utils/command-error-handler.d.ts +14 -0
  28. package/dist/cli/utils/command-error-handler.js +35 -0
  29. package/dist/cli/utils/common-types.d.ts +24 -0
  30. package/dist/cli/utils/common-types.js +6 -0
  31. package/dist/cli/utils/connection-handler.d.ts +37 -0
  32. package/dist/cli/utils/connection-handler.js +90 -0
  33. package/dist/cli/utils/index.d.ts +11 -0
  34. package/dist/cli/utils/index.js +11 -0
  35. package/dist/cli/utils/option-parsers.d.ts +41 -0
  36. package/dist/cli/utils/option-parsers.js +92 -0
  37. package/dist/cli/utils/output-utils.d.ts +12 -0
  38. package/dist/cli/utils/output-utils.js +21 -0
  39. package/dist/cli/utils/transport-resolver.d.ts +33 -0
  40. package/dist/cli/utils/transport-resolver.js +82 -0
  41. package/dist/cli/utils/version-banner.d.ts +10 -0
  42. package/dist/cli/utils/version-banner.js +26 -0
  43. package/dist/config/env-checker.d.ts +37 -0
  44. package/dist/config/env-checker.js +136 -0
  45. package/dist/config/generator.d.ts +19 -0
  46. package/dist/config/generator.js +196 -0
  47. package/dist/config/index.d.ts +9 -0
  48. package/dist/config/index.js +9 -0
  49. package/dist/config/loader.d.ts +19 -0
  50. package/dist/config/loader.js +57 -0
  51. package/dist/config/schema.d.ts +42 -0
  52. package/dist/config/schema.js +181 -0
  53. package/dist/config/syrin.template.yaml +127 -0
  54. package/dist/config/types.d.ts +87 -0
  55. package/dist/config/types.js +6 -0
  56. package/dist/constants/app.d.ts +9 -0
  57. package/dist/constants/app.js +9 -0
  58. package/dist/constants/commands.d.ts +43 -0
  59. package/dist/constants/commands.js +43 -0
  60. package/dist/constants/defaults.d.ts +18 -0
  61. package/dist/constants/defaults.js +18 -0
  62. package/dist/constants/env-vars.d.ts +11 -0
  63. package/dist/constants/env-vars.js +11 -0
  64. package/dist/constants/icons.d.ts +23 -0
  65. package/dist/constants/icons.js +23 -0
  66. package/dist/constants/index.d.ts +17 -0
  67. package/dist/constants/index.js +17 -0
  68. package/dist/constants/labels.d.ts +38 -0
  69. package/dist/constants/labels.js +42 -0
  70. package/dist/constants/links.d.ts +10 -0
  71. package/dist/constants/links.js +11 -0
  72. package/dist/constants/list.d.ts +10 -0
  73. package/dist/constants/list.js +9 -0
  74. package/dist/constants/llm.d.ts +26 -0
  75. package/dist/constants/llm.js +25 -0
  76. package/dist/constants/messages.d.ts +107 -0
  77. package/dist/constants/messages.js +138 -0
  78. package/dist/constants/paths.d.ts +29 -0
  79. package/dist/constants/paths.js +29 -0
  80. package/dist/constants/transport.d.ts +9 -0
  81. package/dist/constants/transport.js +8 -0
  82. package/dist/events/emitter.d.ts +64 -0
  83. package/dist/events/emitter.js +142 -0
  84. package/dist/events/event-type.d.ts +66 -0
  85. package/dist/events/event-type.js +81 -0
  86. package/dist/events/payloads/diagnostics.d.ts +24 -0
  87. package/dist/events/payloads/diagnostics.js +5 -0
  88. package/dist/events/payloads/index.d.ts +15 -0
  89. package/dist/events/payloads/index.js +6 -0
  90. package/dist/events/payloads/llm.d.ts +58 -0
  91. package/dist/events/payloads/llm.js +6 -0
  92. package/dist/events/payloads/registry.d.ts +28 -0
  93. package/dist/events/payloads/registry.js +5 -0
  94. package/dist/events/payloads/session.d.ts +32 -0
  95. package/dist/events/payloads/session.js +5 -0
  96. package/dist/events/payloads/testing.d.ts +17 -0
  97. package/dist/events/payloads/testing.js +5 -0
  98. package/dist/events/payloads/tool.d.ts +29 -0
  99. package/dist/events/payloads/tool.js +5 -0
  100. package/dist/events/payloads/transport.d.ts +30 -0
  101. package/dist/events/payloads/transport.js +5 -0
  102. package/dist/events/payloads/validation.d.ts +37 -0
  103. package/dist/events/payloads/validation.js +5 -0
  104. package/dist/events/payloads/workflow.d.ts +45 -0
  105. package/dist/events/payloads/workflow.js +5 -0
  106. package/dist/events/store/file-store.d.ts +37 -0
  107. package/dist/events/store/file-store.js +113 -0
  108. package/dist/events/store/index.d.ts +7 -0
  109. package/dist/events/store/index.js +6 -0
  110. package/dist/events/store/memory-store.d.ts +26 -0
  111. package/dist/events/store/memory-store.js +39 -0
  112. package/dist/events/store.d.ts +11 -0
  113. package/dist/events/store.js +2 -0
  114. package/dist/events/types.d.ts +14 -0
  115. package/dist/events/types.js +2 -0
  116. package/dist/index.d.ts +8 -0
  117. package/dist/index.js +30 -0
  118. package/dist/presentation/analysis-ui.d.ts +24 -0
  119. package/dist/presentation/analysis-ui.js +158 -0
  120. package/dist/presentation/dev/chat-ui-types.d.ts +68 -0
  121. package/dist/presentation/dev/chat-ui-types.js +5 -0
  122. package/dist/presentation/dev/chat-ui.d.ts +61 -0
  123. package/dist/presentation/dev/chat-ui.js +714 -0
  124. package/dist/presentation/dev/components/assistant-message.d.ts +19 -0
  125. package/dist/presentation/dev/components/assistant-message.js +36 -0
  126. package/dist/presentation/dev/components/header.d.ts +16 -0
  127. package/dist/presentation/dev/components/header.js +22 -0
  128. package/dist/presentation/dev/components/index.d.ts +13 -0
  129. package/dist/presentation/dev/components/index.js +13 -0
  130. package/dist/presentation/dev/components/input-panel.d.ts +22 -0
  131. package/dist/presentation/dev/components/input-panel.js +43 -0
  132. package/dist/presentation/dev/components/message-component.d.ts +16 -0
  133. package/dist/presentation/dev/components/message-component.js +51 -0
  134. package/dist/presentation/dev/components/messages-list.d.ts +24 -0
  135. package/dist/presentation/dev/components/messages-list.js +48 -0
  136. package/dist/presentation/dev/components/system-message.d.ts +16 -0
  137. package/dist/presentation/dev/components/system-message.js +26 -0
  138. package/dist/presentation/dev/components/user-message.d.ts +21 -0
  139. package/dist/presentation/dev/components/user-message.js +35 -0
  140. package/dist/presentation/dev/components/welcome-banner.d.ts +24 -0
  141. package/dist/presentation/dev/components/welcome-banner.js +146 -0
  142. package/dist/presentation/dev/goodbye-messages.d.ts +31 -0
  143. package/dist/presentation/dev/goodbye-messages.js +100 -0
  144. package/dist/presentation/dev/index.d.ts +5 -0
  145. package/dist/presentation/dev/index.js +5 -0
  146. package/dist/presentation/dev/text-wrapper.d.ts +30 -0
  147. package/dist/presentation/dev/text-wrapper.js +74 -0
  148. package/dist/presentation/dev-ui.d.ts +33 -0
  149. package/dist/presentation/dev-ui.js +246 -0
  150. package/dist/presentation/doctor-ui.d.ts +40 -0
  151. package/dist/presentation/doctor-ui.js +157 -0
  152. package/dist/presentation/init-ui.d.ts +14 -0
  153. package/dist/presentation/init-ui.js +41 -0
  154. package/dist/presentation/list-ui.d.ts +44 -0
  155. package/dist/presentation/list-ui.js +139 -0
  156. package/dist/presentation/test-ui.d.ts +49 -0
  157. package/dist/presentation/test-ui.js +358 -0
  158. package/dist/runtime/analysis/analyser.d.ts +14 -0
  159. package/dist/runtime/analysis/analyser.js +88 -0
  160. package/dist/runtime/analysis/dependencies.d.ts +10 -0
  161. package/dist/runtime/analysis/dependencies.js +140 -0
  162. package/dist/runtime/analysis/index.d.ts +10 -0
  163. package/dist/runtime/analysis/index.js +10 -0
  164. package/dist/runtime/analysis/indexer.d.ts +10 -0
  165. package/dist/runtime/analysis/indexer.js +62 -0
  166. package/dist/runtime/analysis/loader.d.ts +15 -0
  167. package/dist/runtime/analysis/loader.js +47 -0
  168. package/dist/runtime/analysis/normalizer.d.ts +14 -0
  169. package/dist/runtime/analysis/normalizer.js +184 -0
  170. package/dist/runtime/analysis/rules/__test-helpers__.d.ts +18 -0
  171. package/dist/runtime/analysis/rules/__test-helpers__.js +40 -0
  172. package/dist/runtime/analysis/rules/base.d.ts +38 -0
  173. package/dist/runtime/analysis/rules/base.js +23 -0
  174. package/dist/runtime/analysis/rules/error-codes.d.ts +64 -0
  175. package/dist/runtime/analysis/rules/error-codes.js +73 -0
  176. package/dist/runtime/analysis/rules/errors/e000-tool-not-found.d.ts +35 -0
  177. package/dist/runtime/analysis/rules/errors/e000-tool-not-found.js +32 -0
  178. package/dist/runtime/analysis/rules/errors/e001-missing-output-schema.d.ts +22 -0
  179. package/dist/runtime/analysis/rules/errors/e001-missing-output-schema.js +30 -0
  180. package/dist/runtime/analysis/rules/errors/e002-underspecified-input.d.ts +24 -0
  181. package/dist/runtime/analysis/rules/errors/e002-underspecified-input.js +52 -0
  182. package/dist/runtime/analysis/rules/errors/e003-type-mismatch.d.ts +23 -0
  183. package/dist/runtime/analysis/rules/errors/e003-type-mismatch.js +73 -0
  184. package/dist/runtime/analysis/rules/errors/e004-free-text-propagation.d.ts +23 -0
  185. package/dist/runtime/analysis/rules/errors/e004-free-text-propagation.js +47 -0
  186. package/dist/runtime/analysis/rules/errors/e005-tool-ambiguity.d.ts +25 -0
  187. package/dist/runtime/analysis/rules/errors/e005-tool-ambiguity.js +73 -0
  188. package/dist/runtime/analysis/rules/errors/e006-param-not-in-description.d.ts +22 -0
  189. package/dist/runtime/analysis/rules/errors/e006-param-not-in-description.js +57 -0
  190. package/dist/runtime/analysis/rules/errors/e007-output-not-guaranteed.d.ts +23 -0
  191. package/dist/runtime/analysis/rules/errors/e007-output-not-guaranteed.js +56 -0
  192. package/dist/runtime/analysis/rules/errors/e008-circular-dependency.d.ts +22 -0
  193. package/dist/runtime/analysis/rules/errors/e008-circular-dependency.js +84 -0
  194. package/dist/runtime/analysis/rules/errors/e009-implicit-user-input.d.ts +23 -0
  195. package/dist/runtime/analysis/rules/errors/e009-implicit-user-input.js +89 -0
  196. package/dist/runtime/analysis/rules/errors/e010-non-serializable.d.ts +25 -0
  197. package/dist/runtime/analysis/rules/errors/e010-non-serializable.js +46 -0
  198. package/dist/runtime/analysis/rules/errors/e011-missing-tool-description.d.ts +24 -0
  199. package/dist/runtime/analysis/rules/errors/e011-missing-tool-description.js +33 -0
  200. package/dist/runtime/analysis/rules/errors/e012-side-effect-detected.d.ts +39 -0
  201. package/dist/runtime/analysis/rules/errors/e012-side-effect-detected.js +40 -0
  202. package/dist/runtime/analysis/rules/errors/e013-non-deterministic-output.d.ts +37 -0
  203. package/dist/runtime/analysis/rules/errors/e013-non-deterministic-output.js +34 -0
  204. package/dist/runtime/analysis/rules/errors/e013-output-explosion.d.ts +39 -0
  205. package/dist/runtime/analysis/rules/errors/e013-output-explosion.js +36 -0
  206. package/dist/runtime/analysis/rules/errors/e014-hidden-dependency.d.ts +42 -0
  207. package/dist/runtime/analysis/rules/errors/e014-hidden-dependency.js +46 -0
  208. package/dist/runtime/analysis/rules/errors/e014-output-explosion.d.ts +39 -0
  209. package/dist/runtime/analysis/rules/errors/e014-output-explosion.js +36 -0
  210. package/dist/runtime/analysis/rules/errors/e015-hidden-dependency.d.ts +42 -0
  211. package/dist/runtime/analysis/rules/errors/e015-hidden-dependency.js +46 -0
  212. package/dist/runtime/analysis/rules/errors/e015-unbounded-execution.d.ts +44 -0
  213. package/dist/runtime/analysis/rules/errors/e015-unbounded-execution.js +66 -0
  214. package/dist/runtime/analysis/rules/errors/e016-output-validation-failed.d.ts +43 -0
  215. package/dist/runtime/analysis/rules/errors/e016-output-validation-failed.js +42 -0
  216. package/dist/runtime/analysis/rules/errors/e016-unbounded-execution.d.ts +44 -0
  217. package/dist/runtime/analysis/rules/errors/e016-unbounded-execution.js +66 -0
  218. package/dist/runtime/analysis/rules/errors/e017-input-validation-failed.d.ts +57 -0
  219. package/dist/runtime/analysis/rules/errors/e017-input-validation-failed.js +80 -0
  220. package/dist/runtime/analysis/rules/errors/e017-output-validation-failed.d.ts +43 -0
  221. package/dist/runtime/analysis/rules/errors/e017-output-validation-failed.js +42 -0
  222. package/dist/runtime/analysis/rules/errors/e018-input-validation-failed.d.ts +57 -0
  223. package/dist/runtime/analysis/rules/errors/e018-input-validation-failed.js +80 -0
  224. package/dist/runtime/analysis/rules/errors/e018-tool-execution-failed.d.ts +38 -0
  225. package/dist/runtime/analysis/rules/errors/e018-tool-execution-failed.js +37 -0
  226. package/dist/runtime/analysis/rules/errors/e019-tool-execution-failed.d.ts +38 -0
  227. package/dist/runtime/analysis/rules/errors/e019-tool-execution-failed.js +37 -0
  228. package/dist/runtime/analysis/rules/errors/e019-unexpected-test-result.d.ts +65 -0
  229. package/dist/runtime/analysis/rules/errors/e019-unexpected-test-result.js +109 -0
  230. package/dist/runtime/analysis/rules/errors/e020-unexpected-test-result.d.ts +65 -0
  231. package/dist/runtime/analysis/rules/errors/e020-unexpected-test-result.js +109 -0
  232. package/dist/runtime/analysis/rules/errors/e100-missing-output-schema.d.ts +22 -0
  233. package/dist/runtime/analysis/rules/errors/e100-missing-output-schema.js +30 -0
  234. package/dist/runtime/analysis/rules/errors/e101-missing-tool-description.d.ts +24 -0
  235. package/dist/runtime/analysis/rules/errors/e101-missing-tool-description.js +33 -0
  236. package/dist/runtime/analysis/rules/errors/e102-underspecified-input.d.ts +24 -0
  237. package/dist/runtime/analysis/rules/errors/e102-underspecified-input.js +52 -0
  238. package/dist/runtime/analysis/rules/errors/e103-type-mismatch.d.ts +23 -0
  239. package/dist/runtime/analysis/rules/errors/e103-type-mismatch.js +72 -0
  240. package/dist/runtime/analysis/rules/errors/e104-param-not-in-description.d.ts +22 -0
  241. package/dist/runtime/analysis/rules/errors/e104-param-not-in-description.js +57 -0
  242. package/dist/runtime/analysis/rules/errors/e105-free-text-propagation.d.ts +23 -0
  243. package/dist/runtime/analysis/rules/errors/e105-free-text-propagation.js +47 -0
  244. package/dist/runtime/analysis/rules/errors/e106-output-not-guaranteed.d.ts +23 -0
  245. package/dist/runtime/analysis/rules/errors/e106-output-not-guaranteed.js +58 -0
  246. package/dist/runtime/analysis/rules/errors/e107-circular-dependency.d.ts +22 -0
  247. package/dist/runtime/analysis/rules/errors/e107-circular-dependency.js +84 -0
  248. package/dist/runtime/analysis/rules/errors/e108-implicit-user-input.d.ts +23 -0
  249. package/dist/runtime/analysis/rules/errors/e108-implicit-user-input.js +94 -0
  250. package/dist/runtime/analysis/rules/errors/e109-non-serializable.d.ts +25 -0
  251. package/dist/runtime/analysis/rules/errors/e109-non-serializable.js +44 -0
  252. package/dist/runtime/analysis/rules/errors/e110-tool-ambiguity.d.ts +25 -0
  253. package/dist/runtime/analysis/rules/errors/e110-tool-ambiguity.js +73 -0
  254. package/dist/runtime/analysis/rules/errors/e200-input-validation-failed.d.ts +57 -0
  255. package/dist/runtime/analysis/rules/errors/e200-input-validation-failed.js +71 -0
  256. package/dist/runtime/analysis/rules/errors/e300-output-validation-failed.d.ts +43 -0
  257. package/dist/runtime/analysis/rules/errors/e300-output-validation-failed.js +44 -0
  258. package/dist/runtime/analysis/rules/errors/e301-output-explosion.d.ts +39 -0
  259. package/dist/runtime/analysis/rules/errors/e301-output-explosion.js +36 -0
  260. package/dist/runtime/analysis/rules/errors/e400-tool-execution-failed.d.ts +38 -0
  261. package/dist/runtime/analysis/rules/errors/e400-tool-execution-failed.js +37 -0
  262. package/dist/runtime/analysis/rules/errors/e403-unbounded-execution.d.ts +44 -0
  263. package/dist/runtime/analysis/rules/errors/e403-unbounded-execution.js +66 -0
  264. package/dist/runtime/analysis/rules/errors/e500-side-effect-detected.d.ts +39 -0
  265. package/dist/runtime/analysis/rules/errors/e500-side-effect-detected.js +40 -0
  266. package/dist/runtime/analysis/rules/errors/e501-hidden-dependency.d.ts +47 -0
  267. package/dist/runtime/analysis/rules/errors/e501-hidden-dependency.js +46 -0
  268. package/dist/runtime/analysis/rules/errors/e600-unexpected-test-result.d.ts +65 -0
  269. package/dist/runtime/analysis/rules/errors/e600-unexpected-test-result.js +109 -0
  270. package/dist/runtime/analysis/rules/index.d.ts +18 -0
  271. package/dist/runtime/analysis/rules/index.js +94 -0
  272. package/dist/runtime/analysis/rules/warnings/w001-implicit-dependency.d.ts +22 -0
  273. package/dist/runtime/analysis/rules/warnings/w001-implicit-dependency.js +39 -0
  274. package/dist/runtime/analysis/rules/warnings/w002-free-text-without-normalization.d.ts +24 -0
  275. package/dist/runtime/analysis/rules/warnings/w002-free-text-without-normalization.js +40 -0
  276. package/dist/runtime/analysis/rules/warnings/w003-missing-examples.d.ts +22 -0
  277. package/dist/runtime/analysis/rules/warnings/w003-missing-examples.js +84 -0
  278. package/dist/runtime/analysis/rules/warnings/w004-overloaded-responsibility.d.ts +23 -0
  279. package/dist/runtime/analysis/rules/warnings/w004-overloaded-responsibility.js +96 -0
  280. package/dist/runtime/analysis/rules/warnings/w005-generic-description.d.ts +53 -0
  281. package/dist/runtime/analysis/rules/warnings/w005-generic-description.js +108 -0
  282. package/dist/runtime/analysis/rules/warnings/w006-optional-as-required.d.ts +22 -0
  283. package/dist/runtime/analysis/rules/warnings/w006-optional-as-required.js +44 -0
  284. package/dist/runtime/analysis/rules/warnings/w007-broad-output-schema.d.ts +23 -0
  285. package/dist/runtime/analysis/rules/warnings/w007-broad-output-schema.js +37 -0
  286. package/dist/runtime/analysis/rules/warnings/w008-multiple-entry-points.d.ts +22 -0
  287. package/dist/runtime/analysis/rules/warnings/w008-multiple-entry-points.js +97 -0
  288. package/dist/runtime/analysis/rules/warnings/w009-hidden-side-effects.d.ts +23 -0
  289. package/dist/runtime/analysis/rules/warnings/w009-hidden-side-effects.js +88 -0
  290. package/dist/runtime/analysis/rules/warnings/w010-output-not-reusable.d.ts +22 -0
  291. package/dist/runtime/analysis/rules/warnings/w010-output-not-reusable.js +81 -0
  292. package/dist/runtime/analysis/rules/warnings/w021-weak-schema.d.ts +40 -0
  293. package/dist/runtime/analysis/rules/warnings/w021-weak-schema.js +32 -0
  294. package/dist/runtime/analysis/rules/warnings/w022-high-entropy-output.d.ts +39 -0
  295. package/dist/runtime/analysis/rules/warnings/w022-high-entropy-output.js +36 -0
  296. package/dist/runtime/analysis/rules/warnings/w023-unstable-defaults.d.ts +38 -0
  297. package/dist/runtime/analysis/rules/warnings/w023-unstable-defaults.js +36 -0
  298. package/dist/runtime/analysis/rules/warnings/w100-implicit-dependency.d.ts +22 -0
  299. package/dist/runtime/analysis/rules/warnings/w100-implicit-dependency.js +89 -0
  300. package/dist/runtime/analysis/rules/warnings/w101-free-text-without-normalization.d.ts +24 -0
  301. package/dist/runtime/analysis/rules/warnings/w101-free-text-without-normalization.js +40 -0
  302. package/dist/runtime/analysis/rules/warnings/w102-missing-examples.d.ts +22 -0
  303. package/dist/runtime/analysis/rules/warnings/w102-missing-examples.js +76 -0
  304. package/dist/runtime/analysis/rules/warnings/w103-overloaded-responsibility.d.ts +23 -0
  305. package/dist/runtime/analysis/rules/warnings/w103-overloaded-responsibility.js +91 -0
  306. package/dist/runtime/analysis/rules/warnings/w104-generic-description.d.ts +53 -0
  307. package/dist/runtime/analysis/rules/warnings/w104-generic-description.js +108 -0
  308. package/dist/runtime/analysis/rules/warnings/w105-optional-as-required.d.ts +22 -0
  309. package/dist/runtime/analysis/rules/warnings/w105-optional-as-required.js +45 -0
  310. package/dist/runtime/analysis/rules/warnings/w106-broad-output-schema.d.ts +23 -0
  311. package/dist/runtime/analysis/rules/warnings/w106-broad-output-schema.js +37 -0
  312. package/dist/runtime/analysis/rules/warnings/w107-multiple-entry-points.d.ts +22 -0
  313. package/dist/runtime/analysis/rules/warnings/w107-multiple-entry-points.js +97 -0
  314. package/dist/runtime/analysis/rules/warnings/w108-hidden-side-effects.d.ts +23 -0
  315. package/dist/runtime/analysis/rules/warnings/w108-hidden-side-effects.js +94 -0
  316. package/dist/runtime/analysis/rules/warnings/w109-output-not-reusable.d.ts +22 -0
  317. package/dist/runtime/analysis/rules/warnings/w109-output-not-reusable.js +63 -0
  318. package/dist/runtime/analysis/rules/warnings/w110-weak-schema.d.ts +40 -0
  319. package/dist/runtime/analysis/rules/warnings/w110-weak-schema.js +32 -0
  320. package/dist/runtime/analysis/rules/warnings/w300-high-entropy-output.d.ts +39 -0
  321. package/dist/runtime/analysis/rules/warnings/w300-high-entropy-output.js +47 -0
  322. package/dist/runtime/analysis/rules/warnings/w301-unstable-defaults.d.ts +38 -0
  323. package/dist/runtime/analysis/rules/warnings/w301-unstable-defaults.js +36 -0
  324. package/dist/runtime/analysis/strict-mode.d.ts +21 -0
  325. package/dist/runtime/analysis/strict-mode.js +44 -0
  326. package/dist/runtime/analysis/types.d.ts +133 -0
  327. package/dist/runtime/analysis/types.js +6 -0
  328. package/dist/runtime/analysis/utils.d.ts +19 -0
  329. package/dist/runtime/analysis/utils.js +21 -0
  330. package/dist/runtime/dev/data-manager.d.ts +55 -0
  331. package/dist/runtime/dev/data-manager.js +87 -0
  332. package/dist/runtime/dev/event-mapper.d.ts +100 -0
  333. package/dist/runtime/dev/event-mapper.js +400 -0
  334. package/dist/runtime/dev/formatter.d.ts +94 -0
  335. package/dist/runtime/dev/formatter.js +236 -0
  336. package/dist/runtime/dev/index.d.ts +9 -0
  337. package/dist/runtime/dev/index.js +9 -0
  338. package/dist/runtime/dev/repl.d.ts +114 -0
  339. package/dist/runtime/dev/repl.js +310 -0
  340. package/dist/runtime/dev/session.d.ts +86 -0
  341. package/dist/runtime/dev/session.js +447 -0
  342. package/dist/runtime/dev/stack-trace.d.ts +77 -0
  343. package/dist/runtime/dev/stack-trace.js +286 -0
  344. package/dist/runtime/dev/types.d.ts +54 -0
  345. package/dist/runtime/dev/types.js +5 -0
  346. package/dist/runtime/llm/claude.d.ts +27 -0
  347. package/dist/runtime/llm/claude.js +150 -0
  348. package/dist/runtime/llm/factory.d.ts +30 -0
  349. package/dist/runtime/llm/factory.js +78 -0
  350. package/dist/runtime/llm/index.d.ts +10 -0
  351. package/dist/runtime/llm/index.js +10 -0
  352. package/dist/runtime/llm/ollama.d.ts +45 -0
  353. package/dist/runtime/llm/ollama.js +449 -0
  354. package/dist/runtime/llm/openai.d.ts +27 -0
  355. package/dist/runtime/llm/openai.js +170 -0
  356. package/dist/runtime/llm/provider.d.ts +32 -0
  357. package/dist/runtime/llm/provider.js +6 -0
  358. package/dist/runtime/llm/types.d.ts +55 -0
  359. package/dist/runtime/llm/types.js +6 -0
  360. package/dist/runtime/mcp/client/base.d.ts +40 -0
  361. package/dist/runtime/mcp/client/base.js +157 -0
  362. package/dist/runtime/mcp/client/manager.d.ts +91 -0
  363. package/dist/runtime/mcp/client/manager.js +248 -0
  364. package/dist/runtime/mcp/client/process.d.ts +31 -0
  365. package/dist/runtime/mcp/client/process.js +82 -0
  366. package/dist/runtime/mcp/connection.d.ts +63 -0
  367. package/dist/runtime/mcp/connection.js +449 -0
  368. package/dist/runtime/mcp/index.d.ts +9 -0
  369. package/dist/runtime/mcp/index.js +9 -0
  370. package/dist/runtime/mcp/list.d.ts +50 -0
  371. package/dist/runtime/mcp/list.js +65 -0
  372. package/dist/runtime/mcp/stdio-transport.d.ts +23 -0
  373. package/dist/runtime/mcp/stdio-transport.js +71 -0
  374. package/dist/runtime/mcp/types.d.ts +85 -0
  375. package/dist/runtime/mcp/types.js +6 -0
  376. package/dist/runtime/sandbox/executor.d.ts +102 -0
  377. package/dist/runtime/sandbox/executor.js +537 -0
  378. package/dist/runtime/sandbox/index.d.ts +9 -0
  379. package/dist/runtime/sandbox/index.js +9 -0
  380. package/dist/runtime/sandbox/io-monitor.d.ts +78 -0
  381. package/dist/runtime/sandbox/io-monitor.js +98 -0
  382. package/dist/runtime/sandbox/time-parser.d.ts +19 -0
  383. package/dist/runtime/sandbox/time-parser.js +67 -0
  384. package/dist/runtime/sandbox/types.d.ts +58 -0
  385. package/dist/runtime/sandbox/types.js +23 -0
  386. package/dist/runtime/test/behavior-observer.d.ts +61 -0
  387. package/dist/runtime/test/behavior-observer.js +140 -0
  388. package/dist/runtime/test/contract-loader.d.ts +41 -0
  389. package/dist/runtime/test/contract-loader.js +158 -0
  390. package/dist/runtime/test/contract-schema.d.ts +46 -0
  391. package/dist/runtime/test/contract-schema.js +107 -0
  392. package/dist/runtime/test/contract-types.d.ts +106 -0
  393. package/dist/runtime/test/contract-types.js +6 -0
  394. package/dist/runtime/test/dependency-tracker.d.ts +66 -0
  395. package/dist/runtime/test/dependency-tracker.js +80 -0
  396. package/dist/runtime/test/formatters.d.ts +18 -0
  397. package/dist/runtime/test/formatters.js +172 -0
  398. package/dist/runtime/test/index.d.ts +12 -0
  399. package/dist/runtime/test/index.js +13 -0
  400. package/dist/runtime/test/input-generator.d.ts +33 -0
  401. package/dist/runtime/test/input-generator.js +498 -0
  402. package/dist/runtime/test/mcp-root-detector.d.ts +31 -0
  403. package/dist/runtime/test/mcp-root-detector.js +105 -0
  404. package/dist/runtime/test/orchestrator.d.ts +131 -0
  405. package/dist/runtime/test/orchestrator.js +738 -0
  406. package/dist/runtime/test/output-validator.d.ts +44 -0
  407. package/dist/runtime/test/output-validator.js +262 -0
  408. package/dist/runtime/test/retry-tester.d.ts +44 -0
  409. package/dist/runtime/test/retry-tester.js +103 -0
  410. package/dist/runtime/test/runner.d.ts +28 -0
  411. package/dist/runtime/test/runner.js +55 -0
  412. package/dist/runtime/test/synthetic-input-generator.d.ts +11 -0
  413. package/dist/runtime/test/synthetic-input-generator.js +154 -0
  414. package/dist/runtime/test/test-runner.d.ts +28 -0
  415. package/dist/runtime/test/test-runner.js +55 -0
  416. package/dist/types/factories.d.ts +16 -0
  417. package/dist/types/factories.js +43 -0
  418. package/dist/types/ids.d.ts +16 -0
  419. package/dist/types/ids.js +2 -0
  420. package/dist/types/opaque.d.ts +4 -0
  421. package/dist/types/opaque.js +2 -0
  422. package/dist/utils/errors.d.ts +92 -0
  423. package/dist/utils/errors.js +97 -0
  424. package/dist/utils/gitignore.d.ts +11 -0
  425. package/dist/utils/gitignore.js +59 -0
  426. package/dist/utils/json-file-saver.d.ts +17 -0
  427. package/dist/utils/json-file-saver.js +81 -0
  428. package/dist/utils/json-formatter.d.ts +63 -0
  429. package/dist/utils/json-formatter.js +344 -0
  430. package/dist/utils/logger.d.ts +184 -0
  431. package/dist/utils/logger.js +330 -0
  432. package/dist/utils/package-manager.d.ts +30 -0
  433. package/dist/utils/package-manager.js +157 -0
  434. package/dist/utils/version-checker.d.ts +47 -0
  435. package/dist/utils/version-checker.js +167 -0
  436. package/dist/utils/version-display.d.ts +10 -0
  437. package/dist/utils/version-display.js +20 -0
  438. package/package.json +106 -0
@@ -0,0 +1,82 @@
1
+ /**
2
+ * Process spawning utilities for MCP servers.
3
+ */
4
+ import * as childProcess from 'child_process';
5
+ import { log } from '../../../utils/logger.js';
6
+ /**
7
+ * Check if a command contains shell operators that require shell execution.
8
+ * We only detect patterns that absolutely require a shell, avoiding false positives.
9
+ * Essential operators: &&, ||, |, ;, $, $(, `
10
+ */
11
+ export function requiresShellExecution(command) {
12
+ return (/\s+&&\s+/.test(command) || // Logical AND (e.g., "cmd1 && cmd2")
13
+ /\s+\|\|\s+/.test(command) || // Logical OR (e.g., "cmd1 || cmd2")
14
+ /\s+\|\s+/.test(command) || // Pipe (e.g., "cmd1 | cmd2")
15
+ /\s+;\s+/.test(command) || // Command separator (e.g., "cmd1; cmd2")
16
+ /\$\{/.test(command) || // Variable expansion ${VAR}
17
+ /\$\(/.test(command) || // Command substitution $(command)
18
+ /\$\w+/.test(command) || // Variable reference $VAR
19
+ /`[^`]*`/.test(command) // Command substitution with backticks
20
+ );
21
+ }
22
+ /**
23
+ * Parse a command into executable and arguments.
24
+ * Handles shell operators by wrapping in shell execution.
25
+ */
26
+ export function parseCommand(command) {
27
+ const needsShell = requiresShellExecution(command);
28
+ if (needsShell) {
29
+ // Command contains shell operators - run through shell
30
+ return {
31
+ executable: process.env.SHELL || '/bin/sh',
32
+ args: ['-c', command],
33
+ };
34
+ }
35
+ // Simple command - split and execute directly
36
+ const parts = command.split(/\s+/);
37
+ return {
38
+ executable: parts[0],
39
+ args: parts.slice(1),
40
+ };
41
+ }
42
+ /**
43
+ * Set up log capture for a child process.
44
+ * Captures stdout and stderr, formatting them appropriately.
45
+ */
46
+ export function setupProcessLogCapture(process) {
47
+ // Capture stdout logs
48
+ process.stdout?.on('data', (data) => {
49
+ const message = data.toString().trim();
50
+ if (message) {
51
+ log.plain(`[Server] ${message}`);
52
+ }
53
+ });
54
+ // Capture stderr logs
55
+ process.stderr?.on('data', (data) => {
56
+ const message = data.toString().trim();
57
+ if (message) {
58
+ // Many tools (like Python/Uvicorn) write INFO logs to stderr, which is normal
59
+ // Only prefix with [Server Error] if it actually looks like an error
60
+ const isError = /ERROR|CRITICAL|FATAL|Exception|Traceback|Error:/i.test(message);
61
+ const prefix = isError ? '[Server Error]' : '[Server]';
62
+ if (isError) {
63
+ log.error(`${prefix} ${message}`);
64
+ }
65
+ else {
66
+ log.plain(`${prefix} ${message}`);
67
+ }
68
+ }
69
+ });
70
+ }
71
+ /**
72
+ * Spawn a process with proper configuration.
73
+ */
74
+ export function spawnProcess(executable, args, options) {
75
+ return childProcess.spawn(executable, args, {
76
+ stdio: ['pipe', 'pipe', 'pipe'],
77
+ env: options?.env ?? process.env,
78
+ cwd: options?.cwd ?? process.cwd(),
79
+ shell: false,
80
+ });
81
+ }
82
+ //# sourceMappingURL=process.js.map
@@ -0,0 +1,63 @@
1
+ /**
2
+ * MCP connection utilities.
3
+ * Provides utilities for connecting to MCP servers via HTTP and stdio transports.
4
+ * This module is reusable for both testing and establishing MCP connections.
5
+ * Uses the official MCP SDK for proper protocol handling.
6
+ */
7
+ import { Client } from '@modelcontextprotocol/sdk/client/index.js';
8
+ import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js';
9
+ import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';
10
+ import type { MCPConnectionResult, MCPConnectionOptions } from './types.js';
11
+ /**
12
+ * Get a connected MCP client that stays open for operations.
13
+ * Use this when you need to perform multiple operations with the same connection.
14
+ * Remember to call close() on the transport when done.
15
+ *
16
+ * @param mcpUrl - The MCP server URL to connect to
17
+ * @param timeout - Connection timeout in milliseconds (default: 5000)
18
+ * @returns Connected client and transport instances
19
+ */
20
+ export declare function getConnectedClient(mcpUrl: string, headers?: Record<string, string>, timeout?: number): Promise<{
21
+ client: Client;
22
+ transport: StreamableHTTPClientTransport;
23
+ }>;
24
+ /**
25
+ * Connect to an MCP server via HTTP transport using the official MCP SDK.
26
+ * This properly handles the SSE protocol and session requirements.
27
+ *
28
+ * @param mcpUrl - The MCP server URL to connect to
29
+ * @param timeout - Connection timeout in milliseconds (default: 5000)
30
+ * @returns Connection result with connection details
31
+ */
32
+ export declare function connectHTTP(mcpUrl: string, headers?: Record<string, string>, timeout?: number): Promise<MCPConnectionResult>;
33
+ /**
34
+ * Get a connected MCP client via stdio transport that stays open for operations.
35
+ * Use this when you need to perform multiple operations with the same connection.
36
+ * Remember to call close() on the transport when done.
37
+ *
38
+ * @param command - The command to execute (e.g., "python3 server.py")
39
+ * @param timeout - Connection timeout in milliseconds (default: 10000)
40
+ * @returns Connected client and transport instances
41
+ */
42
+ export declare function getConnectedStdioClient(command: string, env?: Record<string, string>, timeout?: number): Promise<{
43
+ client: Client;
44
+ transport: StdioClientTransport;
45
+ }>;
46
+ /**
47
+ * Connect to an MCP server via stdio transport using the official MCP SDK.
48
+ * This properly handles the stdio protocol and initialization handshake.
49
+ *
50
+ * @param command - The command to execute (e.g., "python3 server.py")
51
+ * @param timeout - Connection timeout in milliseconds (default: 5000)
52
+ * @returns Connection result
53
+ */
54
+ export declare function connectStdio(command: string, env?: Record<string, string>, timeout?: number): Promise<MCPConnectionResult>;
55
+ /**
56
+ * Connect to an MCP server based on transport type.
57
+ * This is the main entry point for establishing MCP connections.
58
+ *
59
+ * @param options - Connection options including transport type and connection details
60
+ * @returns Connection result
61
+ */
62
+ export declare function connectMCP(options: MCPConnectionOptions): Promise<MCPConnectionResult>;
63
+ //# sourceMappingURL=connection.d.ts.map
@@ -0,0 +1,449 @@
1
+ /**
2
+ * MCP connection utilities.
3
+ * Provides utilities for connecting to MCP servers via HTTP and stdio transports.
4
+ * This module is reusable for both testing and establishing MCP connections.
5
+ * Uses the official MCP SDK for proper protocol handling.
6
+ */
7
+ import { Client } from '@modelcontextprotocol/sdk/client/index.js';
8
+ import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js';
9
+ import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';
10
+ import { v4 as uuidv4 } from 'uuid';
11
+ import { ConfigurationError } from '../../utils/errors.js';
12
+ import { getCurrentVersion } from '../../utils/version-checker.js';
13
+ /**
14
+ * Get a connected MCP client that stays open for operations.
15
+ * Use this when you need to perform multiple operations with the same connection.
16
+ * Remember to call close() on the transport when done.
17
+ *
18
+ * @param mcpUrl - The MCP server URL to connect to
19
+ * @param timeout - Connection timeout in milliseconds (default: 5000)
20
+ * @returns Connected client and transport instances
21
+ */
22
+ export async function getConnectedClient(mcpUrl, headers, timeout = 10000) {
23
+ // Parse URL
24
+ const parsedUrl = new URL(mcpUrl);
25
+ // Create MCP client
26
+ const client = new Client({
27
+ name: 'syrin',
28
+ version: getCurrentVersion(),
29
+ }, {
30
+ capabilities: {},
31
+ });
32
+ // Prepare request init with headers if provided
33
+ const requestInit = headers
34
+ ? {
35
+ headers,
36
+ }
37
+ : undefined;
38
+ // Create HTTP transport using StreamableHTTPClientTransport
39
+ // This properly handles SSE protocol and session requirements
40
+ const transport = new StreamableHTTPClientTransport(parsedUrl, {
41
+ requestInit,
42
+ });
43
+ // Set up error handler
44
+ client.onerror = () => {
45
+ // Error handler - errors are logged but we'll catch them in try-catch
46
+ };
47
+ // Try to connect with timeout
48
+ const connectionPromise = client.connect(transport);
49
+ // Create a timeout promise
50
+ const timeoutPromise = new Promise((_, reject) => {
51
+ setTimeout(() => {
52
+ reject(new Error(`Connection timeout after ${timeout}ms`));
53
+ }, timeout);
54
+ });
55
+ // Race between connection and timeout
56
+ await Promise.race([connectionPromise, timeoutPromise]);
57
+ return { client, transport };
58
+ }
59
+ /**
60
+ * Connect to an MCP server via HTTP transport using the official MCP SDK.
61
+ * This properly handles the SSE protocol and session requirements.
62
+ *
63
+ * @param mcpUrl - The MCP server URL to connect to
64
+ * @param timeout - Connection timeout in milliseconds (default: 5000)
65
+ * @returns Connection result with connection details
66
+ */
67
+ export async function connectHTTP(mcpUrl, headers, timeout = 5000) {
68
+ let client = null;
69
+ let transport = null;
70
+ try {
71
+ // Parse URL
72
+ const parsedUrl = new URL(mcpUrl);
73
+ const details = {
74
+ mcpUrl,
75
+ };
76
+ // Create MCP client
77
+ client = new Client({
78
+ name: 'syrin',
79
+ version: getCurrentVersion(),
80
+ }, {
81
+ capabilities: {},
82
+ });
83
+ // Prepare request init with headers if provided
84
+ const requestInit = headers
85
+ ? {
86
+ headers,
87
+ }
88
+ : undefined;
89
+ // Create HTTP transport using StreamableHTTPClientTransport
90
+ // This properly handles SSE protocol and session requirements
91
+ transport = new StreamableHTTPClientTransport(parsedUrl, {
92
+ requestInit,
93
+ });
94
+ // Set up error handler
95
+ client.onerror = () => {
96
+ // Error handler - errors are logged but we'll catch them in try-catch
97
+ };
98
+ // Try to connect with timeout
99
+ const connectionPromise = client.connect(transport);
100
+ // Create a timeout promise
101
+ const timeoutPromise = new Promise((_, reject) => {
102
+ setTimeout(() => {
103
+ reject(new Error(`Connection timeout after ${timeout}ms`));
104
+ }, timeout);
105
+ });
106
+ // Race between connection and timeout
107
+ try {
108
+ await Promise.race([connectionPromise, timeoutPromise]);
109
+ }
110
+ catch (error) {
111
+ // Check if it's a timeout error
112
+ if (error instanceof Error && error.message.includes('timeout')) {
113
+ return {
114
+ success: false,
115
+ transport: 'http',
116
+ error: error.message,
117
+ details,
118
+ };
119
+ }
120
+ // Re-throw to handle connection errors below
121
+ throw error;
122
+ }
123
+ // Connection successful - get server capabilities and protocol version
124
+ const serverCapabilities = client.getServerCapabilities();
125
+ if (serverCapabilities) {
126
+ // Convert capabilities to a simpler format for display
127
+ // ServerCapabilities is an object where keys are capability names
128
+ // and values are either objects with capability details or empty objects
129
+ const capabilities = {};
130
+ // Extract capability names (keys of the capabilities object)
131
+ for (const [key, value] of Object.entries(serverCapabilities)) {
132
+ capabilities[key] = value;
133
+ }
134
+ details.capabilities = capabilities;
135
+ }
136
+ // Get protocol version from the client
137
+ // The protocol version is negotiated during initialization
138
+ // The SDK uses the latest supported version by default
139
+ details.protocolVersion = '2024-11-05'; // Protocol version used in initialize request
140
+ // Get session ID if available
141
+ if (transport.sessionId) {
142
+ details.sessionId = transport.sessionId;
143
+ details.metadata = {
144
+ sessionId: transport.sessionId,
145
+ };
146
+ }
147
+ // Document the initialize handshake that happened
148
+ // The SDK automatically sends an initialize request during client.connect()
149
+ // This request includes client info and capabilities
150
+ details.initializeRequest = {
151
+ method: 'POST',
152
+ url: mcpUrl,
153
+ headers: {
154
+ Accept: 'text/event-stream',
155
+ 'Content-Type': 'application/json',
156
+ ...(transport.sessionId
157
+ ? { 'mcp-session-id': transport.sessionId }
158
+ : {}),
159
+ },
160
+ body: {
161
+ jsonrpc: '2.0',
162
+ method: 'initialize',
163
+ params: {
164
+ protocolVersion: '2024-11-05',
165
+ capabilities: {},
166
+ clientInfo: {
167
+ name: 'syrin',
168
+ version: getCurrentVersion(),
169
+ },
170
+ },
171
+ },
172
+ };
173
+ // The initialize response contains server capabilities
174
+ // This is how we obtained the capabilities - from the initialize response
175
+ details.initializeResponse = {
176
+ statusCode: 200,
177
+ body: {
178
+ jsonrpc: '2.0',
179
+ result: {
180
+ protocolVersion: details.protocolVersion,
181
+ capabilities: serverCapabilities || {},
182
+ serverInfo: {
183
+ name: 'MCP Server',
184
+ },
185
+ },
186
+ },
187
+ };
188
+ // Clean up - disconnect gracefully
189
+ try {
190
+ await transport.close();
191
+ }
192
+ catch {
193
+ // Ignore errors during cleanup
194
+ }
195
+ return {
196
+ success: true,
197
+ transport: 'http',
198
+ details,
199
+ };
200
+ }
201
+ catch (error) {
202
+ // Clean up on error
203
+ try {
204
+ if (transport) {
205
+ await transport.close();
206
+ }
207
+ }
208
+ catch {
209
+ // Ignore cleanup errors
210
+ }
211
+ // Parse error message
212
+ let errorMessage = 'Unknown error';
213
+ if (error instanceof Error) {
214
+ errorMessage = error.message;
215
+ // Check for common connection errors
216
+ if (errorMessage.includes('ECONNREFUSED') ||
217
+ errorMessage.includes('fetch failed') ||
218
+ errorMessage.includes('NetworkError')) {
219
+ errorMessage = `Cannot connect to MCP server at ${mcpUrl}. Is the server running?`;
220
+ }
221
+ else if (errorMessage.includes('401') ||
222
+ errorMessage.includes('Unauthorized')) {
223
+ errorMessage =
224
+ 'Authentication required. The server rejected the connection.';
225
+ }
226
+ else if (errorMessage.includes('404')) {
227
+ errorMessage = 'MCP endpoint not found. Please check the URL.';
228
+ }
229
+ }
230
+ return {
231
+ success: false,
232
+ transport: 'http',
233
+ error: errorMessage,
234
+ details: {
235
+ mcpUrl,
236
+ discoveryUrl: `${new URL(mcpUrl).protocol}//${new URL(mcpUrl).host}/.well-known/mcp`,
237
+ },
238
+ };
239
+ }
240
+ }
241
+ /**
242
+ * Get a connected MCP client via stdio transport that stays open for operations.
243
+ * Use this when you need to perform multiple operations with the same connection.
244
+ * Remember to call close() on the transport when done.
245
+ *
246
+ * @param command - The command to execute (e.g., "python3 server.py")
247
+ * @param timeout - Connection timeout in milliseconds (default: 10000)
248
+ * @returns Connected client and transport instances
249
+ */
250
+ export async function getConnectedStdioClient(command, env, timeout = 10000) {
251
+ // Split command into executable and arguments
252
+ const parts = command.trim().split(/\s+/);
253
+ const executable = parts[0];
254
+ const args = parts.slice(1);
255
+ if (!executable) {
256
+ throw new Error('Command is empty');
257
+ }
258
+ // Create MCP client
259
+ const client = new Client({
260
+ name: 'syrin',
261
+ version: getCurrentVersion(),
262
+ }, {
263
+ capabilities: {},
264
+ });
265
+ // Merge provided env vars with process.env (provided vars take precedence)
266
+ // Filter out undefined values from process.env
267
+ const processEnvFiltered = {};
268
+ for (const [key, value] of Object.entries(process.env)) {
269
+ if (value !== undefined) {
270
+ processEnvFiltered[key] = value;
271
+ }
272
+ }
273
+ const mergedEnv = env
274
+ ? { ...processEnvFiltered, ...env }
275
+ : processEnvFiltered;
276
+ // Create stdio transport
277
+ const transport = new StdioClientTransport({
278
+ command: executable,
279
+ args,
280
+ env: mergedEnv,
281
+ });
282
+ // Set up error handler
283
+ client.onerror = () => {
284
+ // Error handler - errors are logged but we'll catch them in try-catch
285
+ };
286
+ // Try to connect with timeout
287
+ const connectionPromise = client.connect(transport);
288
+ // Create a timeout promise
289
+ const timeoutPromise = new Promise((_, reject) => {
290
+ setTimeout(() => {
291
+ reject(new Error(`Connection timeout after ${timeout}ms`));
292
+ }, timeout);
293
+ });
294
+ // Race between connection and timeout
295
+ await Promise.race([connectionPromise, timeoutPromise]);
296
+ return { client, transport };
297
+ }
298
+ /**
299
+ * Connect to an MCP server via stdio transport using the official MCP SDK.
300
+ * This properly handles the stdio protocol and initialization handshake.
301
+ *
302
+ * @param command - The command to execute (e.g., "python3 server.py")
303
+ * @param timeout - Connection timeout in milliseconds (default: 5000)
304
+ * @returns Connection result
305
+ */
306
+ export async function connectStdio(command, env, timeout = 5000) {
307
+ let transport = null;
308
+ try {
309
+ // Split command into executable and arguments
310
+ const parts = command.trim().split(/\s+/);
311
+ const executable = parts[0];
312
+ const args = parts.slice(1);
313
+ if (!executable) {
314
+ return {
315
+ success: false,
316
+ transport: 'stdio',
317
+ error: 'Command is empty',
318
+ };
319
+ }
320
+ // Create MCP client
321
+ const client = new Client({
322
+ name: 'syrin',
323
+ version: getCurrentVersion(),
324
+ }, {
325
+ capabilities: {},
326
+ });
327
+ // Merge provided env vars with process.env (provided vars take precedence)
328
+ // Filter out undefined values from process.env
329
+ const processEnvFiltered = {};
330
+ for (const [key, value] of Object.entries(process.env)) {
331
+ if (value !== undefined) {
332
+ processEnvFiltered[key] = value;
333
+ }
334
+ }
335
+ const mergedEnv = env
336
+ ? { ...processEnvFiltered, ...env }
337
+ : processEnvFiltered;
338
+ // Create stdio transport
339
+ transport = new StdioClientTransport({
340
+ command: executable,
341
+ args,
342
+ env: mergedEnv,
343
+ });
344
+ // Set up error handler
345
+ client.onerror = () => {
346
+ // Error handler - errors are logged but we'll catch them in try-catch
347
+ };
348
+ // Try to connect with timeout
349
+ const connectionPromise = client.connect(transport);
350
+ const timeoutPromise = new Promise((_, reject) => {
351
+ setTimeout(() => {
352
+ reject(new Error(`Connection timeout after ${timeout}ms`));
353
+ }, timeout);
354
+ });
355
+ await Promise.race([connectionPromise, timeoutPromise]);
356
+ // Get server capabilities and session info
357
+ const serverCapabilities = client.getServerCapabilities() || {};
358
+ const protocolVersion = '2024-11-05'; // MCP protocol version
359
+ const sessionId = uuidv4();
360
+ const details = {
361
+ command,
362
+ protocolVersion,
363
+ sessionId,
364
+ capabilities: serverCapabilities,
365
+ client: client,
366
+ transport: transport,
367
+ };
368
+ // Close the connection after gathering info (for testing)
369
+ try {
370
+ await transport.close();
371
+ }
372
+ catch {
373
+ // Ignore errors during cleanup
374
+ }
375
+ return {
376
+ success: true,
377
+ transport: 'stdio',
378
+ details,
379
+ };
380
+ }
381
+ catch (error) {
382
+ // Clean up on error
383
+ try {
384
+ if (transport) {
385
+ await transport.close();
386
+ }
387
+ }
388
+ catch {
389
+ // Ignore cleanup errors
390
+ }
391
+ // Parse error message
392
+ let errorMessage = 'Unknown error';
393
+ if (error instanceof Error) {
394
+ errorMessage = error.message;
395
+ // Check for common connection errors
396
+ if (errorMessage.includes('ENOENT') ||
397
+ errorMessage.includes('not found')) {
398
+ errorMessage = `Command "${command.split(/\s+/)[0]}" not found in PATH. Is the command installed?`;
399
+ }
400
+ else if (errorMessage.includes('EACCES') ||
401
+ errorMessage.includes('permission denied')) {
402
+ errorMessage = 'Permission denied. Check if the command is executable.';
403
+ }
404
+ else if (errorMessage.includes('timeout')) {
405
+ errorMessage = `Connection timeout. The MCP server may not be responding.`;
406
+ }
407
+ }
408
+ return {
409
+ success: false,
410
+ transport: 'stdio',
411
+ error: errorMessage,
412
+ details: {
413
+ command,
414
+ },
415
+ };
416
+ }
417
+ }
418
+ /**
419
+ * Connect to an MCP server based on transport type.
420
+ * This is the main entry point for establishing MCP connections.
421
+ *
422
+ * @param options - Connection options including transport type and connection details
423
+ * @returns Connection result
424
+ */
425
+ export async function connectMCP(options) {
426
+ const { transport, url, command, timeout = 5000 } = options;
427
+ if (transport === 'http') {
428
+ if (!url) {
429
+ throw new ConfigurationError('MCP URL is required for HTTP transport');
430
+ }
431
+ // Extract headers from options if available
432
+ const headers = 'headers' in options && options.headers
433
+ ? options.headers
434
+ : undefined;
435
+ return connectHTTP(url, headers, timeout);
436
+ }
437
+ if (transport === 'stdio') {
438
+ if (!command) {
439
+ throw new ConfigurationError('Command is required for stdio transport');
440
+ }
441
+ // Extract env from options if available
442
+ const env = 'env' in options && options.env
443
+ ? options.env
444
+ : undefined;
445
+ return connectStdio(command, env, timeout);
446
+ }
447
+ throw new ConfigurationError(`Unsupported transport type: ${transport}`);
448
+ }
449
+ //# sourceMappingURL=connection.js.map
@@ -0,0 +1,9 @@
1
+ /**
2
+ * MCP runtime utilities.
3
+ * Exports MCP connection, listing, client manager, and related utilities.
4
+ */
5
+ export * from './types.js';
6
+ export * from './connection.js';
7
+ export * from './list.js';
8
+ export * from './client/manager.js';
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,9 @@
1
+ /**
2
+ * MCP runtime utilities.
3
+ * Exports MCP connection, listing, client manager, and related utilities.
4
+ */
5
+ export * from './types.js';
6
+ export * from './connection.js';
7
+ export * from './list.js';
8
+ export * from './client/manager.js';
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,50 @@
1
+ /**
2
+ * MCP listing utilities.
3
+ * Provides functions to list tools, resources, and prompts from MCP servers.
4
+ */
5
+ import { Client } from '@modelcontextprotocol/sdk/client/index.js';
6
+ import type { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js';
7
+ import type { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';
8
+ /**
9
+ * List all tools available from the MCP server.
10
+ */
11
+ export declare function listTools(client: Client): Promise<{
12
+ tools: Array<{
13
+ name: string;
14
+ title?: string;
15
+ description?: string;
16
+ inputSchema?: unknown;
17
+ outputSchema?: unknown;
18
+ }>;
19
+ }>;
20
+ /**
21
+ * List all resources available from the MCP server.
22
+ */
23
+ export declare function listResources(client: Client): Promise<{
24
+ resources: Array<{
25
+ uri: string;
26
+ name?: string;
27
+ description?: string;
28
+ mimeType?: string;
29
+ }>;
30
+ }>;
31
+ /**
32
+ * List all prompts available from the MCP server.
33
+ */
34
+ export declare function listPrompts(client: Client): Promise<{
35
+ prompts: Array<{
36
+ name: string;
37
+ title?: string;
38
+ description?: string;
39
+ arguments?: Array<{
40
+ name: string;
41
+ description?: string;
42
+ required?: boolean;
43
+ }>;
44
+ }>;
45
+ }>;
46
+ /**
47
+ * Close the MCP transport connection.
48
+ */
49
+ export declare function closeConnection(transport: StreamableHTTPClientTransport | StdioClientTransport): Promise<void>;
50
+ //# sourceMappingURL=list.d.ts.map