github-to-mcp-monorepo 1.0.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 (388) hide show
  1. package/.env.example +8 -0
  2. package/.github/CODEOWNERS +6 -0
  3. package/.husky/pre-commit +1 -0
  4. package/.nvmrc +1 -0
  5. package/.prettierignore +5 -0
  6. package/.prettierrc +7 -0
  7. package/.vscode/settings.json +4 -0
  8. package/ARCHITECTURE.md +1429 -0
  9. package/CHANGELOG.md +167 -0
  10. package/CONTRIBUTING.md +327 -0
  11. package/LICENSE +201 -0
  12. package/README.md +1028 -0
  13. package/SECURITY.md +248 -0
  14. package/VISUAL_GUIDE.md +437 -0
  15. package/apps/vscode/IMPLEMENTATION.md +480 -0
  16. package/apps/vscode/README.md +248 -0
  17. package/apps/vscode/package.json +381 -0
  18. package/apps/vscode/resources/icon.png +0 -0
  19. package/apps/vscode/resources/icon.svg +5 -0
  20. package/apps/vscode/src/commands/browseRegistry.ts +211 -0
  21. package/apps/vscode/src/commands/configureClaudeDesktop.ts +332 -0
  22. package/apps/vscode/src/commands/convert.ts +82 -0
  23. package/apps/vscode/src/commands/convertCurrentRepo.ts +109 -0
  24. package/apps/vscode/src/commands/convertFromUrl.ts +138 -0
  25. package/apps/vscode/src/commands/index.ts +121 -0
  26. package/apps/vscode/src/commands/validate.ts +197 -0
  27. package/apps/vscode/src/extension.ts +464 -0
  28. package/apps/vscode/src/global.d.ts +36 -0
  29. package/apps/vscode/src/test/extension.test.ts +73 -0
  30. package/apps/vscode/src/utils/file-generator.ts +529 -0
  31. package/apps/vscode/src/utils/github-api.ts +335 -0
  32. package/apps/vscode/src/utils/index.ts +29 -0
  33. package/apps/vscode/src/utils/mcp-config.ts +334 -0
  34. package/apps/vscode/src/utils/storage.ts +87 -0
  35. package/apps/vscode/src/views/McpServersTreeView.ts +160 -0
  36. package/apps/vscode/src/views/OutputChannelView.ts +195 -0
  37. package/apps/vscode/src/views/StatusBarItem.ts +251 -0
  38. package/apps/vscode/src/views/ToolsExplorerView.ts +314 -0
  39. package/apps/vscode/src/views/historyProvider.ts +75 -0
  40. package/apps/vscode/src/views/index.ts +12 -0
  41. package/apps/vscode/src/views/resultsPanel.ts +330 -0
  42. package/apps/vscode/src/webviews/ConversionPanel.ts +350 -0
  43. package/apps/vscode/src/webviews/ToolDetailsPanel.ts +448 -0
  44. package/apps/vscode/src/webviews/index.ts +9 -0
  45. package/apps/vscode/src/webviews/webview-ui/styles.ts +492 -0
  46. package/apps/vscode/tsconfig.json +20 -0
  47. package/apps/web/PLAYGROUND_GUIDE.md +499 -0
  48. package/apps/web/README.md +505 -0
  49. package/apps/web/app/api/convert/route.ts +100 -0
  50. package/apps/web/app/api/convert/stream/route.ts +198 -0
  51. package/apps/web/app/api/deploy/route.ts +157 -0
  52. package/apps/web/app/api/edge/route.ts +308 -0
  53. package/apps/web/app/api/export-docker/route.ts +284 -0
  54. package/apps/web/app/api/generate-openapi/route.ts +119 -0
  55. package/apps/web/app/api/mcp/[serverId]/route.ts +263 -0
  56. package/apps/web/app/api/playground/connect/route.ts +143 -0
  57. package/apps/web/app/api/playground/disconnect/route.ts +78 -0
  58. package/apps/web/app/api/playground/execute/route.ts +135 -0
  59. package/apps/web/app/api/playground/sessions/route.ts +103 -0
  60. package/apps/web/app/api/playground/tools/route.ts +117 -0
  61. package/apps/web/app/api/playground/v2/connect/route.ts +96 -0
  62. package/apps/web/app/api/playground/v2/disconnect/route.ts +88 -0
  63. package/apps/web/app/api/playground/v2/health/route.ts +80 -0
  64. package/apps/web/app/api/playground/v2/prompts/route.ts +160 -0
  65. package/apps/web/app/api/playground/v2/resources/route.ts +159 -0
  66. package/apps/web/app/api/playground/v2/sessions/route.ts +184 -0
  67. package/apps/web/app/api/playground/v2/tools/route.ts +167 -0
  68. package/apps/web/app/api/stream/route.ts +232 -0
  69. package/apps/web/app/batch/BatchConvertClient.tsx +190 -0
  70. package/apps/web/app/batch/page.tsx +37 -0
  71. package/apps/web/app/convert/page.tsx +269 -0
  72. package/apps/web/app/dashboard/page.tsx +380 -0
  73. package/apps/web/app/globals.css +622 -0
  74. package/apps/web/app/layout.tsx +120 -0
  75. package/apps/web/app/manifest.ts +31 -0
  76. package/apps/web/app/opengraph-image.tsx +112 -0
  77. package/apps/web/app/page.old.tsx +924 -0
  78. package/apps/web/app/page.tsx +77 -0
  79. package/apps/web/app/playground/page.tsx +306 -0
  80. package/apps/web/app/playground/v2/error.tsx +163 -0
  81. package/apps/web/app/playground/v2/layout.tsx +58 -0
  82. package/apps/web/app/playground/v2/loading.tsx +152 -0
  83. package/apps/web/app/playground/v2/page.tsx +644 -0
  84. package/apps/web/app/playground/v2/providers.tsx +214 -0
  85. package/apps/web/app/playground/v2/use-shortcuts.ts +209 -0
  86. package/apps/web/app/playground/v2/use-url-state.ts +296 -0
  87. package/apps/web/app/providers.tsx +22 -0
  88. package/apps/web/app/sitemap.ts +32 -0
  89. package/apps/web/app/twitter-image.tsx +112 -0
  90. package/apps/web/components/BranchSelector.tsx +401 -0
  91. package/apps/web/components/ClaudeConfigExport.tsx +226 -0
  92. package/apps/web/components/Features.tsx +84 -0
  93. package/apps/web/components/Footer.tsx +119 -0
  94. package/apps/web/components/GenerationProgress.tsx +248 -0
  95. package/apps/web/components/GithubUrlInput.tsx +483 -0
  96. package/apps/web/components/Header.tsx +175 -0
  97. package/apps/web/components/Hero.tsx +117 -0
  98. package/apps/web/components/HowItWorks.tsx +119 -0
  99. package/apps/web/components/InstallBanner.tsx +158 -0
  100. package/apps/web/components/Logo.tsx +116 -0
  101. package/apps/web/components/ParticleBackground.tsx +105 -0
  102. package/apps/web/components/Playground.tsx +472 -0
  103. package/apps/web/components/PlaygroundToolTester.tsx +410 -0
  104. package/apps/web/components/ProductCards.tsx +179 -0
  105. package/apps/web/components/SplitView.tsx +194 -0
  106. package/apps/web/components/ToolFilter.tsx +260 -0
  107. package/apps/web/components/ToolList.tsx +325 -0
  108. package/apps/web/components/batch/BatchConvert.tsx +785 -0
  109. package/apps/web/components/batch/index.ts +7 -0
  110. package/apps/web/components/convert/ConfigTabs.tsx +230 -0
  111. package/apps/web/components/convert/ConversionResult.tsx +482 -0
  112. package/apps/web/components/convert/InlinePlayground.tsx +259 -0
  113. package/apps/web/components/convert/LoadingSteps.tsx +311 -0
  114. package/apps/web/components/convert/OneClickInstall.tsx +224 -0
  115. package/apps/web/components/convert/ToolCard.tsx +189 -0
  116. package/apps/web/components/convert/TryInPlayground.tsx +242 -0
  117. package/apps/web/components/convert/index.ts +12 -0
  118. package/apps/web/components/deploy/DeployButton.tsx +369 -0
  119. package/apps/web/components/deploy/index.ts +7 -0
  120. package/apps/web/components/docker/DockerExport.tsx +690 -0
  121. package/apps/web/components/docker/index.ts +7 -0
  122. package/apps/web/components/install/OneClickInstall.tsx +676 -0
  123. package/apps/web/components/install/index.ts +7 -0
  124. package/apps/web/components/playground/CapabilityTabs.tsx +150 -0
  125. package/apps/web/components/playground/ConnectionStatusV2.tsx +322 -0
  126. package/apps/web/components/playground/EmptyStates.tsx +305 -0
  127. package/apps/web/components/playground/ExecutionLog.tsx +260 -0
  128. package/apps/web/components/playground/ExecutionLogV2.tsx +378 -0
  129. package/apps/web/components/playground/JsonViewer.tsx +388 -0
  130. package/apps/web/components/playground/PlaygroundLayout.tsx +244 -0
  131. package/apps/web/components/playground/PromptsPanel.tsx +385 -0
  132. package/apps/web/components/playground/ResourcesPanel.tsx +378 -0
  133. package/apps/web/components/playground/SchemaForm.tsx +477 -0
  134. package/apps/web/components/playground/ServerStatus.tsx +151 -0
  135. package/apps/web/components/playground/ShareButton.tsx +239 -0
  136. package/apps/web/components/playground/ToolsPanel.tsx +309 -0
  137. package/apps/web/components/playground/TransportConfigurator.tsx +563 -0
  138. package/apps/web/components/playground/index.ts +74 -0
  139. package/apps/web/components/playground/types.ts +202 -0
  140. package/apps/web/components/streaming/StreamingProgress.tsx +441 -0
  141. package/apps/web/components/streaming/index.ts +7 -0
  142. package/apps/web/components/ui/badge.tsx +42 -0
  143. package/apps/web/components/ui/button.tsx +88 -0
  144. package/apps/web/components/ui/card.tsx +75 -0
  145. package/apps/web/components/ui/code-block.tsx +122 -0
  146. package/apps/web/components/ui/index.ts +12 -0
  147. package/apps/web/components/ui/input.tsx +55 -0
  148. package/apps/web/components/ui/tabs.tsx +61 -0
  149. package/apps/web/hooks/index.ts +85 -0
  150. package/apps/web/hooks/types.ts +1173 -0
  151. package/apps/web/hooks/use-conversion.ts +133 -0
  152. package/apps/web/hooks/use-execution-history.ts +376 -0
  153. package/apps/web/hooks/use-generation-progress.ts +147 -0
  154. package/apps/web/hooks/use-local-storage.ts +88 -0
  155. package/apps/web/hooks/use-mcp-client.ts +623 -0
  156. package/apps/web/hooks/use-mcp-connection.ts +500 -0
  157. package/apps/web/hooks/use-mcp-execution.ts +282 -0
  158. package/apps/web/hooks/use-mcp-prompts.ts +441 -0
  159. package/apps/web/hooks/use-mcp-resources.ts +430 -0
  160. package/apps/web/hooks/use-mcp-tools.ts +540 -0
  161. package/apps/web/hooks/use-playground-store.ts +299 -0
  162. package/apps/web/hooks/use-playground.ts +184 -0
  163. package/apps/web/hooks/use-streaming-conversion.ts +227 -0
  164. package/apps/web/hooks/useBatchConversion.ts +271 -0
  165. package/apps/web/hooks/useDockerConfig.ts +161 -0
  166. package/apps/web/hooks/usePlatformDetection.ts +80 -0
  167. package/apps/web/hooks/useStreaming.ts +199 -0
  168. package/apps/web/lib/api/errors.ts +386 -0
  169. package/apps/web/lib/api/index.ts +137 -0
  170. package/apps/web/lib/api/logger.ts +187 -0
  171. package/apps/web/lib/api/middleware.ts +364 -0
  172. package/apps/web/lib/api/openapi.ts +977 -0
  173. package/apps/web/lib/api/session-manager.ts +594 -0
  174. package/apps/web/lib/api/types.ts +433 -0
  175. package/apps/web/lib/api/validation.ts +523 -0
  176. package/apps/web/lib/constants.ts +114 -0
  177. package/apps/web/lib/mcp/client.ts +1137 -0
  178. package/apps/web/lib/mcp/events.ts +651 -0
  179. package/apps/web/lib/mcp/index.ts +347 -0
  180. package/apps/web/lib/mcp/logger.ts +428 -0
  181. package/apps/web/lib/mcp/metrics.ts +703 -0
  182. package/apps/web/lib/mcp/retry.ts +616 -0
  183. package/apps/web/lib/mcp/session-manager.ts +779 -0
  184. package/apps/web/lib/mcp/transports.ts +988 -0
  185. package/apps/web/lib/mcp/types.ts +594 -0
  186. package/apps/web/lib/mcp-client-enhanced.ts +871 -0
  187. package/apps/web/lib/mcp-client.ts +778 -0
  188. package/apps/web/lib/mcp-errors.ts +489 -0
  189. package/apps/web/lib/mcp-sandbox.ts +593 -0
  190. package/apps/web/lib/mcp-testing.ts +428 -0
  191. package/apps/web/lib/mcp-types.ts +448 -0
  192. package/apps/web/lib/playground-store.tsx +1147 -0
  193. package/apps/web/lib/utils.ts +439 -0
  194. package/apps/web/next-env.d.ts +5 -0
  195. package/apps/web/next.config.js +23 -0
  196. package/apps/web/package.json +55 -0
  197. package/apps/web/postcss.config.js +6 -0
  198. package/apps/web/public/.well-known/ai-plugin.json +17 -0
  199. package/apps/web/public/logo.svg +6 -0
  200. package/apps/web/public/robots.txt +22 -0
  201. package/apps/web/public/schema.json +27 -0
  202. package/apps/web/tailwind.config.js +26 -0
  203. package/apps/web/tailwind.config.ts +123 -0
  204. package/apps/web/tsconfig.json +20 -0
  205. package/apps/web/types/deploy.ts +139 -0
  206. package/apps/web/types/index.ts +247 -0
  207. package/apps/web/vercel.json +39 -0
  208. package/eslint.config.mjs +23 -0
  209. package/llms.txt +102 -0
  210. package/mkdocs/docs/api/core.md +318 -0
  211. package/mkdocs/docs/api/index.md +128 -0
  212. package/mkdocs/docs/api/mcp-server.md +301 -0
  213. package/mkdocs/docs/api/openapi-parser.md +254 -0
  214. package/mkdocs/docs/assets/logo.svg +7 -0
  215. package/mkdocs/docs/changelog.md +118 -0
  216. package/mkdocs/docs/cli/generate.md +148 -0
  217. package/mkdocs/docs/cli/index.md +52 -0
  218. package/mkdocs/docs/cli/inspect.md +164 -0
  219. package/mkdocs/docs/cli/serve.md +136 -0
  220. package/mkdocs/docs/concepts/classification.md +254 -0
  221. package/mkdocs/docs/concepts/how-it-works.md +299 -0
  222. package/mkdocs/docs/concepts/index.md +77 -0
  223. package/mkdocs/docs/concepts/mcp-protocol.md +362 -0
  224. package/mkdocs/docs/concepts/tool-types.md +382 -0
  225. package/mkdocs/docs/contributing/architecture.md +262 -0
  226. package/mkdocs/docs/contributing/development.md +245 -0
  227. package/mkdocs/docs/contributing/index.md +73 -0
  228. package/mkdocs/docs/contributing/testing.md +320 -0
  229. package/mkdocs/docs/getting-started/configuration.md +235 -0
  230. package/mkdocs/docs/getting-started/index.md +54 -0
  231. package/mkdocs/docs/getting-started/installation.md +145 -0
  232. package/mkdocs/docs/getting-started/quickstart.md +160 -0
  233. package/mkdocs/docs/guides/batch.md +375 -0
  234. package/mkdocs/docs/guides/claude-desktop.md +227 -0
  235. package/mkdocs/docs/guides/cursor.md +188 -0
  236. package/mkdocs/docs/guides/custom-tools.md +367 -0
  237. package/mkdocs/docs/guides/index.md +78 -0
  238. package/mkdocs/docs/guides/private-repos.md +221 -0
  239. package/mkdocs/docs/guides/vscode.md +247 -0
  240. package/mkdocs/docs/index.md +175 -0
  241. package/mkdocs/docs/reference/config.md +223 -0
  242. package/mkdocs/docs/reference/env.md +192 -0
  243. package/mkdocs/docs/reference/index.md +102 -0
  244. package/mkdocs/docs/reference/tools.md +309 -0
  245. package/mkdocs/docs/stylesheets/extra.css +231 -0
  246. package/mkdocs/mkdocs.yml +204 -0
  247. package/mkdocs/overrides/.gitkeep +1 -0
  248. package/mkdocs/overrides/main.html +7 -0
  249. package/mkdocs/python-deps.txt +7 -0
  250. package/mkdocs/vercel.json +11 -0
  251. package/package.json +63 -0
  252. package/packages/core/package.json +61 -0
  253. package/packages/core/src/__tests__/bitbucket-client.test.ts +366 -0
  254. package/packages/core/src/__tests__/cli.test.ts +235 -0
  255. package/packages/core/src/__tests__/code-extractor.test.ts +378 -0
  256. package/packages/core/src/__tests__/docker-generator.test.ts +255 -0
  257. package/packages/core/src/__tests__/github-client.test.ts +390 -0
  258. package/packages/core/src/__tests__/gitlab-client.test.ts +319 -0
  259. package/packages/core/src/__tests__/go-extractor.test.ts +351 -0
  260. package/packages/core/src/__tests__/graphql-extractor.test.ts +330 -0
  261. package/packages/core/src/__tests__/java-extractor.test.ts +497 -0
  262. package/packages/core/src/__tests__/plugins.test.ts +467 -0
  263. package/packages/core/src/__tests__/readme-extractor.test.ts +258 -0
  264. package/packages/core/src/__tests__/redis-cache.test.ts +307 -0
  265. package/packages/core/src/__tests__/rust-extractor.test.ts +252 -0
  266. package/packages/core/src/__tests__/streaming.test.ts +251 -0
  267. package/packages/core/src/additional-extractors.ts +333 -0
  268. package/packages/core/src/cache/cache-interface.ts +179 -0
  269. package/packages/core/src/cache/index.ts +210 -0
  270. package/packages/core/src/cache/redis-cache.ts +291 -0
  271. package/packages/core/src/cache/upstash-cache.ts +379 -0
  272. package/packages/core/src/cache.ts +251 -0
  273. package/packages/core/src/cli.ts +822 -0
  274. package/packages/core/src/code-extractor.ts +696 -0
  275. package/packages/core/src/docker-generator.ts +470 -0
  276. package/packages/core/src/edge-compatible.ts +491 -0
  277. package/packages/core/src/extractors/go-extractor.ts +791 -0
  278. package/packages/core/src/extractors/index.ts +9 -0
  279. package/packages/core/src/extractors/java-extractor.ts +937 -0
  280. package/packages/core/src/extractors/rust-extractor.ts +744 -0
  281. package/packages/core/src/github-client.ts +319 -0
  282. package/packages/core/src/go-generator.ts +356 -0
  283. package/packages/core/src/graphql-extractor.ts +358 -0
  284. package/packages/core/src/index.ts +797 -0
  285. package/packages/core/src/langchain-exporter.ts +617 -0
  286. package/packages/core/src/language-parsers.ts +1114 -0
  287. package/packages/core/src/mcp-introspector.ts +279 -0
  288. package/packages/core/src/monorepo-detector.ts +378 -0
  289. package/packages/core/src/plugins/index.ts +370 -0
  290. package/packages/core/src/plugins/registry.ts +404 -0
  291. package/packages/core/src/plugins/types.ts +215 -0
  292. package/packages/core/src/providers/base-provider.ts +246 -0
  293. package/packages/core/src/providers/bitbucket-client.ts +464 -0
  294. package/packages/core/src/providers/gitlab-client.ts +388 -0
  295. package/packages/core/src/providers/index.ts +176 -0
  296. package/packages/core/src/python-generator.ts +260 -0
  297. package/packages/core/src/queue/index.ts +100 -0
  298. package/packages/core/src/queue/memory-queue.ts +445 -0
  299. package/packages/core/src/queue/redis-queue.ts +578 -0
  300. package/packages/core/src/queue/types.ts +251 -0
  301. package/packages/core/src/readme-extractor.ts +409 -0
  302. package/packages/core/src/schema-generator.ts +638 -0
  303. package/packages/core/src/streaming.ts +999 -0
  304. package/packages/core/src/types.ts +289 -0
  305. package/packages/core/tsconfig.json +9 -0
  306. package/packages/core/tsup.config.ts +25 -0
  307. package/packages/mcp-server/README.md +297 -0
  308. package/packages/mcp-server/package.json +55 -0
  309. package/packages/mcp-server/src/__tests__/mcp-server.test.ts +177 -0
  310. package/packages/mcp-server/src/__tests__/tools.test.ts +217 -0
  311. package/packages/mcp-server/src/index.ts +1206 -0
  312. package/packages/mcp-server/src/prompts/index.ts +601 -0
  313. package/packages/mcp-server/src/tools/export-docker.ts +362 -0
  314. package/packages/mcp-server/src/tools/generate-openapi.ts +162 -0
  315. package/packages/mcp-server/src/tools/monitor-mcp-server.ts +448 -0
  316. package/packages/mcp-server/src/tools/stream-convert.ts +398 -0
  317. package/packages/mcp-server/src/tools/test-mcp-tool.ts +531 -0
  318. package/packages/mcp-server/tsconfig.json +12 -0
  319. package/packages/mcp-server/tsup.config.ts +14 -0
  320. package/packages/openapi-parser/package-lock.json +3028 -0
  321. package/packages/openapi-parser/package.json +41 -0
  322. package/packages/openapi-parser/src/analyzer.ts +700 -0
  323. package/packages/openapi-parser/src/asyncapi-parser.ts +475 -0
  324. package/packages/openapi-parser/src/cli.ts +302 -0
  325. package/packages/openapi-parser/src/generator.ts +570 -0
  326. package/packages/openapi-parser/src/generators/express-analyzer.ts +649 -0
  327. package/packages/openapi-parser/src/generators/fastapi-analyzer.ts +960 -0
  328. package/packages/openapi-parser/src/generators/index.ts +200 -0
  329. package/packages/openapi-parser/src/generators/nextjs-analyzer.ts +768 -0
  330. package/packages/openapi-parser/src/generators/openapi-builder.ts +527 -0
  331. package/packages/openapi-parser/src/generators/types.ts +298 -0
  332. package/packages/openapi-parser/src/graphql-parser.ts +462 -0
  333. package/packages/openapi-parser/src/grpc-parser.ts +649 -0
  334. package/packages/openapi-parser/src/har-parser.ts +723 -0
  335. package/packages/openapi-parser/src/index.ts +635 -0
  336. package/packages/openapi-parser/src/insomnia-parser.ts +614 -0
  337. package/packages/openapi-parser/src/parser.ts +231 -0
  338. package/packages/openapi-parser/src/postman-parser.ts +611 -0
  339. package/packages/openapi-parser/src/ref-resolver.ts +313 -0
  340. package/packages/openapi-parser/src/transformer.ts +459 -0
  341. package/packages/openapi-parser/tests/generators/express.test.ts +209 -0
  342. package/packages/openapi-parser/tests/generators/fastapi.test.ts +236 -0
  343. package/packages/openapi-parser/tests/generators/nextjs.test.ts +273 -0
  344. package/packages/openapi-parser/tests/parsers.test.ts +847 -0
  345. package/packages/openapi-parser/tsconfig.json +9 -0
  346. package/packages/openapi-parser/tsup.config.ts +11 -0
  347. package/packages/registry/package.json +59 -0
  348. package/packages/registry/src/cli.ts +456 -0
  349. package/packages/registry/src/index.ts +44 -0
  350. package/packages/registry/src/popular/github.json +47 -0
  351. package/packages/registry/src/popular/index.ts +55 -0
  352. package/packages/registry/src/popular/linear.json +42 -0
  353. package/packages/registry/src/popular/notion.json +42 -0
  354. package/packages/registry/src/popular/openai.json +40 -0
  355. package/packages/registry/src/popular/resend.json +38 -0
  356. package/packages/registry/src/popular/slack.json +42 -0
  357. package/packages/registry/src/popular/stripe.json +163 -0
  358. package/packages/registry/src/popular/supabase.json +42 -0
  359. package/packages/registry/src/popular/twilio.json +40 -0
  360. package/packages/registry/src/popular/vercel.json +40 -0
  361. package/packages/registry/src/registry.ts +492 -0
  362. package/packages/registry/src/storage.ts +334 -0
  363. package/packages/registry/src/types.ts +275 -0
  364. package/packages/registry/src/updater.ts +208 -0
  365. package/packages/registry/tsconfig.json +10 -0
  366. package/packages/registry/tsup.config.ts +11 -0
  367. package/pnpm-workspace.yaml +3 -0
  368. package/scripts/build-docs.sh +16 -0
  369. package/server.json +9 -0
  370. package/templates/Dockerfile.python.template +60 -0
  371. package/templates/Dockerfile.typescript.template +60 -0
  372. package/templates/docker-compose.template.yml +68 -0
  373. package/tests/fixtures/express-app/index.js +34 -0
  374. package/tests/fixtures/express-app/routes/posts.js +43 -0
  375. package/tests/fixtures/express-app/routes/users.js +58 -0
  376. package/tests/fixtures/fastapi-app/main.py +125 -0
  377. package/tests/fixtures/fastapi-app/routes/admin.py +42 -0
  378. package/tests/fixtures/graphql/simple-schema.graphql +65 -0
  379. package/tests/fixtures/mocks/github-api-responses.json +63 -0
  380. package/tests/fixtures/nextjs-app/app/api/posts/route.ts +55 -0
  381. package/tests/fixtures/nextjs-app/app/api/users/[id]/route.ts +63 -0
  382. package/tests/fixtures/nextjs-app/app/api/users/route.ts +44 -0
  383. package/tests/fixtures/nextjs-app/pages/api/health.ts +28 -0
  384. package/tests/fixtures/openapi/petstore.yaml +179 -0
  385. package/tests/integration/langchain-export.test.ts +405 -0
  386. package/tests/integration/openapi-conversion.test.ts +221 -0
  387. package/tsconfig.json +18 -0
  388. package/vitest.config.ts +32 -0
