raiton 6.8.9-beta.25 → 6.11.0-beta.29
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 +67 -0
- package/README.md +65 -1
- package/benchmarks/README.md +31 -0
- package/benchmarks/ai-debug.json +145 -0
- package/benchmarks/ai-debug.md +64 -0
- package/benchmarks/latest.json +172 -0
- package/benchmarks/latest.md +66 -0
- package/build/bin/index.mjs +37621 -21866
- 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/call.command.d.ts +10 -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/debug.shared.d.ts +16 -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/explain.command.d.ts +8 -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 +12 -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/requests.command.d.ts +8 -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/verify.command.d.ts +8 -0
- package/build/types/commands/why.command.d.ts +7 -0
- package/build/types/contracts/decorators.d.ts +59 -0
- package/build/types/contracts/errors.d.ts +68 -0
- package/build/types/contracts/index.d.ts +4 -0
- package/build/types/contracts/schema.d.ts +83 -0
- package/build/types/contracts/typebox.d.ts +81 -0
- package/build/types/core/application.d.ts +45 -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/debug/cli.d.ts +33 -0
- package/build/types/debug/collector.d.ts +41 -0
- package/build/types/debug/collector.internal.d.ts +27 -0
- package/build/types/debug/config.d.ts +19 -0
- package/build/types/debug/examples.d.ts +43 -0
- package/build/types/debug/explain.d.ts +9 -0
- package/build/types/debug/index.d.ts +15 -0
- package/build/types/debug/invocation.d.ts +53 -0
- package/build/types/debug/journal.d.ts +49 -0
- package/build/types/debug/mcp-http.d.ts +17 -0
- package/build/types/debug/mcp.d.ts +14 -0
- package/build/types/debug/redaction.d.ts +48 -0
- package/build/types/debug/requests.d.ts +37 -0
- package/build/types/debug/runtime.d.ts +52 -0
- package/build/types/debug/session.d.ts +21 -0
- package/build/types/debug/source.d.ts +17 -0
- package/build/types/debug/surface.d.ts +10 -0
- package/build/types/debug/types.d.ts +271 -0
- package/build/types/debug/verify.d.ts +23 -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 +57 -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 +241 -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 +112 -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 +31 -0
- package/docs/generated/config-schema.json +243 -0
- package/docs/generated/manifest-schema.json +312 -0
- package/docs/generated/manifest.json +118 -0
- package/docs/llms-full.txt +1450 -0
- package/docs/llms.txt +51 -0
- package/docs/user-guide/README.md +19 -12
- package/docs/user-guide/cli.md +26 -0
- package/docs/user-guide/config.md +32 -0
- package/docs/user-guide/contracts.md +67 -0
- package/docs/user-guide/debug.md +130 -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 +42 -7
- package/scripts/bench-ai-debug.ts +572 -0
- 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 +31 -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/call.command.ts +247 -0
- package/source/commands/client.command.ts +64 -0
- package/source/commands/contract.command.ts +104 -0
- package/source/commands/debug.shared.ts +90 -0
- package/source/commands/docs.command.ts +269 -0
- package/source/commands/doctor.command.ts +226 -0
- package/source/commands/explain.command.ts +119 -0
- package/source/commands/generate.command.ts +58 -0
- package/source/commands/inspect.command.ts +108 -0
- package/source/commands/mcp.command.ts +322 -0
- package/source/commands/new.command.ts +135 -0
- package/source/commands/openapi.command.ts +95 -0
- package/source/commands/requests.command.ts +137 -0
- package/source/commands/routes.command.ts +39 -0
- package/source/commands/verify.command.ts +173 -0
- package/source/commands/why.command.ts +61 -0
- package/source/contracts/decorators.ts +216 -0
- package/source/contracts/errors.ts +135 -0
- package/source/contracts/index.ts +4 -0
- package/source/contracts/schema.ts +438 -0
- package/source/contracts/typebox.ts +193 -0
- package/source/core/application.ts +322 -72
- package/source/core/builder.ts +10 -2
- package/source/core/config/config.ts +155 -26
- package/source/core/config/define.ts +35 -8
- package/source/core/config/index.ts +2 -1
- package/source/core/config/schema.ts +406 -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 +246 -37
- 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/debug/cli.ts +206 -0
- package/source/debug/collector.internal.ts +27 -0
- package/source/debug/collector.ts +294 -0
- package/source/debug/config.ts +142 -0
- package/source/debug/examples.ts +188 -0
- package/source/debug/explain.ts +187 -0
- package/source/debug/index.ts +15 -0
- package/source/debug/invocation.ts +695 -0
- package/source/debug/journal.ts +249 -0
- package/source/debug/mcp-http.ts +145 -0
- package/source/debug/mcp.ts +410 -0
- package/source/debug/redaction.ts +225 -0
- package/source/debug/requests.ts +136 -0
- package/source/debug/runtime.ts +181 -0
- package/source/debug/session.ts +107 -0
- package/source/debug/source.ts +95 -0
- package/source/debug/surface.ts +375 -0
- package/source/debug/types.ts +311 -0
- package/source/debug/verify.ts +186 -0
- package/source/framework/artifacts.ts +47 -15
- 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 +205 -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 +139 -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 +733 -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 +57 -0
- package/source/manifest/manifest.ts +364 -0
- package/source/manifest/schema.ts +200 -0
- package/source/types/builder.ts +5 -0
- package/source/types/config.ts +120 -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
|
@@ -2,26 +2,59 @@ import type {
|
|
|
2
2
|
JsonRpcRequest,
|
|
3
3
|
JsonRpcResponse,
|
|
4
4
|
McpElementMetaInterface,
|
|
5
|
+
McpInvocationContext,
|
|
5
6
|
McpServerRegistrationInterface,
|
|
6
7
|
McpToolResultContent,
|
|
7
8
|
} from "../../types/index.ts";
|
|
8
9
|
import {
|
|
9
10
|
JsonRpcErrorCode,
|
|
10
11
|
LatestProtocolVersion,
|
|
12
|
+
SUPPORTED_PROTOCOL_VERSIONS,
|
|
11
13
|
rpcError,
|
|
12
14
|
rpcFailure,
|
|
13
15
|
rpcSuccess,
|
|
14
16
|
} from "./protocol.ts";
|
|
15
17
|
import {Injection} from "../../core/injection/index.ts";
|
|
18
|
+
import {RaitonConfig} from "../../core/config/config.ts";
|
|
19
|
+
import {contractToJsonSchema, validateContract} from "../../contracts/index.ts";
|
|
20
|
+
import {McpAudit} from "./audit.ts";
|
|
21
|
+
import {mcpRateLimiter} from "./rate-limit.ts";
|
|
16
22
|
|
|
17
23
|
export interface McpHandleResult {
|
|
18
24
|
kind: 'response' | 'notification';
|
|
19
25
|
message?: JsonRpcResponse | JsonRpcResponse[];
|
|
20
26
|
}
|
|
21
27
|
|
|
28
|
+
function isDestructive(tool: McpElementMetaInterface): boolean {
|
|
29
|
+
return tool.annotations?.destructiveHint === true || tool.destructive === true;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Default-deny: destructive tools are hidden unless the server explicitly
|
|
34
|
+
* exposes them or project configuration opts in.
|
|
35
|
+
*/
|
|
36
|
+
export function isToolExposed(entry: McpServerRegistrationInterface, tool: McpElementMetaInterface): boolean {
|
|
37
|
+
if (!isDestructive(tool)) return true;
|
|
38
|
+
return entry.metadata.exposeDestructive === true
|
|
39
|
+
|| RaitonConfig.get("mcp")?.exposeDestructive === true;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function exposedTools(entry: McpServerRegistrationInterface): McpElementMetaInterface[] {
|
|
43
|
+
return entry.metadata.tools.filter(tool => isToolExposed(entry, tool));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function toolInputSchema(tool: McpElementMetaInterface) {
|
|
47
|
+
return tool.inputSchema ? contractToJsonSchema(tool.inputSchema) : argumentsToSchema(tool.arguments);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function toolOutputSchema(tool: McpElementMetaInterface) {
|
|
51
|
+
return tool.outputSchema ? contractToJsonSchema(tool.outputSchema) : undefined;
|
|
52
|
+
}
|
|
53
|
+
|
|
22
54
|
export async function handleMcpRequest(
|
|
23
55
|
registryEntry: McpServerRegistrationInterface,
|
|
24
56
|
body: any,
|
|
57
|
+
context?: McpInvocationContext,
|
|
25
58
|
): Promise<McpHandleResult> {
|
|
26
59
|
const requests = Array.isArray(body) ? body : [body];
|
|
27
60
|
const responses: JsonRpcResponse[] = [];
|
|
@@ -40,7 +73,7 @@ export async function handleMcpRequest(
|
|
|
40
73
|
const request = raw as JsonRpcRequest
|
|
41
74
|
const isNotification = request.id === undefined || request.id === null
|
|
42
75
|
|
|
43
|
-
const handled = await dispatchMcpMethod(registryEntry, request)
|
|
76
|
+
const handled = await dispatchMcpMethod(registryEntry, request, context)
|
|
44
77
|
if (handled.kind === 'response' && handled.message) {
|
|
45
78
|
const message = Array.isArray(handled.message) ? handled.message[0] : handled.message
|
|
46
79
|
// Notifications never carry a response unless it's part of a batch with ids
|
|
@@ -69,6 +102,7 @@ export async function handleMcpRequest(
|
|
|
69
102
|
async function dispatchMcpMethod(
|
|
70
103
|
entry: McpServerRegistrationInterface,
|
|
71
104
|
request: JsonRpcRequest,
|
|
105
|
+
context?: McpInvocationContext,
|
|
72
106
|
): Promise<McpHandleResult> {
|
|
73
107
|
const method = request.method
|
|
74
108
|
const params = request.params || {}
|
|
@@ -76,6 +110,12 @@ async function dispatchMcpMethod(
|
|
|
76
110
|
try {
|
|
77
111
|
switch (method) {
|
|
78
112
|
case 'initialize':
|
|
113
|
+
if (params?.protocolVersion && !SUPPORTED_PROTOCOL_VERSIONS.has(params.protocolVersion)) {
|
|
114
|
+
return {kind: 'response', message: rpcFailure(request.id, rpcError(
|
|
115
|
+
JsonRpcErrorCode.INVALID_REQUEST,
|
|
116
|
+
`Unsupported protocol version: ${params.protocolVersion}`,
|
|
117
|
+
))}
|
|
118
|
+
}
|
|
79
119
|
return {kind: 'response', message: rpcSuccess(request.id, handleInitialize(entry, params))}
|
|
80
120
|
|
|
81
121
|
case 'notifications/initialized':
|
|
@@ -88,7 +128,7 @@ async function dispatchMcpMethod(
|
|
|
88
128
|
return {kind: 'response', message: rpcSuccess(request.id, listTools(entry))}
|
|
89
129
|
|
|
90
130
|
case 'tools/call':
|
|
91
|
-
return {kind: 'response', message: await callTool(entry, request.id, params)}
|
|
131
|
+
return {kind: 'response', message: await callTool(entry, request.id, params, context)}
|
|
92
132
|
|
|
93
133
|
case 'prompts/list':
|
|
94
134
|
return {kind: 'response', message: rpcSuccess(request.id, listPrompts(entry))}
|
|
@@ -122,7 +162,7 @@ async function dispatchMcpMethod(
|
|
|
122
162
|
}
|
|
123
163
|
}
|
|
124
164
|
|
|
125
|
-
function handleInitialize(entry: McpServerRegistrationInterface,
|
|
165
|
+
function handleInitialize(entry: McpServerRegistrationInterface, _params: any) {
|
|
126
166
|
return {
|
|
127
167
|
protocolVersion: LatestProtocolVersion,
|
|
128
168
|
capabilities: {
|
|
@@ -142,10 +182,15 @@ function handleInitialize(entry: McpServerRegistrationInterface, params: any) {
|
|
|
142
182
|
|
|
143
183
|
function listTools(entry: McpServerRegistrationInterface) {
|
|
144
184
|
return {
|
|
145
|
-
tools: entry.
|
|
185
|
+
tools: exposedTools(entry).map(element => ({
|
|
146
186
|
name: element.name,
|
|
187
|
+
title: element.title,
|
|
147
188
|
description: element.description,
|
|
148
|
-
inputSchema:
|
|
189
|
+
inputSchema: toolInputSchema(element),
|
|
190
|
+
...(toolOutputSchema(element) ? {outputSchema: toolOutputSchema(element)} : {}),
|
|
191
|
+
...(element.annotations && Object.keys(element.annotations).length
|
|
192
|
+
? {annotations: element.annotations}
|
|
193
|
+
: {}),
|
|
149
194
|
})),
|
|
150
195
|
}
|
|
151
196
|
}
|
|
@@ -166,34 +211,107 @@ function argumentsToSchema(args: {name: string; description?: string; required?:
|
|
|
166
211
|
}
|
|
167
212
|
}
|
|
168
213
|
|
|
169
|
-
|
|
214
|
+
function toolFailure(
|
|
215
|
+
id: JsonRpcRequest['id'],
|
|
216
|
+
code: string,
|
|
217
|
+
message: string,
|
|
218
|
+
details?: any,
|
|
219
|
+
schema?: any,
|
|
220
|
+
): JsonRpcResponse {
|
|
221
|
+
return rpcSuccess(id, {
|
|
222
|
+
content: [{type: 'text', text: message}],
|
|
223
|
+
structuredContent: {
|
|
224
|
+
error: true,
|
|
225
|
+
code,
|
|
226
|
+
message,
|
|
227
|
+
...(details !== undefined ? {details} : {}),
|
|
228
|
+
...(schema !== undefined ? {schema} : {}),
|
|
229
|
+
},
|
|
230
|
+
isError: true,
|
|
231
|
+
})
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
async function callTool(
|
|
235
|
+
entry: McpServerRegistrationInterface,
|
|
236
|
+
id: JsonRpcRequest['id'],
|
|
237
|
+
params: any,
|
|
238
|
+
context?: McpInvocationContext,
|
|
239
|
+
): Promise<JsonRpcResponse> {
|
|
170
240
|
const name = params?.name
|
|
171
|
-
const
|
|
241
|
+
const rawInput = params?.arguments || {}
|
|
172
242
|
if (!name) {
|
|
173
243
|
return rpcFailure(id, rpcError(JsonRpcErrorCode.INVALID_PARAMS, 'Tool name required'))
|
|
174
244
|
}
|
|
175
245
|
|
|
176
|
-
const tool = entry.
|
|
246
|
+
const tool = exposedTools(entry).find(t => t.name === name)
|
|
177
247
|
if (!tool) {
|
|
248
|
+
// Hidden destructive tools are indistinguishable from unknown tools.
|
|
178
249
|
return rpcFailure(id, rpcError(JsonRpcErrorCode.METHOD_NOT_FOUND, `Tool not found: ${name}`))
|
|
179
250
|
}
|
|
180
251
|
|
|
252
|
+
if (tool.scopes?.length) {
|
|
253
|
+
const granted = context?.scopes ?? [];
|
|
254
|
+
if (!tool.scopes.some(scope => granted.includes(scope))) {
|
|
255
|
+
return toolFailure(id, 'MCP_FORBIDDEN', `Missing scope for tool: ${name}`, {
|
|
256
|
+
required: tool.scopes,
|
|
257
|
+
})
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
const limit = entry.metadata.rateLimitPerMinute
|
|
262
|
+
?? RaitonConfig.get("mcp")?.rateLimitPerMinute
|
|
263
|
+
?? 0;
|
|
264
|
+
if (!mcpRateLimiter.consume(`${entry.name}:${tool.name}`, limit)) {
|
|
265
|
+
return toolFailure(id, 'MCP_RATE_LIMITED', `Rate limit exceeded for tool: ${name}`)
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
const schema = toolInputSchema(tool) as any
|
|
269
|
+
const validation = await validateContract(schema, rawInput)
|
|
270
|
+
if (!validation.success) {
|
|
271
|
+
return toolFailure(
|
|
272
|
+
id,
|
|
273
|
+
'MCP_INVALID_ARGUMENTS',
|
|
274
|
+
`Invalid arguments for tool: ${name}`,
|
|
275
|
+
validation.issues,
|
|
276
|
+
schema,
|
|
277
|
+
)
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
const input = (validation.value ?? rawInput) as Record<string, any>
|
|
181
281
|
const instance: any = Injection.resolve(entry.construct)
|
|
182
282
|
if (!instance || typeof instance[tool.propertyKey] !== 'function') {
|
|
183
283
|
return rpcFailure(id, rpcError(JsonRpcErrorCode.INTERNAL_ERROR, `Tool handler unavailable: ${name}`))
|
|
184
284
|
}
|
|
185
285
|
|
|
286
|
+
const callId = `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`
|
|
287
|
+
const started = performance.now()
|
|
288
|
+
let success = false
|
|
289
|
+
let auditResult: any = undefined
|
|
290
|
+
|
|
186
291
|
try {
|
|
187
292
|
const args = collectArguments(instance, tool, input)
|
|
188
293
|
const result = await instance[tool.propertyKey](...args)
|
|
294
|
+
auditResult = result
|
|
295
|
+
|
|
296
|
+
const outputSchema = toolOutputSchema(tool)
|
|
297
|
+
if (outputSchema) {
|
|
298
|
+
const output = await validateContract(outputSchema as any, result)
|
|
299
|
+
if (!output.success) {
|
|
300
|
+
return toolFailure(id, 'MCP_OUTPUT_VALIDATION_ERROR', `Invalid output for tool: ${name}`, output.issues)
|
|
301
|
+
}
|
|
302
|
+
}
|
|
189
303
|
|
|
190
304
|
const content: McpToolResultContent[] = [{
|
|
191
305
|
type: 'text',
|
|
192
306
|
text: normalizeToolResult(result),
|
|
193
307
|
}]
|
|
194
308
|
|
|
309
|
+
success = true
|
|
195
310
|
return rpcSuccess(id, {
|
|
196
311
|
content,
|
|
312
|
+
...(result !== null && typeof result === 'object' && !Array.isArray(result)
|
|
313
|
+
? {structuredContent: result}
|
|
314
|
+
: {}),
|
|
197
315
|
isError: false,
|
|
198
316
|
})
|
|
199
317
|
} catch (e: any) {
|
|
@@ -201,6 +319,18 @@ async function callTool(entry: McpServerRegistrationInterface, id: JsonRpcReques
|
|
|
201
319
|
content: [{type: 'text', text: `Error: ${e.message ?? e}`}],
|
|
202
320
|
isError: true,
|
|
203
321
|
})
|
|
322
|
+
} finally {
|
|
323
|
+
McpAudit.emit({
|
|
324
|
+
callId,
|
|
325
|
+
server: entry.name,
|
|
326
|
+
tool: name,
|
|
327
|
+
actor: context?.actor,
|
|
328
|
+
transport: context?.transport,
|
|
329
|
+
durationMs: Math.round(performance.now() - started),
|
|
330
|
+
success,
|
|
331
|
+
arguments: input,
|
|
332
|
+
result: auditResult,
|
|
333
|
+
})
|
|
204
334
|
}
|
|
205
335
|
}
|
|
206
336
|
|
|
@@ -366,4 +496,4 @@ function coerceArgument(value: any, arg: {schema?: any; metatype?: any}): any {
|
|
|
366
496
|
default:
|
|
367
497
|
return value
|
|
368
498
|
}
|
|
369
|
-
}
|
|
499
|
+
}
|
|
@@ -1,3 +1,8 @@
|
|
|
1
1
|
export * from "./protocol.ts"
|
|
2
2
|
export * from "./handler.ts"
|
|
3
|
-
export * from "./streamable-http.ts"
|
|
3
|
+
export * from "./streamable-http.ts"
|
|
4
|
+
// `stdio.ts` and `conformance.ts` depend on node:readline/node:stream and are
|
|
5
|
+
// intentionally available through their subpaths so the framework barrel stays
|
|
6
|
+
// runtime-agnostic.
|
|
7
|
+
export * from "./audit.ts"
|
|
8
|
+
export * from "./rate-limit.ts"
|
|
@@ -6,6 +6,12 @@ import type {
|
|
|
6
6
|
|
|
7
7
|
export const McpVersion = '2024-11-05'
|
|
8
8
|
export const LatestProtocolVersion = '2024-11-05'
|
|
9
|
+
export const SUPPORTED_PROTOCOL_VERSIONS = new Set([
|
|
10
|
+
'2024-11-05',
|
|
11
|
+
'2025-03-26',
|
|
12
|
+
'2025-06-18',
|
|
13
|
+
'2025-11-25',
|
|
14
|
+
])
|
|
9
15
|
|
|
10
16
|
export enum JsonRpcErrorCode {
|
|
11
17
|
PARSE_ERROR = -32700,
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
interface Bucket {
|
|
2
|
+
count: number;
|
|
3
|
+
resetAt: number;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Simple per-tool fixed window limiter. Disabled when `limit <= 0`.
|
|
8
|
+
* Opt-in only: no timers, no background work.
|
|
9
|
+
*/
|
|
10
|
+
export class McpRateLimiter {
|
|
11
|
+
private buckets = new Map<string, Bucket>();
|
|
12
|
+
|
|
13
|
+
consume(key: string, limitPerMinute: number): boolean {
|
|
14
|
+
if (!limitPerMinute || limitPerMinute <= 0) return true;
|
|
15
|
+
const now = Date.now();
|
|
16
|
+
let bucket = this.buckets.get(key);
|
|
17
|
+
|
|
18
|
+
if (!bucket || bucket.resetAt <= now) {
|
|
19
|
+
bucket = {count: 0, resetAt: now + 60_000};
|
|
20
|
+
this.buckets.set(key, bucket);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (bucket.count >= limitPerMinute) return false;
|
|
24
|
+
bucket.count += 1;
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
reset(): void {
|
|
29
|
+
this.buckets.clear();
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export const mcpRateLimiter = new McpRateLimiter();
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import {createInterface, type Interface} from "node:readline";
|
|
2
|
+
import type {Readable, Writable} from "node:stream";
|
|
3
|
+
import type {
|
|
4
|
+
JsonRpcRequest,
|
|
5
|
+
JsonRpcResponse,
|
|
6
|
+
McpInvocationContext,
|
|
7
|
+
McpServerRegistrationInterface,
|
|
8
|
+
} from "../../types/index.ts";
|
|
9
|
+
import {handleMcpRequest} from "./handler.ts";
|
|
10
|
+
import {JsonRpcErrorCode, rpcError, rpcFailure} from "./protocol.ts";
|
|
11
|
+
|
|
12
|
+
export interface McpStdioOptions {
|
|
13
|
+
input?: Readable;
|
|
14
|
+
output?: Writable;
|
|
15
|
+
error?: Writable;
|
|
16
|
+
context?: McpInvocationContext;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* MCP stdio transport: newline-delimited JSON-RPC on stdin/stdout, exactly as
|
|
21
|
+
* specified by the Model Context Protocol. Logs go to stderr so stdout remains
|
|
22
|
+
* a pure protocol channel.
|
|
23
|
+
*/
|
|
24
|
+
export class McpStdioServer {
|
|
25
|
+
private readonly input: Readable;
|
|
26
|
+
private readonly output: Writable;
|
|
27
|
+
private readonly error: Writable;
|
|
28
|
+
private readonly context: McpInvocationContext;
|
|
29
|
+
private readline?: Interface;
|
|
30
|
+
private nextId = 1;
|
|
31
|
+
private pending = new Map<string | number, {
|
|
32
|
+
resolve: (value: any) => void;
|
|
33
|
+
reject: (error: Error) => void;
|
|
34
|
+
}>();
|
|
35
|
+
private closed = false;
|
|
36
|
+
|
|
37
|
+
constructor(
|
|
38
|
+
public readonly entry: McpServerRegistrationInterface,
|
|
39
|
+
options: McpStdioOptions = {},
|
|
40
|
+
) {
|
|
41
|
+
this.input = options.input ?? process.stdin;
|
|
42
|
+
this.output = options.output ?? process.stdout;
|
|
43
|
+
this.error = options.error ?? process.stderr;
|
|
44
|
+
this.context = {...options.context, transport: "stdio"};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
start(): this {
|
|
48
|
+
this.readline = createInterface({input: this.input, crlfDelay: Infinity});
|
|
49
|
+
this.readline.on("line", line => {
|
|
50
|
+
void this.handleLine(line);
|
|
51
|
+
});
|
|
52
|
+
this.readline.on("close", () => {
|
|
53
|
+
this.closed = true;
|
|
54
|
+
for (const pending of this.pending.values()) {
|
|
55
|
+
pending.reject(new Error("MCP stdio transport closed"));
|
|
56
|
+
}
|
|
57
|
+
this.pending.clear();
|
|
58
|
+
});
|
|
59
|
+
return this;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
private async handleLine(line: string): Promise<void> {
|
|
63
|
+
const trimmed = line.trim();
|
|
64
|
+
if (!trimmed) return;
|
|
65
|
+
|
|
66
|
+
let body: any;
|
|
67
|
+
try {
|
|
68
|
+
body = JSON.parse(trimmed);
|
|
69
|
+
} catch (error: any) {
|
|
70
|
+
this.write({
|
|
71
|
+
jsonrpc: "2.0",
|
|
72
|
+
id: null,
|
|
73
|
+
error: rpcError(JsonRpcErrorCode.PARSE_ERROR, "Parse error"),
|
|
74
|
+
});
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
try {
|
|
79
|
+
const result = await handleMcpRequest(this.entry, body, this.context);
|
|
80
|
+
if (result.kind === "notification" || !result.message) return;
|
|
81
|
+
const responses = Array.isArray(result.message) ? result.message : [result.message];
|
|
82
|
+
for (const response of responses) {
|
|
83
|
+
this.write(response);
|
|
84
|
+
this.settle(response);
|
|
85
|
+
}
|
|
86
|
+
} catch (error: any) {
|
|
87
|
+
this.error.write(`[raiton:mcp] ${error?.message ?? error}\n`);
|
|
88
|
+
if (body && typeof body === "object" && !Array.isArray(body)) {
|
|
89
|
+
this.write(rpcFailure((body as JsonRpcRequest).id ?? null, rpcError(
|
|
90
|
+
JsonRpcErrorCode.INTERNAL_ERROR,
|
|
91
|
+
error?.message ?? "Internal error",
|
|
92
|
+
)));
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
private settle(response: JsonRpcResponse) {
|
|
98
|
+
const id = response.id;
|
|
99
|
+
if (id === null || id === undefined) return;
|
|
100
|
+
const pending = this.pending.get(id);
|
|
101
|
+
if (!pending) return;
|
|
102
|
+
this.pending.delete(id);
|
|
103
|
+
if (response.error) pending.reject(new Error(response.error.message));
|
|
104
|
+
else pending.resolve(response.result);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
private write(response: JsonRpcResponse) {
|
|
108
|
+
this.output.write(`${JSON.stringify(response)}\n`);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Client-style request used by `raiton mcp test`, conformance tests and
|
|
113
|
+
* integrations. Close to the wire in both directions.
|
|
114
|
+
*/
|
|
115
|
+
request(method: string, params?: any): Promise<any> {
|
|
116
|
+
if (this.closed) return Promise.reject(new Error("MCP stdio transport closed"));
|
|
117
|
+
const id = this.nextId++;
|
|
118
|
+
const message: JsonRpcRequest = {jsonrpc: "2.0", id, method, params};
|
|
119
|
+
return new Promise<any>((resolve, reject) => {
|
|
120
|
+
this.pending.set(id, {resolve, reject});
|
|
121
|
+
// Feed the request through the same line handler a real client would.
|
|
122
|
+
void this.handleLine(JSON.stringify(message));
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
notify(method: string, params?: any): void {
|
|
127
|
+
this.output.write(`${JSON.stringify({jsonrpc: "2.0", method, params})}\n`);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
stop(): void {
|
|
131
|
+
this.readline?.close();
|
|
132
|
+
this.closed = true;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Serve a registered MCP server over stdio until stdin closes.
|
|
138
|
+
*/
|
|
139
|
+
export async function serveMcpStdio(
|
|
140
|
+
entry: McpServerRegistrationInterface,
|
|
141
|
+
options: McpStdioOptions = {},
|
|
142
|
+
): Promise<void> {
|
|
143
|
+
const server = new McpStdioServer(entry, options).start();
|
|
144
|
+
await new Promise<void>(resolve => {
|
|
145
|
+
const input = options.input ?? process.stdin;
|
|
146
|
+
input.once("end", resolve);
|
|
147
|
+
input.once("close", resolve);
|
|
148
|
+
});
|
|
149
|
+
server.stop();
|
|
150
|
+
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type {
|
|
2
|
+
McpInvocationContext,
|
|
2
3
|
McpServerRegistrationInterface,
|
|
3
4
|
} from "../../types/index.ts";
|
|
4
|
-
import {McpVersion} from "./protocol.ts";
|
|
5
|
+
import {McpVersion, SUPPORTED_PROTOCOL_VERSIONS} from "./protocol.ts";
|
|
5
6
|
import {handleMcpRequest} from "./handler.ts";
|
|
6
7
|
|
|
7
8
|
export const SESSION_HEADER = 'mcp-session-id'
|
|
@@ -10,11 +11,36 @@ function randomId(): string {
|
|
|
10
11
|
return `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`
|
|
11
12
|
}
|
|
12
13
|
|
|
13
|
-
const SUPPORTED_VERSIONS = new Set(['2024-11-05', '2025-03-26', '2025-06-18', '2025-11-25'])
|
|
14
|
-
|
|
15
14
|
function isCompatibleVersion(version: string | undefined): boolean {
|
|
16
15
|
if (version === undefined || version === null) return false
|
|
17
|
-
return
|
|
16
|
+
return SUPPORTED_PROTOCOL_VERSIONS.has(version)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function header(headers: any, name: string): string | undefined {
|
|
20
|
+
if (!headers) return undefined;
|
|
21
|
+
if (typeof headers.get === "function") return headers.get(name) ?? undefined;
|
|
22
|
+
const lower = name.toLowerCase();
|
|
23
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
24
|
+
if (key.toLowerCase() === lower && value !== undefined) return String(value);
|
|
25
|
+
}
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Build the invocation context (actor, scopes, transport) from HTTP headers.
|
|
31
|
+
* Authentication itself belongs to a future auth spec; scopes are enforced as
|
|
32
|
+
* soon as they are present here.
|
|
33
|
+
*/
|
|
34
|
+
export function mcpContextFromHeaders(headers: any): McpInvocationContext {
|
|
35
|
+
const scopes = (header(headers, "x-mcp-scopes") ?? "")
|
|
36
|
+
.split(",")
|
|
37
|
+
.map(scope => scope.trim())
|
|
38
|
+
.filter(Boolean);
|
|
39
|
+
return {
|
|
40
|
+
actor: header(headers, "x-mcp-actor"),
|
|
41
|
+
scopes,
|
|
42
|
+
transport: "streamable-http",
|
|
43
|
+
};
|
|
18
44
|
}
|
|
19
45
|
|
|
20
46
|
export function isMcpJsonRpc(body: any): boolean {
|
|
@@ -36,6 +62,7 @@ export async function mcpHandlePost(
|
|
|
36
62
|
entry: McpServerRegistrationInterface,
|
|
37
63
|
body: any,
|
|
38
64
|
existingSessionId?: string,
|
|
65
|
+
context?: McpInvocationContext,
|
|
39
66
|
): Promise<McpHttpResult> {
|
|
40
67
|
if (!body || (!Array.isArray(body) && typeof body !== 'object')) {
|
|
41
68
|
return {
|
|
@@ -61,7 +88,11 @@ export async function mcpHandlePost(
|
|
|
61
88
|
}
|
|
62
89
|
|
|
63
90
|
const sessionId = existingSessionId || randomId()
|
|
64
|
-
const result = await handleMcpRequest(entry, body
|
|
91
|
+
const result = await handleMcpRequest(entry, body, {
|
|
92
|
+
transport: 'streamable-http',
|
|
93
|
+
sessionId,
|
|
94
|
+
...context,
|
|
95
|
+
})
|
|
65
96
|
|
|
66
97
|
if (result.kind === 'notification') {
|
|
67
98
|
return {
|