palaryn 0.1.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/LICENSE +21 -0
- package/README.md +716 -0
- package/dist/sdk/typescript/src/client.d.ts +71 -0
- package/dist/sdk/typescript/src/client.d.ts.map +1 -0
- package/dist/sdk/typescript/src/client.js +176 -0
- package/dist/sdk/typescript/src/client.js.map +1 -0
- package/dist/sdk/typescript/src/errors.d.ts +50 -0
- package/dist/sdk/typescript/src/errors.d.ts.map +1 -0
- package/dist/sdk/typescript/src/errors.js +103 -0
- package/dist/sdk/typescript/src/errors.js.map +1 -0
- package/dist/sdk/typescript/src/index.d.ts +4 -0
- package/dist/sdk/typescript/src/index.d.ts.map +1 -0
- package/dist/sdk/typescript/src/index.js +15 -0
- package/dist/sdk/typescript/src/index.js.map +1 -0
- package/dist/sdk/typescript/src/types.d.ts +101 -0
- package/dist/sdk/typescript/src/types.d.ts.map +1 -0
- package/dist/sdk/typescript/src/types.js +6 -0
- package/dist/sdk/typescript/src/types.js.map +1 -0
- package/dist/src/admin/index.d.ts +2 -0
- package/dist/src/admin/index.d.ts.map +1 -0
- package/dist/src/admin/index.js +6 -0
- package/dist/src/admin/index.js.map +1 -0
- package/dist/src/admin/routes.d.ts +5 -0
- package/dist/src/admin/routes.d.ts.map +1 -0
- package/dist/src/admin/routes.js +471 -0
- package/dist/src/admin/routes.js.map +1 -0
- package/dist/src/admin/templates.d.ts +51 -0
- package/dist/src/admin/templates.d.ts.map +1 -0
- package/dist/src/admin/templates.js +500 -0
- package/dist/src/admin/templates.js.map +1 -0
- package/dist/src/anomaly/detector.d.ts +141 -0
- package/dist/src/anomaly/detector.d.ts.map +1 -0
- package/dist/src/anomaly/detector.js +554 -0
- package/dist/src/anomaly/detector.js.map +1 -0
- package/dist/src/anomaly/index.d.ts +2 -0
- package/dist/src/anomaly/index.d.ts.map +1 -0
- package/dist/src/anomaly/index.js +7 -0
- package/dist/src/anomaly/index.js.map +1 -0
- package/dist/src/approval/manager.d.ts +147 -0
- package/dist/src/approval/manager.d.ts.map +1 -0
- package/dist/src/approval/manager.js +511 -0
- package/dist/src/approval/manager.js.map +1 -0
- package/dist/src/approval/webhook.d.ts +36 -0
- package/dist/src/approval/webhook.d.ts.map +1 -0
- package/dist/src/approval/webhook.js +135 -0
- package/dist/src/approval/webhook.js.map +1 -0
- package/dist/src/audit/logger.d.ts +70 -0
- package/dist/src/audit/logger.d.ts.map +1 -0
- package/dist/src/audit/logger.js +440 -0
- package/dist/src/audit/logger.js.map +1 -0
- package/dist/src/auth/index.d.ts +6 -0
- package/dist/src/auth/index.d.ts.map +1 -0
- package/dist/src/auth/index.js +22 -0
- package/dist/src/auth/index.js.map +1 -0
- package/dist/src/auth/password.d.ts +3 -0
- package/dist/src/auth/password.d.ts.map +1 -0
- package/dist/src/auth/password.js +25 -0
- package/dist/src/auth/password.js.map +1 -0
- package/dist/src/auth/pkce.d.ts +13 -0
- package/dist/src/auth/pkce.d.ts.map +1 -0
- package/dist/src/auth/pkce.js +58 -0
- package/dist/src/auth/pkce.js.map +1 -0
- package/dist/src/auth/providers.d.ts +28 -0
- package/dist/src/auth/providers.d.ts.map +1 -0
- package/dist/src/auth/providers.js +198 -0
- package/dist/src/auth/providers.js.map +1 -0
- package/dist/src/auth/routes.d.ts +14 -0
- package/dist/src/auth/routes.d.ts.map +1 -0
- package/dist/src/auth/routes.js +431 -0
- package/dist/src/auth/routes.js.map +1 -0
- package/dist/src/auth/session.d.ts +24 -0
- package/dist/src/auth/session.d.ts.map +1 -0
- package/dist/src/auth/session.js +105 -0
- package/dist/src/auth/session.js.map +1 -0
- package/dist/src/billing/index.d.ts +7 -0
- package/dist/src/billing/index.d.ts.map +1 -0
- package/dist/src/billing/index.js +14 -0
- package/dist/src/billing/index.js.map +1 -0
- package/dist/src/billing/plan-enforcer.d.ts +44 -0
- package/dist/src/billing/plan-enforcer.d.ts.map +1 -0
- package/dist/src/billing/plan-enforcer.js +110 -0
- package/dist/src/billing/plan-enforcer.js.map +1 -0
- package/dist/src/billing/routes.d.ts +15 -0
- package/dist/src/billing/routes.d.ts.map +1 -0
- package/dist/src/billing/routes.js +193 -0
- package/dist/src/billing/routes.js.map +1 -0
- package/dist/src/billing/stripe-client.d.ts +14 -0
- package/dist/src/billing/stripe-client.d.ts.map +1 -0
- package/dist/src/billing/stripe-client.js +51 -0
- package/dist/src/billing/stripe-client.js.map +1 -0
- package/dist/src/billing/webhook-handler.d.ts +19 -0
- package/dist/src/billing/webhook-handler.d.ts.map +1 -0
- package/dist/src/billing/webhook-handler.js +169 -0
- package/dist/src/billing/webhook-handler.js.map +1 -0
- package/dist/src/billing/webhook-routes.d.ts +5 -0
- package/dist/src/billing/webhook-routes.d.ts.map +1 -0
- package/dist/src/billing/webhook-routes.js +30 -0
- package/dist/src/billing/webhook-routes.js.map +1 -0
- package/dist/src/budget/manager.d.ts +95 -0
- package/dist/src/budget/manager.d.ts.map +1 -0
- package/dist/src/budget/manager.js +547 -0
- package/dist/src/budget/manager.js.map +1 -0
- package/dist/src/budget/usage-extractor.d.ts +38 -0
- package/dist/src/budget/usage-extractor.d.ts.map +1 -0
- package/dist/src/budget/usage-extractor.js +165 -0
- package/dist/src/budget/usage-extractor.js.map +1 -0
- package/dist/src/cli.d.ts +3 -0
- package/dist/src/cli.d.ts.map +1 -0
- package/dist/src/cli.js +115 -0
- package/dist/src/cli.js.map +1 -0
- package/dist/src/config/defaults.d.ts +3 -0
- package/dist/src/config/defaults.d.ts.map +1 -0
- package/dist/src/config/defaults.js +243 -0
- package/dist/src/config/defaults.js.map +1 -0
- package/dist/src/config/validate.d.ts +15 -0
- package/dist/src/config/validate.d.ts.map +1 -0
- package/dist/src/config/validate.js +105 -0
- package/dist/src/config/validate.js.map +1 -0
- package/dist/src/dlp/composite-scanner.d.ts +47 -0
- package/dist/src/dlp/composite-scanner.d.ts.map +1 -0
- package/dist/src/dlp/composite-scanner.js +186 -0
- package/dist/src/dlp/composite-scanner.js.map +1 -0
- package/dist/src/dlp/index.d.ts +10 -0
- package/dist/src/dlp/index.d.ts.map +1 -0
- package/dist/src/dlp/index.js +26 -0
- package/dist/src/dlp/index.js.map +1 -0
- package/dist/src/dlp/interfaces.d.ts +33 -0
- package/dist/src/dlp/interfaces.d.ts.map +1 -0
- package/dist/src/dlp/interfaces.js +3 -0
- package/dist/src/dlp/interfaces.js.map +1 -0
- package/dist/src/dlp/patterns.d.ts +9 -0
- package/dist/src/dlp/patterns.d.ts.map +1 -0
- package/dist/src/dlp/patterns.js +25 -0
- package/dist/src/dlp/patterns.js.map +1 -0
- package/dist/src/dlp/prompt-injection-backend.d.ts +68 -0
- package/dist/src/dlp/prompt-injection-backend.d.ts.map +1 -0
- package/dist/src/dlp/prompt-injection-backend.js +148 -0
- package/dist/src/dlp/prompt-injection-backend.js.map +1 -0
- package/dist/src/dlp/prompt-injection-patterns.d.ts +32 -0
- package/dist/src/dlp/prompt-injection-patterns.d.ts.map +1 -0
- package/dist/src/dlp/prompt-injection-patterns.js +290 -0
- package/dist/src/dlp/prompt-injection-patterns.js.map +1 -0
- package/dist/src/dlp/regex-backend.d.ts +32 -0
- package/dist/src/dlp/regex-backend.d.ts.map +1 -0
- package/dist/src/dlp/regex-backend.js +153 -0
- package/dist/src/dlp/regex-backend.js.map +1 -0
- package/dist/src/dlp/scanner.d.ts +122 -0
- package/dist/src/dlp/scanner.d.ts.map +1 -0
- package/dist/src/dlp/scanner.js +444 -0
- package/dist/src/dlp/scanner.js.map +1 -0
- package/dist/src/dlp/text-normalizer.d.ts +41 -0
- package/dist/src/dlp/text-normalizer.d.ts.map +1 -0
- package/dist/src/dlp/text-normalizer.js +203 -0
- package/dist/src/dlp/text-normalizer.js.map +1 -0
- package/dist/src/dlp/trufflehog-backend.d.ts +64 -0
- package/dist/src/dlp/trufflehog-backend.d.ts.map +1 -0
- package/dist/src/dlp/trufflehog-backend.js +151 -0
- package/dist/src/dlp/trufflehog-backend.js.map +1 -0
- package/dist/src/executor/http-executor.d.ts +25 -0
- package/dist/src/executor/http-executor.d.ts.map +1 -0
- package/dist/src/executor/http-executor.js +333 -0
- package/dist/src/executor/http-executor.js.map +1 -0
- package/dist/src/executor/index.d.ts +6 -0
- package/dist/src/executor/index.d.ts.map +1 -0
- package/dist/src/executor/index.js +12 -0
- package/dist/src/executor/index.js.map +1 -0
- package/dist/src/executor/interfaces.d.ts +11 -0
- package/dist/src/executor/interfaces.d.ts.map +1 -0
- package/dist/src/executor/interfaces.js +3 -0
- package/dist/src/executor/interfaces.js.map +1 -0
- package/dist/src/executor/noop-executor.d.ts +13 -0
- package/dist/src/executor/noop-executor.d.ts.map +1 -0
- package/dist/src/executor/noop-executor.js +21 -0
- package/dist/src/executor/noop-executor.js.map +1 -0
- package/dist/src/executor/registry.d.ts +30 -0
- package/dist/src/executor/registry.d.ts.map +1 -0
- package/dist/src/executor/registry.js +62 -0
- package/dist/src/executor/registry.js.map +1 -0
- package/dist/src/executor/slack-executor.d.ts +24 -0
- package/dist/src/executor/slack-executor.d.ts.map +1 -0
- package/dist/src/executor/slack-executor.js +147 -0
- package/dist/src/executor/slack-executor.js.map +1 -0
- package/dist/src/index.d.ts +25 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +74 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/mcp/auth-verifier.d.ts +23 -0
- package/dist/src/mcp/auth-verifier.d.ts.map +1 -0
- package/dist/src/mcp/auth-verifier.js +162 -0
- package/dist/src/mcp/auth-verifier.js.map +1 -0
- package/dist/src/mcp/bridge.d.ts +132 -0
- package/dist/src/mcp/bridge.d.ts.map +1 -0
- package/dist/src/mcp/bridge.js +734 -0
- package/dist/src/mcp/bridge.js.map +1 -0
- package/dist/src/mcp/http-transport.d.ts +32 -0
- package/dist/src/mcp/http-transport.d.ts.map +1 -0
- package/dist/src/mcp/http-transport.js +538 -0
- package/dist/src/mcp/http-transport.js.map +1 -0
- package/dist/src/mcp/index.d.ts +10 -0
- package/dist/src/mcp/index.d.ts.map +1 -0
- package/dist/src/mcp/index.js +17 -0
- package/dist/src/mcp/index.js.map +1 -0
- package/dist/src/mcp/oauth-pages.d.ts +23 -0
- package/dist/src/mcp/oauth-pages.d.ts.map +1 -0
- package/dist/src/mcp/oauth-pages.js +121 -0
- package/dist/src/mcp/oauth-pages.js.map +1 -0
- package/dist/src/mcp/oauth-postgres-stores.d.ts +55 -0
- package/dist/src/mcp/oauth-postgres-stores.d.ts.map +1 -0
- package/dist/src/mcp/oauth-postgres-stores.js +226 -0
- package/dist/src/mcp/oauth-postgres-stores.js.map +1 -0
- package/dist/src/mcp/oauth-provider.d.ts +95 -0
- package/dist/src/mcp/oauth-provider.d.ts.map +1 -0
- package/dist/src/mcp/oauth-provider.js +360 -0
- package/dist/src/mcp/oauth-provider.js.map +1 -0
- package/dist/src/mcp/oauth-stores.d.ts +62 -0
- package/dist/src/mcp/oauth-stores.d.ts.map +1 -0
- package/dist/src/mcp/oauth-stores.js +154 -0
- package/dist/src/mcp/oauth-stores.js.map +1 -0
- package/dist/src/mcp/server.d.ts +18 -0
- package/dist/src/mcp/server.d.ts.map +1 -0
- package/dist/src/mcp/server.js +51 -0
- package/dist/src/mcp/server.js.map +1 -0
- package/dist/src/metrics/collector.d.ts +106 -0
- package/dist/src/metrics/collector.d.ts.map +1 -0
- package/dist/src/metrics/collector.js +311 -0
- package/dist/src/metrics/collector.js.map +1 -0
- package/dist/src/metrics/index.d.ts +2 -0
- package/dist/src/metrics/index.d.ts.map +1 -0
- package/dist/src/metrics/index.js +6 -0
- package/dist/src/metrics/index.js.map +1 -0
- package/dist/src/middleware/auth.d.ts +77 -0
- package/dist/src/middleware/auth.d.ts.map +1 -0
- package/dist/src/middleware/auth.js +720 -0
- package/dist/src/middleware/auth.js.map +1 -0
- package/dist/src/middleware/session.d.ts +18 -0
- package/dist/src/middleware/session.d.ts.map +1 -0
- package/dist/src/middleware/session.js +67 -0
- package/dist/src/middleware/session.js.map +1 -0
- package/dist/src/middleware/validate.d.ts +3 -0
- package/dist/src/middleware/validate.d.ts.map +1 -0
- package/dist/src/middleware/validate.js +85 -0
- package/dist/src/middleware/validate.js.map +1 -0
- package/dist/src/policy/engine.d.ts +107 -0
- package/dist/src/policy/engine.d.ts.map +1 -0
- package/dist/src/policy/engine.js +646 -0
- package/dist/src/policy/engine.js.map +1 -0
- package/dist/src/policy/index.d.ts +3 -0
- package/dist/src/policy/index.d.ts.map +1 -0
- package/dist/src/policy/index.js +8 -0
- package/dist/src/policy/index.js.map +1 -0
- package/dist/src/policy/opa-engine.d.ts +176 -0
- package/dist/src/policy/opa-engine.d.ts.map +1 -0
- package/dist/src/policy/opa-engine.js +790 -0
- package/dist/src/policy/opa-engine.js.map +1 -0
- package/dist/src/proxy/forward-proxy.d.ts +30 -0
- package/dist/src/proxy/forward-proxy.d.ts.map +1 -0
- package/dist/src/proxy/forward-proxy.js +580 -0
- package/dist/src/proxy/forward-proxy.js.map +1 -0
- package/dist/src/proxy/index.d.ts +2 -0
- package/dist/src/proxy/index.d.ts.map +1 -0
- package/dist/src/proxy/index.js +8 -0
- package/dist/src/proxy/index.js.map +1 -0
- package/dist/src/ratelimit/limiter.d.ts +45 -0
- package/dist/src/ratelimit/limiter.d.ts.map +1 -0
- package/dist/src/ratelimit/limiter.js +158 -0
- package/dist/src/ratelimit/limiter.js.map +1 -0
- package/dist/src/replay/engine.d.ts +40 -0
- package/dist/src/replay/engine.d.ts.map +1 -0
- package/dist/src/replay/engine.js +106 -0
- package/dist/src/replay/engine.js.map +1 -0
- package/dist/src/replay/index.d.ts +2 -0
- package/dist/src/replay/index.d.ts.map +1 -0
- package/dist/src/replay/index.js +6 -0
- package/dist/src/replay/index.js.map +1 -0
- package/dist/src/saas/index.d.ts +2 -0
- package/dist/src/saas/index.d.ts.map +1 -0
- package/dist/src/saas/index.js +18 -0
- package/dist/src/saas/index.js.map +1 -0
- package/dist/src/saas/routes.d.ts +18 -0
- package/dist/src/saas/routes.d.ts.map +1 -0
- package/dist/src/saas/routes.js +1566 -0
- package/dist/src/saas/routes.js.map +1 -0
- package/dist/src/server/app.d.ts +44 -0
- package/dist/src/server/app.d.ts.map +1 -0
- package/dist/src/server/app.js +854 -0
- package/dist/src/server/app.js.map +1 -0
- package/dist/src/server/errors.d.ts +32 -0
- package/dist/src/server/errors.d.ts.map +1 -0
- package/dist/src/server/errors.js +39 -0
- package/dist/src/server/errors.js.map +1 -0
- package/dist/src/server/gateway.d.ts +165 -0
- package/dist/src/server/gateway.d.ts.map +1 -0
- package/dist/src/server/gateway.js +964 -0
- package/dist/src/server/gateway.js.map +1 -0
- package/dist/src/server/index.d.ts +2 -0
- package/dist/src/server/index.d.ts.map +1 -0
- package/dist/src/server/index.js +295 -0
- package/dist/src/server/index.js.map +1 -0
- package/dist/src/server/logger.d.ts +33 -0
- package/dist/src/server/logger.d.ts.map +1 -0
- package/dist/src/server/logger.js +230 -0
- package/dist/src/server/logger.js.map +1 -0
- package/dist/src/server/stream-proxy.d.ts +32 -0
- package/dist/src/server/stream-proxy.d.ts.map +1 -0
- package/dist/src/server/stream-proxy.js +184 -0
- package/dist/src/server/stream-proxy.js.map +1 -0
- package/dist/src/storage/file-persistence.d.ts +48 -0
- package/dist/src/storage/file-persistence.d.ts.map +1 -0
- package/dist/src/storage/file-persistence.js +280 -0
- package/dist/src/storage/file-persistence.js.map +1 -0
- package/dist/src/storage/index.d.ts +5 -0
- package/dist/src/storage/index.d.ts.map +1 -0
- package/dist/src/storage/index.js +21 -0
- package/dist/src/storage/index.js.map +1 -0
- package/dist/src/storage/interfaces.d.ts +237 -0
- package/dist/src/storage/interfaces.d.ts.map +1 -0
- package/dist/src/storage/interfaces.js +3 -0
- package/dist/src/storage/interfaces.js.map +1 -0
- package/dist/src/storage/memory.d.ts +162 -0
- package/dist/src/storage/memory.d.ts.map +1 -0
- package/dist/src/storage/memory.js +603 -0
- package/dist/src/storage/memory.js.map +1 -0
- package/dist/src/storage/postgres.d.ts +267 -0
- package/dist/src/storage/postgres.d.ts.map +1 -0
- package/dist/src/storage/postgres.js +1555 -0
- package/dist/src/storage/postgres.js.map +1 -0
- package/dist/src/storage/redis.d.ts +202 -0
- package/dist/src/storage/redis.d.ts.map +1 -0
- package/dist/src/storage/redis.js +629 -0
- package/dist/src/storage/redis.js.map +1 -0
- package/dist/src/tracing/index.d.ts +2 -0
- package/dist/src/tracing/index.d.ts.map +1 -0
- package/dist/src/tracing/index.js +6 -0
- package/dist/src/tracing/index.js.map +1 -0
- package/dist/src/tracing/provider.d.ts +43 -0
- package/dist/src/tracing/provider.d.ts.map +1 -0
- package/dist/src/tracing/provider.js +74 -0
- package/dist/src/tracing/provider.js.map +1 -0
- package/dist/src/trust/calculator.d.ts +54 -0
- package/dist/src/trust/calculator.d.ts.map +1 -0
- package/dist/src/trust/calculator.js +102 -0
- package/dist/src/trust/calculator.js.map +1 -0
- package/dist/src/trust/index.d.ts +2 -0
- package/dist/src/trust/index.d.ts.map +1 -0
- package/dist/src/trust/index.js +7 -0
- package/dist/src/trust/index.js.map +1 -0
- package/dist/src/types/budget.d.ts +30 -0
- package/dist/src/types/budget.d.ts.map +1 -0
- package/dist/src/types/budget.js +3 -0
- package/dist/src/types/budget.js.map +1 -0
- package/dist/src/types/config.d.ts +176 -0
- package/dist/src/types/config.d.ts.map +1 -0
- package/dist/src/types/config.js +3 -0
- package/dist/src/types/config.js.map +1 -0
- package/dist/src/types/events.d.ts +24 -0
- package/dist/src/types/events.d.ts.map +1 -0
- package/dist/src/types/events.js +3 -0
- package/dist/src/types/events.js.map +1 -0
- package/dist/src/types/index.d.ts +8 -0
- package/dist/src/types/index.d.ts.map +1 -0
- package/dist/src/types/index.js +24 -0
- package/dist/src/types/index.js.map +1 -0
- package/dist/src/types/policy.d.ts +60 -0
- package/dist/src/types/policy.d.ts.map +1 -0
- package/dist/src/types/policy.js +3 -0
- package/dist/src/types/policy.js.map +1 -0
- package/dist/src/types/stripe-config.d.ts +12 -0
- package/dist/src/types/stripe-config.d.ts.map +1 -0
- package/dist/src/types/stripe-config.js +3 -0
- package/dist/src/types/stripe-config.js.map +1 -0
- package/dist/src/types/subscription.d.ts +24 -0
- package/dist/src/types/subscription.d.ts.map +1 -0
- package/dist/src/types/subscription.js +38 -0
- package/dist/src/types/subscription.js.map +1 -0
- package/dist/src/types/tool-call.d.ts +42 -0
- package/dist/src/types/tool-call.d.ts.map +1 -0
- package/dist/src/types/tool-call.js +3 -0
- package/dist/src/types/tool-call.js.map +1 -0
- package/dist/src/types/tool-result.d.ts +58 -0
- package/dist/src/types/tool-result.d.ts.map +1 -0
- package/dist/src/types/tool-result.js +3 -0
- package/dist/src/types/tool-result.js.map +1 -0
- package/dist/src/types/user.d.ts +101 -0
- package/dist/src/types/user.d.ts.map +1 -0
- package/dist/src/types/user.js +6 -0
- package/dist/src/types/user.js.map +1 -0
- package/dist/tests/integration/api.test.d.ts +2 -0
- package/dist/tests/integration/api.test.d.ts.map +1 -0
- package/dist/tests/integration/api.test.js +1199 -0
- package/dist/tests/integration/api.test.js.map +1 -0
- package/dist/tests/integration/proxy.test.d.ts +2 -0
- package/dist/tests/integration/proxy.test.d.ts.map +1 -0
- package/dist/tests/integration/proxy.test.js +251 -0
- package/dist/tests/integration/proxy.test.js.map +1 -0
- package/dist/tests/integration/storage.test.d.ts +16 -0
- package/dist/tests/integration/storage.test.d.ts.map +1 -0
- package/dist/tests/integration/storage.test.js +826 -0
- package/dist/tests/integration/storage.test.js.map +1 -0
- package/dist/tests/unit/admin.test.d.ts +2 -0
- package/dist/tests/unit/admin.test.d.ts.map +1 -0
- package/dist/tests/unit/admin.test.js +698 -0
- package/dist/tests/unit/admin.test.js.map +1 -0
- package/dist/tests/unit/anomaly-detector.test.d.ts +2 -0
- package/dist/tests/unit/anomaly-detector.test.d.ts.map +1 -0
- package/dist/tests/unit/anomaly-detector.test.js +903 -0
- package/dist/tests/unit/anomaly-detector.test.js.map +1 -0
- package/dist/tests/unit/approval-manager.test.d.ts +2 -0
- package/dist/tests/unit/approval-manager.test.d.ts.map +1 -0
- package/dist/tests/unit/approval-manager.test.js +528 -0
- package/dist/tests/unit/approval-manager.test.js.map +1 -0
- package/dist/tests/unit/approval-webhook.test.d.ts +2 -0
- package/dist/tests/unit/approval-webhook.test.d.ts.map +1 -0
- package/dist/tests/unit/approval-webhook.test.js +355 -0
- package/dist/tests/unit/approval-webhook.test.js.map +1 -0
- package/dist/tests/unit/audit-logger.test.d.ts +2 -0
- package/dist/tests/unit/audit-logger.test.d.ts.map +1 -0
- package/dist/tests/unit/audit-logger.test.js +635 -0
- package/dist/tests/unit/audit-logger.test.js.map +1 -0
- package/dist/tests/unit/auth-routes.test.d.ts +2 -0
- package/dist/tests/unit/auth-routes.test.d.ts.map +1 -0
- package/dist/tests/unit/auth-routes.test.js +281 -0
- package/dist/tests/unit/auth-routes.test.js.map +1 -0
- package/dist/tests/unit/auth.test.d.ts +2 -0
- package/dist/tests/unit/auth.test.d.ts.map +1 -0
- package/dist/tests/unit/auth.test.js +1382 -0
- package/dist/tests/unit/auth.test.js.map +1 -0
- package/dist/tests/unit/billing.test.d.ts +2 -0
- package/dist/tests/unit/billing.test.d.ts.map +1 -0
- package/dist/tests/unit/billing.test.js +579 -0
- package/dist/tests/unit/billing.test.js.map +1 -0
- package/dist/tests/unit/budget-manager.test.d.ts +2 -0
- package/dist/tests/unit/budget-manager.test.d.ts.map +1 -0
- package/dist/tests/unit/budget-manager.test.js +778 -0
- package/dist/tests/unit/budget-manager.test.js.map +1 -0
- package/dist/tests/unit/budget-race.test.d.ts +2 -0
- package/dist/tests/unit/budget-race.test.d.ts.map +1 -0
- package/dist/tests/unit/budget-race.test.js +58 -0
- package/dist/tests/unit/budget-race.test.js.map +1 -0
- package/dist/tests/unit/cli.test.d.ts +2 -0
- package/dist/tests/unit/cli.test.d.ts.map +1 -0
- package/dist/tests/unit/cli.test.js +93 -0
- package/dist/tests/unit/cli.test.js.map +1 -0
- package/dist/tests/unit/concurrency.test.d.ts +2 -0
- package/dist/tests/unit/concurrency.test.d.ts.map +1 -0
- package/dist/tests/unit/concurrency.test.js +1270 -0
- package/dist/tests/unit/concurrency.test.js.map +1 -0
- package/dist/tests/unit/config-validate.test.d.ts +2 -0
- package/dist/tests/unit/config-validate.test.d.ts.map +1 -0
- package/dist/tests/unit/config-validate.test.js +230 -0
- package/dist/tests/unit/config-validate.test.js.map +1 -0
- package/dist/tests/unit/defaults.test.d.ts +2 -0
- package/dist/tests/unit/defaults.test.d.ts.map +1 -0
- package/dist/tests/unit/defaults.test.js +364 -0
- package/dist/tests/unit/defaults.test.js.map +1 -0
- package/dist/tests/unit/dlp-backends.test.d.ts +2 -0
- package/dist/tests/unit/dlp-backends.test.d.ts.map +1 -0
- package/dist/tests/unit/dlp-backends.test.js +563 -0
- package/dist/tests/unit/dlp-backends.test.js.map +1 -0
- package/dist/tests/unit/dlp-scanner.test.d.ts +2 -0
- package/dist/tests/unit/dlp-scanner.test.d.ts.map +1 -0
- package/dist/tests/unit/dlp-scanner.test.js +739 -0
- package/dist/tests/unit/dlp-scanner.test.js.map +1 -0
- package/dist/tests/unit/error-responses.test.d.ts +2 -0
- package/dist/tests/unit/error-responses.test.d.ts.map +1 -0
- package/dist/tests/unit/error-responses.test.js +101 -0
- package/dist/tests/unit/error-responses.test.js.map +1 -0
- package/dist/tests/unit/executor-registry.test.d.ts +2 -0
- package/dist/tests/unit/executor-registry.test.d.ts.map +1 -0
- package/dist/tests/unit/executor-registry.test.js +390 -0
- package/dist/tests/unit/executor-registry.test.js.map +1 -0
- package/dist/tests/unit/forward-proxy.test.d.ts +2 -0
- package/dist/tests/unit/forward-proxy.test.d.ts.map +1 -0
- package/dist/tests/unit/forward-proxy.test.js +621 -0
- package/dist/tests/unit/forward-proxy.test.js.map +1 -0
- package/dist/tests/unit/gateway-features.test.d.ts +2 -0
- package/dist/tests/unit/gateway-features.test.d.ts.map +1 -0
- package/dist/tests/unit/gateway-features.test.js +753 -0
- package/dist/tests/unit/gateway-features.test.js.map +1 -0
- package/dist/tests/unit/http-executor.test.d.ts +2 -0
- package/dist/tests/unit/http-executor.test.d.ts.map +1 -0
- package/dist/tests/unit/http-executor.test.js +310 -0
- package/dist/tests/unit/http-executor.test.js.map +1 -0
- package/dist/tests/unit/mcp-bridge.test.d.ts +2 -0
- package/dist/tests/unit/mcp-bridge.test.d.ts.map +1 -0
- package/dist/tests/unit/mcp-bridge.test.js +1136 -0
- package/dist/tests/unit/mcp-bridge.test.js.map +1 -0
- package/dist/tests/unit/mcp-http-transport.test.d.ts +2 -0
- package/dist/tests/unit/mcp-http-transport.test.d.ts.map +1 -0
- package/dist/tests/unit/mcp-http-transport.test.js +899 -0
- package/dist/tests/unit/mcp-http-transport.test.js.map +1 -0
- package/dist/tests/unit/mcp-oauth.test.d.ts +2 -0
- package/dist/tests/unit/mcp-oauth.test.d.ts.map +1 -0
- package/dist/tests/unit/mcp-oauth.test.js +759 -0
- package/dist/tests/unit/mcp-oauth.test.js.map +1 -0
- package/dist/tests/unit/mcp-server.test.d.ts +15 -0
- package/dist/tests/unit/mcp-server.test.d.ts.map +1 -0
- package/dist/tests/unit/mcp-server.test.js +158 -0
- package/dist/tests/unit/mcp-server.test.js.map +1 -0
- package/dist/tests/unit/metrics.test.d.ts +2 -0
- package/dist/tests/unit/metrics.test.d.ts.map +1 -0
- package/dist/tests/unit/metrics.test.js +208 -0
- package/dist/tests/unit/metrics.test.js.map +1 -0
- package/dist/tests/unit/oauth.test.d.ts +2 -0
- package/dist/tests/unit/oauth.test.d.ts.map +1 -0
- package/dist/tests/unit/oauth.test.js +281 -0
- package/dist/tests/unit/oauth.test.js.map +1 -0
- package/dist/tests/unit/opa-circuit-breaker.test.d.ts +2 -0
- package/dist/tests/unit/opa-circuit-breaker.test.d.ts.map +1 -0
- package/dist/tests/unit/opa-circuit-breaker.test.js +297 -0
- package/dist/tests/unit/opa-circuit-breaker.test.js.map +1 -0
- package/dist/tests/unit/opa-engine.test.d.ts +2 -0
- package/dist/tests/unit/opa-engine.test.d.ts.map +1 -0
- package/dist/tests/unit/opa-engine.test.js +1813 -0
- package/dist/tests/unit/opa-engine.test.js.map +1 -0
- package/dist/tests/unit/pipeline-timing.test.d.ts +2 -0
- package/dist/tests/unit/pipeline-timing.test.d.ts.map +1 -0
- package/dist/tests/unit/pipeline-timing.test.js +528 -0
- package/dist/tests/unit/pipeline-timing.test.js.map +1 -0
- package/dist/tests/unit/policy-engine.test.d.ts +2 -0
- package/dist/tests/unit/policy-engine.test.d.ts.map +1 -0
- package/dist/tests/unit/policy-engine.test.js +1345 -0
- package/dist/tests/unit/policy-engine.test.js.map +1 -0
- package/dist/tests/unit/policy-store.test.d.ts +2 -0
- package/dist/tests/unit/policy-store.test.d.ts.map +1 -0
- package/dist/tests/unit/policy-store.test.js +60 -0
- package/dist/tests/unit/policy-store.test.js.map +1 -0
- package/dist/tests/unit/postgres-storage.test.d.ts +2 -0
- package/dist/tests/unit/postgres-storage.test.d.ts.map +1 -0
- package/dist/tests/unit/postgres-storage.test.js +614 -0
- package/dist/tests/unit/postgres-storage.test.js.map +1 -0
- package/dist/tests/unit/prompt-injection-backend.test.d.ts +2 -0
- package/dist/tests/unit/prompt-injection-backend.test.d.ts.map +1 -0
- package/dist/tests/unit/prompt-injection-backend.test.js +621 -0
- package/dist/tests/unit/prompt-injection-backend.test.js.map +1 -0
- package/dist/tests/unit/proxy-hardening.test.d.ts +2 -0
- package/dist/tests/unit/proxy-hardening.test.d.ts.map +1 -0
- package/dist/tests/unit/proxy-hardening.test.js +166 -0
- package/dist/tests/unit/proxy-hardening.test.js.map +1 -0
- package/dist/tests/unit/rate-limiter.test.d.ts +2 -0
- package/dist/tests/unit/rate-limiter.test.d.ts.map +1 -0
- package/dist/tests/unit/rate-limiter.test.js +443 -0
- package/dist/tests/unit/rate-limiter.test.js.map +1 -0
- package/dist/tests/unit/redis-storage.test.d.ts +2 -0
- package/dist/tests/unit/redis-storage.test.d.ts.map +1 -0
- package/dist/tests/unit/redis-storage.test.js +766 -0
- package/dist/tests/unit/redis-storage.test.js.map +1 -0
- package/dist/tests/unit/replay-engine.test.d.ts +2 -0
- package/dist/tests/unit/replay-engine.test.d.ts.map +1 -0
- package/dist/tests/unit/replay-engine.test.js +371 -0
- package/dist/tests/unit/replay-engine.test.js.map +1 -0
- package/dist/tests/unit/saas-routes.test.d.ts +2 -0
- package/dist/tests/unit/saas-routes.test.d.ts.map +1 -0
- package/dist/tests/unit/saas-routes.test.js +1399 -0
- package/dist/tests/unit/saas-routes.test.js.map +1 -0
- package/dist/tests/unit/session.test.d.ts +2 -0
- package/dist/tests/unit/session.test.d.ts.map +1 -0
- package/dist/tests/unit/session.test.js +532 -0
- package/dist/tests/unit/session.test.js.map +1 -0
- package/dist/tests/unit/slack-executor.test.d.ts +2 -0
- package/dist/tests/unit/slack-executor.test.d.ts.map +1 -0
- package/dist/tests/unit/slack-executor.test.js +209 -0
- package/dist/tests/unit/slack-executor.test.js.map +1 -0
- package/dist/tests/unit/storage-hardening.test.d.ts +2 -0
- package/dist/tests/unit/storage-hardening.test.d.ts.map +1 -0
- package/dist/tests/unit/storage-hardening.test.js +165 -0
- package/dist/tests/unit/storage-hardening.test.js.map +1 -0
- package/dist/tests/unit/storage.test.d.ts +2 -0
- package/dist/tests/unit/storage.test.d.ts.map +1 -0
- package/dist/tests/unit/storage.test.js +698 -0
- package/dist/tests/unit/storage.test.js.map +1 -0
- package/dist/tests/unit/text-normalizer.test.d.ts +2 -0
- package/dist/tests/unit/text-normalizer.test.d.ts.map +1 -0
- package/dist/tests/unit/text-normalizer.test.js +229 -0
- package/dist/tests/unit/text-normalizer.test.js.map +1 -0
- package/dist/tests/unit/tracing.test.d.ts +2 -0
- package/dist/tests/unit/tracing.test.d.ts.map +1 -0
- package/dist/tests/unit/tracing.test.js +611 -0
- package/dist/tests/unit/tracing.test.js.map +1 -0
- package/dist/tests/unit/trust-calculator.test.d.ts +2 -0
- package/dist/tests/unit/trust-calculator.test.d.ts.map +1 -0
- package/dist/tests/unit/trust-calculator.test.js +497 -0
- package/dist/tests/unit/trust-calculator.test.js.map +1 -0
- package/dist/tests/unit/ts-sdk.test.d.ts +2 -0
- package/dist/tests/unit/ts-sdk.test.d.ts.map +1 -0
- package/dist/tests/unit/ts-sdk.test.js +421 -0
- package/dist/tests/unit/ts-sdk.test.js.map +1 -0
- package/dist/tests/unit/usage-extractor-llm.test.d.ts +2 -0
- package/dist/tests/unit/usage-extractor-llm.test.d.ts.map +1 -0
- package/dist/tests/unit/usage-extractor-llm.test.js +139 -0
- package/dist/tests/unit/usage-extractor-llm.test.js.map +1 -0
- package/dist/tests/unit/usage-extractor.test.d.ts +2 -0
- package/dist/tests/unit/usage-extractor.test.d.ts.map +1 -0
- package/dist/tests/unit/usage-extractor.test.js +271 -0
- package/dist/tests/unit/usage-extractor.test.js.map +1 -0
- package/dist/tests/unit/user-stores.test.d.ts +2 -0
- package/dist/tests/unit/user-stores.test.d.ts.map +1 -0
- package/dist/tests/unit/user-stores.test.js +687 -0
- package/dist/tests/unit/user-stores.test.js.map +1 -0
- package/dist/tests/unit/validate.test.d.ts +2 -0
- package/dist/tests/unit/validate.test.d.ts.map +1 -0
- package/dist/tests/unit/validate.test.js +545 -0
- package/dist/tests/unit/validate.test.js.map +1 -0
- package/package.json +86 -0
- package/policy-packs/README.md +42 -0
- package/policy-packs/default.yaml +46 -0
- package/policy-packs/dev_fast.yaml +54 -0
- package/policy-packs/prod_strict.yaml +83 -0
|
@@ -0,0 +1,899 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const express_1 = __importDefault(require("express"));
|
|
7
|
+
const supertest_1 = __importDefault(require("supertest"));
|
|
8
|
+
// ---------------------------------------------------------------------------
|
|
9
|
+
// Mock Gateway
|
|
10
|
+
// ---------------------------------------------------------------------------
|
|
11
|
+
function buildToolResult(overrides) {
|
|
12
|
+
return {
|
|
13
|
+
tool_call_id: 'tc-001',
|
|
14
|
+
task_id: 'task-001',
|
|
15
|
+
status: 'ok',
|
|
16
|
+
policy: {
|
|
17
|
+
decision: 'allow',
|
|
18
|
+
rule_id: 'rule-1',
|
|
19
|
+
reasons: ['Allowed by default policy'],
|
|
20
|
+
},
|
|
21
|
+
dlp: {
|
|
22
|
+
detected: [],
|
|
23
|
+
redactions: [],
|
|
24
|
+
severity: 'low',
|
|
25
|
+
},
|
|
26
|
+
budget: {
|
|
27
|
+
estimated_cost_usd: 0.001,
|
|
28
|
+
spent_cost_usd_task: 0.005,
|
|
29
|
+
remaining_cost_usd_task: 1.995,
|
|
30
|
+
},
|
|
31
|
+
output: {
|
|
32
|
+
http_status: 200,
|
|
33
|
+
body: { data: 'test response' },
|
|
34
|
+
},
|
|
35
|
+
timing: {
|
|
36
|
+
started_at: new Date().toISOString(),
|
|
37
|
+
duration_ms: 42,
|
|
38
|
+
},
|
|
39
|
+
...overrides,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
function createMockGateway() {
|
|
43
|
+
return {
|
|
44
|
+
execute: jest.fn().mockResolvedValue(buildToolResult()),
|
|
45
|
+
shutdown: jest.fn(),
|
|
46
|
+
registerExecutor: jest.fn(),
|
|
47
|
+
preExecute: jest.fn(),
|
|
48
|
+
postExecute: jest.fn(),
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
// ---------------------------------------------------------------------------
|
|
52
|
+
// Import after mocks
|
|
53
|
+
// ---------------------------------------------------------------------------
|
|
54
|
+
const http_transport_1 = require("../../src/mcp/http-transport");
|
|
55
|
+
// ---------------------------------------------------------------------------
|
|
56
|
+
// Test helpers
|
|
57
|
+
// ---------------------------------------------------------------------------
|
|
58
|
+
function createTestApp(gateway, config) {
|
|
59
|
+
const app = (0, express_1.default)();
|
|
60
|
+
app.use(express_1.default.json());
|
|
61
|
+
const handler = (0, http_transport_1.createMCPHttpHandler)(gateway, config);
|
|
62
|
+
app.use('/mcp', handler.router);
|
|
63
|
+
return { app, handler };
|
|
64
|
+
}
|
|
65
|
+
const INIT_REQUEST = {
|
|
66
|
+
jsonrpc: '2.0',
|
|
67
|
+
id: 1,
|
|
68
|
+
method: 'initialize',
|
|
69
|
+
params: {
|
|
70
|
+
protocolVersion: '2025-03-26',
|
|
71
|
+
capabilities: {},
|
|
72
|
+
clientInfo: { name: 'test-client', version: '1.0.0' },
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
const INITIALIZED_NOTIFICATION = {
|
|
76
|
+
jsonrpc: '2.0',
|
|
77
|
+
method: 'notifications/initialized',
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* Initialize an MCP session and return the session ID.
|
|
81
|
+
* Sends initialize + initialized notification.
|
|
82
|
+
*/
|
|
83
|
+
async function initSession(app) {
|
|
84
|
+
const res = await (0, supertest_1.default)(app)
|
|
85
|
+
.post('/mcp')
|
|
86
|
+
.send(INIT_REQUEST)
|
|
87
|
+
.set('Accept', 'application/json, text/event-stream');
|
|
88
|
+
// Parse session ID from response headers
|
|
89
|
+
const sessionId = res.headers['mcp-session-id'];
|
|
90
|
+
if (!sessionId) {
|
|
91
|
+
throw new Error(`No session ID in response. Status: ${res.status}, Body: ${JSON.stringify(res.body)}`);
|
|
92
|
+
}
|
|
93
|
+
// Send initialized notification
|
|
94
|
+
await (0, supertest_1.default)(app)
|
|
95
|
+
.post('/mcp')
|
|
96
|
+
.send(INITIALIZED_NOTIFICATION)
|
|
97
|
+
.set('mcp-session-id', sessionId)
|
|
98
|
+
.set('Accept', 'application/json, text/event-stream');
|
|
99
|
+
return sessionId;
|
|
100
|
+
}
|
|
101
|
+
// ---------------------------------------------------------------------------
|
|
102
|
+
// Tests
|
|
103
|
+
// ---------------------------------------------------------------------------
|
|
104
|
+
describe('MCP HTTP Transport', () => {
|
|
105
|
+
let gateway;
|
|
106
|
+
let app;
|
|
107
|
+
let handler;
|
|
108
|
+
beforeEach(() => {
|
|
109
|
+
gateway = createMockGateway();
|
|
110
|
+
const result = createTestApp(gateway);
|
|
111
|
+
app = result.app;
|
|
112
|
+
handler = result.handler;
|
|
113
|
+
});
|
|
114
|
+
afterEach(async () => {
|
|
115
|
+
await handler.close();
|
|
116
|
+
});
|
|
117
|
+
// -- Initialization -------------------------------------------------------
|
|
118
|
+
describe('initialization', () => {
|
|
119
|
+
it('returns server info and session ID on initialize', async () => {
|
|
120
|
+
const res = await (0, supertest_1.default)(app)
|
|
121
|
+
.post('/mcp')
|
|
122
|
+
.send(INIT_REQUEST)
|
|
123
|
+
.set('Accept', 'application/json, text/event-stream');
|
|
124
|
+
expect(res.status).toBe(200);
|
|
125
|
+
expect(res.headers['mcp-session-id']).toBeDefined();
|
|
126
|
+
// Response may be SSE or JSON depending on transport
|
|
127
|
+
const body = parseSSEOrJSON(res);
|
|
128
|
+
expect(body.result).toBeDefined();
|
|
129
|
+
expect(body.result.protocolVersion).toBe('2025-03-26');
|
|
130
|
+
expect(body.result.serverInfo.name).toBe('palaryn-mcp');
|
|
131
|
+
expect(body.result.serverInfo.version).toBe('1.0.0');
|
|
132
|
+
expect(body.result.capabilities.tools).toBeDefined();
|
|
133
|
+
});
|
|
134
|
+
it('returns 404 for invalid session ID', async () => {
|
|
135
|
+
const res = await (0, supertest_1.default)(app)
|
|
136
|
+
.post('/mcp')
|
|
137
|
+
.send({ jsonrpc: '2.0', id: 1, method: 'tools/list', params: {} })
|
|
138
|
+
.set('mcp-session-id', 'nonexistent-session')
|
|
139
|
+
.set('Accept', 'application/json, text/event-stream');
|
|
140
|
+
expect(res.status).toBe(404);
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
// -- Tool listing ---------------------------------------------------------
|
|
144
|
+
describe('tools/list', () => {
|
|
145
|
+
it('returns 3 tools', async () => {
|
|
146
|
+
const sessionId = await initSession(app);
|
|
147
|
+
const res = await (0, supertest_1.default)(app)
|
|
148
|
+
.post('/mcp')
|
|
149
|
+
.send({ jsonrpc: '2.0', id: 2, method: 'tools/list', params: {} })
|
|
150
|
+
.set('mcp-session-id', sessionId)
|
|
151
|
+
.set('Accept', 'application/json, text/event-stream');
|
|
152
|
+
expect(res.status).toBe(200);
|
|
153
|
+
const body = parseSSEOrJSON(res);
|
|
154
|
+
expect(body.result.tools).toHaveLength(3);
|
|
155
|
+
const toolNames = body.result.tools.map((t) => t.name);
|
|
156
|
+
expect(toolNames).toContain('http_request');
|
|
157
|
+
expect(toolNames).toContain('http_get');
|
|
158
|
+
expect(toolNames).toContain('http_post');
|
|
159
|
+
});
|
|
160
|
+
it('http_get has readOnlyHint annotation', async () => {
|
|
161
|
+
const sessionId = await initSession(app);
|
|
162
|
+
const res = await (0, supertest_1.default)(app)
|
|
163
|
+
.post('/mcp')
|
|
164
|
+
.send({ jsonrpc: '2.0', id: 2, method: 'tools/list', params: {} })
|
|
165
|
+
.set('mcp-session-id', sessionId)
|
|
166
|
+
.set('Accept', 'application/json, text/event-stream');
|
|
167
|
+
const body = parseSSEOrJSON(res);
|
|
168
|
+
const httpGet = body.result.tools.find((t) => t.name === 'http_get');
|
|
169
|
+
expect(httpGet.annotations.readOnlyHint).toBe(true);
|
|
170
|
+
expect(httpGet.annotations.destructiveHint).toBe(false);
|
|
171
|
+
});
|
|
172
|
+
it('http_request has destructiveHint annotation', async () => {
|
|
173
|
+
const sessionId = await initSession(app);
|
|
174
|
+
const res = await (0, supertest_1.default)(app)
|
|
175
|
+
.post('/mcp')
|
|
176
|
+
.send({ jsonrpc: '2.0', id: 2, method: 'tools/list', params: {} })
|
|
177
|
+
.set('mcp-session-id', sessionId)
|
|
178
|
+
.set('Accept', 'application/json, text/event-stream');
|
|
179
|
+
const body = parseSSEOrJSON(res);
|
|
180
|
+
const httpReq = body.result.tools.find((t) => t.name === 'http_request');
|
|
181
|
+
expect(httpReq.annotations.destructiveHint).toBe(true);
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
// -- Tool execution -------------------------------------------------------
|
|
185
|
+
describe('tools/call', () => {
|
|
186
|
+
it('http_get rejects when no auth identity present (S1)', async () => {
|
|
187
|
+
const sessionId = await initSession(app);
|
|
188
|
+
const res = await (0, supertest_1.default)(app)
|
|
189
|
+
.post('/mcp')
|
|
190
|
+
.send({
|
|
191
|
+
jsonrpc: '2.0',
|
|
192
|
+
id: 3,
|
|
193
|
+
method: 'tools/call',
|
|
194
|
+
params: {
|
|
195
|
+
name: 'http_get',
|
|
196
|
+
arguments: { url: 'https://api.example.com/data' },
|
|
197
|
+
},
|
|
198
|
+
})
|
|
199
|
+
.set('mcp-session-id', sessionId)
|
|
200
|
+
.set('Accept', 'application/json, text/event-stream');
|
|
201
|
+
expect(res.status).toBe(200);
|
|
202
|
+
// gateway.execute should NOT have been called — auth rejection happens before execution
|
|
203
|
+
expect(gateway.execute).not.toHaveBeenCalled();
|
|
204
|
+
const body = parseSSEOrJSON(res);
|
|
205
|
+
expect(body.result.isError).toBe(true);
|
|
206
|
+
const errorPayload = JSON.parse(body.result.content[0].text);
|
|
207
|
+
expect(errorPayload.error_code).toBe('AUTH_REQUIRED');
|
|
208
|
+
});
|
|
209
|
+
it('http_post builds correct ToolCall with body (with auth)', async () => {
|
|
210
|
+
// Create app with auth middleware
|
|
211
|
+
const authApp = (0, express_1.default)();
|
|
212
|
+
authApp.use(express_1.default.json());
|
|
213
|
+
authApp.use((req, _res, next) => {
|
|
214
|
+
req.auth = { workspace_id: 'ws-test', actor_id: 'actor-test', permissions: ['tool:execute'] };
|
|
215
|
+
next();
|
|
216
|
+
});
|
|
217
|
+
const authHandler = (0, http_transport_1.createMCPHttpHandler)(gateway);
|
|
218
|
+
authApp.use('/mcp', authHandler.router);
|
|
219
|
+
const sessionId = await initSession(authApp);
|
|
220
|
+
await (0, supertest_1.default)(authApp)
|
|
221
|
+
.post('/mcp')
|
|
222
|
+
.send({
|
|
223
|
+
jsonrpc: '2.0',
|
|
224
|
+
id: 3,
|
|
225
|
+
method: 'tools/call',
|
|
226
|
+
params: {
|
|
227
|
+
name: 'http_post',
|
|
228
|
+
arguments: {
|
|
229
|
+
url: 'https://api.example.com/submit',
|
|
230
|
+
body: '{"key":"value"}',
|
|
231
|
+
headers: { 'Content-Type': 'application/json' },
|
|
232
|
+
},
|
|
233
|
+
},
|
|
234
|
+
})
|
|
235
|
+
.set('mcp-session-id', sessionId)
|
|
236
|
+
.set('Accept', 'application/json, text/event-stream');
|
|
237
|
+
expect(gateway.execute).toHaveBeenCalledTimes(1);
|
|
238
|
+
const toolCall = gateway.execute.mock.calls[0][0];
|
|
239
|
+
expect(toolCall.tool.name).toBe('http.post');
|
|
240
|
+
expect(toolCall.tool.capability).toBe('write');
|
|
241
|
+
expect(toolCall.args.method).toBe('POST');
|
|
242
|
+
expect(toolCall.args.body).toEqual({ key: 'value' }); // parsed JSON
|
|
243
|
+
await authHandler.close();
|
|
244
|
+
});
|
|
245
|
+
it('http_request with DELETE method has delete capability (with auth)', async () => {
|
|
246
|
+
const authApp = (0, express_1.default)();
|
|
247
|
+
authApp.use(express_1.default.json());
|
|
248
|
+
authApp.use((req, _res, next) => {
|
|
249
|
+
req.auth = { workspace_id: 'ws-test', actor_id: 'actor-test', permissions: ['tool:execute'] };
|
|
250
|
+
next();
|
|
251
|
+
});
|
|
252
|
+
const authHandler = (0, http_transport_1.createMCPHttpHandler)(gateway);
|
|
253
|
+
authApp.use('/mcp', authHandler.router);
|
|
254
|
+
const sessionId = await initSession(authApp);
|
|
255
|
+
await (0, supertest_1.default)(authApp)
|
|
256
|
+
.post('/mcp')
|
|
257
|
+
.send({
|
|
258
|
+
jsonrpc: '2.0',
|
|
259
|
+
id: 3,
|
|
260
|
+
method: 'tools/call',
|
|
261
|
+
params: {
|
|
262
|
+
name: 'http_request',
|
|
263
|
+
arguments: { url: 'https://api.example.com/item/1', method: 'DELETE' },
|
|
264
|
+
},
|
|
265
|
+
})
|
|
266
|
+
.set('mcp-session-id', sessionId)
|
|
267
|
+
.set('Accept', 'application/json, text/event-stream');
|
|
268
|
+
const toolCall = gateway.execute.mock.calls[0][0];
|
|
269
|
+
expect(toolCall.tool.name).toBe('http.request');
|
|
270
|
+
expect(toolCall.tool.capability).toBe('delete');
|
|
271
|
+
expect(toolCall.args.method).toBe('DELETE');
|
|
272
|
+
await authHandler.close();
|
|
273
|
+
});
|
|
274
|
+
it('http_request defaults to GET when no method specified (with auth)', async () => {
|
|
275
|
+
const authApp = (0, express_1.default)();
|
|
276
|
+
authApp.use(express_1.default.json());
|
|
277
|
+
authApp.use((req, _res, next) => {
|
|
278
|
+
req.auth = { workspace_id: 'ws-test', actor_id: 'actor-test', permissions: ['tool:execute'] };
|
|
279
|
+
next();
|
|
280
|
+
});
|
|
281
|
+
const authHandler = (0, http_transport_1.createMCPHttpHandler)(gateway);
|
|
282
|
+
authApp.use('/mcp', authHandler.router);
|
|
283
|
+
const sessionId = await initSession(authApp);
|
|
284
|
+
await (0, supertest_1.default)(authApp)
|
|
285
|
+
.post('/mcp')
|
|
286
|
+
.send({
|
|
287
|
+
jsonrpc: '2.0',
|
|
288
|
+
id: 3,
|
|
289
|
+
method: 'tools/call',
|
|
290
|
+
params: {
|
|
291
|
+
name: 'http_request',
|
|
292
|
+
arguments: { url: 'https://api.example.com/data' },
|
|
293
|
+
},
|
|
294
|
+
})
|
|
295
|
+
.set('mcp-session-id', sessionId)
|
|
296
|
+
.set('Accept', 'application/json, text/event-stream');
|
|
297
|
+
const toolCall = gateway.execute.mock.calls[0][0];
|
|
298
|
+
expect(toolCall.args.method).toBe('GET');
|
|
299
|
+
expect(toolCall.tool.capability).toBe('read');
|
|
300
|
+
await authHandler.close();
|
|
301
|
+
});
|
|
302
|
+
it('passes constraints and context from tool arguments (with auth)', async () => {
|
|
303
|
+
const authApp = (0, express_1.default)();
|
|
304
|
+
authApp.use(express_1.default.json());
|
|
305
|
+
authApp.use((req, _res, next) => {
|
|
306
|
+
req.auth = { workspace_id: 'ws-test', actor_id: 'actor-test', permissions: ['tool:execute'] };
|
|
307
|
+
next();
|
|
308
|
+
});
|
|
309
|
+
const authHandler = (0, http_transport_1.createMCPHttpHandler)(gateway);
|
|
310
|
+
authApp.use('/mcp', authHandler.router);
|
|
311
|
+
const sessionId = await initSession(authApp);
|
|
312
|
+
await (0, supertest_1.default)(authApp)
|
|
313
|
+
.post('/mcp')
|
|
314
|
+
.send({
|
|
315
|
+
jsonrpc: '2.0',
|
|
316
|
+
id: 3,
|
|
317
|
+
method: 'tools/call',
|
|
318
|
+
params: {
|
|
319
|
+
name: 'http_get',
|
|
320
|
+
arguments: {
|
|
321
|
+
url: 'https://api.example.com/data',
|
|
322
|
+
timeout_ms: 5000,
|
|
323
|
+
max_cost_usd: 0.01,
|
|
324
|
+
purpose: 'Fetching user data',
|
|
325
|
+
labels: ['user-data', 'read-only'],
|
|
326
|
+
},
|
|
327
|
+
},
|
|
328
|
+
})
|
|
329
|
+
.set('mcp-session-id', sessionId)
|
|
330
|
+
.set('Accept', 'application/json, text/event-stream');
|
|
331
|
+
const toolCall = gateway.execute.mock.calls[0][0];
|
|
332
|
+
expect(toolCall.constraints).toEqual({ timeout_ms: 5000, max_cost_usd: 0.01 });
|
|
333
|
+
expect(toolCall.context).toEqual({ purpose: 'Fetching user data', labels: ['user-data', 'read-only'] });
|
|
334
|
+
await authHandler.close();
|
|
335
|
+
});
|
|
336
|
+
it('returns formatted result with gateway metadata (with auth)', async () => {
|
|
337
|
+
const authApp = (0, express_1.default)();
|
|
338
|
+
authApp.use(express_1.default.json());
|
|
339
|
+
authApp.use((req, _res, next) => {
|
|
340
|
+
req.auth = { workspace_id: 'ws-test', actor_id: 'actor-test', permissions: ['tool:execute'] };
|
|
341
|
+
next();
|
|
342
|
+
});
|
|
343
|
+
const authHandler = (0, http_transport_1.createMCPHttpHandler)(gateway);
|
|
344
|
+
authApp.use('/mcp', authHandler.router);
|
|
345
|
+
const sessionId = await initSession(authApp);
|
|
346
|
+
const res = await (0, supertest_1.default)(authApp)
|
|
347
|
+
.post('/mcp')
|
|
348
|
+
.send({
|
|
349
|
+
jsonrpc: '2.0',
|
|
350
|
+
id: 3,
|
|
351
|
+
method: 'tools/call',
|
|
352
|
+
params: {
|
|
353
|
+
name: 'http_get',
|
|
354
|
+
arguments: { url: 'https://api.example.com/data' },
|
|
355
|
+
},
|
|
356
|
+
})
|
|
357
|
+
.set('mcp-session-id', sessionId)
|
|
358
|
+
.set('Accept', 'application/json, text/event-stream');
|
|
359
|
+
const body = parseSSEOrJSON(res);
|
|
360
|
+
expect(body.result.content).toHaveLength(2);
|
|
361
|
+
expect(body.result.content[0].type).toBe('text');
|
|
362
|
+
// Primary content should have the response body
|
|
363
|
+
const primary = JSON.parse(body.result.content[0].text);
|
|
364
|
+
expect(primary.data).toBe('test response');
|
|
365
|
+
// Metadata block
|
|
366
|
+
expect(body.result.content[1].text).toContain('Gateway Metadata');
|
|
367
|
+
expect(body.result.content[1].text).toContain('tc-001');
|
|
368
|
+
await authHandler.close();
|
|
369
|
+
});
|
|
370
|
+
it('returns isError for blocked results (with auth)', async () => {
|
|
371
|
+
gateway.execute.mockResolvedValueOnce(buildToolResult({
|
|
372
|
+
status: 'blocked',
|
|
373
|
+
error: 'Policy denied: domain not allowed',
|
|
374
|
+
policy: { decision: 'deny', rule_id: 'block-rule', reasons: ['Domain blocked'] },
|
|
375
|
+
}));
|
|
376
|
+
const authApp = (0, express_1.default)();
|
|
377
|
+
authApp.use(express_1.default.json());
|
|
378
|
+
authApp.use((req, _res, next) => {
|
|
379
|
+
req.auth = { workspace_id: 'ws-test', actor_id: 'actor-test', permissions: ['tool:execute'] };
|
|
380
|
+
next();
|
|
381
|
+
});
|
|
382
|
+
const authHandler = (0, http_transport_1.createMCPHttpHandler)(gateway);
|
|
383
|
+
authApp.use('/mcp', authHandler.router);
|
|
384
|
+
const sessionId = await initSession(authApp);
|
|
385
|
+
const res = await (0, supertest_1.default)(authApp)
|
|
386
|
+
.post('/mcp')
|
|
387
|
+
.send({
|
|
388
|
+
jsonrpc: '2.0',
|
|
389
|
+
id: 3,
|
|
390
|
+
method: 'tools/call',
|
|
391
|
+
params: {
|
|
392
|
+
name: 'http_get',
|
|
393
|
+
arguments: { url: 'https://blocked.example.com' },
|
|
394
|
+
},
|
|
395
|
+
})
|
|
396
|
+
.set('mcp-session-id', sessionId)
|
|
397
|
+
.set('Accept', 'application/json, text/event-stream');
|
|
398
|
+
const body = parseSSEOrJSON(res);
|
|
399
|
+
expect(body.result.isError).toBe(true);
|
|
400
|
+
expect(body.result.content[0].text).toContain('Policy denied');
|
|
401
|
+
await authHandler.close();
|
|
402
|
+
});
|
|
403
|
+
});
|
|
404
|
+
// -- Session management ---------------------------------------------------
|
|
405
|
+
describe('session management', () => {
|
|
406
|
+
it('GET without session ID returns 400', async () => {
|
|
407
|
+
const res = await (0, supertest_1.default)(app).get('/mcp');
|
|
408
|
+
expect(res.status).toBe(400);
|
|
409
|
+
});
|
|
410
|
+
it('DELETE without session ID returns 404', async () => {
|
|
411
|
+
const res = await (0, supertest_1.default)(app).delete('/mcp');
|
|
412
|
+
expect(res.status).toBe(404);
|
|
413
|
+
});
|
|
414
|
+
it('DELETE with invalid session ID returns 404', async () => {
|
|
415
|
+
const res = await (0, supertest_1.default)(app)
|
|
416
|
+
.delete('/mcp')
|
|
417
|
+
.set('mcp-session-id', 'invalid-session');
|
|
418
|
+
expect(res.status).toBe(404);
|
|
419
|
+
});
|
|
420
|
+
});
|
|
421
|
+
// -- Configuration --------------------------------------------------------
|
|
422
|
+
describe('configuration', () => {
|
|
423
|
+
it('uses authenticated identity and custom platform', async () => {
|
|
424
|
+
const customApp = (0, express_1.default)();
|
|
425
|
+
customApp.use(express_1.default.json());
|
|
426
|
+
customApp.use((req, _res, next) => {
|
|
427
|
+
req.auth = {
|
|
428
|
+
workspace_id: 'custom-ws',
|
|
429
|
+
actor_id: 'custom-actor',
|
|
430
|
+
auth_method: 'api_key',
|
|
431
|
+
};
|
|
432
|
+
next();
|
|
433
|
+
});
|
|
434
|
+
const customHandler = (0, http_transport_1.createMCPHttpHandler)(gateway, {
|
|
435
|
+
platform: 'custom_platform',
|
|
436
|
+
});
|
|
437
|
+
customApp.use('/mcp', customHandler.router);
|
|
438
|
+
const sessionId = await initSession(customApp);
|
|
439
|
+
await (0, supertest_1.default)(customApp)
|
|
440
|
+
.post('/mcp')
|
|
441
|
+
.send({
|
|
442
|
+
jsonrpc: '2.0',
|
|
443
|
+
id: 3,
|
|
444
|
+
method: 'tools/call',
|
|
445
|
+
params: {
|
|
446
|
+
name: 'http_get',
|
|
447
|
+
arguments: { url: 'https://example.com' },
|
|
448
|
+
},
|
|
449
|
+
})
|
|
450
|
+
.set('mcp-session-id', sessionId)
|
|
451
|
+
.set('Accept', 'application/json, text/event-stream');
|
|
452
|
+
const toolCall = gateway.execute.mock.calls[0][0];
|
|
453
|
+
expect(toolCall.workspace_id).toBe('custom-ws');
|
|
454
|
+
expect(toolCall.actor.id).toBe('custom-actor');
|
|
455
|
+
expect(toolCall.source.platform).toBe('custom_platform');
|
|
456
|
+
await customHandler.close();
|
|
457
|
+
});
|
|
458
|
+
});
|
|
459
|
+
// -- Session limits and timeout -------------------------------------------
|
|
460
|
+
describe('session limits', () => {
|
|
461
|
+
it('evicts the oldest session when MAX_SESSIONS is reached', async () => {
|
|
462
|
+
const { MAX_SESSIONS } = require('../../src/mcp/http-transport');
|
|
463
|
+
// Create 2 sessions and verify both are accessible
|
|
464
|
+
const sessionId1 = await initSession(app);
|
|
465
|
+
const sessionId2 = await initSession(app);
|
|
466
|
+
const res1 = await (0, supertest_1.default)(app)
|
|
467
|
+
.post('/mcp')
|
|
468
|
+
.send({ jsonrpc: '2.0', id: 100, method: 'tools/list', params: {} })
|
|
469
|
+
.set('mcp-session-id', sessionId1)
|
|
470
|
+
.set('Accept', 'application/json, text/event-stream');
|
|
471
|
+
expect(res1.status).toBe(200);
|
|
472
|
+
const res2 = await (0, supertest_1.default)(app)
|
|
473
|
+
.post('/mcp')
|
|
474
|
+
.send({ jsonrpc: '2.0', id: 101, method: 'tools/list', params: {} })
|
|
475
|
+
.set('mcp-session-id', sessionId2)
|
|
476
|
+
.set('Accept', 'application/json, text/event-stream');
|
|
477
|
+
expect(res2.status).toBe(200);
|
|
478
|
+
expect(MAX_SESSIONS).toBe(1000);
|
|
479
|
+
});
|
|
480
|
+
it('updates session activity on POST with session ID', async () => {
|
|
481
|
+
const sessionId = await initSession(app);
|
|
482
|
+
await (0, supertest_1.default)(app)
|
|
483
|
+
.post('/mcp')
|
|
484
|
+
.send({ jsonrpc: '2.0', id: 50, method: 'ping' })
|
|
485
|
+
.set('mcp-session-id', sessionId)
|
|
486
|
+
.set('Accept', 'application/json, text/event-stream');
|
|
487
|
+
const res = await (0, supertest_1.default)(app)
|
|
488
|
+
.post('/mcp')
|
|
489
|
+
.send({ jsonrpc: '2.0', id: 51, method: 'tools/list', params: {} })
|
|
490
|
+
.set('mcp-session-id', sessionId)
|
|
491
|
+
.set('Accept', 'application/json, text/event-stream');
|
|
492
|
+
expect(res.status).toBe(200);
|
|
493
|
+
});
|
|
494
|
+
it('exports SESSION_TIMEOUT_MS constant', () => {
|
|
495
|
+
const { SESSION_TIMEOUT_MS } = require('../../src/mcp/http-transport');
|
|
496
|
+
expect(SESSION_TIMEOUT_MS).toBe(30 * 60 * 1000);
|
|
497
|
+
});
|
|
498
|
+
});
|
|
499
|
+
// -- Auth identity resolution -----------------------------------------------
|
|
500
|
+
describe('auth identity resolution', () => {
|
|
501
|
+
it('uses authenticated identity when authInfo present', async () => {
|
|
502
|
+
// Create app with middleware that sets req.auth (simulating auth middleware)
|
|
503
|
+
const authApp = (0, express_1.default)();
|
|
504
|
+
authApp.use(express_1.default.json());
|
|
505
|
+
authApp.use((req, _res, next) => {
|
|
506
|
+
req.auth = {
|
|
507
|
+
workspace_id: 'ws-from-auth',
|
|
508
|
+
actor_id: 'actor-from-auth',
|
|
509
|
+
roles: ['agent'],
|
|
510
|
+
permissions: ['tool:execute'],
|
|
511
|
+
auth_method: 'api_key',
|
|
512
|
+
};
|
|
513
|
+
next();
|
|
514
|
+
});
|
|
515
|
+
const authHandler = (0, http_transport_1.createMCPHttpHandler)(gateway);
|
|
516
|
+
authApp.use('/mcp', authHandler.router);
|
|
517
|
+
const sessionId = await initSession(authApp);
|
|
518
|
+
await (0, supertest_1.default)(authApp)
|
|
519
|
+
.post('/mcp')
|
|
520
|
+
.send({
|
|
521
|
+
jsonrpc: '2.0',
|
|
522
|
+
id: 3,
|
|
523
|
+
method: 'tools/call',
|
|
524
|
+
params: {
|
|
525
|
+
name: 'http_get',
|
|
526
|
+
arguments: { url: 'https://api.example.com/data' },
|
|
527
|
+
},
|
|
528
|
+
})
|
|
529
|
+
.set('mcp-session-id', sessionId)
|
|
530
|
+
.set('Accept', 'application/json, text/event-stream');
|
|
531
|
+
expect(gateway.execute).toHaveBeenCalledTimes(1);
|
|
532
|
+
const toolCall = gateway.execute.mock.calls[0][0];
|
|
533
|
+
expect(toolCall.workspace_id).toBe('ws-from-auth');
|
|
534
|
+
expect(toolCall.actor.id).toBe('actor-from-auth');
|
|
535
|
+
await authHandler.close();
|
|
536
|
+
});
|
|
537
|
+
it('uses authenticated identity for http_post tool', async () => {
|
|
538
|
+
const authApp = (0, express_1.default)();
|
|
539
|
+
authApp.use(express_1.default.json());
|
|
540
|
+
authApp.use((req, _res, next) => {
|
|
541
|
+
req.auth = {
|
|
542
|
+
workspace_id: 'ws-post-auth',
|
|
543
|
+
actor_id: 'actor-post-auth',
|
|
544
|
+
roles: ['agent'],
|
|
545
|
+
permissions: ['tool:execute'],
|
|
546
|
+
auth_method: 'api_key',
|
|
547
|
+
};
|
|
548
|
+
next();
|
|
549
|
+
});
|
|
550
|
+
const authHandler = (0, http_transport_1.createMCPHttpHandler)(gateway);
|
|
551
|
+
authApp.use('/mcp', authHandler.router);
|
|
552
|
+
const sessionId = await initSession(authApp);
|
|
553
|
+
await (0, supertest_1.default)(authApp)
|
|
554
|
+
.post('/mcp')
|
|
555
|
+
.send({
|
|
556
|
+
jsonrpc: '2.0',
|
|
557
|
+
id: 3,
|
|
558
|
+
method: 'tools/call',
|
|
559
|
+
params: {
|
|
560
|
+
name: 'http_post',
|
|
561
|
+
arguments: { url: 'https://api.example.com/submit', body: '{"key":"value"}' },
|
|
562
|
+
},
|
|
563
|
+
})
|
|
564
|
+
.set('mcp-session-id', sessionId)
|
|
565
|
+
.set('Accept', 'application/json, text/event-stream');
|
|
566
|
+
const toolCall = gateway.execute.mock.calls[0][0];
|
|
567
|
+
expect(toolCall.workspace_id).toBe('ws-post-auth');
|
|
568
|
+
expect(toolCall.actor.id).toBe('actor-post-auth');
|
|
569
|
+
await authHandler.close();
|
|
570
|
+
});
|
|
571
|
+
it('uses authenticated identity for http_request tool', async () => {
|
|
572
|
+
const authApp = (0, express_1.default)();
|
|
573
|
+
authApp.use(express_1.default.json());
|
|
574
|
+
authApp.use((req, _res, next) => {
|
|
575
|
+
req.auth = {
|
|
576
|
+
workspace_id: 'ws-req-auth',
|
|
577
|
+
actor_id: 'actor-req-auth',
|
|
578
|
+
roles: ['agent'],
|
|
579
|
+
permissions: ['tool:execute'],
|
|
580
|
+
auth_method: 'api_key',
|
|
581
|
+
};
|
|
582
|
+
next();
|
|
583
|
+
});
|
|
584
|
+
const authHandler = (0, http_transport_1.createMCPHttpHandler)(gateway);
|
|
585
|
+
authApp.use('/mcp', authHandler.router);
|
|
586
|
+
const sessionId = await initSession(authApp);
|
|
587
|
+
await (0, supertest_1.default)(authApp)
|
|
588
|
+
.post('/mcp')
|
|
589
|
+
.send({
|
|
590
|
+
jsonrpc: '2.0',
|
|
591
|
+
id: 3,
|
|
592
|
+
method: 'tools/call',
|
|
593
|
+
params: {
|
|
594
|
+
name: 'http_request',
|
|
595
|
+
arguments: { url: 'https://api.example.com/item/1', method: 'DELETE' },
|
|
596
|
+
},
|
|
597
|
+
})
|
|
598
|
+
.set('mcp-session-id', sessionId)
|
|
599
|
+
.set('Accept', 'application/json, text/event-stream');
|
|
600
|
+
const toolCall = gateway.execute.mock.calls[0][0];
|
|
601
|
+
expect(toolCall.workspace_id).toBe('ws-req-auth');
|
|
602
|
+
expect(toolCall.actor.id).toBe('actor-req-auth');
|
|
603
|
+
await authHandler.close();
|
|
604
|
+
});
|
|
605
|
+
it('always uses auth identity — auth is the only way to run MCP', async () => {
|
|
606
|
+
const authApp = (0, express_1.default)();
|
|
607
|
+
authApp.use(express_1.default.json());
|
|
608
|
+
authApp.use((req, _res, next) => {
|
|
609
|
+
req.auth = {
|
|
610
|
+
workspace_id: 'ws-always-used',
|
|
611
|
+
actor_id: 'actor-always-used',
|
|
612
|
+
roles: ['agent'],
|
|
613
|
+
permissions: ['tool:execute'],
|
|
614
|
+
auth_method: 'api_key',
|
|
615
|
+
};
|
|
616
|
+
next();
|
|
617
|
+
});
|
|
618
|
+
const authHandler = (0, http_transport_1.createMCPHttpHandler)(gateway);
|
|
619
|
+
authApp.use('/mcp', authHandler.router);
|
|
620
|
+
const sessionId = await initSession(authApp);
|
|
621
|
+
await (0, supertest_1.default)(authApp)
|
|
622
|
+
.post('/mcp')
|
|
623
|
+
.send({
|
|
624
|
+
jsonrpc: '2.0',
|
|
625
|
+
id: 3,
|
|
626
|
+
method: 'tools/call',
|
|
627
|
+
params: {
|
|
628
|
+
name: 'http_get',
|
|
629
|
+
arguments: { url: 'https://api.example.com/data' },
|
|
630
|
+
},
|
|
631
|
+
})
|
|
632
|
+
.set('mcp-session-id', sessionId)
|
|
633
|
+
.set('Accept', 'application/json, text/event-stream');
|
|
634
|
+
const toolCall = gateway.execute.mock.calls[0][0];
|
|
635
|
+
expect(toolCall.workspace_id).toBe('ws-always-used');
|
|
636
|
+
expect(toolCall.actor.id).toBe('actor-always-used');
|
|
637
|
+
await authHandler.close();
|
|
638
|
+
});
|
|
639
|
+
it('rejects with AUTH_REQUIRED when authInfo is missing fields (S1)', async () => {
|
|
640
|
+
const authApp = (0, express_1.default)();
|
|
641
|
+
authApp.use(express_1.default.json());
|
|
642
|
+
// Auth middleware sets req.auth but without workspace_id
|
|
643
|
+
authApp.use((req, _res, next) => {
|
|
644
|
+
req.auth = {
|
|
645
|
+
actor_id: 'actor-only',
|
|
646
|
+
roles: ['agent'],
|
|
647
|
+
permissions: ['tool:execute'],
|
|
648
|
+
auth_method: 'api_key',
|
|
649
|
+
};
|
|
650
|
+
next();
|
|
651
|
+
});
|
|
652
|
+
const authHandler = (0, http_transport_1.createMCPHttpHandler)(gateway);
|
|
653
|
+
authApp.use('/mcp', authHandler.router);
|
|
654
|
+
const sessionId = await initSession(authApp);
|
|
655
|
+
const res = await (0, supertest_1.default)(authApp)
|
|
656
|
+
.post('/mcp')
|
|
657
|
+
.send({
|
|
658
|
+
jsonrpc: '2.0',
|
|
659
|
+
id: 3,
|
|
660
|
+
method: 'tools/call',
|
|
661
|
+
params: {
|
|
662
|
+
name: 'http_get',
|
|
663
|
+
arguments: { url: 'https://api.example.com/data' },
|
|
664
|
+
},
|
|
665
|
+
})
|
|
666
|
+
.set('mcp-session-id', sessionId)
|
|
667
|
+
.set('Accept', 'application/json, text/event-stream');
|
|
668
|
+
// Missing workspace_id in authInfo → auth rejection, no fallback
|
|
669
|
+
expect(gateway.execute).not.toHaveBeenCalled();
|
|
670
|
+
const body = parseSSEOrJSON(res);
|
|
671
|
+
expect(body.result.isError).toBe(true);
|
|
672
|
+
const errorPayload = JSON.parse(body.result.content[0].text);
|
|
673
|
+
expect(errorPayload.error_code).toBe('AUTH_REQUIRED');
|
|
674
|
+
await authHandler.close();
|
|
675
|
+
});
|
|
676
|
+
it('rejects with AUTH_REQUIRED when no authInfo at all (S1)', async () => {
|
|
677
|
+
// No middleware sets req.auth
|
|
678
|
+
const authHandler = (0, http_transport_1.createMCPHttpHandler)(gateway);
|
|
679
|
+
const noAuthApp = (0, express_1.default)();
|
|
680
|
+
noAuthApp.use(express_1.default.json());
|
|
681
|
+
noAuthApp.use('/mcp', authHandler.router);
|
|
682
|
+
const sessionId = await initSession(noAuthApp);
|
|
683
|
+
const res = await (0, supertest_1.default)(noAuthApp)
|
|
684
|
+
.post('/mcp')
|
|
685
|
+
.send({
|
|
686
|
+
jsonrpc: '2.0',
|
|
687
|
+
id: 3,
|
|
688
|
+
method: 'tools/call',
|
|
689
|
+
params: {
|
|
690
|
+
name: 'http_get',
|
|
691
|
+
arguments: { url: 'https://api.example.com/data' },
|
|
692
|
+
},
|
|
693
|
+
})
|
|
694
|
+
.set('mcp-session-id', sessionId)
|
|
695
|
+
.set('Accept', 'application/json, text/event-stream');
|
|
696
|
+
// No authInfo → auth rejection, no fallback
|
|
697
|
+
expect(gateway.execute).not.toHaveBeenCalled();
|
|
698
|
+
const body = parseSSEOrJSON(res);
|
|
699
|
+
expect(body.result.isError).toBe(true);
|
|
700
|
+
const errorPayload = JSON.parse(body.result.content[0].text);
|
|
701
|
+
expect(errorPayload.error_code).toBe('AUTH_REQUIRED');
|
|
702
|
+
await authHandler.close();
|
|
703
|
+
});
|
|
704
|
+
});
|
|
705
|
+
// -- Capability-level RBAC (S10) ------------------------------------------
|
|
706
|
+
describe('capability-level RBAC (S10)', () => {
|
|
707
|
+
function createAuthApp(permissions) {
|
|
708
|
+
const authApp = (0, express_1.default)();
|
|
709
|
+
authApp.use(express_1.default.json());
|
|
710
|
+
authApp.use((req, _res, next) => {
|
|
711
|
+
req.auth = {
|
|
712
|
+
workspace_id: 'ws-rbac',
|
|
713
|
+
actor_id: 'actor-rbac',
|
|
714
|
+
roles: ['agent'],
|
|
715
|
+
permissions,
|
|
716
|
+
auth_method: 'api_key',
|
|
717
|
+
};
|
|
718
|
+
next();
|
|
719
|
+
});
|
|
720
|
+
const authHandler = (0, http_transport_1.createMCPHttpHandler)(gateway);
|
|
721
|
+
authApp.use('/mcp', authHandler.router);
|
|
722
|
+
return { authApp, authHandler };
|
|
723
|
+
}
|
|
724
|
+
it('allows http_get when user has tool:execute:read permission', async () => {
|
|
725
|
+
const { authApp, authHandler } = createAuthApp(['tool:execute:read']);
|
|
726
|
+
const sessionId = await initSession(authApp);
|
|
727
|
+
await (0, supertest_1.default)(authApp)
|
|
728
|
+
.post('/mcp')
|
|
729
|
+
.send({
|
|
730
|
+
jsonrpc: '2.0', id: 3, method: 'tools/call',
|
|
731
|
+
params: { name: 'http_get', arguments: { url: 'https://example.com' } },
|
|
732
|
+
})
|
|
733
|
+
.set('mcp-session-id', sessionId)
|
|
734
|
+
.set('Accept', 'application/json, text/event-stream');
|
|
735
|
+
expect(gateway.execute).toHaveBeenCalledTimes(1);
|
|
736
|
+
await authHandler.close();
|
|
737
|
+
});
|
|
738
|
+
it('denies http_post when user only has tool:execute:read permission', async () => {
|
|
739
|
+
const { authApp, authHandler } = createAuthApp(['tool:execute:read']);
|
|
740
|
+
const sessionId = await initSession(authApp);
|
|
741
|
+
const res = await (0, supertest_1.default)(authApp)
|
|
742
|
+
.post('/mcp')
|
|
743
|
+
.send({
|
|
744
|
+
jsonrpc: '2.0', id: 3, method: 'tools/call',
|
|
745
|
+
params: { name: 'http_post', arguments: { url: 'https://example.com', body: '{}' } },
|
|
746
|
+
})
|
|
747
|
+
.set('mcp-session-id', sessionId)
|
|
748
|
+
.set('Accept', 'application/json, text/event-stream');
|
|
749
|
+
expect(gateway.execute).not.toHaveBeenCalled();
|
|
750
|
+
const body = parseSSEOrJSON(res);
|
|
751
|
+
expect(body.result.isError).toBe(true);
|
|
752
|
+
const errorPayload = JSON.parse(body.result.content[0].text);
|
|
753
|
+
expect(errorPayload.error_code).toBe('AUTH_INSUFFICIENT_PERMS');
|
|
754
|
+
expect(errorPayload.error).toContain('tool:execute:write');
|
|
755
|
+
await authHandler.close();
|
|
756
|
+
});
|
|
757
|
+
it('denies http_request DELETE when user only has tool:execute:write permission', async () => {
|
|
758
|
+
const { authApp, authHandler } = createAuthApp(['tool:execute:write']);
|
|
759
|
+
const sessionId = await initSession(authApp);
|
|
760
|
+
const res = await (0, supertest_1.default)(authApp)
|
|
761
|
+
.post('/mcp')
|
|
762
|
+
.send({
|
|
763
|
+
jsonrpc: '2.0', id: 3, method: 'tools/call',
|
|
764
|
+
params: { name: 'http_request', arguments: { url: 'https://example.com/item/1', method: 'DELETE' } },
|
|
765
|
+
})
|
|
766
|
+
.set('mcp-session-id', sessionId)
|
|
767
|
+
.set('Accept', 'application/json, text/event-stream');
|
|
768
|
+
expect(gateway.execute).not.toHaveBeenCalled();
|
|
769
|
+
const body = parseSSEOrJSON(res);
|
|
770
|
+
expect(body.result.isError).toBe(true);
|
|
771
|
+
const errorPayload = JSON.parse(body.result.content[0].text);
|
|
772
|
+
expect(errorPayload.error_code).toBe('AUTH_INSUFFICIENT_PERMS');
|
|
773
|
+
expect(errorPayload.error).toContain('tool:execute:delete');
|
|
774
|
+
await authHandler.close();
|
|
775
|
+
});
|
|
776
|
+
it('allows all capabilities with wildcard tool:execute permission', async () => {
|
|
777
|
+
const { authApp, authHandler } = createAuthApp(['tool:execute']);
|
|
778
|
+
const sessionId = await initSession(authApp);
|
|
779
|
+
// GET (read)
|
|
780
|
+
await (0, supertest_1.default)(authApp)
|
|
781
|
+
.post('/mcp')
|
|
782
|
+
.send({
|
|
783
|
+
jsonrpc: '2.0', id: 3, method: 'tools/call',
|
|
784
|
+
params: { name: 'http_get', arguments: { url: 'https://example.com' } },
|
|
785
|
+
})
|
|
786
|
+
.set('mcp-session-id', sessionId)
|
|
787
|
+
.set('Accept', 'application/json, text/event-stream');
|
|
788
|
+
expect(gateway.execute).toHaveBeenCalledTimes(1);
|
|
789
|
+
// POST (write)
|
|
790
|
+
await (0, supertest_1.default)(authApp)
|
|
791
|
+
.post('/mcp')
|
|
792
|
+
.send({
|
|
793
|
+
jsonrpc: '2.0', id: 4, method: 'tools/call',
|
|
794
|
+
params: { name: 'http_post', arguments: { url: 'https://example.com', body: '{}' } },
|
|
795
|
+
})
|
|
796
|
+
.set('mcp-session-id', sessionId)
|
|
797
|
+
.set('Accept', 'application/json, text/event-stream');
|
|
798
|
+
expect(gateway.execute).toHaveBeenCalledTimes(2);
|
|
799
|
+
// DELETE
|
|
800
|
+
await (0, supertest_1.default)(authApp)
|
|
801
|
+
.post('/mcp')
|
|
802
|
+
.send({
|
|
803
|
+
jsonrpc: '2.0', id: 5, method: 'tools/call',
|
|
804
|
+
params: { name: 'http_request', arguments: { url: 'https://example.com/1', method: 'DELETE' } },
|
|
805
|
+
})
|
|
806
|
+
.set('mcp-session-id', sessionId)
|
|
807
|
+
.set('Accept', 'application/json, text/event-stream');
|
|
808
|
+
expect(gateway.execute).toHaveBeenCalledTimes(3);
|
|
809
|
+
await authHandler.close();
|
|
810
|
+
});
|
|
811
|
+
it('allows all capabilities with admin:full permission', async () => {
|
|
812
|
+
const { authApp, authHandler } = createAuthApp(['admin:full']);
|
|
813
|
+
const sessionId = await initSession(authApp);
|
|
814
|
+
await (0, supertest_1.default)(authApp)
|
|
815
|
+
.post('/mcp')
|
|
816
|
+
.send({
|
|
817
|
+
jsonrpc: '2.0', id: 3, method: 'tools/call',
|
|
818
|
+
params: { name: 'http_request', arguments: { url: 'https://example.com/1', method: 'DELETE' } },
|
|
819
|
+
})
|
|
820
|
+
.set('mcp-session-id', sessionId)
|
|
821
|
+
.set('Accept', 'application/json, text/event-stream');
|
|
822
|
+
expect(gateway.execute).toHaveBeenCalledTimes(1);
|
|
823
|
+
await authHandler.close();
|
|
824
|
+
});
|
|
825
|
+
it('skips capability check when no permissions in authInfo (auth disabled)', async () => {
|
|
826
|
+
// Auth middleware sets identity but no permissions (simulating auth disabled)
|
|
827
|
+
const authApp = (0, express_1.default)();
|
|
828
|
+
authApp.use(express_1.default.json());
|
|
829
|
+
authApp.use((req, _res, next) => {
|
|
830
|
+
req.auth = { workspace_id: 'ws-noauth', actor_id: 'actor-noauth' };
|
|
831
|
+
next();
|
|
832
|
+
});
|
|
833
|
+
const authHandler = (0, http_transport_1.createMCPHttpHandler)(gateway);
|
|
834
|
+
authApp.use('/mcp', authHandler.router);
|
|
835
|
+
const sessionId = await initSession(authApp);
|
|
836
|
+
await (0, supertest_1.default)(authApp)
|
|
837
|
+
.post('/mcp')
|
|
838
|
+
.send({
|
|
839
|
+
jsonrpc: '2.0', id: 3, method: 'tools/call',
|
|
840
|
+
params: { name: 'http_post', arguments: { url: 'https://example.com', body: '{}' } },
|
|
841
|
+
})
|
|
842
|
+
.set('mcp-session-id', sessionId)
|
|
843
|
+
.set('Accept', 'application/json, text/event-stream');
|
|
844
|
+
// No permissions array → capability check skipped → execute allowed
|
|
845
|
+
expect(gateway.execute).toHaveBeenCalledTimes(1);
|
|
846
|
+
await authHandler.close();
|
|
847
|
+
});
|
|
848
|
+
});
|
|
849
|
+
// -- Close ----------------------------------------------------------------
|
|
850
|
+
describe('close', () => {
|
|
851
|
+
it('close() resolves without error', async () => {
|
|
852
|
+
await expect(handler.close()).resolves.toBeUndefined();
|
|
853
|
+
});
|
|
854
|
+
it('close() cleans up sessions', async () => {
|
|
855
|
+
await initSession(app);
|
|
856
|
+
await handler.close();
|
|
857
|
+
// After close, no sessions should remain — verify by trying to use one
|
|
858
|
+
// (the handler is closed, so this is a best-effort check)
|
|
859
|
+
await expect(handler.close()).resolves.toBeUndefined();
|
|
860
|
+
});
|
|
861
|
+
});
|
|
862
|
+
});
|
|
863
|
+
// ---------------------------------------------------------------------------
|
|
864
|
+
// SSE / JSON response parser helper
|
|
865
|
+
// ---------------------------------------------------------------------------
|
|
866
|
+
/**
|
|
867
|
+
* The MCP Streamable HTTP transport may respond with either:
|
|
868
|
+
* - SSE (text/event-stream): `event: message\ndata: {...}\n\n`
|
|
869
|
+
* - JSON (application/json): `{...}`
|
|
870
|
+
*
|
|
871
|
+
* This helper parses both formats and returns the JSON-RPC response body.
|
|
872
|
+
*/
|
|
873
|
+
function parseSSEOrJSON(res) {
|
|
874
|
+
const contentType = res.headers['content-type'] || '';
|
|
875
|
+
if (contentType.includes('text/event-stream')) {
|
|
876
|
+
// Parse SSE format: find the last `data:` line
|
|
877
|
+
const text = res.text;
|
|
878
|
+
const lines = text.split('\n');
|
|
879
|
+
for (let i = lines.length - 1; i >= 0; i--) {
|
|
880
|
+
const line = lines[i].trim();
|
|
881
|
+
if (line.startsWith('data:')) {
|
|
882
|
+
const data = line.slice(5).trim();
|
|
883
|
+
try {
|
|
884
|
+
return JSON.parse(data);
|
|
885
|
+
}
|
|
886
|
+
catch {
|
|
887
|
+
continue;
|
|
888
|
+
}
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
throw new Error(`No parseable SSE data in response: ${text}`);
|
|
892
|
+
}
|
|
893
|
+
// JSON response (might be an array for batched responses)
|
|
894
|
+
if (Array.isArray(res.body)) {
|
|
895
|
+
return res.body[0];
|
|
896
|
+
}
|
|
897
|
+
return res.body;
|
|
898
|
+
}
|
|
899
|
+
//# sourceMappingURL=mcp-http-transport.test.js.map
|