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.
- package/.env.example +8 -0
- package/.github/CODEOWNERS +6 -0
- package/.husky/pre-commit +1 -0
- package/.nvmrc +1 -0
- package/.prettierignore +5 -0
- package/.prettierrc +7 -0
- package/.vscode/settings.json +4 -0
- package/ARCHITECTURE.md +1429 -0
- package/CHANGELOG.md +167 -0
- package/CONTRIBUTING.md +327 -0
- package/LICENSE +201 -0
- package/README.md +1028 -0
- package/SECURITY.md +248 -0
- package/VISUAL_GUIDE.md +437 -0
- package/apps/vscode/IMPLEMENTATION.md +480 -0
- package/apps/vscode/README.md +248 -0
- package/apps/vscode/package.json +381 -0
- package/apps/vscode/resources/icon.png +0 -0
- package/apps/vscode/resources/icon.svg +5 -0
- package/apps/vscode/src/commands/browseRegistry.ts +211 -0
- package/apps/vscode/src/commands/configureClaudeDesktop.ts +332 -0
- package/apps/vscode/src/commands/convert.ts +82 -0
- package/apps/vscode/src/commands/convertCurrentRepo.ts +109 -0
- package/apps/vscode/src/commands/convertFromUrl.ts +138 -0
- package/apps/vscode/src/commands/index.ts +121 -0
- package/apps/vscode/src/commands/validate.ts +197 -0
- package/apps/vscode/src/extension.ts +464 -0
- package/apps/vscode/src/global.d.ts +36 -0
- package/apps/vscode/src/test/extension.test.ts +73 -0
- package/apps/vscode/src/utils/file-generator.ts +529 -0
- package/apps/vscode/src/utils/github-api.ts +335 -0
- package/apps/vscode/src/utils/index.ts +29 -0
- package/apps/vscode/src/utils/mcp-config.ts +334 -0
- package/apps/vscode/src/utils/storage.ts +87 -0
- package/apps/vscode/src/views/McpServersTreeView.ts +160 -0
- package/apps/vscode/src/views/OutputChannelView.ts +195 -0
- package/apps/vscode/src/views/StatusBarItem.ts +251 -0
- package/apps/vscode/src/views/ToolsExplorerView.ts +314 -0
- package/apps/vscode/src/views/historyProvider.ts +75 -0
- package/apps/vscode/src/views/index.ts +12 -0
- package/apps/vscode/src/views/resultsPanel.ts +330 -0
- package/apps/vscode/src/webviews/ConversionPanel.ts +350 -0
- package/apps/vscode/src/webviews/ToolDetailsPanel.ts +448 -0
- package/apps/vscode/src/webviews/index.ts +9 -0
- package/apps/vscode/src/webviews/webview-ui/styles.ts +492 -0
- package/apps/vscode/tsconfig.json +20 -0
- package/apps/web/PLAYGROUND_GUIDE.md +499 -0
- package/apps/web/README.md +505 -0
- package/apps/web/app/api/convert/route.ts +100 -0
- package/apps/web/app/api/convert/stream/route.ts +198 -0
- package/apps/web/app/api/deploy/route.ts +157 -0
- package/apps/web/app/api/edge/route.ts +308 -0
- package/apps/web/app/api/export-docker/route.ts +284 -0
- package/apps/web/app/api/generate-openapi/route.ts +119 -0
- package/apps/web/app/api/mcp/[serverId]/route.ts +263 -0
- package/apps/web/app/api/playground/connect/route.ts +143 -0
- package/apps/web/app/api/playground/disconnect/route.ts +78 -0
- package/apps/web/app/api/playground/execute/route.ts +135 -0
- package/apps/web/app/api/playground/sessions/route.ts +103 -0
- package/apps/web/app/api/playground/tools/route.ts +117 -0
- package/apps/web/app/api/playground/v2/connect/route.ts +96 -0
- package/apps/web/app/api/playground/v2/disconnect/route.ts +88 -0
- package/apps/web/app/api/playground/v2/health/route.ts +80 -0
- package/apps/web/app/api/playground/v2/prompts/route.ts +160 -0
- package/apps/web/app/api/playground/v2/resources/route.ts +159 -0
- package/apps/web/app/api/playground/v2/sessions/route.ts +184 -0
- package/apps/web/app/api/playground/v2/tools/route.ts +167 -0
- package/apps/web/app/api/stream/route.ts +232 -0
- package/apps/web/app/batch/BatchConvertClient.tsx +190 -0
- package/apps/web/app/batch/page.tsx +37 -0
- package/apps/web/app/convert/page.tsx +269 -0
- package/apps/web/app/dashboard/page.tsx +380 -0
- package/apps/web/app/globals.css +622 -0
- package/apps/web/app/layout.tsx +120 -0
- package/apps/web/app/manifest.ts +31 -0
- package/apps/web/app/opengraph-image.tsx +112 -0
- package/apps/web/app/page.old.tsx +924 -0
- package/apps/web/app/page.tsx +77 -0
- package/apps/web/app/playground/page.tsx +306 -0
- package/apps/web/app/playground/v2/error.tsx +163 -0
- package/apps/web/app/playground/v2/layout.tsx +58 -0
- package/apps/web/app/playground/v2/loading.tsx +152 -0
- package/apps/web/app/playground/v2/page.tsx +644 -0
- package/apps/web/app/playground/v2/providers.tsx +214 -0
- package/apps/web/app/playground/v2/use-shortcuts.ts +209 -0
- package/apps/web/app/playground/v2/use-url-state.ts +296 -0
- package/apps/web/app/providers.tsx +22 -0
- package/apps/web/app/sitemap.ts +32 -0
- package/apps/web/app/twitter-image.tsx +112 -0
- package/apps/web/components/BranchSelector.tsx +401 -0
- package/apps/web/components/ClaudeConfigExport.tsx +226 -0
- package/apps/web/components/Features.tsx +84 -0
- package/apps/web/components/Footer.tsx +119 -0
- package/apps/web/components/GenerationProgress.tsx +248 -0
- package/apps/web/components/GithubUrlInput.tsx +483 -0
- package/apps/web/components/Header.tsx +175 -0
- package/apps/web/components/Hero.tsx +117 -0
- package/apps/web/components/HowItWorks.tsx +119 -0
- package/apps/web/components/InstallBanner.tsx +158 -0
- package/apps/web/components/Logo.tsx +116 -0
- package/apps/web/components/ParticleBackground.tsx +105 -0
- package/apps/web/components/Playground.tsx +472 -0
- package/apps/web/components/PlaygroundToolTester.tsx +410 -0
- package/apps/web/components/ProductCards.tsx +179 -0
- package/apps/web/components/SplitView.tsx +194 -0
- package/apps/web/components/ToolFilter.tsx +260 -0
- package/apps/web/components/ToolList.tsx +325 -0
- package/apps/web/components/batch/BatchConvert.tsx +785 -0
- package/apps/web/components/batch/index.ts +7 -0
- package/apps/web/components/convert/ConfigTabs.tsx +230 -0
- package/apps/web/components/convert/ConversionResult.tsx +482 -0
- package/apps/web/components/convert/InlinePlayground.tsx +259 -0
- package/apps/web/components/convert/LoadingSteps.tsx +311 -0
- package/apps/web/components/convert/OneClickInstall.tsx +224 -0
- package/apps/web/components/convert/ToolCard.tsx +189 -0
- package/apps/web/components/convert/TryInPlayground.tsx +242 -0
- package/apps/web/components/convert/index.ts +12 -0
- package/apps/web/components/deploy/DeployButton.tsx +369 -0
- package/apps/web/components/deploy/index.ts +7 -0
- package/apps/web/components/docker/DockerExport.tsx +690 -0
- package/apps/web/components/docker/index.ts +7 -0
- package/apps/web/components/install/OneClickInstall.tsx +676 -0
- package/apps/web/components/install/index.ts +7 -0
- package/apps/web/components/playground/CapabilityTabs.tsx +150 -0
- package/apps/web/components/playground/ConnectionStatusV2.tsx +322 -0
- package/apps/web/components/playground/EmptyStates.tsx +305 -0
- package/apps/web/components/playground/ExecutionLog.tsx +260 -0
- package/apps/web/components/playground/ExecutionLogV2.tsx +378 -0
- package/apps/web/components/playground/JsonViewer.tsx +388 -0
- package/apps/web/components/playground/PlaygroundLayout.tsx +244 -0
- package/apps/web/components/playground/PromptsPanel.tsx +385 -0
- package/apps/web/components/playground/ResourcesPanel.tsx +378 -0
- package/apps/web/components/playground/SchemaForm.tsx +477 -0
- package/apps/web/components/playground/ServerStatus.tsx +151 -0
- package/apps/web/components/playground/ShareButton.tsx +239 -0
- package/apps/web/components/playground/ToolsPanel.tsx +309 -0
- package/apps/web/components/playground/TransportConfigurator.tsx +563 -0
- package/apps/web/components/playground/index.ts +74 -0
- package/apps/web/components/playground/types.ts +202 -0
- package/apps/web/components/streaming/StreamingProgress.tsx +441 -0
- package/apps/web/components/streaming/index.ts +7 -0
- package/apps/web/components/ui/badge.tsx +42 -0
- package/apps/web/components/ui/button.tsx +88 -0
- package/apps/web/components/ui/card.tsx +75 -0
- package/apps/web/components/ui/code-block.tsx +122 -0
- package/apps/web/components/ui/index.ts +12 -0
- package/apps/web/components/ui/input.tsx +55 -0
- package/apps/web/components/ui/tabs.tsx +61 -0
- package/apps/web/hooks/index.ts +85 -0
- package/apps/web/hooks/types.ts +1173 -0
- package/apps/web/hooks/use-conversion.ts +133 -0
- package/apps/web/hooks/use-execution-history.ts +376 -0
- package/apps/web/hooks/use-generation-progress.ts +147 -0
- package/apps/web/hooks/use-local-storage.ts +88 -0
- package/apps/web/hooks/use-mcp-client.ts +623 -0
- package/apps/web/hooks/use-mcp-connection.ts +500 -0
- package/apps/web/hooks/use-mcp-execution.ts +282 -0
- package/apps/web/hooks/use-mcp-prompts.ts +441 -0
- package/apps/web/hooks/use-mcp-resources.ts +430 -0
- package/apps/web/hooks/use-mcp-tools.ts +540 -0
- package/apps/web/hooks/use-playground-store.ts +299 -0
- package/apps/web/hooks/use-playground.ts +184 -0
- package/apps/web/hooks/use-streaming-conversion.ts +227 -0
- package/apps/web/hooks/useBatchConversion.ts +271 -0
- package/apps/web/hooks/useDockerConfig.ts +161 -0
- package/apps/web/hooks/usePlatformDetection.ts +80 -0
- package/apps/web/hooks/useStreaming.ts +199 -0
- package/apps/web/lib/api/errors.ts +386 -0
- package/apps/web/lib/api/index.ts +137 -0
- package/apps/web/lib/api/logger.ts +187 -0
- package/apps/web/lib/api/middleware.ts +364 -0
- package/apps/web/lib/api/openapi.ts +977 -0
- package/apps/web/lib/api/session-manager.ts +594 -0
- package/apps/web/lib/api/types.ts +433 -0
- package/apps/web/lib/api/validation.ts +523 -0
- package/apps/web/lib/constants.ts +114 -0
- package/apps/web/lib/mcp/client.ts +1137 -0
- package/apps/web/lib/mcp/events.ts +651 -0
- package/apps/web/lib/mcp/index.ts +347 -0
- package/apps/web/lib/mcp/logger.ts +428 -0
- package/apps/web/lib/mcp/metrics.ts +703 -0
- package/apps/web/lib/mcp/retry.ts +616 -0
- package/apps/web/lib/mcp/session-manager.ts +779 -0
- package/apps/web/lib/mcp/transports.ts +988 -0
- package/apps/web/lib/mcp/types.ts +594 -0
- package/apps/web/lib/mcp-client-enhanced.ts +871 -0
- package/apps/web/lib/mcp-client.ts +778 -0
- package/apps/web/lib/mcp-errors.ts +489 -0
- package/apps/web/lib/mcp-sandbox.ts +593 -0
- package/apps/web/lib/mcp-testing.ts +428 -0
- package/apps/web/lib/mcp-types.ts +448 -0
- package/apps/web/lib/playground-store.tsx +1147 -0
- package/apps/web/lib/utils.ts +439 -0
- package/apps/web/next-env.d.ts +5 -0
- package/apps/web/next.config.js +23 -0
- package/apps/web/package.json +55 -0
- package/apps/web/postcss.config.js +6 -0
- package/apps/web/public/.well-known/ai-plugin.json +17 -0
- package/apps/web/public/logo.svg +6 -0
- package/apps/web/public/robots.txt +22 -0
- package/apps/web/public/schema.json +27 -0
- package/apps/web/tailwind.config.js +26 -0
- package/apps/web/tailwind.config.ts +123 -0
- package/apps/web/tsconfig.json +20 -0
- package/apps/web/types/deploy.ts +139 -0
- package/apps/web/types/index.ts +247 -0
- package/apps/web/vercel.json +39 -0
- package/eslint.config.mjs +23 -0
- package/llms.txt +102 -0
- package/mkdocs/docs/api/core.md +318 -0
- package/mkdocs/docs/api/index.md +128 -0
- package/mkdocs/docs/api/mcp-server.md +301 -0
- package/mkdocs/docs/api/openapi-parser.md +254 -0
- package/mkdocs/docs/assets/logo.svg +7 -0
- package/mkdocs/docs/changelog.md +118 -0
- package/mkdocs/docs/cli/generate.md +148 -0
- package/mkdocs/docs/cli/index.md +52 -0
- package/mkdocs/docs/cli/inspect.md +164 -0
- package/mkdocs/docs/cli/serve.md +136 -0
- package/mkdocs/docs/concepts/classification.md +254 -0
- package/mkdocs/docs/concepts/how-it-works.md +299 -0
- package/mkdocs/docs/concepts/index.md +77 -0
- package/mkdocs/docs/concepts/mcp-protocol.md +362 -0
- package/mkdocs/docs/concepts/tool-types.md +382 -0
- package/mkdocs/docs/contributing/architecture.md +262 -0
- package/mkdocs/docs/contributing/development.md +245 -0
- package/mkdocs/docs/contributing/index.md +73 -0
- package/mkdocs/docs/contributing/testing.md +320 -0
- package/mkdocs/docs/getting-started/configuration.md +235 -0
- package/mkdocs/docs/getting-started/index.md +54 -0
- package/mkdocs/docs/getting-started/installation.md +145 -0
- package/mkdocs/docs/getting-started/quickstart.md +160 -0
- package/mkdocs/docs/guides/batch.md +375 -0
- package/mkdocs/docs/guides/claude-desktop.md +227 -0
- package/mkdocs/docs/guides/cursor.md +188 -0
- package/mkdocs/docs/guides/custom-tools.md +367 -0
- package/mkdocs/docs/guides/index.md +78 -0
- package/mkdocs/docs/guides/private-repos.md +221 -0
- package/mkdocs/docs/guides/vscode.md +247 -0
- package/mkdocs/docs/index.md +175 -0
- package/mkdocs/docs/reference/config.md +223 -0
- package/mkdocs/docs/reference/env.md +192 -0
- package/mkdocs/docs/reference/index.md +102 -0
- package/mkdocs/docs/reference/tools.md +309 -0
- package/mkdocs/docs/stylesheets/extra.css +231 -0
- package/mkdocs/mkdocs.yml +204 -0
- package/mkdocs/overrides/.gitkeep +1 -0
- package/mkdocs/overrides/main.html +7 -0
- package/mkdocs/python-deps.txt +7 -0
- package/mkdocs/vercel.json +11 -0
- package/package.json +63 -0
- package/packages/core/package.json +61 -0
- package/packages/core/src/__tests__/bitbucket-client.test.ts +366 -0
- package/packages/core/src/__tests__/cli.test.ts +235 -0
- package/packages/core/src/__tests__/code-extractor.test.ts +378 -0
- package/packages/core/src/__tests__/docker-generator.test.ts +255 -0
- package/packages/core/src/__tests__/github-client.test.ts +390 -0
- package/packages/core/src/__tests__/gitlab-client.test.ts +319 -0
- package/packages/core/src/__tests__/go-extractor.test.ts +351 -0
- package/packages/core/src/__tests__/graphql-extractor.test.ts +330 -0
- package/packages/core/src/__tests__/java-extractor.test.ts +497 -0
- package/packages/core/src/__tests__/plugins.test.ts +467 -0
- package/packages/core/src/__tests__/readme-extractor.test.ts +258 -0
- package/packages/core/src/__tests__/redis-cache.test.ts +307 -0
- package/packages/core/src/__tests__/rust-extractor.test.ts +252 -0
- package/packages/core/src/__tests__/streaming.test.ts +251 -0
- package/packages/core/src/additional-extractors.ts +333 -0
- package/packages/core/src/cache/cache-interface.ts +179 -0
- package/packages/core/src/cache/index.ts +210 -0
- package/packages/core/src/cache/redis-cache.ts +291 -0
- package/packages/core/src/cache/upstash-cache.ts +379 -0
- package/packages/core/src/cache.ts +251 -0
- package/packages/core/src/cli.ts +822 -0
- package/packages/core/src/code-extractor.ts +696 -0
- package/packages/core/src/docker-generator.ts +470 -0
- package/packages/core/src/edge-compatible.ts +491 -0
- package/packages/core/src/extractors/go-extractor.ts +791 -0
- package/packages/core/src/extractors/index.ts +9 -0
- package/packages/core/src/extractors/java-extractor.ts +937 -0
- package/packages/core/src/extractors/rust-extractor.ts +744 -0
- package/packages/core/src/github-client.ts +319 -0
- package/packages/core/src/go-generator.ts +356 -0
- package/packages/core/src/graphql-extractor.ts +358 -0
- package/packages/core/src/index.ts +797 -0
- package/packages/core/src/langchain-exporter.ts +617 -0
- package/packages/core/src/language-parsers.ts +1114 -0
- package/packages/core/src/mcp-introspector.ts +279 -0
- package/packages/core/src/monorepo-detector.ts +378 -0
- package/packages/core/src/plugins/index.ts +370 -0
- package/packages/core/src/plugins/registry.ts +404 -0
- package/packages/core/src/plugins/types.ts +215 -0
- package/packages/core/src/providers/base-provider.ts +246 -0
- package/packages/core/src/providers/bitbucket-client.ts +464 -0
- package/packages/core/src/providers/gitlab-client.ts +388 -0
- package/packages/core/src/providers/index.ts +176 -0
- package/packages/core/src/python-generator.ts +260 -0
- package/packages/core/src/queue/index.ts +100 -0
- package/packages/core/src/queue/memory-queue.ts +445 -0
- package/packages/core/src/queue/redis-queue.ts +578 -0
- package/packages/core/src/queue/types.ts +251 -0
- package/packages/core/src/readme-extractor.ts +409 -0
- package/packages/core/src/schema-generator.ts +638 -0
- package/packages/core/src/streaming.ts +999 -0
- package/packages/core/src/types.ts +289 -0
- package/packages/core/tsconfig.json +9 -0
- package/packages/core/tsup.config.ts +25 -0
- package/packages/mcp-server/README.md +297 -0
- package/packages/mcp-server/package.json +55 -0
- package/packages/mcp-server/src/__tests__/mcp-server.test.ts +177 -0
- package/packages/mcp-server/src/__tests__/tools.test.ts +217 -0
- package/packages/mcp-server/src/index.ts +1206 -0
- package/packages/mcp-server/src/prompts/index.ts +601 -0
- package/packages/mcp-server/src/tools/export-docker.ts +362 -0
- package/packages/mcp-server/src/tools/generate-openapi.ts +162 -0
- package/packages/mcp-server/src/tools/monitor-mcp-server.ts +448 -0
- package/packages/mcp-server/src/tools/stream-convert.ts +398 -0
- package/packages/mcp-server/src/tools/test-mcp-tool.ts +531 -0
- package/packages/mcp-server/tsconfig.json +12 -0
- package/packages/mcp-server/tsup.config.ts +14 -0
- package/packages/openapi-parser/package-lock.json +3028 -0
- package/packages/openapi-parser/package.json +41 -0
- package/packages/openapi-parser/src/analyzer.ts +700 -0
- package/packages/openapi-parser/src/asyncapi-parser.ts +475 -0
- package/packages/openapi-parser/src/cli.ts +302 -0
- package/packages/openapi-parser/src/generator.ts +570 -0
- package/packages/openapi-parser/src/generators/express-analyzer.ts +649 -0
- package/packages/openapi-parser/src/generators/fastapi-analyzer.ts +960 -0
- package/packages/openapi-parser/src/generators/index.ts +200 -0
- package/packages/openapi-parser/src/generators/nextjs-analyzer.ts +768 -0
- package/packages/openapi-parser/src/generators/openapi-builder.ts +527 -0
- package/packages/openapi-parser/src/generators/types.ts +298 -0
- package/packages/openapi-parser/src/graphql-parser.ts +462 -0
- package/packages/openapi-parser/src/grpc-parser.ts +649 -0
- package/packages/openapi-parser/src/har-parser.ts +723 -0
- package/packages/openapi-parser/src/index.ts +635 -0
- package/packages/openapi-parser/src/insomnia-parser.ts +614 -0
- package/packages/openapi-parser/src/parser.ts +231 -0
- package/packages/openapi-parser/src/postman-parser.ts +611 -0
- package/packages/openapi-parser/src/ref-resolver.ts +313 -0
- package/packages/openapi-parser/src/transformer.ts +459 -0
- package/packages/openapi-parser/tests/generators/express.test.ts +209 -0
- package/packages/openapi-parser/tests/generators/fastapi.test.ts +236 -0
- package/packages/openapi-parser/tests/generators/nextjs.test.ts +273 -0
- package/packages/openapi-parser/tests/parsers.test.ts +847 -0
- package/packages/openapi-parser/tsconfig.json +9 -0
- package/packages/openapi-parser/tsup.config.ts +11 -0
- package/packages/registry/package.json +59 -0
- package/packages/registry/src/cli.ts +456 -0
- package/packages/registry/src/index.ts +44 -0
- package/packages/registry/src/popular/github.json +47 -0
- package/packages/registry/src/popular/index.ts +55 -0
- package/packages/registry/src/popular/linear.json +42 -0
- package/packages/registry/src/popular/notion.json +42 -0
- package/packages/registry/src/popular/openai.json +40 -0
- package/packages/registry/src/popular/resend.json +38 -0
- package/packages/registry/src/popular/slack.json +42 -0
- package/packages/registry/src/popular/stripe.json +163 -0
- package/packages/registry/src/popular/supabase.json +42 -0
- package/packages/registry/src/popular/twilio.json +40 -0
- package/packages/registry/src/popular/vercel.json +40 -0
- package/packages/registry/src/registry.ts +492 -0
- package/packages/registry/src/storage.ts +334 -0
- package/packages/registry/src/types.ts +275 -0
- package/packages/registry/src/updater.ts +208 -0
- package/packages/registry/tsconfig.json +10 -0
- package/packages/registry/tsup.config.ts +11 -0
- package/pnpm-workspace.yaml +3 -0
- package/scripts/build-docs.sh +16 -0
- package/server.json +9 -0
- package/templates/Dockerfile.python.template +60 -0
- package/templates/Dockerfile.typescript.template +60 -0
- package/templates/docker-compose.template.yml +68 -0
- package/tests/fixtures/express-app/index.js +34 -0
- package/tests/fixtures/express-app/routes/posts.js +43 -0
- package/tests/fixtures/express-app/routes/users.js +58 -0
- package/tests/fixtures/fastapi-app/main.py +125 -0
- package/tests/fixtures/fastapi-app/routes/admin.py +42 -0
- package/tests/fixtures/graphql/simple-schema.graphql +65 -0
- package/tests/fixtures/mocks/github-api-responses.json +63 -0
- package/tests/fixtures/nextjs-app/app/api/posts/route.ts +55 -0
- package/tests/fixtures/nextjs-app/app/api/users/[id]/route.ts +63 -0
- package/tests/fixtures/nextjs-app/app/api/users/route.ts +44 -0
- package/tests/fixtures/nextjs-app/pages/api/health.ts +28 -0
- package/tests/fixtures/openapi/petstore.yaml +179 -0
- package/tests/integration/langchain-export.test.ts +405 -0
- package/tests/integration/openapi-conversion.test.ts +221 -0
- package/tsconfig.json +18 -0
- package/vitest.config.ts +32 -0
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview API route to export Docker configuration
|
|
3
|
+
* POST /api/export-docker
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { NextRequest, NextResponse } from 'next/server';
|
|
7
|
+
|
|
8
|
+
export interface ExportDockerRequest {
|
|
9
|
+
language: 'typescript' | 'python';
|
|
10
|
+
serverName?: string;
|
|
11
|
+
port?: number;
|
|
12
|
+
envVars?: Record<string, string>;
|
|
13
|
+
includeHealthcheck?: boolean;
|
|
14
|
+
multiStage?: boolean;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface DockerConfig {
|
|
18
|
+
dockerfile: string;
|
|
19
|
+
dockerCompose: string;
|
|
20
|
+
dockerignore: string;
|
|
21
|
+
buildScript: string;
|
|
22
|
+
claudeConfig: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface ExportDockerResponse {
|
|
26
|
+
success: boolean;
|
|
27
|
+
config?: DockerConfig;
|
|
28
|
+
error?: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Docker configuration templates
|
|
33
|
+
*/
|
|
34
|
+
const DOCKER_TEMPLATES = {
|
|
35
|
+
typescript: {
|
|
36
|
+
dockerfile: (options: { multiStage: boolean; includeHealthcheck: boolean }) => {
|
|
37
|
+
if (options.multiStage) {
|
|
38
|
+
return `# TypeScript MCP Server Dockerfile (Multi-stage)
|
|
39
|
+
FROM node:20-slim AS builder
|
|
40
|
+
|
|
41
|
+
WORKDIR /app
|
|
42
|
+
|
|
43
|
+
# Install dependencies
|
|
44
|
+
COPY package*.json ./
|
|
45
|
+
RUN npm ci
|
|
46
|
+
|
|
47
|
+
# Copy source and build
|
|
48
|
+
COPY . .
|
|
49
|
+
RUN npm run build
|
|
50
|
+
|
|
51
|
+
# Production image
|
|
52
|
+
FROM node:20-slim
|
|
53
|
+
|
|
54
|
+
WORKDIR /app
|
|
55
|
+
|
|
56
|
+
# Copy built files and production dependencies
|
|
57
|
+
COPY --from=builder /app/dist ./dist
|
|
58
|
+
COPY --from=builder /app/package*.json ./
|
|
59
|
+
RUN npm ci --only=production
|
|
60
|
+
|
|
61
|
+
# Security: Run as non-root user
|
|
62
|
+
USER node
|
|
63
|
+
|
|
64
|
+
${options.includeHealthcheck ? `# Health check
|
|
65
|
+
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \\
|
|
66
|
+
CMD node -e "console.log('healthy')" || exit 1
|
|
67
|
+
|
|
68
|
+
` : ''}# Run the server
|
|
69
|
+
CMD ["node", "dist/index.js"]
|
|
70
|
+
`;
|
|
71
|
+
}
|
|
72
|
+
return `# TypeScript MCP Server Dockerfile
|
|
73
|
+
FROM node:20-slim
|
|
74
|
+
|
|
75
|
+
WORKDIR /app
|
|
76
|
+
|
|
77
|
+
# Install dependencies
|
|
78
|
+
COPY package*.json ./
|
|
79
|
+
RUN npm ci --only=production
|
|
80
|
+
|
|
81
|
+
# Copy source
|
|
82
|
+
COPY . .
|
|
83
|
+
|
|
84
|
+
# Build TypeScript
|
|
85
|
+
RUN npm run build
|
|
86
|
+
|
|
87
|
+
${options.includeHealthcheck ? `# Health check
|
|
88
|
+
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \\
|
|
89
|
+
CMD node -e "console.log('healthy')" || exit 1
|
|
90
|
+
|
|
91
|
+
` : ''}# Run the server
|
|
92
|
+
CMD ["node", "dist/index.js"]
|
|
93
|
+
`;
|
|
94
|
+
},
|
|
95
|
+
dockerignore: `node_modules
|
|
96
|
+
npm-debug.log
|
|
97
|
+
.git
|
|
98
|
+
.gitignore
|
|
99
|
+
.env
|
|
100
|
+
*.md
|
|
101
|
+
dist
|
|
102
|
+
coverage
|
|
103
|
+
.nyc_output
|
|
104
|
+
*.test.ts
|
|
105
|
+
*.spec.ts
|
|
106
|
+
__tests__
|
|
107
|
+
`,
|
|
108
|
+
},
|
|
109
|
+
python: {
|
|
110
|
+
dockerfile: (options: { includeHealthcheck: boolean }) => `# Python MCP Server Dockerfile
|
|
111
|
+
FROM python:3.11-slim
|
|
112
|
+
|
|
113
|
+
WORKDIR /app
|
|
114
|
+
|
|
115
|
+
# Install system dependencies
|
|
116
|
+
RUN apt-get update && apt-get install -y --no-install-recommends \\
|
|
117
|
+
build-essential \\
|
|
118
|
+
&& rm -rf /var/lib/apt/lists/*
|
|
119
|
+
|
|
120
|
+
# Install Python dependencies
|
|
121
|
+
COPY requirements.txt ./
|
|
122
|
+
RUN pip install --no-cache-dir -r requirements.txt
|
|
123
|
+
|
|
124
|
+
# Copy source
|
|
125
|
+
COPY . .
|
|
126
|
+
|
|
127
|
+
# Security: Run as non-root user
|
|
128
|
+
RUN useradd -m -r mcpuser && chown -R mcpuser:mcpuser /app
|
|
129
|
+
USER mcpuser
|
|
130
|
+
|
|
131
|
+
${options.includeHealthcheck ? `# Health check
|
|
132
|
+
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \\
|
|
133
|
+
CMD python -c "print('healthy')" || exit 1
|
|
134
|
+
|
|
135
|
+
` : ''}# Run the server
|
|
136
|
+
CMD ["python", "-m", "mcp_server"]
|
|
137
|
+
`,
|
|
138
|
+
dockerignore: `__pycache__
|
|
139
|
+
*.py[cod]
|
|
140
|
+
*$py.class
|
|
141
|
+
*.so
|
|
142
|
+
.Python
|
|
143
|
+
.git
|
|
144
|
+
.gitignore
|
|
145
|
+
.env
|
|
146
|
+
venv/
|
|
147
|
+
ENV/
|
|
148
|
+
*.md
|
|
149
|
+
.pytest_cache/
|
|
150
|
+
.coverage
|
|
151
|
+
htmlcov/
|
|
152
|
+
dist/
|
|
153
|
+
build/
|
|
154
|
+
*.egg-info/
|
|
155
|
+
`,
|
|
156
|
+
},
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
function generateDockerCompose(
|
|
160
|
+
serverName: string,
|
|
161
|
+
port?: number,
|
|
162
|
+
envVars?: Record<string, string>
|
|
163
|
+
): string {
|
|
164
|
+
const envLines = envVars
|
|
165
|
+
? Object.entries(envVars)
|
|
166
|
+
.map(([key, value]) => ` - ${key}=${value}`)
|
|
167
|
+
.join('\n')
|
|
168
|
+
: ' - NODE_ENV=production';
|
|
169
|
+
|
|
170
|
+
const portSection = port
|
|
171
|
+
? ` ports:
|
|
172
|
+
- "${port}:${port}"
|
|
173
|
+
`
|
|
174
|
+
: '';
|
|
175
|
+
|
|
176
|
+
return `version: '3.8'
|
|
177
|
+
|
|
178
|
+
services:
|
|
179
|
+
${serverName}:
|
|
180
|
+
build: .
|
|
181
|
+
environment:
|
|
182
|
+
${envLines}
|
|
183
|
+
${portSection} volumes:
|
|
184
|
+
- ./config:/app/config:ro
|
|
185
|
+
restart: unless-stopped
|
|
186
|
+
logging:
|
|
187
|
+
driver: json-file
|
|
188
|
+
options:
|
|
189
|
+
max-size: "10m"
|
|
190
|
+
max-file: "3"
|
|
191
|
+
`;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function generateBuildScript(serverName: string): string {
|
|
195
|
+
return `#!/bin/bash
|
|
196
|
+
# Build and run the MCP server in Docker
|
|
197
|
+
set -e
|
|
198
|
+
|
|
199
|
+
echo "Building Docker image..."
|
|
200
|
+
docker build -t ${serverName} .
|
|
201
|
+
|
|
202
|
+
echo "Image built successfully!"
|
|
203
|
+
echo ""
|
|
204
|
+
echo "To run the MCP server:"
|
|
205
|
+
echo " docker run -it --rm ${serverName}"
|
|
206
|
+
echo ""
|
|
207
|
+
echo "Or with docker-compose:"
|
|
208
|
+
echo " docker-compose up -d"
|
|
209
|
+
`;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
function generateClaudeConfig(serverName: string): string {
|
|
213
|
+
return JSON.stringify(
|
|
214
|
+
{
|
|
215
|
+
mcpServers: {
|
|
216
|
+
[serverName]: {
|
|
217
|
+
command: 'docker',
|
|
218
|
+
args: ['run', '-i', '--rm', serverName],
|
|
219
|
+
},
|
|
220
|
+
},
|
|
221
|
+
},
|
|
222
|
+
null,
|
|
223
|
+
2
|
|
224
|
+
);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
export async function POST(request: NextRequest): Promise<NextResponse<ExportDockerResponse>> {
|
|
228
|
+
try {
|
|
229
|
+
const body = await request.json() as ExportDockerRequest;
|
|
230
|
+
|
|
231
|
+
// Validate request
|
|
232
|
+
if (!body.language || !['typescript', 'python'].includes(body.language)) {
|
|
233
|
+
return NextResponse.json(
|
|
234
|
+
{ success: false, error: 'Language must be "typescript" or "python"' },
|
|
235
|
+
{ status: 400 }
|
|
236
|
+
);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
const serverName = body.serverName || 'mcp-server';
|
|
240
|
+
const includeHealthcheck = body.includeHealthcheck ?? false;
|
|
241
|
+
const multiStage = body.multiStage ?? true;
|
|
242
|
+
|
|
243
|
+
const template = DOCKER_TEMPLATES[body.language];
|
|
244
|
+
|
|
245
|
+
const dockerfile = body.language === 'typescript'
|
|
246
|
+
? template.dockerfile({ multiStage, includeHealthcheck })
|
|
247
|
+
: (template as typeof DOCKER_TEMPLATES.python).dockerfile({ includeHealthcheck });
|
|
248
|
+
|
|
249
|
+
const config: DockerConfig = {
|
|
250
|
+
dockerfile,
|
|
251
|
+
dockerCompose: generateDockerCompose(serverName, body.port, body.envVars),
|
|
252
|
+
dockerignore: template.dockerignore,
|
|
253
|
+
buildScript: generateBuildScript(serverName),
|
|
254
|
+
claudeConfig: generateClaudeConfig(serverName),
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
return NextResponse.json({
|
|
258
|
+
success: true,
|
|
259
|
+
config,
|
|
260
|
+
});
|
|
261
|
+
} catch (error) {
|
|
262
|
+
console.error('Docker config generation error:', error);
|
|
263
|
+
|
|
264
|
+
return NextResponse.json(
|
|
265
|
+
{
|
|
266
|
+
success: false,
|
|
267
|
+
error: error instanceof Error ? error.message : 'Docker config generation failed',
|
|
268
|
+
},
|
|
269
|
+
{ status: 500 }
|
|
270
|
+
);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
// Support OPTIONS for CORS preflight
|
|
275
|
+
export async function OPTIONS(): Promise<NextResponse> {
|
|
276
|
+
return new NextResponse(null, {
|
|
277
|
+
status: 204,
|
|
278
|
+
headers: {
|
|
279
|
+
'Access-Control-Allow-Origin': '*',
|
|
280
|
+
'Access-Control-Allow-Methods': 'POST, OPTIONS',
|
|
281
|
+
'Access-Control-Allow-Headers': 'Content-Type',
|
|
282
|
+
},
|
|
283
|
+
});
|
|
284
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview API route to generate OpenAPI spec from uploaded code
|
|
3
|
+
* POST /api/generate-openapi
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
// @ts-nocheck - Temporarily disabled due to missing openapi-parser types
|
|
7
|
+
import { NextRequest, NextResponse } from 'next/server';
|
|
8
|
+
import { generateOpenApiFromCodeWithDetails } from '@github-to-mcp/openapi-parser';
|
|
9
|
+
import type { FileContent, GeneratorOptions } from '@github-to-mcp/openapi-parser';
|
|
10
|
+
|
|
11
|
+
export interface GenerateOpenApiRequest {
|
|
12
|
+
files: Array<{
|
|
13
|
+
path: string;
|
|
14
|
+
content: string;
|
|
15
|
+
language?: 'typescript' | 'javascript' | 'python';
|
|
16
|
+
}>;
|
|
17
|
+
options?: GeneratorOptions;
|
|
18
|
+
format?: 'json' | 'yaml' | 'both';
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface GenerateOpenApiResponse {
|
|
22
|
+
success: boolean;
|
|
23
|
+
spec?: object;
|
|
24
|
+
json?: string;
|
|
25
|
+
yaml?: string;
|
|
26
|
+
analysis?: {
|
|
27
|
+
framework: string;
|
|
28
|
+
routesCount: number;
|
|
29
|
+
schemasCount: number;
|
|
30
|
+
warnings: string[];
|
|
31
|
+
errors: string[];
|
|
32
|
+
};
|
|
33
|
+
error?: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export async function POST(request: NextRequest): Promise<NextResponse<GenerateOpenApiResponse>> {
|
|
37
|
+
try {
|
|
38
|
+
const body = await request.json() as GenerateOpenApiRequest;
|
|
39
|
+
|
|
40
|
+
// Validate request
|
|
41
|
+
if (!body.files || !Array.isArray(body.files) || body.files.length === 0) {
|
|
42
|
+
return NextResponse.json(
|
|
43
|
+
{ success: false, error: 'Files array is required and must not be empty' },
|
|
44
|
+
{ status: 400 }
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Validate each file
|
|
49
|
+
for (const file of body.files) {
|
|
50
|
+
if (!file.path || typeof file.path !== 'string') {
|
|
51
|
+
return NextResponse.json(
|
|
52
|
+
{ success: false, error: 'Each file must have a path' },
|
|
53
|
+
{ status: 400 }
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
if (!file.content || typeof file.content !== 'string') {
|
|
57
|
+
return NextResponse.json(
|
|
58
|
+
{ success: false, error: 'Each file must have content' },
|
|
59
|
+
{ status: 400 }
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Convert to FileContent format
|
|
65
|
+
const files: FileContent[] = body.files.map(f => ({
|
|
66
|
+
path: f.path,
|
|
67
|
+
content: f.content,
|
|
68
|
+
language: f.language,
|
|
69
|
+
}));
|
|
70
|
+
|
|
71
|
+
// Generate OpenAPI spec
|
|
72
|
+
const result = await generateOpenApiFromCodeWithDetails(files, body.options || {});
|
|
73
|
+
|
|
74
|
+
const format = body.format || 'json';
|
|
75
|
+
const response: GenerateOpenApiResponse = {
|
|
76
|
+
success: true,
|
|
77
|
+
analysis: {
|
|
78
|
+
framework: result.analysis.framework,
|
|
79
|
+
routesCount: result.analysis.routes.length,
|
|
80
|
+
schemasCount: Object.keys(result.analysis.schemas).length,
|
|
81
|
+
warnings: result.analysis.warnings,
|
|
82
|
+
errors: result.analysis.errors,
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
if (format === 'json' || format === 'both') {
|
|
87
|
+
response.spec = result.spec;
|
|
88
|
+
response.json = result.json;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (format === 'yaml' || format === 'both') {
|
|
92
|
+
response.yaml = result.yaml;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return NextResponse.json(response);
|
|
96
|
+
} catch (error) {
|
|
97
|
+
console.error('OpenAPI generation error:', error);
|
|
98
|
+
|
|
99
|
+
return NextResponse.json(
|
|
100
|
+
{
|
|
101
|
+
success: false,
|
|
102
|
+
error: error instanceof Error ? error.message : 'OpenAPI generation failed',
|
|
103
|
+
},
|
|
104
|
+
{ status: 500 }
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// Support OPTIONS for CORS preflight
|
|
110
|
+
export async function OPTIONS(): Promise<NextResponse> {
|
|
111
|
+
return new NextResponse(null, {
|
|
112
|
+
status: 204,
|
|
113
|
+
headers: {
|
|
114
|
+
'Access-Control-Allow-Origin': '*',
|
|
115
|
+
'Access-Control-Allow-Methods': 'POST, OPTIONS',
|
|
116
|
+
'Access-Control-Allow-Headers': 'Content-Type',
|
|
117
|
+
},
|
|
118
|
+
});
|
|
119
|
+
}
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cloud MCP Server Endpoint - HTTP/SSE Transport
|
|
3
|
+
* @copyright 2024-2026 nirholas
|
|
4
|
+
* @license MIT
|
|
5
|
+
*
|
|
6
|
+
* This is the actual MCP server that runs in the cloud.
|
|
7
|
+
* It receives MCP protocol messages via HTTP POST and returns responses.
|
|
8
|
+
*
|
|
9
|
+
* Supports:
|
|
10
|
+
* - tools/list - List available tools
|
|
11
|
+
* - tools/call - Execute a tool
|
|
12
|
+
* - initialize - Initialize connection
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { NextRequest, NextResponse } from 'next/server';
|
|
16
|
+
|
|
17
|
+
export const runtime = 'edge';
|
|
18
|
+
|
|
19
|
+
interface McpRequest {
|
|
20
|
+
jsonrpc: '2.0';
|
|
21
|
+
id: string | number;
|
|
22
|
+
method: string;
|
|
23
|
+
params?: Record<string, unknown>;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
interface McpResponse {
|
|
27
|
+
jsonrpc: '2.0';
|
|
28
|
+
id: string | number;
|
|
29
|
+
result?: unknown;
|
|
30
|
+
error?: {
|
|
31
|
+
code: number;
|
|
32
|
+
message: string;
|
|
33
|
+
data?: unknown;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// In production, this would load from database
|
|
38
|
+
// For demo, we'll parse from request headers or mock data
|
|
39
|
+
async function getServerConfig(serverId: string, apiKey?: string): Promise<{
|
|
40
|
+
name: string;
|
|
41
|
+
tools: Array<{
|
|
42
|
+
name: string;
|
|
43
|
+
description: string;
|
|
44
|
+
inputSchema: object;
|
|
45
|
+
}>;
|
|
46
|
+
} | null> {
|
|
47
|
+
// Demo: Return mock tools for testing
|
|
48
|
+
// In production: Load from database, verify API key
|
|
49
|
+
|
|
50
|
+
return {
|
|
51
|
+
name: `mcp-server-${serverId}`,
|
|
52
|
+
tools: [
|
|
53
|
+
{
|
|
54
|
+
name: 'echo',
|
|
55
|
+
description: 'Echo back the input message',
|
|
56
|
+
inputSchema: {
|
|
57
|
+
type: 'object',
|
|
58
|
+
properties: {
|
|
59
|
+
message: { type: 'string', description: 'Message to echo' },
|
|
60
|
+
},
|
|
61
|
+
required: ['message'],
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
name: 'get_time',
|
|
66
|
+
description: 'Get the current server time',
|
|
67
|
+
inputSchema: {
|
|
68
|
+
type: 'object',
|
|
69
|
+
properties: {},
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
],
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Execute a tool (in production, this would run sandboxed code)
|
|
77
|
+
async function executeTool(
|
|
78
|
+
toolName: string,
|
|
79
|
+
args: Record<string, unknown>,
|
|
80
|
+
serverId: string
|
|
81
|
+
): Promise<{ result?: unknown; error?: string }> {
|
|
82
|
+
// Demo implementations
|
|
83
|
+
switch (toolName) {
|
|
84
|
+
case 'echo':
|
|
85
|
+
return { result: { message: args.message, echoed: true } };
|
|
86
|
+
|
|
87
|
+
case 'get_time':
|
|
88
|
+
return {
|
|
89
|
+
result: {
|
|
90
|
+
time: new Date().toISOString(),
|
|
91
|
+
timezone: 'UTC',
|
|
92
|
+
serverId,
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
default:
|
|
97
|
+
return { error: `Unknown tool: ${toolName}` };
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* POST /api/mcp/[serverId] - Handle MCP protocol requests
|
|
103
|
+
*/
|
|
104
|
+
export async function POST(
|
|
105
|
+
request: NextRequest,
|
|
106
|
+
{ params }: { params: Promise<{ serverId: string }> }
|
|
107
|
+
): Promise<NextResponse<McpResponse>> {
|
|
108
|
+
const { serverId } = await params;
|
|
109
|
+
const startTime = Date.now();
|
|
110
|
+
|
|
111
|
+
try {
|
|
112
|
+
// Get API key from header
|
|
113
|
+
const apiKey = request.headers.get('Authorization')?.replace('Bearer ', '');
|
|
114
|
+
|
|
115
|
+
// Load server config
|
|
116
|
+
const config = await getServerConfig(serverId, apiKey);
|
|
117
|
+
if (!config) {
|
|
118
|
+
return NextResponse.json({
|
|
119
|
+
jsonrpc: '2.0',
|
|
120
|
+
id: 0,
|
|
121
|
+
error: {
|
|
122
|
+
code: -32001,
|
|
123
|
+
message: 'Server not found or unauthorized',
|
|
124
|
+
},
|
|
125
|
+
}, { status: 404 });
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// Parse MCP request
|
|
129
|
+
const body = await request.json() as McpRequest;
|
|
130
|
+
|
|
131
|
+
// Handle different MCP methods
|
|
132
|
+
switch (body.method) {
|
|
133
|
+
case 'initialize': {
|
|
134
|
+
return NextResponse.json({
|
|
135
|
+
jsonrpc: '2.0',
|
|
136
|
+
id: body.id,
|
|
137
|
+
result: {
|
|
138
|
+
protocolVersion: '2024-11-05',
|
|
139
|
+
serverInfo: {
|
|
140
|
+
name: config.name,
|
|
141
|
+
version: '1.0.0',
|
|
142
|
+
},
|
|
143
|
+
capabilities: {
|
|
144
|
+
tools: {},
|
|
145
|
+
},
|
|
146
|
+
},
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
case 'tools/list': {
|
|
151
|
+
return NextResponse.json({
|
|
152
|
+
jsonrpc: '2.0',
|
|
153
|
+
id: body.id,
|
|
154
|
+
result: {
|
|
155
|
+
tools: config.tools.map(t => ({
|
|
156
|
+
name: t.name,
|
|
157
|
+
description: t.description,
|
|
158
|
+
inputSchema: t.inputSchema,
|
|
159
|
+
})),
|
|
160
|
+
},
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
case 'tools/call': {
|
|
165
|
+
const toolParams = body.params as { name: string; arguments: Record<string, unknown> } | undefined;
|
|
166
|
+
if (!toolParams?.name) {
|
|
167
|
+
return NextResponse.json({
|
|
168
|
+
jsonrpc: '2.0',
|
|
169
|
+
id: body.id,
|
|
170
|
+
error: {
|
|
171
|
+
code: -32602,
|
|
172
|
+
message: 'Missing tool name',
|
|
173
|
+
},
|
|
174
|
+
}, { status: 400 });
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
const { result, error } = await executeTool(
|
|
178
|
+
toolParams.name,
|
|
179
|
+
toolParams.arguments || {},
|
|
180
|
+
serverId
|
|
181
|
+
);
|
|
182
|
+
|
|
183
|
+
if (error) {
|
|
184
|
+
return NextResponse.json({
|
|
185
|
+
jsonrpc: '2.0',
|
|
186
|
+
id: body.id,
|
|
187
|
+
result: {
|
|
188
|
+
content: [{ type: 'text', text: `Error: ${error}` }],
|
|
189
|
+
isError: true,
|
|
190
|
+
},
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
return NextResponse.json({
|
|
195
|
+
jsonrpc: '2.0',
|
|
196
|
+
id: body.id,
|
|
197
|
+
result: {
|
|
198
|
+
content: [{
|
|
199
|
+
type: 'text',
|
|
200
|
+
text: JSON.stringify(result, null, 2),
|
|
201
|
+
}],
|
|
202
|
+
},
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
case 'notifications/initialized': {
|
|
207
|
+
// Acknowledgment, no response needed
|
|
208
|
+
return NextResponse.json({
|
|
209
|
+
jsonrpc: '2.0',
|
|
210
|
+
id: body.id,
|
|
211
|
+
result: {},
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
default: {
|
|
216
|
+
return NextResponse.json({
|
|
217
|
+
jsonrpc: '2.0',
|
|
218
|
+
id: body.id,
|
|
219
|
+
error: {
|
|
220
|
+
code: -32601,
|
|
221
|
+
message: `Method not found: ${body.method}`,
|
|
222
|
+
},
|
|
223
|
+
}, { status: 400 });
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
} catch (error) {
|
|
227
|
+
console.error(`MCP error for server ${serverId}:`, error);
|
|
228
|
+
return NextResponse.json({
|
|
229
|
+
jsonrpc: '2.0',
|
|
230
|
+
id: 0,
|
|
231
|
+
error: {
|
|
232
|
+
code: -32603,
|
|
233
|
+
message: error instanceof Error ? error.message : 'Internal error',
|
|
234
|
+
},
|
|
235
|
+
}, { status: 500 });
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* GET /api/mcp/[serverId] - Server info endpoint
|
|
241
|
+
*/
|
|
242
|
+
export async function GET(
|
|
243
|
+
request: NextRequest,
|
|
244
|
+
{ params }: { params: Promise<{ serverId: string }> }
|
|
245
|
+
): Promise<NextResponse> {
|
|
246
|
+
const { serverId } = await params;
|
|
247
|
+
const config = await getServerConfig(serverId);
|
|
248
|
+
|
|
249
|
+
if (!config) {
|
|
250
|
+
return NextResponse.json({ error: 'Server not found' }, { status: 404 });
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
return NextResponse.json({
|
|
254
|
+
name: config.name,
|
|
255
|
+
serverId,
|
|
256
|
+
status: 'active',
|
|
257
|
+
toolCount: config.tools.length,
|
|
258
|
+
tools: config.tools.map(t => t.name),
|
|
259
|
+
endpoint: `${process.env.NEXT_PUBLIC_APP_URL || ''}/api/mcp/${serverId}`,
|
|
260
|
+
protocol: 'MCP 2024-11-05',
|
|
261
|
+
transport: 'HTTP/POST',
|
|
262
|
+
});
|
|
263
|
+
}
|