raiton 6.8.8-beta.24 → 6.10.0-beta.28
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/CHANGELOG.md +50 -0
- package/README.md +46 -1
- package/benchmarks/README.md +16 -0
- package/benchmarks/latest.json +172 -0
- package/benchmarks/latest.md +66 -0
- package/build/bin/index.mjs +33575 -21723
- package/build/types/bin/bootstrapper.d.ts +2 -0
- package/build/types/bin/cli-output.d.ts +46 -0
- package/build/types/bin/cli-tools.d.ts +13 -0
- package/build/types/bin/cli.d.ts +3 -0
- package/build/types/bin/commands.registry.d.ts +4 -0
- package/build/types/bin/constants.d.ts +3 -0
- package/build/types/bin/file-utils.d.ts +21 -0
- package/build/types/bin/index.d.ts +2 -0
- package/build/types/bin/name-utils.d.ts +4 -0
- package/build/types/bin/project-utils.d.ts +12 -0
- package/build/types/commands/artifact.command.d.ts +7 -0
- package/build/types/commands/build.command.d.ts +8 -0
- package/build/types/commands/client.command.d.ts +7 -0
- package/build/types/commands/contract.command.d.ts +8 -0
- package/build/types/commands/develop.command.d.ts +9 -0
- package/build/types/commands/docs.command.d.ts +8 -0
- package/build/types/commands/doctor.command.d.ts +9 -0
- package/build/types/commands/generate.command.d.ts +7 -0
- package/build/types/commands/inspect.command.d.ts +7 -0
- package/build/types/commands/mcp.command.d.ts +11 -0
- package/build/types/commands/new.command.d.ts +7 -0
- package/build/types/commands/openapi.command.d.ts +7 -0
- package/build/types/commands/routes.command.d.ts +7 -0
- package/build/types/commands/start.command.d.ts +9 -0
- package/build/types/commands/why.command.d.ts +7 -0
- package/build/types/contracts/decorators.d.ts +41 -0
- package/build/types/contracts/errors.d.ts +42 -0
- package/build/types/contracts/index.d.ts +4 -0
- package/build/types/contracts/schema.d.ts +70 -0
- package/build/types/contracts/typebox.d.ts +81 -0
- package/build/types/core/application.d.ts +37 -0
- package/build/types/core/artifacts/artifact.d.ts +3 -0
- package/build/types/core/artifacts/index.d.ts +1 -0
- package/build/types/core/artifacts/runner.d.ts +1 -0
- package/build/types/core/builder.d.ts +42 -0
- package/build/types/core/bytes.util.d.ts +3 -0
- package/build/types/core/command.d.ts +13 -0
- package/build/types/core/commands.d.ts +10 -0
- package/build/types/core/config/config.d.ts +27 -0
- package/build/types/core/config/define.d.ts +8 -0
- package/build/types/core/config/index.d.ts +3 -0
- package/build/types/core/config/schema.d.ts +24 -0
- package/build/types/core/context.d.ts +11 -0
- package/build/types/core/controller/builder.d.ts +26 -0
- package/build/types/core/controller/compiler.d.ts +2 -0
- package/build/types/core/controller/index.d.ts +4 -0
- package/build/types/core/controller/metadata.d.ts +3 -0
- package/build/types/core/controller/tracker.d.ts +9 -0
- package/build/types/core/directories.d.ts +10 -0
- package/build/types/core/guards.d.ts +11 -0
- package/build/types/core/helpers/index.d.ts +1 -0
- package/build/types/core/helpers/raiton.d.ts +1 -0
- package/build/types/core/hooks.d.ts +14 -0
- package/build/types/core/index.d.ts +17 -0
- package/build/types/core/injection/index.d.ts +1 -0
- package/build/types/core/injection/injection.d.ts +37 -0
- package/build/types/core/mcp/builder.d.ts +2 -0
- package/build/types/core/mcp/index.d.ts +3 -0
- package/build/types/core/mcp/metadata.d.ts +9 -0
- package/build/types/core/mcp/tracker.d.ts +9 -0
- package/build/types/core/middleware/compose.d.ts +8 -0
- package/build/types/core/middleware/index.d.ts +2 -0
- package/build/types/core/middleware/pipeline.d.ts +12 -0
- package/build/types/core/plugins/index.d.ts +2 -0
- package/build/types/core/plugins/plugin.d.ts +2 -0
- package/build/types/core/plugins/scope.d.ts +15 -0
- package/build/types/core/process.util.d.ts +1 -0
- package/build/types/core/raiton.d.ts +15 -0
- package/build/types/core/router/handler.d.ts +2 -0
- package/build/types/core/router/handler.utils.d.ts +37 -0
- package/build/types/core/router/index.d.ts +4 -0
- package/build/types/core/router/matcher.d.ts +50 -0
- package/build/types/core/router/route.d.ts +52 -0
- package/build/types/core/router/router.d.ts +23 -0
- package/build/types/core/scheduler/builder.d.ts +2 -0
- package/build/types/core/scheduler/cron.d.ts +32 -0
- package/build/types/core/scheduler/duration.d.ts +7 -0
- package/build/types/core/scheduler/index.d.ts +6 -0
- package/build/types/core/scheduler/manager.d.ts +47 -0
- package/build/types/core/scheduler/metadata.d.ts +8 -0
- package/build/types/core/scheduler/queue/backend.d.ts +42 -0
- package/build/types/core/scheduler/queue/index.d.ts +3 -0
- package/build/types/core/scheduler/queue/rabbitmq.backend.d.ts +37 -0
- package/build/types/core/scheduler/queue/redis.backend.d.ts +38 -0
- package/build/types/core/server.d.ts +9 -0
- package/build/types/core/socket/builder.d.ts +1 -0
- package/build/types/core/socket/index.d.ts +2 -0
- package/build/types/core/socket/metadata.d.ts +14 -0
- package/build/types/core/thread.d.ts +21 -0
- package/build/types/framework/artifacts.d.ts +20 -0
- package/build/types/framework/cache/cache.d.ts +84 -0
- package/build/types/framework/cache/cache.decorator.d.ts +21 -0
- package/build/types/framework/cache/etag.d.ts +62 -0
- package/build/types/framework/cache/index.d.ts +4 -0
- package/build/types/framework/cache/types.d.ts +89 -0
- package/build/types/framework/constants/decorators.constant.d.ts +28 -0
- package/build/types/framework/constants/index.d.ts +2 -0
- package/build/types/framework/constants/microservices.constant.d.ts +3 -0
- package/build/types/framework/controllers.d.ts +2 -0
- package/build/types/framework/data-transfer-object.d.ts +5 -0
- package/build/types/framework/decorators/access-guard.decorator.d.ts +1 -0
- package/build/types/framework/decorators/api-response.decorator.d.ts +66 -0
- package/build/types/framework/decorators/api.decorator.d.ts +160 -0
- package/build/types/framework/decorators/controllable.decorator.d.ts +3 -0
- package/build/types/framework/decorators/csrf-guard.decorator.d.ts +2 -0
- package/build/types/framework/decorators/csrf-token.decorator.d.ts +1 -0
- package/build/types/framework/decorators/guard.decorator.d.ts +2 -0
- package/build/types/framework/decorators/health-check.decorator.d.ts +17 -0
- package/build/types/framework/decorators/index.d.ts +15 -0
- package/build/types/framework/decorators/injection.decorator.d.ts +5 -0
- package/build/types/framework/decorators/mcp.decorator.d.ts +68 -0
- package/build/types/framework/decorators/middleware.decorator.d.ts +3 -0
- package/build/types/framework/decorators/parametrable.decorator.d.ts +9 -0
- package/build/types/framework/decorators/routable.decorator.d.ts +12 -0
- package/build/types/framework/decorators/route-interaction.decorator.d.ts +81 -0
- package/build/types/framework/decorators/scheduler.decorator.d.ts +54 -0
- package/build/types/framework/decorators/socket.decorator.d.ts +5 -0
- package/build/types/framework/encryption.d.ts +25 -0
- package/build/types/framework/enums/csrf.enum.d.ts +4 -0
- package/build/types/framework/enums/encrypted.enum.d.ts +20 -0
- package/build/types/framework/enums/event.message.enum.d.ts +4 -0
- package/build/types/framework/enums/http-method.enum.d.ts +10 -0
- package/build/types/framework/enums/http-parameters.enum.d.ts +11 -0
- package/build/types/framework/enums/http-status.enum.d.ts +64 -0
- package/build/types/framework/enums/index.d.ts +9 -0
- package/build/types/framework/enums/runtime.enum.d.ts +5 -0
- package/build/types/framework/enums/scheduler.enum.d.ts +21 -0
- package/build/types/framework/enums/timestamp.enum.d.ts +6 -0
- package/build/types/framework/env.d.ts +3 -0
- package/build/types/framework/errors/catalog.d.ts +42 -0
- package/build/types/framework/exceptions/http-exception.d.ts +18 -0
- package/build/types/framework/exceptions/index.d.ts +2 -0
- package/build/types/framework/exceptions/throwable.d.ts +76 -0
- package/build/types/framework/health-check.d.ts +42 -0
- package/build/types/framework/index.d.ts +20 -0
- package/build/types/framework/mcp/audit.d.ts +12 -0
- package/build/types/framework/mcp/conformance.d.ts +31 -0
- package/build/types/framework/mcp/handler.d.ts +11 -0
- package/build/types/framework/mcp/index.d.ts +5 -0
- package/build/types/framework/mcp/protocol.d.ts +17 -0
- package/build/types/framework/mcp/rate-limit.d.ts +10 -0
- package/build/types/framework/mcp/stdio.d.ts +40 -0
- package/build/types/framework/mcp/streamable-http.d.ts +17 -0
- package/build/types/framework/observability/index.d.ts +6 -0
- package/build/types/framework/observability/metrics.d.ts +23 -0
- package/build/types/framework/observability/plugin.d.ts +20 -0
- package/build/types/framework/observability/readiness.d.ts +9 -0
- package/build/types/framework/observability/request.d.ts +7 -0
- package/build/types/framework/observability/shutdown.d.ts +21 -0
- package/build/types/framework/observability/trace.d.ts +96 -0
- package/build/types/framework/parameter-bag.d.ts +14 -0
- package/build/types/framework/plugins/body-parser.plugin.d.ts +3 -0
- package/build/types/framework/plugins/dev.plugin.d.ts +12 -0
- package/build/types/framework/plugins/index.d.ts +5 -0
- package/build/types/framework/plugins/mcp.plugin.d.ts +15 -0
- package/build/types/framework/plugins/openapi.plugin.d.ts +58 -0
- package/build/types/framework/plugins/security/body-limit.d.ts +1 -0
- package/build/types/framework/plugins/security/cors.d.ts +10 -0
- package/build/types/framework/plugins/security/csrf.d.ts +2 -0
- package/build/types/framework/plugins/security/headers.d.ts +1 -0
- package/build/types/framework/plugins/security/index.d.ts +13 -0
- package/build/types/framework/plugins/security/method-guard.d.ts +1 -0
- package/build/types/framework/plugins/security/rate-limit.d.ts +5 -0
- package/build/types/framework/repositories.d.ts +5 -0
- package/build/types/framework/responses/error.d.ts +13 -0
- package/build/types/framework/responses/helpers.d.ts +7 -0
- package/build/types/framework/responses/http-throwable.d.ts +14 -0
- package/build/types/framework/responses/http.d.ts +13 -0
- package/build/types/framework/responses/index.d.ts +4 -0
- package/build/types/framework/runtime/bun/server.d.ts +2 -0
- package/build/types/framework/runtime/deno/server.d.ts +2 -0
- package/build/types/framework/runtime/index.d.ts +17 -0
- package/build/types/framework/runtime/node/reply.d.ts +12 -0
- package/build/types/framework/runtime/node/request.d.ts +33 -0
- package/build/types/framework/runtime/node/server.d.ts +2 -0
- package/build/types/framework/runtime/web/server.d.ts +1 -0
- package/build/types/framework/services.d.ts +5 -0
- package/build/types/framework/utilities/alias-path.util.d.ts +1 -0
- package/build/types/framework/utilities/artifact.util.d.ts +7 -0
- package/build/types/framework/utilities/callable.util.d.ts +1 -0
- package/build/types/framework/utilities/cookie.util.d.ts +1 -0
- package/build/types/framework/utilities/csrf.util.d.ts +26 -0
- package/build/types/framework/utilities/https.util.d.ts +49 -0
- package/build/types/framework/utilities/index.d.ts +12 -0
- package/build/types/framework/utilities/ip.util.d.ts +15 -0
- package/build/types/framework/utilities/json.util.d.ts +10 -0
- package/build/types/framework/utilities/openapi.utils.d.ts +7 -0
- package/build/types/framework/utilities/openapi.utils.impl.d.ts +18 -0
- package/build/types/framework/utilities/path.util.d.ts +3 -0
- package/build/types/framework/utilities/route-suggestion.util.d.ts +10 -0
- package/build/types/framework/utilities/url.util.d.ts +1 -0
- package/build/types/framework/utilities/utilities.util.d.ts +3 -0
- package/build/types/framework/utilities/validation.util.d.ts +8 -0
- package/build/types/framework/view-model.d.ts +4 -0
- package/build/types/generators/artifact.templates.d.ts +7 -0
- package/build/types/generators/index.d.ts +2 -0
- package/build/types/generators/project.templates.d.ts +21 -0
- package/build/types/manifest/client.d.ts +12 -0
- package/build/types/manifest/contract.d.ts +25 -0
- package/build/types/manifest/index.d.ts +5 -0
- package/build/types/manifest/introspect.d.ts +18 -0
- package/build/types/manifest/manifest.d.ts +18 -0
- package/build/types/manifest/schema.d.ts +177 -0
- package/build/types/requirements.d.ts +1 -0
- package/build/types/types/access-guards.d.ts +4 -0
- package/build/types/types/application.d.ts +32 -0
- package/build/types/types/artifact.d.ts +8 -0
- package/build/types/types/builder.d.ts +37 -0
- package/build/types/types/config.d.ts +62 -0
- package/build/types/types/controller.d.ts +27 -0
- package/build/types/types/contruct.d.ts +1 -0
- package/build/types/types/core.d.ts +11 -0
- package/build/types/types/csrf.d.ts +33 -0
- package/build/types/types/directory.d.ts +6 -0
- package/build/types/types/encryption.d.ts +14 -0
- package/build/types/types/generic.d.ts +2 -0
- package/build/types/types/guard.d.ts +9 -0
- package/build/types/types/http-responses.d.ts +7 -0
- package/build/types/types/index.d.ts +27 -0
- package/build/types/types/injection.d.ts +11 -0
- package/build/types/types/lifecycle.d.ts +9 -0
- package/build/types/types/mcp.d.ts +148 -0
- package/build/types/types/middleware.d.ts +12 -0
- package/build/types/types/parseable.d.ts +3 -0
- package/build/types/types/plugin.d.ts +6 -0
- package/build/types/types/raiton.d.ts +13 -0
- package/build/types/types/responses.d.ts +20 -0
- package/build/types/types/router.d.ts +13 -0
- package/build/types/types/runtime.d.ts +48 -0
- package/build/types/types/scheduler.d.ts +140 -0
- package/build/types/types/scheme.d.ts +125 -0
- package/build/types/types/server.d.ts +10 -0
- package/build/types/types/socket.d.ts +11 -0
- package/build/types/types/thread.d.ts +25 -0
- package/build/types/types/utilities.d.ts +4 -0
- package/build/types/types/values.d.ts +2 -0
- package/docs/AGENTS.md +55 -0
- package/docs/CLAUDE.md +55 -0
- package/docs/README.md +5 -0
- package/docs/contributors/cli/README.md +17 -3
- package/docs/contributors/cli/commands.md +28 -17
- package/docs/contributors/framework/plugins/openapi.md +12 -3
- package/docs/generated/cli/commands.md +26 -0
- package/docs/generated/config-schema.json +150 -0
- package/docs/generated/manifest-schema.json +236 -0
- package/docs/generated/manifest.json +101 -0
- package/docs/llms-full.txt +1271 -0
- package/docs/llms.txt +46 -0
- package/docs/user-guide/README.md +18 -12
- package/docs/user-guide/cli.md +21 -0
- package/docs/user-guide/config.md +14 -0
- package/docs/user-guide/contracts.md +67 -0
- package/docs/user-guide/en/README.md +83 -0
- package/docs/user-guide/getting-started.md +13 -1
- package/docs/user-guide/mcp.md +45 -2
- package/docs/user-guide/observability.md +74 -0
- package/docs/user-guide/openapi/plugin.md +10 -0
- package/docs/user-guide/recipes/README.md +32 -0
- package/docs/user-guide/recipes/contracts.md +52 -0
- package/docs/user-guide/recipes/doctor.md +16 -0
- package/docs/user-guide/recipes/generate.md +28 -0
- package/docs/user-guide/recipes/manifest.md +17 -0
- package/docs/user-guide/recipes/mcp-stdio.md +35 -0
- package/docs/user-guide/recipes/new-project.md +34 -0
- package/docs/user-guide/recipes/observability.md +17 -0
- package/package.json +40 -7
- package/scripts/bench.ts +586 -0
- package/scripts/postinstall.mjs +15 -0
- package/source/bin/cli-output.ts +139 -0
- package/source/bin/commands.registry.ts +23 -3
- package/source/bin/file-utils.ts +95 -0
- package/source/bin/name-utils.ts +26 -0
- package/source/bin/project-utils.ts +78 -0
- package/source/commands/artifact.command.ts +30 -15
- package/source/commands/client.command.ts +64 -0
- package/source/commands/contract.command.ts +104 -0
- package/source/commands/docs.command.ts +263 -0
- package/source/commands/doctor.command.ts +226 -0
- package/source/commands/generate.command.ts +58 -0
- package/source/commands/inspect.command.ts +108 -0
- package/source/commands/mcp.command.ts +258 -0
- package/source/commands/new.command.ts +135 -0
- package/source/commands/openapi.command.ts +95 -0
- package/source/commands/routes.command.ts +39 -0
- package/source/commands/why.command.ts +61 -0
- package/source/contracts/decorators.ts +151 -0
- package/source/contracts/errors.ts +76 -0
- package/source/contracts/index.ts +4 -0
- package/source/contracts/schema.ts +377 -0
- package/source/contracts/typebox.ts +193 -0
- package/source/core/application.ts +215 -73
- package/source/core/builder.ts +6 -2
- package/source/core/config/config.ts +144 -26
- package/source/core/config/define.ts +35 -8
- package/source/core/config/index.ts +2 -1
- package/source/core/config/schema.ts +263 -0
- package/source/core/controller/builder.ts +38 -13
- package/source/core/controller/compiler.ts +14 -7
- package/source/core/controller/metadata.ts +1 -1
- package/source/core/hooks.ts +13 -1
- package/source/core/injection/injection.ts +47 -9
- package/source/core/mcp/builder.ts +13 -2
- package/source/core/mcp/metadata.ts +2 -1
- package/source/core/middleware/compose.ts +48 -0
- package/source/core/middleware/pipeline.ts +69 -46
- package/source/core/raiton.ts +8 -0
- package/source/core/router/handler.ts +91 -31
- package/source/core/router/handler.utils.ts +107 -51
- package/source/core/router/matcher.ts +195 -24
- package/source/core/router/route.ts +100 -31
- package/source/core/router/router.ts +27 -2
- package/source/core/scheduler/metadata.ts +1 -1
- package/source/core/socket/metadata.ts +1 -1
- package/source/core/thread.ts +37 -2
- package/source/framework/artifacts.ts +92 -19
- package/source/framework/cache/cache.ts +48 -3
- package/source/framework/constants/decorators.constant.ts +5 -0
- package/source/framework/data-transfer-object.ts +4 -3
- package/source/framework/decorators/controllable.decorator.ts +3 -3
- package/source/framework/decorators/csrf-guard.decorator.ts +3 -2
- package/source/framework/decorators/csrf-token.decorator.ts +1 -1
- package/source/framework/decorators/guard.decorator.ts +3 -2
- package/source/framework/decorators/health-check.decorator.ts +1 -1
- package/source/framework/decorators/mcp.decorator.ts +38 -7
- package/source/framework/decorators/middleware.decorator.ts +2 -2
- package/source/framework/decorators/parametrable.decorator.ts +2 -1
- package/source/framework/decorators/routable.decorator.ts +3 -3
- package/source/framework/decorators/route-interaction.decorator.ts +2 -2
- package/source/framework/decorators/scheduler.decorator.ts +3 -3
- package/source/framework/decorators/socket.decorator.ts +3 -3
- package/source/framework/encryption.ts +46 -7
- package/source/framework/errors/catalog.ts +159 -0
- package/source/framework/exceptions/http-exception.ts +1 -1
- package/source/framework/health-check.ts +18 -0
- package/source/framework/index.ts +2 -0
- package/source/framework/mcp/audit.ts +57 -0
- package/source/framework/mcp/conformance.ts +195 -0
- package/source/framework/mcp/handler.ts +131 -9
- package/source/framework/mcp/index.ts +6 -1
- package/source/framework/mcp/protocol.ts +6 -0
- package/source/framework/mcp/rate-limit.ts +33 -0
- package/source/framework/mcp/stdio.ts +150 -0
- package/source/framework/mcp/streamable-http.ts +36 -5
- package/source/framework/observability/index.ts +6 -0
- package/source/framework/observability/metrics.ts +162 -0
- package/source/framework/observability/plugin.ts +151 -0
- package/source/framework/observability/readiness.ts +22 -0
- package/source/framework/observability/request.ts +31 -0
- package/source/framework/observability/shutdown.ts +68 -0
- package/source/framework/observability/trace.ts +241 -0
- package/source/framework/plugins/body-parser.plugin.ts +88 -85
- package/source/framework/plugins/dev.plugin.ts +227 -0
- package/source/framework/plugins/index.ts +2 -1
- package/source/framework/plugins/mcp.plugin.ts +14 -3
- package/source/framework/plugins/openapi.plugin.ts +56 -13
- package/source/framework/responses/helpers.ts +4 -4
- package/source/framework/responses/http-throwable.ts +1 -1
- package/source/framework/runtime/bun/server.ts +2 -1
- package/source/framework/runtime/deno/server.ts +2 -1
- package/source/framework/runtime/index.ts +45 -13
- package/source/framework/runtime/node/request.ts +59 -13
- package/source/framework/utilities/index.ts +3 -1
- package/source/framework/utilities/openapi.utils.impl.ts +705 -0
- package/source/framework/utilities/openapi.utils.ts +6 -636
- package/source/framework/utilities/route-suggestion.util.ts +59 -0
- package/source/framework/utilities/validation.util.ts +20 -0
- package/source/generators/artifact.templates.ts +230 -0
- package/source/generators/index.ts +2 -0
- package/source/generators/project.templates.ts +392 -0
- package/source/manifest/client.ts +299 -0
- package/source/manifest/contract.ts +138 -0
- package/source/manifest/index.ts +5 -0
- package/source/manifest/introspect.ts +52 -0
- package/source/manifest/manifest.ts +341 -0
- package/source/manifest/schema.ts +149 -0
- package/source/types/builder.ts +5 -0
- package/source/types/config.ts +64 -2
- package/source/types/mcp.ts +63 -1
- package/tsconfig.build.json +13 -0
- package/source/commands/grafts.command.ts +0 -27
- package/tests/artifact-resolution.test.ts +0 -60
|
@@ -1,8 +1,41 @@
|
|
|
1
1
|
import crypto from "node:crypto";
|
|
2
|
-
import
|
|
2
|
+
import type {Options} from "argon2";
|
|
3
3
|
import {HashAlgoEnum, PasswordAlgoEnum} from "./enums/index.ts";
|
|
4
|
-
import
|
|
5
|
-
|
|
4
|
+
import type {DerivationOptionsInterface, EncryptionResultType, ScryptOptionsInterface} from "../types/index.ts";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Optional password hashing dependencies are loaded lazily: importing the
|
|
8
|
+
* framework entry must not pay for argon2/bcrypt when the application never
|
|
9
|
+
* hashes passwords.
|
|
10
|
+
*/
|
|
11
|
+
let argon2Module: Promise<any> | undefined
|
|
12
|
+
let bcryptModule: Promise<any> | undefined
|
|
13
|
+
|
|
14
|
+
function loadArgon2(): Promise<any> {
|
|
15
|
+
return (argon2Module ??= import("argon2")
|
|
16
|
+
.then(module => (module as any).default ?? module)
|
|
17
|
+
.catch((error: any) => {
|
|
18
|
+
argon2Module = undefined
|
|
19
|
+
throw new Error(
|
|
20
|
+
'Argon2 requires the optional "argon2" package. ' +
|
|
21
|
+
'Install it with `bun add argon2` or `npm install argon2`. ' +
|
|
22
|
+
`Original error: ${error?.message ?? error}`
|
|
23
|
+
)
|
|
24
|
+
}))
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function loadBcrypt(): Promise<any> {
|
|
28
|
+
return (bcryptModule ??= import("bcrypt")
|
|
29
|
+
.then(module => (module as any).default ?? module)
|
|
30
|
+
.catch((error: any) => {
|
|
31
|
+
bcryptModule = undefined
|
|
32
|
+
throw new Error(
|
|
33
|
+
'Bcrypt requires the optional "bcrypt" package. ' +
|
|
34
|
+
'Install it with `bun add bcrypt` or `npm install bcrypt`. ' +
|
|
35
|
+
`Original error: ${error?.message ?? error}`
|
|
36
|
+
)
|
|
37
|
+
}))
|
|
38
|
+
}
|
|
6
39
|
|
|
7
40
|
export class Encryption {
|
|
8
41
|
static get algos() {
|
|
@@ -124,6 +157,7 @@ export class Encryption {
|
|
|
124
157
|
}) | (string | number) | undefined): Promise<EncryptionResultType> {
|
|
125
158
|
switch (this.algo) {
|
|
126
159
|
case HashAlgoEnum.ARGON2ID: {
|
|
160
|
+
const argon2 = await loadArgon2()
|
|
127
161
|
return await argon2.hash(value, {
|
|
128
162
|
...(typeof options === 'object' ? options : {}),
|
|
129
163
|
type: argon2.argon2id
|
|
@@ -131,13 +165,14 @@ export class Encryption {
|
|
|
131
165
|
}
|
|
132
166
|
case HashAlgoEnum.BCRYPT: {
|
|
133
167
|
try {
|
|
168
|
+
const bcrypt = await loadBcrypt()
|
|
134
169
|
const saltRounds = 12;
|
|
135
170
|
return await bcrypt.hash(
|
|
136
171
|
value,
|
|
137
172
|
(typeof options === 'string' || typeof options === 'number') ? options : saltRounds
|
|
138
173
|
);
|
|
139
|
-
} catch (e) {
|
|
140
|
-
throw new Error(`BCRYPT not supported without optional dependency "bcrypt"`);
|
|
174
|
+
} catch (e: any) {
|
|
175
|
+
throw new Error(`BCRYPT not supported without optional dependency "bcrypt": ${e?.message ?? e}`);
|
|
141
176
|
}
|
|
142
177
|
}
|
|
143
178
|
default:
|
|
@@ -147,10 +182,14 @@ export class Encryption {
|
|
|
147
182
|
|
|
148
183
|
async checkPassword(hash: string, password: string): Promise<boolean> {
|
|
149
184
|
switch (this.algo) {
|
|
150
|
-
case HashAlgoEnum.ARGON2ID:
|
|
185
|
+
case HashAlgoEnum.ARGON2ID: {
|
|
186
|
+
const argon2 = await loadArgon2()
|
|
151
187
|
return await argon2.verify(hash, password);
|
|
152
|
-
|
|
188
|
+
}
|
|
189
|
+
case HashAlgoEnum.BCRYPT: {
|
|
190
|
+
const bcrypt = await loadBcrypt()
|
|
153
191
|
return await bcrypt.compare(password, hash);
|
|
192
|
+
}
|
|
154
193
|
}
|
|
155
194
|
return false;
|
|
156
195
|
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import {HttpStatus} from "../enums/index.ts";
|
|
2
|
+
|
|
3
|
+
export interface ErrorCatalogEntry {
|
|
4
|
+
code: string;
|
|
5
|
+
status: HttpStatus;
|
|
6
|
+
message: string;
|
|
7
|
+
docsPath: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const DOCS_BASE = "https://github.com/protorians/raiton/blob/main/docs";
|
|
11
|
+
|
|
12
|
+
export function errorDocsUrl(path: string): string {
|
|
13
|
+
return `${DOCS_BASE}/${path.replace(/^\//, "")}`;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Stable public error catalogue. Codes never change once published; new codes
|
|
18
|
+
* are additive and documented before release.
|
|
19
|
+
*/
|
|
20
|
+
export const ERROR_CATALOG: Record<string, ErrorCatalogEntry> = {
|
|
21
|
+
BAD_REQUEST: {
|
|
22
|
+
code: "BAD_REQUEST",
|
|
23
|
+
status: HttpStatus.BAD_REQUEST,
|
|
24
|
+
message: "Bad request",
|
|
25
|
+
docsPath: "user-guide/responses.md",
|
|
26
|
+
},
|
|
27
|
+
VALIDATION_ERROR: {
|
|
28
|
+
code: "VALIDATION_ERROR",
|
|
29
|
+
status: HttpStatus.BAD_REQUEST,
|
|
30
|
+
message: "Invalid request",
|
|
31
|
+
docsPath: "user-guide/recipes/contracts.md",
|
|
32
|
+
},
|
|
33
|
+
OUTPUT_VALIDATION_ERROR: {
|
|
34
|
+
code: "OUTPUT_VALIDATION_ERROR",
|
|
35
|
+
status: HttpStatus.INTERNAL_SERVER_ERROR,
|
|
36
|
+
message: "Response does not match its contract",
|
|
37
|
+
docsPath: "user-guide/recipes/contracts.md",
|
|
38
|
+
},
|
|
39
|
+
UNAUTHORIZED: {
|
|
40
|
+
code: "UNAUTHORIZED",
|
|
41
|
+
status: HttpStatus.UNAUTHORIZED,
|
|
42
|
+
message: "Unauthorized",
|
|
43
|
+
docsPath: "user-guide/security.md",
|
|
44
|
+
},
|
|
45
|
+
FORBIDDEN: {
|
|
46
|
+
code: "FORBIDDEN",
|
|
47
|
+
status: HttpStatus.FORBIDDEN,
|
|
48
|
+
message: "Forbidden",
|
|
49
|
+
docsPath: "user-guide/security.md",
|
|
50
|
+
},
|
|
51
|
+
NOT_FOUND: {
|
|
52
|
+
code: "NOT_FOUND",
|
|
53
|
+
status: HttpStatus.NOT_FOUND,
|
|
54
|
+
message: "Not found",
|
|
55
|
+
docsPath: "user-guide/api/routes.md",
|
|
56
|
+
},
|
|
57
|
+
METHOD_NOT_ALLOWED: {
|
|
58
|
+
code: "METHOD_NOT_ALLOWED",
|
|
59
|
+
status: HttpStatus.METHOD_NOT_ALLOWED,
|
|
60
|
+
message: "Method not allowed",
|
|
61
|
+
docsPath: "user-guide/api/routes.md",
|
|
62
|
+
},
|
|
63
|
+
CONFLICT: {
|
|
64
|
+
code: "CONFLICT",
|
|
65
|
+
status: HttpStatus.CONFLICT,
|
|
66
|
+
message: "Conflict",
|
|
67
|
+
docsPath: "user-guide/responses.md",
|
|
68
|
+
},
|
|
69
|
+
RATE_LIMITED: {
|
|
70
|
+
code: "RATE_LIMITED",
|
|
71
|
+
status: HttpStatus.TOO_MANY_REQUESTS,
|
|
72
|
+
message: "Too many requests",
|
|
73
|
+
docsPath: "user-guide/security.md",
|
|
74
|
+
},
|
|
75
|
+
INTERNAL_SERVER_ERROR: {
|
|
76
|
+
code: "INTERNAL_SERVER_ERROR",
|
|
77
|
+
status: HttpStatus.INTERNAL_SERVER_ERROR,
|
|
78
|
+
message: "Internal server error",
|
|
79
|
+
docsPath: "user-guide/responses.md",
|
|
80
|
+
},
|
|
81
|
+
SERVICE_UNAVAILABLE: {
|
|
82
|
+
code: "SERVICE_UNAVAILABLE",
|
|
83
|
+
status: HttpStatus.SERVICE_UNAVAILABLE,
|
|
84
|
+
message: "Service unavailable",
|
|
85
|
+
docsPath: "user-guide/health-check.md",
|
|
86
|
+
},
|
|
87
|
+
CONFIGURATION_ERROR: {
|
|
88
|
+
code: "CONFIGURATION_ERROR",
|
|
89
|
+
status: HttpStatus.INTERNAL_SERVER_ERROR,
|
|
90
|
+
message: "Invalid application configuration",
|
|
91
|
+
docsPath: "user-guide/config.md",
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
export interface ErrorPayloadOptions {
|
|
96
|
+
message?: string;
|
|
97
|
+
details?: any;
|
|
98
|
+
requestId?: string;
|
|
99
|
+
statusCode?: number;
|
|
100
|
+
docsUrl?: string;
|
|
101
|
+
data?: any;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Build a stable error body. In production it never contains a stack trace or
|
|
106
|
+
* internal detail beyond the catalogue entry and validated public fields.
|
|
107
|
+
*/
|
|
108
|
+
export function errorPayload(code: string, options: ErrorPayloadOptions = {}) {
|
|
109
|
+
const entry = ERROR_CATALOG[code] ?? ERROR_CATALOG.INTERNAL_SERVER_ERROR;
|
|
110
|
+
return {
|
|
111
|
+
error: true,
|
|
112
|
+
code: entry.code,
|
|
113
|
+
statusCode: options.statusCode ?? entry.status,
|
|
114
|
+
message: options.message ?? entry.message,
|
|
115
|
+
docsUrl: options.docsUrl ?? errorDocsUrl(entry.docsPath),
|
|
116
|
+
...(options.requestId ? {requestId: options.requestId} : {}),
|
|
117
|
+
...(options.details !== undefined ? {details: options.details} : {}),
|
|
118
|
+
...(options.data !== undefined ? {data: options.data} : {}),
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export function catalogEntry(code: string): ErrorCatalogEntry {
|
|
123
|
+
return ERROR_CATALOG[code] ?? ERROR_CATALOG.INTERNAL_SERVER_ERROR;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const STATUS_TO_CODE: Record<number, string> = {
|
|
127
|
+
400: "BAD_REQUEST",
|
|
128
|
+
401: "UNAUTHORIZED",
|
|
129
|
+
403: "FORBIDDEN",
|
|
130
|
+
404: "NOT_FOUND",
|
|
131
|
+
405: "METHOD_NOT_ALLOWED",
|
|
132
|
+
409: "CONFLICT",
|
|
133
|
+
429: "RATE_LIMITED",
|
|
134
|
+
500: "INTERNAL_SERVER_ERROR",
|
|
135
|
+
503: "SERVICE_UNAVAILABLE",
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
export function codeForStatus(status: number): string {
|
|
139
|
+
return STATUS_TO_CODE[status] ?? "INTERNAL_SERVER_ERROR";
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Enrich a legacy exception payload with the stable catalogue fields without
|
|
144
|
+
* removing existing fields (backward-compatible additive change).
|
|
145
|
+
*/
|
|
146
|
+
export function enrichErrorPayload(payload: any, statusCode?: number, requestId?: string) {
|
|
147
|
+
const code = payload?.code
|
|
148
|
+
?? (typeof payload?.errorCode === "string" ? payload.errorCode : undefined)
|
|
149
|
+
?? codeForStatus(statusCode ?? payload?.statusCode ?? 500);
|
|
150
|
+
const known = ERROR_CATALOG[code];
|
|
151
|
+
const fallback = catalogEntry(codeForStatus(statusCode ?? payload?.statusCode ?? 500));
|
|
152
|
+
return {
|
|
153
|
+
...payload,
|
|
154
|
+
code: known?.code ?? code,
|
|
155
|
+
statusCode: payload?.statusCode ?? statusCode ?? known?.status ?? fallback.status,
|
|
156
|
+
docsUrl: payload?.docsUrl ?? errorDocsUrl(known?.docsPath ?? fallback.docsPath),
|
|
157
|
+
...(requestId ? {requestId} : {}),
|
|
158
|
+
};
|
|
159
|
+
}
|
|
@@ -2,6 +2,7 @@ import {HttpStatus, HttpMethod} from "./enums/index.ts";
|
|
|
2
2
|
import {RaitonResponses} from "./responses/helpers.ts";
|
|
3
3
|
import {ApplicationInterface} from "../types/application.ts";
|
|
4
4
|
import {RequestContext} from "../core/context.ts";
|
|
5
|
+
import {Readiness} from "./observability/readiness.ts";
|
|
5
6
|
|
|
6
7
|
export interface HealthCheckConfig {
|
|
7
8
|
enabled: boolean;
|
|
@@ -86,6 +87,22 @@ export class HealthCheckManager {
|
|
|
86
87
|
return this._customHandler(ctx);
|
|
87
88
|
}
|
|
88
89
|
|
|
90
|
+
if (!Readiness.isReady) {
|
|
91
|
+
const state = Readiness.snapshot();
|
|
92
|
+
return RaitonResponses(
|
|
93
|
+
'Service is shutting down',
|
|
94
|
+
{
|
|
95
|
+
status: 'unhealthy',
|
|
96
|
+
ready: false,
|
|
97
|
+
reason: state.reason,
|
|
98
|
+
timestamp: new Date().toISOString(),
|
|
99
|
+
uptime: process.uptime(),
|
|
100
|
+
},
|
|
101
|
+
HttpStatus.SERVICE_UNAVAILABLE,
|
|
102
|
+
{error: true}
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
|
|
89
106
|
const checks = await this.runChecks();
|
|
90
107
|
const timestamp = new Date().toISOString();
|
|
91
108
|
|
|
@@ -104,6 +121,7 @@ export class HealthCheckManager {
|
|
|
104
121
|
this._config.response?.message || `Service is ${overallStatus}`,
|
|
105
122
|
{
|
|
106
123
|
status: overallStatus,
|
|
124
|
+
ready: Readiness.isReady,
|
|
107
125
|
timestamp,
|
|
108
126
|
checks: checks.length > 0 ? checks : undefined,
|
|
109
127
|
uptime: process.uptime(),
|
|
@@ -2,6 +2,8 @@ export * from "./enums/index.ts"
|
|
|
2
2
|
export * from "./constants/index.ts"
|
|
3
3
|
export * from "./utilities/index.ts"
|
|
4
4
|
export * from "./responses/index.ts"
|
|
5
|
+
export * from "./errors/catalog.ts"
|
|
6
|
+
export * from "./observability/index.ts"
|
|
5
7
|
export * from "./decorators/index.ts"
|
|
6
8
|
export * from "./cache/index.ts"
|
|
7
9
|
export * from "./plugins/index.ts"
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import {Logger} from "@protorians/logger";
|
|
2
|
+
import type {McpAuditEvent} from "../../types/index.ts";
|
|
3
|
+
|
|
4
|
+
const SENSITIVE = /(authorization|token|secret|password|passphrase|api[-_]?key|credential|cookie)/i;
|
|
5
|
+
|
|
6
|
+
export function redact(value: any, depth = 0): any {
|
|
7
|
+
if (depth > 6) return "[truncated]";
|
|
8
|
+
if (value === null || value === undefined) return value;
|
|
9
|
+
if (typeof value === "string") return value.length > 512 ? `${value.slice(0, 512)}…` : value;
|
|
10
|
+
if (Array.isArray(value)) return value.map(item => redact(item, depth + 1));
|
|
11
|
+
if (typeof value === "object") {
|
|
12
|
+
const output: Record<string, any> = {};
|
|
13
|
+
for (const [key, child] of Object.entries(value)) {
|
|
14
|
+
output[key] = SENSITIVE.test(key) ? "[redacted]" : redact(child, depth + 1);
|
|
15
|
+
}
|
|
16
|
+
return output;
|
|
17
|
+
}
|
|
18
|
+
return value;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* MCP audit trail. Emits a structured event for every tool call and logs it on
|
|
23
|
+
* stderr through the framework logger. Secrets are always redacted.
|
|
24
|
+
*/
|
|
25
|
+
export class McpAudit {
|
|
26
|
+
private static listeners = new Set<(event: McpAuditEvent) => void>();
|
|
27
|
+
|
|
28
|
+
static on(listener: (event: McpAuditEvent) => void): () => void {
|
|
29
|
+
this.listeners.add(listener);
|
|
30
|
+
return () => this.listeners.delete(listener);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
static emit(event: McpAuditEvent): McpAuditEvent {
|
|
34
|
+
const safe: McpAuditEvent = {
|
|
35
|
+
...event,
|
|
36
|
+
arguments: redact(event.arguments),
|
|
37
|
+
result: redact(event.result),
|
|
38
|
+
};
|
|
39
|
+
for (const listener of this.listeners) {
|
|
40
|
+
try {
|
|
41
|
+
listener(safe);
|
|
42
|
+
} catch {
|
|
43
|
+
// An audit listener must never break a tool call.
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
Logger.info(
|
|
47
|
+
`[mcp:audit] ${safe.server}.${safe.tool} call=${safe.callId} ` +
|
|
48
|
+
`actor=${safe.actor ?? "anonymous"} transport=${safe.transport ?? "unknown"} ` +
|
|
49
|
+
`duration=${safe.durationMs}ms success=${safe.success}`
|
|
50
|
+
);
|
|
51
|
+
return safe;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
static clear(): void {
|
|
55
|
+
this.listeners.clear();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import type {McpInvocationContext, McpServerRegistrationInterface} from "../../types/index.ts";
|
|
2
|
+
import {LatestProtocolVersion} from "./protocol.ts";
|
|
3
|
+
import {mcpHandlePost} from "./streamable-http.ts";
|
|
4
|
+
import {McpStdioServer} from "./stdio.ts";
|
|
5
|
+
import {PassThrough} from "node:stream";
|
|
6
|
+
import {RaitonConfig} from "../../core/config/config.ts";
|
|
7
|
+
|
|
8
|
+
export interface McpConformanceTransport {
|
|
9
|
+
name: "streamable-http" | "stdio";
|
|
10
|
+
request(method: string, params?: any): Promise<any>;
|
|
11
|
+
close?(): void | Promise<void>;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface McpConformanceCheck {
|
|
15
|
+
name: string;
|
|
16
|
+
passed: boolean;
|
|
17
|
+
detail?: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface McpConformanceResult {
|
|
21
|
+
transport: string;
|
|
22
|
+
passed: boolean;
|
|
23
|
+
checks: McpConformanceCheck[];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function sampleValue(schema: any): any {
|
|
27
|
+
if (!schema) return undefined;
|
|
28
|
+
if (schema.default !== undefined) return schema.default;
|
|
29
|
+
if (Array.isArray(schema.enum) && schema.enum.length) return schema.enum[0];
|
|
30
|
+
switch (schema.type) {
|
|
31
|
+
case "string":
|
|
32
|
+
return "conformance";
|
|
33
|
+
case "number":
|
|
34
|
+
case "integer":
|
|
35
|
+
return 1;
|
|
36
|
+
case "boolean":
|
|
37
|
+
return true;
|
|
38
|
+
case "array":
|
|
39
|
+
return [];
|
|
40
|
+
case "object":
|
|
41
|
+
return {};
|
|
42
|
+
default:
|
|
43
|
+
return "conformance";
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function sampleArguments(schema: any): Record<string, any> {
|
|
48
|
+
const output: Record<string, any> = {};
|
|
49
|
+
const required: string[] = Array.isArray(schema?.required) ? schema.required : [];
|
|
50
|
+
for (const key of required) {
|
|
51
|
+
output[key] = sampleValue(schema?.properties?.[key]);
|
|
52
|
+
}
|
|
53
|
+
return output;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* The same conformance suite runs against the HTTP and stdio transports.
|
|
58
|
+
*/
|
|
59
|
+
export async function runMcpConformance(
|
|
60
|
+
transport: McpConformanceTransport,
|
|
61
|
+
options: {allowDestructive?: boolean} = {},
|
|
62
|
+
): Promise<McpConformanceResult> {
|
|
63
|
+
const checks: McpConformanceCheck[] = [];
|
|
64
|
+
const add = (name: string, passed: boolean, detail?: string) => checks.push({name, passed, detail});
|
|
65
|
+
|
|
66
|
+
let initialized: any;
|
|
67
|
+
try {
|
|
68
|
+
initialized = await transport.request("initialize", {
|
|
69
|
+
protocolVersion: LatestProtocolVersion,
|
|
70
|
+
capabilities: {},
|
|
71
|
+
clientInfo: {name: "raiton-conformance", version: "1.0.0"},
|
|
72
|
+
});
|
|
73
|
+
add("initialize", Boolean(initialized?.serverInfo?.name), initialized?.serverInfo?.name);
|
|
74
|
+
} catch (error: any) {
|
|
75
|
+
add("initialize", false, error?.message ?? String(error));
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
try {
|
|
79
|
+
await transport.request("initialize", {
|
|
80
|
+
protocolVersion: "0000-00-00",
|
|
81
|
+
capabilities: {},
|
|
82
|
+
clientInfo: {name: "raiton-conformance", version: "1.0.0"},
|
|
83
|
+
});
|
|
84
|
+
add("initialize unsupported version", false, "expected an error");
|
|
85
|
+
} catch {
|
|
86
|
+
add("initialize unsupported version", true);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
try {
|
|
90
|
+
const pong = await transport.request("ping");
|
|
91
|
+
add("ping", pong !== undefined);
|
|
92
|
+
} catch (error: any) {
|
|
93
|
+
add("ping", false, error?.message ?? String(error));
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
let tools: any[] = [];
|
|
97
|
+
try {
|
|
98
|
+
const listing = await transport.request("tools/list");
|
|
99
|
+
tools = Array.isArray(listing?.tools) ? listing.tools : [];
|
|
100
|
+
const schemasValid = tools.every(tool => tool.inputSchema && typeof tool.inputSchema === "object");
|
|
101
|
+
const destructiveVisible = tools.some(tool => tool.annotations?.destructiveHint === true);
|
|
102
|
+
add("tools/list", schemasValid && (options.allowDestructive || !destructiveVisible), `${tools.length} tool(s)`);
|
|
103
|
+
} catch (error: any) {
|
|
104
|
+
add("tools/list", false, error?.message ?? String(error));
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (tools.length > 0) {
|
|
108
|
+
const tool = tools[0];
|
|
109
|
+
try {
|
|
110
|
+
const result = await transport.request("tools/call", {
|
|
111
|
+
name: tool.name,
|
|
112
|
+
arguments: sampleArguments(tool.inputSchema),
|
|
113
|
+
});
|
|
114
|
+
const hasContent = Array.isArray(result?.content) || result?.structuredContent !== undefined;
|
|
115
|
+
add("tools/call", hasContent, tool.name);
|
|
116
|
+
} catch (error: any) {
|
|
117
|
+
add("tools/call", false, error?.message ?? String(error));
|
|
118
|
+
}
|
|
119
|
+
} else {
|
|
120
|
+
add("tools/call", true, "no tools exposed");
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
try {
|
|
124
|
+
await transport.request("tools/call", {name: "__raiton_missing_tool__", arguments: {}});
|
|
125
|
+
add("tools/call unknown", false, "expected an error");
|
|
126
|
+
} catch {
|
|
127
|
+
add("tools/call unknown", true);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return {
|
|
131
|
+
transport: transport.name,
|
|
132
|
+
passed: checks.every(check => check.passed),
|
|
133
|
+
checks,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* HTTP transport adapter used by `raiton mcp conformance` and tests.
|
|
139
|
+
*/
|
|
140
|
+
export function createHttpConformanceTransport(
|
|
141
|
+
entry: McpServerRegistrationInterface,
|
|
142
|
+
context?: McpInvocationContext,
|
|
143
|
+
): McpConformanceTransport {
|
|
144
|
+
let id = 0;
|
|
145
|
+
return {
|
|
146
|
+
name: "streamable-http",
|
|
147
|
+
async request(method, params) {
|
|
148
|
+
const response = await mcpHandlePost(entry, {
|
|
149
|
+
jsonrpc: "2.0",
|
|
150
|
+
id: ++id,
|
|
151
|
+
method,
|
|
152
|
+
params,
|
|
153
|
+
}, undefined, context);
|
|
154
|
+
const payload: any = response.body;
|
|
155
|
+
if (payload?.error) throw new Error(payload.error.message ?? "JSON-RPC error");
|
|
156
|
+
return payload?.result;
|
|
157
|
+
},
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* stdio transport adapter backed by an in-memory stream pair.
|
|
163
|
+
*/
|
|
164
|
+
export function createStdioConformanceTransport(
|
|
165
|
+
entry: McpServerRegistrationInterface,
|
|
166
|
+
context?: McpInvocationContext,
|
|
167
|
+
): McpConformanceTransport {
|
|
168
|
+
const input = new PassThrough();
|
|
169
|
+
const output = new PassThrough();
|
|
170
|
+
const error = new PassThrough();
|
|
171
|
+
const server = new McpStdioServer(entry, {input, output, error, context}).start();
|
|
172
|
+
|
|
173
|
+
return {
|
|
174
|
+
name: "stdio",
|
|
175
|
+
request(method, params) {
|
|
176
|
+
return server.request(method, params);
|
|
177
|
+
},
|
|
178
|
+
close() {
|
|
179
|
+
server.stop();
|
|
180
|
+
input.end();
|
|
181
|
+
},
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export async function runAllConformance(
|
|
186
|
+
entry: McpServerRegistrationInterface,
|
|
187
|
+
): Promise<McpConformanceResult[]> {
|
|
188
|
+
const allowDestructive = entry.metadata.exposeDestructive === true
|
|
189
|
+
|| RaitonConfig.get("mcp")?.exposeDestructive === true;
|
|
190
|
+
const http = await runMcpConformance(createHttpConformanceTransport(entry), {allowDestructive});
|
|
191
|
+
const stdioTransport = createStdioConformanceTransport(entry);
|
|
192
|
+
const stdio = await runMcpConformance(stdioTransport, {allowDestructive});
|
|
193
|
+
await stdioTransport.close?.();
|
|
194
|
+
return [http, stdio];
|
|
195
|
+
}
|