@@ -0,0 +1,459 @@
1
+ /**
2
+ * @fileoverview transformer module implementation
3
+ * Enhanced with OpenAPI 3.1 support and example extraction
4
+ * @copyright Copyright (c) 2024-2026 nirholas
5
+ * @license MIT
6
+ */
7
+
8
+ import { OpenAPIV3 } from 'openapi-types';
9
+ import type { EndpointInfo, ParameterInfo, PaginationPattern, OperationExample } from './analyzer.js';
10
+
11
+ export interface McpToolDefinition {
12
+ name: string;
13
+ description: string;
14
+ inputSchema: {
15
+ type: 'object';
16
+ properties: Record<string, any>;
17
+ required?: string[];
18
+ };
19
+ metadata: {
20
+ endpoint: {
21
+ path: string;
22
+ method: string;
23
+ };
24
+ auth?: {
25
+ type: string;
26
+ required: boolean;
27
+ envVar?: string;
28
+ headerName?: string;
29
+ };
30
+ pagination?: PaginationPattern;
31
+ tags?: string[];
32
+ deprecated?: boolean;
33
+ isWebhook?: boolean;
34
+ };
35
+ examples?: OperationExample[];
36
+ }
37
+
38
+ export interface TransformOptions {
39
+ naming?: {
40
+ prefix?: string;
41
+ style?: 'snake_case' | 'camelCase';
42
+ };
43
+ auth?: {
44
+ type: 'bearer' | 'basic' | 'apiKey' | 'oauth';
45
+ envVar?: string;
46
+ header?: string;
47
+ };
48
+ features?: {
49
+ pagination?: boolean;
50
+ retry?: boolean;
51
+ cache?: boolean;
52
+ validation?: boolean;
53
+ includeExamples?: boolean;
54
+ };
55
+ }
56
+
57
+ /**
58
+ * Transforms OpenAPI endpoints into MCP tool definitions
59
+ * Enhanced for OpenAPI 3.1 support
60
+ */
61
+ export class OpenApiTransformer {
62
+ constructor(
63
+ private spec: OpenAPIV3.Document,
64
+ private options: TransformOptions = {}
65
+ ) {}
66
+
67
+ /**
68
+ * Transform an endpoint into an MCP tool definition
69
+ */
70
+ transformEndpoint(endpoint: EndpointInfo, pagination?: PaginationPattern): McpToolDefinition {
71
+ const name = this.generateToolName(endpoint);
72
+ const description = this.generateDescription(endpoint);
73
+ const inputSchema = this.generateInputSchema(endpoint);
74
+
75
+ // Build auth metadata with enhanced info
76
+ let authMeta: McpToolDefinition['metadata']['auth'] | undefined;
77
+ if (endpoint.security && endpoint.security.length > 0) {
78
+ const securityScheme = this.getSecurityScheme(endpoint.security[0].name);
79
+ authMeta = {
80
+ type: securityScheme?.type || endpoint.security[0].name || 'unknown',
81
+ required: true,
82
+ envVar: this.generateEnvVar(endpoint.security[0].name),
83
+ headerName: securityScheme?.name,
84
+ };
85
+ }
86
+
87
+ return {
88
+ name,
89
+ description,
90
+ inputSchema,
91
+ metadata: {
92
+ endpoint: {
93
+ path: endpoint.path,
94
+ method: endpoint.method,
95
+ },
96
+ auth: authMeta,
97
+ pagination,
98
+ tags: endpoint.tags,
99
+ deprecated: endpoint.deprecated,
100
+ isWebhook: endpoint.isWebhook,
101
+ },
102
+ examples: this.options.features?.includeExamples !== false ? endpoint.examples : undefined,
103
+ };
104
+ }
105
+
106
+ /**
107
+ * Get security scheme from spec
108
+ */
109
+ private getSecurityScheme(name: string): any {
110
+ return this.spec.components?.securitySchemes?.[name];
111
+ }
112
+
113
+ /**
114
+ * Generate environment variable name for auth
115
+ */
116
+ private generateEnvVar(schemeName: string): string {
117
+ return `${schemeName.toUpperCase().replace(/[^A-Z0-9_]/g, '_')}_TOKEN`;
118
+ }
119
+
120
+ /**
121
+ * Transform multiple endpoints
122
+ */
123
+ transformEndpoints(
124
+ endpoints: EndpointInfo[],
125
+ paginationMap?: Map<string, PaginationPattern>
126
+ ): McpToolDefinition[] {
127
+ return endpoints.map(endpoint => {
128
+ const key = `${endpoint.method}:${endpoint.path}`;
129
+ const pagination = paginationMap?.get(key);
130
+ return this.transformEndpoint(endpoint, pagination);
131
+ });
132
+ }
133
+
134
+ /**
135
+ * Generate MCP tool name from endpoint
136
+ */
137
+ private generateToolName(endpoint: EndpointInfo): string {
138
+ let name: string;
139
+
140
+ // Use operationId if available
141
+ if (endpoint.operationId) {
142
+ name = endpoint.operationId;
143
+ } else {
144
+ // Generate from method + path
145
+ const pathParts = endpoint.path
146
+ .split('/')
147
+ .filter(Boolean)
148
+ .filter(part => !part.startsWith('{')) // Remove path parameters
149
+ .join('_');
150
+
151
+ const method = endpoint.method.toLowerCase();
152
+ name = `${method}_${pathParts}`;
153
+ }
154
+
155
+ // Apply naming style
156
+ if (this.options.naming?.style === 'camelCase') {
157
+ name = this.toCamelCase(name);
158
+ } else {
159
+ name = this.toSnakeCase(name);
160
+ }
161
+
162
+ // Add prefix
163
+ if (this.options.naming?.prefix) {
164
+ name = `${this.options.naming.prefix}_${name}`;
165
+ }
166
+
167
+ return name;
168
+ }
169
+
170
+ /**
171
+ * Generate description from endpoint info
172
+ */
173
+ private generateDescription(endpoint: EndpointInfo): string {
174
+ if (endpoint.description) {
175
+ return endpoint.description;
176
+ }
177
+
178
+ if (endpoint.summary) {
179
+ return endpoint.summary;
180
+ }
181
+
182
+ // Generate basic description
183
+ const action = this.getActionWord(endpoint.method);
184
+ const resource = this.getResourceName(endpoint.path);
185
+ return `${action} ${resource}`;
186
+ }
187
+
188
+ /**
189
+ * Generate JSON Schema for tool inputs
190
+ */
191
+ private generateInputSchema(endpoint: EndpointInfo): McpToolDefinition['inputSchema'] {
192
+ const properties: Record<string, any> = {};
193
+ const required: string[] = [];
194
+
195
+ // Add path parameters
196
+ for (const param of endpoint.parameters.filter(p => p.in === 'path')) {
197
+ properties[param.name] = this.convertSchemaToJsonSchema(param.schema, param.description);
198
+ if (param.required) {
199
+ required.push(param.name);
200
+ }
201
+ }
202
+
203
+ // Add query parameters
204
+ for (const param of endpoint.parameters.filter(p => p.in === 'query')) {
205
+ properties[param.name] = this.convertSchemaToJsonSchema(param.schema, param.description);
206
+ if (param.required) {
207
+ required.push(param.name);
208
+ }
209
+ }
210
+
211
+ // Add header parameters (except auth headers)
212
+ for (const param of endpoint.parameters.filter(p => p.in === 'header')) {
213
+ if (!this.isAuthHeader(param.name)) {
214
+ properties[param.name] = this.convertSchemaToJsonSchema(param.schema, param.description);
215
+ if (param.required) {
216
+ required.push(param.name);
217
+ }
218
+ }
219
+ }
220
+
221
+ // Add request body
222
+ if (endpoint.requestBody) {
223
+ const jsonContent = endpoint.requestBody.content['application/json'];
224
+ if (jsonContent?.schema) {
225
+ // Flatten request body into parameters or nest it
226
+ if (this.shouldFlattenRequestBody(jsonContent.schema)) {
227
+ const bodySchema = this.convertSchemaToJsonSchema(jsonContent.schema);
228
+ if (bodySchema.properties) {
229
+ Object.assign(properties, bodySchema.properties);
230
+ if (bodySchema.required) {
231
+ required.push(...bodySchema.required);
232
+ }
233
+ }
234
+ } else {
235
+ properties.body = this.convertSchemaToJsonSchema(
236
+ jsonContent.schema,
237
+ endpoint.requestBody.description
238
+ );
239
+ if (endpoint.requestBody.required) {
240
+ required.push('body');
241
+ }
242
+ }
243
+ }
244
+ }
245
+
246
+ return {
247
+ type: 'object',
248
+ properties,
249
+ required: required.length > 0 ? required : undefined,
250
+ };
251
+ }
252
+
253
+ /**
254
+ * Convert OpenAPI schema to JSON Schema
255
+ * Enhanced to support OpenAPI 3.1 features
256
+ */
257
+ private convertSchemaToJsonSchema(schema: any, description?: string): any {
258
+ if (!schema) {
259
+ return { type: 'string' };
260
+ }
261
+
262
+ if ('$ref' in schema) {
263
+ // $ref should be resolved by parser
264
+ return { type: 'object' };
265
+ }
266
+
267
+ const jsonSchema: any = {};
268
+
269
+ // Handle OpenAPI 3.1 type arrays (e.g., ["string", "null"])
270
+ if (Array.isArray(schema.type)) {
271
+ // Check if it's nullable
272
+ if (schema.type.includes('null')) {
273
+ const types = schema.type.filter((t: string) => t !== 'null');
274
+ if (types.length === 1) {
275
+ jsonSchema.type = types[0];
276
+ jsonSchema.nullable = true;
277
+ } else {
278
+ jsonSchema.type = types;
279
+ }
280
+ } else {
281
+ jsonSchema.type = schema.type;
282
+ }
283
+ } else {
284
+ jsonSchema.type = schema.type;
285
+ }
286
+
287
+ // Description
288
+ if (description || schema.description) {
289
+ jsonSchema.description = description || schema.description;
290
+ }
291
+
292
+ // Copy common properties
293
+ if (schema.format) jsonSchema.format = schema.format;
294
+ if (schema.enum) jsonSchema.enum = schema.enum;
295
+ if (schema.default !== undefined) jsonSchema.default = schema.default;
296
+ if (schema.example !== undefined) jsonSchema.example = schema.example;
297
+ if (schema.minimum !== undefined) jsonSchema.minimum = schema.minimum;
298
+ if (schema.maximum !== undefined) jsonSchema.maximum = schema.maximum;
299
+ if (schema.exclusiveMinimum !== undefined) jsonSchema.exclusiveMinimum = schema.exclusiveMinimum;
300
+ if (schema.exclusiveMaximum !== undefined) jsonSchema.exclusiveMaximum = schema.exclusiveMaximum;
301
+ if (schema.minLength !== undefined) jsonSchema.minLength = schema.minLength;
302
+ if (schema.maxLength !== undefined) jsonSchema.maxLength = schema.maxLength;
303
+ if (schema.pattern) jsonSchema.pattern = schema.pattern;
304
+ if (schema.minItems !== undefined) jsonSchema.minItems = schema.minItems;
305
+ if (schema.maxItems !== undefined) jsonSchema.maxItems = schema.maxItems;
306
+ if (schema.uniqueItems !== undefined) jsonSchema.uniqueItems = schema.uniqueItems;
307
+ if (schema.minProperties !== undefined) jsonSchema.minProperties = schema.minProperties;
308
+ if (schema.maxProperties !== undefined) jsonSchema.maxProperties = schema.maxProperties;
309
+
310
+ // OpenAPI 3.1 / JSON Schema 2020-12 support
311
+ if (schema.const !== undefined) jsonSchema.const = schema.const;
312
+ if (schema.$id) jsonSchema.$id = schema.$id;
313
+ if (schema.$anchor) jsonSchema.$anchor = schema.$anchor;
314
+ if (schema.$comment) jsonSchema.$comment = schema.$comment;
315
+ if (schema.contentEncoding) jsonSchema.contentEncoding = schema.contentEncoding;
316
+ if (schema.contentMediaType) jsonSchema.contentMediaType = schema.contentMediaType;
317
+ if (schema.deprecated !== undefined) jsonSchema.deprecated = schema.deprecated;
318
+ if (schema.readOnly !== undefined) jsonSchema.readOnly = schema.readOnly;
319
+ if (schema.writeOnly !== undefined) jsonSchema.writeOnly = schema.writeOnly;
320
+
321
+ // Handle nullable (OpenAPI 3.0 style)
322
+ if (schema.nullable === true && !Array.isArray(schema.type)) {
323
+ jsonSchema.nullable = true;
324
+ }
325
+
326
+ // Handle object type
327
+ const typeVal = Array.isArray(schema.type) ? schema.type[0] : schema.type;
328
+ if (typeVal === 'object' && schema.properties) {
329
+ jsonSchema.properties = {};
330
+ for (const [key, value] of Object.entries(schema.properties)) {
331
+ jsonSchema.properties[key] = this.convertSchemaToJsonSchema(value);
332
+ }
333
+ if (schema.required) {
334
+ jsonSchema.required = schema.required;
335
+ }
336
+ if (schema.additionalProperties !== undefined) {
337
+ if (typeof schema.additionalProperties === 'boolean') {
338
+ jsonSchema.additionalProperties = schema.additionalProperties;
339
+ } else {
340
+ jsonSchema.additionalProperties = this.convertSchemaToJsonSchema(schema.additionalProperties);
341
+ }
342
+ }
343
+ }
344
+
345
+ // Handle array type
346
+ if (typeVal === 'array' && schema.items) {
347
+ jsonSchema.items = this.convertSchemaToJsonSchema(schema.items);
348
+ }
349
+ // Handle prefixItems (OpenAPI 3.1 / JSON Schema 2020-12)
350
+ if (schema.prefixItems) {
351
+ jsonSchema.prefixItems = schema.prefixItems.map((s: any) => this.convertSchemaToJsonSchema(s));
352
+ }
353
+ if (schema.contains) {
354
+ jsonSchema.contains = this.convertSchemaToJsonSchema(schema.contains);
355
+ }
356
+
357
+ // Handle oneOf, anyOf, allOf
358
+ if (schema.oneOf) {
359
+ jsonSchema.oneOf = schema.oneOf.map((s: any) => this.convertSchemaToJsonSchema(s));
360
+ }
361
+ if (schema.anyOf) {
362
+ jsonSchema.anyOf = schema.anyOf.map((s: any) => this.convertSchemaToJsonSchema(s));
363
+ }
364
+ if (schema.allOf) {
365
+ jsonSchema.allOf = schema.allOf.map((s: any) => this.convertSchemaToJsonSchema(s));
366
+ }
367
+ if (schema.not) {
368
+ jsonSchema.not = this.convertSchemaToJsonSchema(schema.not);
369
+ }
370
+
371
+ // Handle if/then/else (JSON Schema 2020-12)
372
+ if (schema.if) jsonSchema.if = this.convertSchemaToJsonSchema(schema.if);
373
+ if (schema.then) jsonSchema.then = this.convertSchemaToJsonSchema(schema.then);
374
+ if (schema.else) jsonSchema.else = this.convertSchemaToJsonSchema(schema.else);
375
+
376
+ // Handle dependentSchemas and dependentRequired (JSON Schema 2020-12)
377
+ if (schema.dependentSchemas) {
378
+ jsonSchema.dependentSchemas = {};
379
+ for (const [key, value] of Object.entries(schema.dependentSchemas)) {
380
+ jsonSchema.dependentSchemas[key] = this.convertSchemaToJsonSchema(value);
381
+ }
382
+ }
383
+ if (schema.dependentRequired) {
384
+ jsonSchema.dependentRequired = schema.dependentRequired;
385
+ }
386
+
387
+ return jsonSchema;
388
+ }
389
+
390
+ /**
391
+ * Determine if request body should be flattened
392
+ */
393
+ private shouldFlattenRequestBody(schema: any): boolean {
394
+ // Flatten if it's a simple object with properties
395
+ if (schema.type === 'object' && schema.properties) {
396
+ const propCount = Object.keys(schema.properties).length;
397
+ // Flatten if <= 5 properties
398
+ return propCount <= 5;
399
+ }
400
+ return false;
401
+ }
402
+
403
+ /**
404
+ * Check if header is authentication header
405
+ */
406
+ private isAuthHeader(name: string): boolean {
407
+ const authHeaders = ['authorization', 'x-api-key', 'api-key', 'apikey'];
408
+ return authHeaders.includes(name.toLowerCase());
409
+ }
410
+
411
+ /**
412
+ * Get action word from HTTP method
413
+ */
414
+ private getActionWord(method: string): string {
415
+ const actions: Record<string, string> = {
416
+ GET: 'Get',
417
+ POST: 'Create',
418
+ PUT: 'Update',
419
+ PATCH: 'Modify',
420
+ DELETE: 'Delete',
421
+ };
422
+ return actions[method.toUpperCase()] || method;
423
+ }
424
+
425
+ /**
426
+ * Extract resource name from path
427
+ */
428
+ private getResourceName(path: string): string {
429
+ const parts = path.split('/').filter(Boolean);
430
+ const lastPart = parts[parts.length - 1];
431
+
432
+ // If last part is a parameter, use second to last
433
+ if (lastPart?.startsWith('{')) {
434
+ return parts[parts.length - 2] || 'resource';
435
+ }
436
+
437
+ return lastPart || 'resource';
438
+ }
439
+
440
+ /**
441
+ * Convert string to camelCase
442
+ */
443
+ private toCamelCase(str: string): string {
444
+ return str
445
+ .toLowerCase()
446
+ .replace(/[_-](.)/g, (_, char) => char.toUpperCase());
447
+ }
448
+
449
+ /**
450
+ * Convert string to snake_case
451
+ */
452
+ private toSnakeCase(str: string): string {
453
+ return str
454
+ .replace(/([A-Z])/g, '_$1')
455
+ .toLowerCase()
456
+ .replace(/[_-]+/g, '_')
457
+ .replace(/^_/, '');
458
+ }
459
+ }
@@ -0,0 +1,209 @@
1
+ /**
2
+ * Tests for Express.js analyzer
3
+ */
4
+ import { describe, it, expect, beforeAll } from 'vitest';
5
+ import { ExpressAnalyzer } from '../../src/generators/express-analyzer.js';
6
+ import { FileContent } from '../../src/generators/types.js';
7
+ import { promises as fs } from 'fs';
8
+ import path from 'path';
9
+
10
+ describe('ExpressAnalyzer', () => {
11
+ let analyzer: ExpressAnalyzer;
12
+ let fixtureFiles: FileContent[];
13
+
14
+ beforeAll(async () => {
15
+ analyzer = new ExpressAnalyzer();
16
+
17
+ // Load fixture files
18
+ const fixturesPath = path.join(__dirname, '../../../tests/fixtures/express-app');
19
+
20
+ const indexContent = await fs.readFile(
21
+ path.join(fixturesPath, 'index.js'),
22
+ 'utf-8'
23
+ );
24
+ const usersContent = await fs.readFile(
25
+ path.join(fixturesPath, 'routes/users.js'),
26
+ 'utf-8'
27
+ );
28
+ const postsContent = await fs.readFile(
29
+ path.join(fixturesPath, 'routes/posts.js'),
30
+ 'utf-8'
31
+ );
32
+
33
+ fixtureFiles = [
34
+ { path: 'index.js', content: indexContent },
35
+ { path: 'routes/users.js', content: usersContent },
36
+ { path: 'routes/posts.js', content: postsContent },
37
+ ];
38
+ });
39
+
40
+ describe('canAnalyze', () => {
41
+ it('should detect Express.js code', () => {
42
+ const files: FileContent[] = [
43
+ { path: 'app.js', content: "const express = require('express');" },
44
+ ];
45
+ expect(analyzer.canAnalyze(files)).toBe(true);
46
+ });
47
+
48
+ it('should detect Express router usage', () => {
49
+ const files: FileContent[] = [
50
+ { path: 'routes.js', content: "router.get('/users', handler);" },
51
+ ];
52
+ expect(analyzer.canAnalyze(files)).toBe(true);
53
+ });
54
+
55
+ it('should not match non-Express code', () => {
56
+ const files: FileContent[] = [
57
+ { path: 'utils.js', content: 'function helper() { return 42; }' },
58
+ ];
59
+ expect(analyzer.canAnalyze(files)).toBe(false);
60
+ });
61
+ });
62
+
63
+ describe('analyze', () => {
64
+ it('should extract routes from Express.js files', async () => {
65
+ const result = await analyzer.analyze(fixtureFiles);
66
+
67
+ expect(result.framework).toBe('express');
68
+ expect(result.routes.length).toBeGreaterThan(0);
69
+ expect(result.filesAnalyzed.length).toBeGreaterThan(0);
70
+ });
71
+
72
+ it('should extract user routes', async () => {
73
+ const result = await analyzer.analyze(fixtureFiles);
74
+
75
+ const userRoutes = result.routes.filter(r => r.path.includes('/users'));
76
+ expect(userRoutes.length).toBeGreaterThan(0);
77
+
78
+ // Check GET /users exists
79
+ const getUsersRoute = userRoutes.find(
80
+ r => r.method === 'get' && r.path === '/users'
81
+ );
82
+ expect(getUsersRoute).toBeDefined();
83
+ expect(getUsersRoute?.tags).toContain('Users');
84
+ });
85
+
86
+ it('should extract path parameters', async () => {
87
+ const result = await analyzer.analyze(fixtureFiles);
88
+
89
+ const getUserByIdRoute = result.routes.find(
90
+ r => r.method === 'get' && r.path === '/users/:id'
91
+ );
92
+
93
+ expect(getUserByIdRoute).toBeDefined();
94
+ expect(getUserByIdRoute?.openApiPath).toBe('/users/{id}');
95
+ expect(getUserByIdRoute?.pathParameters).toHaveLength(1);
96
+ expect(getUserByIdRoute?.pathParameters[0].name).toBe('id');
97
+ });
98
+
99
+ it('should detect deprecated endpoints', async () => {
100
+ const result = await analyzer.analyze(fixtureFiles);
101
+
102
+ const deprecatedRoute = result.routes.find(
103
+ r => r.method === 'put' && r.path.includes('/users')
104
+ );
105
+
106
+ expect(deprecatedRoute?.deprecated).toBe(true);
107
+ });
108
+
109
+ it('should extract post routes', async () => {
110
+ const result = await analyzer.analyze(fixtureFiles);
111
+
112
+ const postRoutes = result.routes.filter(r => r.path.includes('/posts'));
113
+ expect(postRoutes.length).toBeGreaterThan(0);
114
+ });
115
+
116
+ it('should generate operation IDs', async () => {
117
+ const result = await analyzer.analyze(fixtureFiles);
118
+
119
+ for (const route of result.routes) {
120
+ expect(route.operationId).toBeDefined();
121
+ expect(route.operationId).not.toBe('');
122
+ }
123
+ });
124
+ });
125
+
126
+ describe('inline code analysis', () => {
127
+ it('should parse app.method() patterns', async () => {
128
+ const files: FileContent[] = [
129
+ {
130
+ path: 'api.js',
131
+ content: `
132
+ const express = require('express');
133
+ const app = express();
134
+
135
+ app.get('/items', (req, res) => {
136
+ res.json([]);
137
+ });
138
+
139
+ app.post('/items', (req, res) => {
140
+ res.status(201).json(req.body);
141
+ });
142
+
143
+ app.delete('/items/:id', (req, res) => {
144
+ res.status(204).send();
145
+ });
146
+ `,
147
+ },
148
+ ];
149
+
150
+ const result = await analyzer.analyze(files);
151
+
152
+ expect(result.routes).toHaveLength(3);
153
+ expect(result.routes.map(r => r.method)).toContain('get');
154
+ expect(result.routes.map(r => r.method)).toContain('post');
155
+ expect(result.routes.map(r => r.method)).toContain('delete');
156
+ });
157
+
158
+ it('should parse router.route() chains', async () => {
159
+ const files: FileContent[] = [
160
+ {
161
+ path: 'router.js',
162
+ content: `
163
+ const router = require('express').Router();
164
+
165
+ router.route('/products')
166
+ .get((req, res) => res.json([]))
167
+ .post((req, res) => res.status(201).json({}));
168
+
169
+ router.route('/products/:id')
170
+ .get((req, res) => res.json({}))
171
+ .put((req, res) => res.json({}))
172
+ .delete((req, res) => res.status(204).send());
173
+ `,
174
+ },
175
+ ];
176
+
177
+ const result = await analyzer.analyze(files);
178
+
179
+ expect(result.routes.length).toBeGreaterThanOrEqual(5);
180
+ });
181
+ });
182
+
183
+ describe('response inference', () => {
184
+ it('should infer default responses based on method', async () => {
185
+ const files: FileContent[] = [
186
+ {
187
+ path: 'api.js',
188
+ content: `
189
+ const app = require('express')();
190
+ app.get('/test', handler);
191
+ app.post('/test', handler);
192
+ app.delete('/test/:id', handler);
193
+ `,
194
+ },
195
+ ];
196
+
197
+ const result = await analyzer.analyze(files);
198
+
199
+ const getRoute = result.routes.find(r => r.method === 'get');
200
+ expect(getRoute?.responses.some(r => r.statusCode === 200)).toBe(true);
201
+
202
+ const postRoute = result.routes.find(r => r.method === 'post');
203
+ expect(postRoute?.responses.some(r => r.statusCode === 201)).toBe(true);
204
+
205
+ const deleteRoute = result.routes.find(r => r.method === 'delete');
206
+ expect(deleteRoute?.responses.some(r => r.statusCode === 204)).toBe(true);
207
+ });
208
+ });
209
+ });