@opensaas/stack-core 0.42.3 → 0.44.0-alpha.1
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 +2745 -0
- package/README.md +182 -115
- package/dist/.build-hash +1 -0
- package/dist/access/declared-dependencies.d.ts +102 -88
- package/dist/access/declared-dependencies.d.ts.map +1 -1
- package/dist/access/declared-dependencies.js +83 -71
- package/dist/access/declared-dependencies.js.map +1 -1
- package/dist/access/depth-limits.d.ts +4 -0
- package/dist/access/depth-limits.d.ts.map +1 -1
- package/dist/access/depth-limits.js +4 -0
- package/dist/access/depth-limits.js.map +1 -1
- package/dist/access/engine.d.ts +68 -20
- package/dist/access/engine.d.ts.map +1 -1
- package/dist/access/engine.js +151 -37
- package/dist/access/engine.js.map +1 -1
- package/dist/access/errors.d.ts +33 -48
- package/dist/access/errors.d.ts.map +1 -1
- package/dist/access/errors.js +73 -63
- package/dist/access/errors.js.map +1 -1
- package/dist/access/field-access.d.ts +76 -5
- package/dist/access/field-access.d.ts.map +1 -1
- package/dist/access/field-access.js +235 -61
- package/dist/access/field-access.js.map +1 -1
- package/dist/access/field-visibility.d.ts +50 -4
- package/dist/access/field-visibility.d.ts.map +1 -1
- package/dist/access/field-visibility.js +143 -160
- package/dist/access/field-visibility.js.map +1 -1
- package/dist/access/index.d.ts +5 -12
- package/dist/access/index.d.ts.map +1 -1
- package/dist/access/index.js +6 -19
- package/dist/access/index.js.map +1 -1
- package/dist/access/orm-client.d.ts +19 -0
- package/dist/access/orm-client.d.ts.map +1 -0
- package/dist/access/orm-client.js +37 -0
- package/dist/access/orm-client.js.map +1 -0
- package/dist/access/query-validation.d.ts +7 -129
- package/dist/access/query-validation.d.ts.map +1 -1
- package/dist/access/query-validation.js +12 -314
- package/dist/access/query-validation.js.map +1 -1
- package/dist/access/system-fields.d.ts +2 -0
- package/dist/access/system-fields.d.ts.map +1 -0
- package/dist/access/system-fields.js +7 -0
- package/dist/access/system-fields.js.map +1 -0
- package/dist/access/transaction-registry.d.ts +25 -2
- package/dist/access/transaction-registry.d.ts.map +1 -1
- package/dist/access/transaction-registry.js +34 -17
- package/dist/access/transaction-registry.js.map +1 -1
- package/dist/access/types.d.ts +217 -131
- package/dist/access/types.d.ts.map +1 -1
- package/dist/config/field-kind.d.ts +66 -0
- package/dist/config/field-kind.d.ts.map +1 -0
- package/dist/config/field-kind.js +63 -0
- package/dist/config/field-kind.js.map +1 -0
- package/dist/config/hook-only-fields.d.ts +3 -0
- package/dist/config/hook-only-fields.d.ts.map +1 -0
- package/dist/config/hook-only-fields.js +17 -0
- package/dist/config/hook-only-fields.js.map +1 -0
- package/dist/config/index.d.ts +3 -1
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/index.js +6 -3
- package/dist/config/index.js.map +1 -1
- package/dist/config/mcp-tool-names.d.ts +3 -0
- package/dist/config/mcp-tool-names.d.ts.map +1 -0
- package/dist/config/mcp-tool-names.js +25 -0
- package/dist/config/mcp-tool-names.js.map +1 -0
- package/dist/config/nav-count.d.ts.map +1 -1
- package/dist/config/nav-count.js +4 -4
- package/dist/config/nav-count.js.map +1 -1
- package/dist/config/plugin-engine.d.ts +8 -2
- package/dist/config/plugin-engine.d.ts.map +1 -1
- package/dist/config/plugin-engine.js +102 -38
- package/dist/config/plugin-engine.js.map +1 -1
- package/dist/config/types.d.ts +966 -614
- package/dist/config/types.d.ts.map +1 -1
- package/dist/context/apply-defaults.d.ts +18 -1
- package/dist/context/apply-defaults.d.ts.map +1 -1
- package/dist/context/apply-defaults.js +30 -4
- package/dist/context/apply-defaults.js.map +1 -1
- package/dist/context/engine-context.d.ts +73 -0
- package/dist/context/engine-context.d.ts.map +1 -0
- package/dist/context/engine-context.js +67 -0
- package/dist/context/engine-context.js.map +1 -0
- package/dist/context/hook-pipeline.d.ts +9 -2
- package/dist/context/hook-pipeline.d.ts.map +1 -1
- package/dist/context/hook-pipeline.js +5 -4
- package/dist/context/hook-pipeline.js.map +1 -1
- package/dist/context/index.d.ts +98 -89
- package/dist/context/index.d.ts.map +1 -1
- package/dist/context/index.js +917 -722
- package/dist/context/index.js.map +1 -1
- package/dist/context/junction.d.ts +59 -0
- package/dist/context/junction.d.ts.map +1 -0
- package/dist/context/junction.js +126 -0
- package/dist/context/junction.js.map +1 -0
- package/dist/context/plugin-field-read.d.ts +33 -0
- package/dist/context/plugin-field-read.d.ts.map +1 -0
- package/dist/context/plugin-field-read.js +41 -0
- package/dist/context/plugin-field-read.js.map +1 -0
- package/dist/context/plugin-field-write.d.ts +104 -0
- package/dist/context/plugin-field-write.d.ts.map +1 -0
- package/dist/context/plugin-field-write.js +184 -0
- package/dist/context/plugin-field-write.js.map +1 -0
- package/dist/context/relationship-input.d.ts +146 -0
- package/dist/context/relationship-input.d.ts.map +1 -0
- package/dist/context/relationship-input.js +453 -0
- package/dist/context/relationship-input.js.map +1 -0
- package/dist/context/transaction-boundary.d.ts +54 -28
- package/dist/context/transaction-boundary.d.ts.map +1 -1
- package/dist/context/transaction-boundary.js +87 -169
- package/dist/context/transaction-boundary.js.map +1 -1
- package/dist/context/write-pipeline.d.ts +33 -51
- package/dist/context/write-pipeline.d.ts.map +1 -1
- package/dist/context/write-pipeline.js +372 -185
- package/dist/context/write-pipeline.js.map +1 -1
- package/dist/contract/dependencies.d.ts +88 -0
- package/dist/contract/dependencies.d.ts.map +1 -0
- package/dist/contract/dependencies.js +237 -0
- package/dist/contract/dependencies.js.map +1 -0
- package/dist/contract/derive.d.ts +49 -0
- package/dist/contract/derive.d.ts.map +1 -0
- package/dist/contract/derive.js +540 -0
- package/dist/contract/derive.js.map +1 -0
- package/dist/contract/fixtures/contract-configs.d.ts +64 -0
- package/dist/contract/fixtures/contract-configs.d.ts.map +1 -0
- package/dist/contract/fixtures/contract-configs.js +345 -0
- package/dist/contract/fixtures/contract-configs.js.map +1 -0
- package/dist/contract/id-boundary.d.ts +53 -0
- package/dist/contract/id-boundary.d.ts.map +1 -0
- package/dist/contract/id-boundary.js +76 -0
- package/dist/contract/id-boundary.js.map +1 -0
- package/dist/contract/index.d.ts +8 -0
- package/dist/contract/index.d.ts.map +1 -0
- package/dist/contract/index.js +11 -0
- package/dist/contract/index.js.map +1 -0
- package/dist/contract/prisma.d.ts +58 -0
- package/dist/contract/prisma.d.ts.map +1 -0
- package/dist/contract/prisma.js +282 -0
- package/dist/contract/prisma.js.map +1 -0
- package/dist/contract/relation-graph.d.ts +70 -0
- package/dist/contract/relation-graph.d.ts.map +1 -0
- package/dist/contract/relation-graph.js +113 -0
- package/dist/contract/relation-graph.js.map +1 -0
- package/dist/contract/types.d.ts +135 -0
- package/dist/contract/types.d.ts.map +1 -0
- package/dist/contract/types.js +2 -0
- package/dist/contract/types.js.map +1 -0
- package/dist/db/client.d.ts +55 -0
- package/dist/db/client.d.ts.map +1 -0
- package/dist/db/client.js +73 -0
- package/dist/db/client.js.map +1 -0
- package/dist/db/dev-database.d.ts +124 -0
- package/dist/db/dev-database.d.ts.map +1 -0
- package/dist/db/dev-database.js +291 -0
- package/dist/db/dev-database.js.map +1 -0
- package/dist/db/password-front.d.ts +10 -0
- package/dist/db/password-front.d.ts.map +1 -0
- package/dist/db/password-front.js +147 -0
- package/dist/db/password-front.js.map +1 -0
- package/dist/db/process-identity.d.ts +36 -0
- package/dist/db/process-identity.d.ts.map +1 -0
- package/dist/db/process-identity.js +114 -0
- package/dist/db/process-identity.js.map +1 -0
- package/dist/db/state-file.d.ts +54 -0
- package/dist/db/state-file.d.ts.map +1 -0
- package/dist/db/state-file.js +91 -0
- package/dist/db/state-file.js.map +1 -0
- package/dist/db/url.d.ts +89 -0
- package/dist/db/url.d.ts.map +1 -0
- package/dist/db/url.js +118 -0
- package/dist/db/url.js.map +1 -0
- package/dist/extend.d.ts +13 -2
- package/dist/extend.d.ts.map +1 -1
- package/dist/extend.js +24 -1
- package/dist/extend.js.map +1 -1
- package/dist/fields/index.d.ts +87 -42
- package/dist/fields/index.d.ts.map +1 -1
- package/dist/fields/index.js +457 -677
- package/dist/fields/index.js.map +1 -1
- package/dist/filter/collect.d.ts +3 -4
- package/dist/filter/collect.d.ts.map +1 -1
- package/dist/filter/collect.js +2 -2
- package/dist/filter/collect.js.map +1 -1
- package/dist/filter/index.d.ts +1 -2
- package/dist/filter/index.d.ts.map +1 -1
- package/dist/filter/index.js +0 -1
- package/dist/filter/index.js.map +1 -1
- package/dist/filter/map.d.ts +12 -5
- package/dist/filter/map.d.ts.map +1 -1
- package/dist/filter/map.js +47 -19
- package/dist/filter/map.js.map +1 -1
- package/dist/filter/types.d.ts +10 -24
- package/dist/filter/types.d.ts.map +1 -1
- package/dist/filter/types.js +2 -11
- package/dist/filter/types.js.map +1 -1
- package/dist/hooks/index.d.ts +22 -31
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/index.js +33 -37
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/transition-guard.d.ts +61 -0
- package/dist/hooks/transition-guard.d.ts.map +1 -0
- package/dist/hooks/transition-guard.js +93 -0
- package/dist/hooks/transition-guard.js.map +1 -0
- package/dist/index.d.ts +52 -15
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +105 -44
- package/dist/index.js.map +1 -1
- package/dist/internal.d.ts +4 -2
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.js +16 -0
- package/dist/internal.js.map +1 -1
- package/dist/lib/case-utils.d.ts +0 -1
- package/dist/lib/case-utils.d.ts.map +1 -1
- package/dist/lib/case-utils.js +0 -3
- package/dist/lib/case-utils.js.map +1 -1
- package/dist/lib/client-safe-error.d.ts +9 -0
- package/dist/lib/client-safe-error.d.ts.map +1 -0
- package/dist/lib/client-safe-error.js +23 -0
- package/dist/lib/client-safe-error.js.map +1 -0
- package/dist/lib/database-errors.d.ts +78 -0
- package/dist/lib/database-errors.d.ts.map +1 -0
- package/dist/lib/database-errors.js +148 -0
- package/dist/lib/database-errors.js.map +1 -0
- package/dist/lib/null-prototype-registry.d.ts +9 -0
- package/dist/lib/null-prototype-registry.d.ts.map +1 -0
- package/dist/lib/null-prototype-registry.js +11 -0
- package/dist/lib/null-prototype-registry.js.map +1 -0
- package/dist/lib/prisma-errors.d.ts +30 -32
- package/dist/lib/prisma-errors.d.ts.map +1 -1
- package/dist/lib/prisma-errors.js +86 -46
- package/dist/lib/prisma-errors.js.map +1 -1
- package/dist/lib/process-global.d.ts +23 -0
- package/dist/lib/process-global.d.ts.map +1 -0
- package/dist/lib/process-global.js +33 -0
- package/dist/lib/process-global.js.map +1 -0
- package/dist/lib/warn-once.d.ts +7 -0
- package/dist/lib/warn-once.d.ts.map +1 -0
- package/dist/lib/warn-once.js +13 -0
- package/dist/lib/warn-once.js.map +1 -0
- package/dist/mcp/advertise.d.ts +16 -0
- package/dist/mcp/advertise.d.ts.map +1 -0
- package/dist/mcp/advertise.js +25 -0
- package/dist/mcp/advertise.js.map +1 -0
- package/dist/mcp/arguments.d.ts +10 -0
- package/dist/mcp/arguments.d.ts.map +1 -0
- package/dist/mcp/arguments.js +143 -0
- package/dist/mcp/arguments.js.map +1 -0
- package/dist/mcp/field-schema.d.ts +50 -5
- package/dist/mcp/field-schema.d.ts.map +1 -1
- package/dist/mcp/field-schema.js +137 -14
- package/dist/mcp/field-schema.js.map +1 -1
- package/dist/mcp/handler.d.ts +16 -5
- package/dist/mcp/handler.d.ts.map +1 -1
- package/dist/mcp/handler.js +404 -126
- package/dist/mcp/handler.js.map +1 -1
- package/dist/mcp/index.d.ts +1 -0
- package/dist/mcp/index.d.ts.map +1 -1
- package/dist/mcp/index.js +1 -0
- package/dist/mcp/index.js.map +1 -1
- package/dist/mcp/projection.d.ts +42 -34
- package/dist/mcp/projection.d.ts.map +1 -1
- package/dist/mcp/projection.js +246 -200
- package/dist/mcp/projection.js.map +1 -1
- package/dist/mcp/tool-error.d.ts +8 -0
- package/dist/mcp/tool-error.d.ts.map +1 -0
- package/dist/mcp/tool-error.js +11 -0
- package/dist/mcp/tool-error.js.map +1 -0
- package/dist/mcp/types.d.ts +3 -2
- package/dist/mcp/types.d.ts.map +1 -1
- package/dist/mcp/where-id-boundary.d.ts +28 -0
- package/dist/mcp/where-id-boundary.d.ts.map +1 -0
- package/dist/mcp/where-id-boundary.js +187 -0
- package/dist/mcp/where-id-boundary.js.map +1 -0
- package/dist/origin.d.ts +147 -0
- package/dist/origin.d.ts.map +1 -0
- package/dist/origin.js +191 -0
- package/dist/origin.js.map +1 -0
- package/dist/query/relationship-options.d.ts +35 -6
- package/dist/query/relationship-options.d.ts.map +1 -1
- package/dist/query/relationship-options.js +33 -23
- package/dist/query/relationship-options.js.map +1 -1
- package/dist/secured/aggregate.d.ts +32 -0
- package/dist/secured/aggregate.d.ts.map +1 -0
- package/dist/secured/aggregate.js +31 -0
- package/dist/secured/aggregate.js.map +1 -0
- package/dist/secured/include.d.ts +320 -0
- package/dist/secured/include.d.ts.map +1 -0
- package/dist/secured/include.js +650 -0
- package/dist/secured/include.js.map +1 -0
- package/dist/secured/lock.d.ts +127 -0
- package/dist/secured/lock.d.ts.map +1 -0
- package/dist/secured/lock.js +275 -0
- package/dist/secured/lock.js.map +1 -0
- package/dist/secured/lower.d.ts +82 -0
- package/dist/secured/lower.d.ts.map +1 -0
- package/dist/secured/lower.js +162 -0
- package/dist/secured/lower.js.map +1 -0
- package/dist/secured/operators.d.ts +7 -0
- package/dist/secured/operators.d.ts.map +1 -0
- package/dist/secured/operators.js +18 -0
- package/dist/secured/operators.js.map +1 -0
- package/dist/secured/read.d.ts +208 -0
- package/dist/secured/read.d.ts.map +1 -0
- package/dist/secured/read.js +1245 -0
- package/dist/secured/read.js.map +1 -0
- package/dist/secured/select.d.ts +87 -0
- package/dist/secured/select.d.ts.map +1 -0
- package/dist/secured/select.js +250 -0
- package/dist/secured/select.js.map +1 -0
- package/dist/secured/vector.d.ts +58 -0
- package/dist/secured/vector.d.ts.map +1 -0
- package/dist/secured/vector.js +113 -0
- package/dist/secured/vector.js.map +1 -0
- package/dist/secured/vocabulary.d.ts +227 -0
- package/dist/secured/vocabulary.d.ts.map +1 -0
- package/dist/secured/vocabulary.js +578 -0
- package/dist/secured/vocabulary.js.map +1 -0
- package/dist/secured/write.d.ts +58 -0
- package/dist/secured/write.d.ts.map +1 -0
- package/dist/secured/write.js +87 -0
- package/dist/secured/write.js.map +1 -0
- package/dist/testing/context.d.ts +236 -0
- package/dist/testing/context.d.ts.map +1 -0
- package/dist/testing/context.js +457 -0
- package/dist/testing/context.js.map +1 -0
- package/dist/testing/escape.d.ts +83 -0
- package/dist/testing/escape.d.ts.map +1 -0
- package/dist/testing/escape.js +148 -0
- package/dist/testing/escape.js.map +1 -0
- package/dist/testing/extensions.d.ts +48 -0
- package/dist/testing/extensions.d.ts.map +1 -0
- package/dist/testing/extensions.js +107 -0
- package/dist/testing/extensions.js.map +1 -0
- package/dist/testing/index.d.ts +5 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +11 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/testing/plans.d.ts +64 -0
- package/dist/testing/plans.d.ts.map +1 -0
- package/dist/testing/plans.js +47 -0
- package/dist/testing/plans.js.map +1 -0
- package/dist/types/context.d.ts +110 -0
- package/dist/types/context.d.ts.map +1 -0
- package/dist/types/context.js +2 -0
- package/dist/types/context.js.map +1 -0
- package/dist/types/contract.d.ts +198 -0
- package/dist/types/contract.d.ts.map +1 -0
- package/dist/types/contract.js +2 -0
- package/dist/types/contract.js.map +1 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +11 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/inputs.d.ts +83 -0
- package/dist/types/inputs.d.ts.map +1 -0
- package/dist/types/inputs.js +2 -0
- package/dist/types/inputs.js.map +1 -0
- package/dist/types/rows.d.ts +76 -0
- package/dist/types/rows.d.ts.map +1 -0
- package/dist/types/rows.js +2 -0
- package/dist/types/rows.js.map +1 -0
- package/dist/types/secured-list.d.ts +396 -0
- package/dist/types/secured-list.d.ts.map +1 -0
- package/dist/types/secured-list.js +2 -0
- package/dist/types/secured-list.js.map +1 -0
- package/dist/unsafe.d.ts +162 -0
- package/dist/unsafe.d.ts.map +1 -0
- package/dist/unsafe.js +177 -0
- package/dist/unsafe.js.map +1 -0
- package/dist/validation/config-refusal.d.ts +16 -0
- package/dist/validation/config-refusal.d.ts.map +1 -0
- package/dist/validation/config-refusal.js +2 -0
- package/dist/validation/config-refusal.js.map +1 -0
- package/dist/validation/database-config.d.ts +19 -0
- package/dist/validation/database-config.d.ts.map +1 -0
- package/dist/validation/database-config.js +221 -0
- package/dist/validation/database-config.js.map +1 -0
- package/dist/validation/default-value.d.ts +21 -0
- package/dist/validation/default-value.d.ts.map +1 -0
- package/dist/validation/default-value.js +72 -0
- package/dist/validation/default-value.js.map +1 -0
- package/dist/validation/extension-packs.d.ts +11 -0
- package/dist/validation/extension-packs.d.ts.map +1 -0
- package/dist/validation/extension-packs.js +53 -0
- package/dist/validation/extension-packs.js.map +1 -0
- package/dist/validation/field-config.d.ts +35 -21
- package/dist/validation/field-config.d.ts.map +1 -1
- package/dist/validation/field-config.js +51 -41
- package/dist/validation/field-config.js.map +1 -1
- package/dist/validation/field-names.d.ts +15 -0
- package/dist/validation/field-names.d.ts.map +1 -0
- package/dist/validation/field-names.js +155 -0
- package/dist/validation/field-names.js.map +1 -0
- package/dist/validation/identifier-names.d.ts +4 -0
- package/dist/validation/identifier-names.d.ts.map +1 -0
- package/dist/validation/identifier-names.js +39 -0
- package/dist/validation/identifier-names.js.map +1 -0
- package/dist/validation/needs-closure.d.ts +20 -30
- package/dist/validation/needs-closure.d.ts.map +1 -1
- package/dist/validation/needs-closure.js +29 -105
- package/dist/validation/needs-closure.js.map +1 -1
- package/dist/validation/relations.d.ts +17 -0
- package/dist/validation/relations.d.ts.map +1 -0
- package/dist/validation/relations.js +268 -0
- package/dist/validation/relations.js.map +1 -0
- package/dist/validation/schema.d.ts.map +1 -1
- package/dist/validation/schema.js +1 -3
- package/dist/validation/schema.js.map +1 -1
- package/dist/where/like.d.ts +32 -0
- package/dist/where/like.d.ts.map +1 -0
- package/dist/where/like.js +42 -0
- package/dist/where/like.js.map +1 -0
- package/package.json +70 -8
- package/.turbo/turbo-build.log +0 -4
- package/CLAUDE.md +0 -609
- package/dist/access/access-filter.d.ts +0 -241
- package/dist/access/access-filter.d.ts.map +0 -1
- package/dist/access/access-filter.js +0 -692
- package/dist/access/access-filter.js.map +0 -1
- package/dist/access/access-filter.test.d.ts +0 -2
- package/dist/access/access-filter.test.d.ts.map +0 -1
- package/dist/access/access-filter.test.js +0 -1256
- package/dist/access/access-filter.test.js.map +0 -1
- package/dist/access/declared-dependencies.test.d.ts +0 -2
- package/dist/access/declared-dependencies.test.d.ts.map +0 -1
- package/dist/access/declared-dependencies.test.js +0 -226
- package/dist/access/declared-dependencies.test.js.map +0 -1
- package/dist/access/denied-relation-visibility.test.d.ts +0 -2
- package/dist/access/denied-relation-visibility.test.d.ts.map +0 -1
- package/dist/access/denied-relation-visibility.test.js +0 -114
- package/dist/access/denied-relation-visibility.test.js.map +0 -1
- package/dist/access/engine.test.d.ts +0 -2
- package/dist/access/engine.test.d.ts.map +0 -1
- package/dist/access/engine.test.js +0 -56
- package/dist/access/engine.test.js.map +0 -1
- package/dist/access/field-access.test.d.ts +0 -2
- package/dist/access/field-access.test.d.ts.map +0 -1
- package/dist/access/field-access.test.js +0 -635
- package/dist/access/field-access.test.js.map +0 -1
- package/dist/access/multi-column-read-write.test.d.ts +0 -2
- package/dist/access/multi-column-read-write.test.d.ts.map +0 -1
- package/dist/access/multi-column-read-write.test.js +0 -183
- package/dist/access/multi-column-read-write.test.js.map +0 -1
- package/dist/access/relationship-count.d.ts +0 -98
- package/dist/access/relationship-count.d.ts.map +0 -1
- package/dist/access/relationship-count.js +0 -262
- package/dist/access/relationship-count.js.map +0 -1
- package/dist/access/relationship-count.test.d.ts +0 -2
- package/dist/access/relationship-count.test.d.ts.map +0 -1
- package/dist/access/relationship-count.test.js +0 -247
- package/dist/access/relationship-count.test.js.map +0 -1
- package/dist/access/relationship-label-filter.d.ts +0 -45
- package/dist/access/relationship-label-filter.d.ts.map +0 -1
- package/dist/access/relationship-label-filter.js +0 -22
- package/dist/access/relationship-label-filter.js.map +0 -1
- package/dist/access/relationship-label-filter.test.d.ts +0 -2
- package/dist/access/relationship-label-filter.test.d.ts.map +0 -1
- package/dist/access/relationship-label-filter.test.js +0 -89
- package/dist/access/relationship-label-filter.test.js.map +0 -1
- package/dist/access/synthetic-include-read.test.d.ts +0 -2
- package/dist/access/synthetic-include-read.test.d.ts.map +0 -1
- package/dist/access/synthetic-include-read.test.js +0 -121
- package/dist/access/synthetic-include-read.test.js.map +0 -1
- package/dist/context/nested-operations.d.ts +0 -47
- package/dist/context/nested-operations.d.ts.map +0 -1
- package/dist/context/nested-operations.js +0 -731
- package/dist/context/nested-operations.js.map +0 -1
- package/dist/fields/calendar-day.test.d.ts +0 -2
- package/dist/fields/calendar-day.test.d.ts.map +0 -1
- package/dist/fields/calendar-day.test.js +0 -246
- package/dist/fields/calendar-day.test.js.map +0 -1
- package/dist/fields/format-prisma-default.d.ts +0 -35
- package/dist/fields/format-prisma-default.d.ts.map +0 -1
- package/dist/fields/format-prisma-default.js +0 -49
- package/dist/fields/format-prisma-default.js.map +0 -1
- package/dist/fields/format-prisma-default.test.d.ts +0 -2
- package/dist/fields/format-prisma-default.test.d.ts.map +0 -1
- package/dist/fields/format-prisma-default.test.js +0 -54
- package/dist/fields/format-prisma-default.test.js.map +0 -1
- package/dist/fields/relationship-foreign-key.test.d.ts +0 -2
- package/dist/fields/relationship-foreign-key.test.d.ts.map +0 -1
- package/dist/fields/relationship-foreign-key.test.js +0 -18
- package/dist/fields/relationship-foreign-key.test.js.map +0 -1
- package/dist/fields/select.test.d.ts +0 -2
- package/dist/fields/select.test.d.ts.map +0 -1
- package/dist/fields/select.test.js +0 -279
- package/dist/fields/select.test.js.map +0 -1
- package/dist/fields/text-keystone-compat.test.d.ts +0 -2
- package/dist/fields/text-keystone-compat.test.d.ts.map +0 -1
- package/dist/fields/text-keystone-compat.test.js +0 -93
- package/dist/fields/text-keystone-compat.test.js.map +0 -1
- package/dist/filter/filter.test.d.ts +0 -2
- package/dist/filter/filter.test.d.ts.map +0 -1
- package/dist/filter/filter.test.js +0 -431
- package/dist/filter/filter.test.js.map +0 -1
- package/dist/filter/serialize.test.d.ts +0 -2
- package/dist/filter/serialize.test.d.ts.map +0 -1
- package/dist/filter/serialize.test.js +0 -83
- package/dist/filter/serialize.test.js.map +0 -1
- package/dist/index.test.d.ts +0 -2
- package/dist/index.test.d.ts.map +0 -1
- package/dist/index.test.js +0 -33
- package/dist/index.test.js.map +0 -1
- package/dist/lib/case-utils.test.d.ts +0 -2
- package/dist/lib/case-utils.test.d.ts.map +0 -1
- package/dist/lib/case-utils.test.js +0 -123
- package/dist/lib/case-utils.test.js.map +0 -1
- package/dist/query/index.d.ts +0 -127
- package/dist/query/index.d.ts.map +0 -1
- package/dist/query/index.js +0 -179
- package/dist/query/index.js.map +0 -1
- package/dist/query/index.test.d.ts +0 -2
- package/dist/query/index.test.d.ts.map +0 -1
- package/dist/query/index.test.js +0 -632
- package/dist/query/index.test.js.map +0 -1
- package/dist/query/relationship-options.test.d.ts +0 -2
- package/dist/query/relationship-options.test.d.ts.map +0 -1
- package/dist/query/relationship-options.test.js +0 -150
- package/dist/query/relationship-options.test.js.map +0 -1
- package/dist/validation/field-config.test.d.ts +0 -2
- package/dist/validation/field-config.test.d.ts.map +0 -1
- package/dist/validation/field-config.test.js +0 -159
- package/dist/validation/field-config.test.js.map +0 -1
- package/dist/validation/schema.test.d.ts +0 -2
- package/dist/validation/schema.test.d.ts.map +0 -1
- package/dist/validation/schema.test.js +0 -409
- package/dist/validation/schema.test.js.map +0 -1
- package/docs/type-distribution-fix.md +0 -136
- package/src/access/access-filter.test.ts +0 -1919
- package/src/access/access-filter.ts +0 -1041
- package/src/access/declared-dependencies.test.ts +0 -277
- package/src/access/declared-dependencies.ts +0 -220
- package/src/access/denied-relation-visibility.test.ts +0 -173
- package/src/access/depth-limits.ts +0 -27
- package/src/access/engine.test.ts +0 -67
- package/src/access/engine.ts +0 -193
- package/src/access/errors.ts +0 -242
- package/src/access/field-access.test.ts +0 -792
- package/src/access/field-access.ts +0 -353
- package/src/access/field-transforms.ts +0 -68
- package/src/access/field-visibility.ts +0 -569
- package/src/access/index.ts +0 -82
- package/src/access/multi-column-read-write.test.ts +0 -305
- package/src/access/query-validation.ts +0 -486
- package/src/access/relationship-count.test.ts +0 -344
- package/src/access/relationship-count.ts +0 -346
- package/src/access/relationship-label-filter.test.ts +0 -128
- package/src/access/relationship-label-filter.ts +0 -63
- package/src/access/synthetic-include-read.test.ts +0 -179
- package/src/access/transaction-registry.ts +0 -58
- package/src/access/types.ts +0 -391
- package/src/config/index.ts +0 -177
- package/src/config/label.ts +0 -51
- package/src/config/nav-count.ts +0 -77
- package/src/config/plugin-engine.ts +0 -261
- package/src/config/types.ts +0 -3270
- package/src/context/apply-defaults.ts +0 -47
- package/src/context/hook-pipeline.ts +0 -137
- package/src/context/index.ts +0 -1737
- package/src/context/nested-operations.ts +0 -1325
- package/src/context/transaction-boundary.ts +0 -485
- package/src/context/write-pipeline.ts +0 -732
- package/src/extend.ts +0 -28
- package/src/fields/calendar-day.test.ts +0 -291
- package/src/fields/format-prisma-default.test.ts +0 -64
- package/src/fields/format-prisma-default.ts +0 -64
- package/src/fields/index.ts +0 -1901
- package/src/fields/relationship-foreign-key.test.ts +0 -29
- package/src/fields/select.test.ts +0 -336
- package/src/fields/text-keystone-compat.test.ts +0 -126
- package/src/filter/collect.ts +0 -108
- package/src/filter/filter.test.ts +0 -538
- package/src/filter/index.ts +0 -26
- package/src/filter/map.ts +0 -63
- package/src/filter/parse.ts +0 -99
- package/src/filter/serialize.test.ts +0 -115
- package/src/filter/serialize.ts +0 -73
- package/src/filter/types.ts +0 -120
- package/src/hooks/index.ts +0 -752
- package/src/index.test.ts +0 -50
- package/src/index.ts +0 -184
- package/src/internal.ts +0 -61
- package/src/lib/case-utils.test.ts +0 -159
- package/src/lib/case-utils.ts +0 -68
- package/src/lib/prisma-errors.ts +0 -86
- package/src/mcp/constants.ts +0 -24
- package/src/mcp/field-schema.ts +0 -84
- package/src/mcp/handler.ts +0 -633
- package/src/mcp/index.ts +0 -7
- package/src/mcp/projection.ts +0 -497
- package/src/mcp/types.ts +0 -18
- package/src/query/index.test.ts +0 -830
- package/src/query/index.ts +0 -352
- package/src/query/relationship-options.test.ts +0 -194
- package/src/query/relationship-options.ts +0 -78
- package/src/utils/password.ts +0 -80
- package/src/validation/field-config.test.ts +0 -199
- package/src/validation/field-config.ts +0 -139
- package/src/validation/needs-closure.ts +0 -188
- package/src/validation/schema.test.ts +0 -487
- package/src/validation/schema.ts +0 -51
- package/tests/access-relationships.test.ts +0 -646
- package/tests/access.test.ts +0 -590
- package/tests/apply-defaults.test.ts +0 -119
- package/tests/bare-read-scalars.test.ts +0 -147
- package/tests/computed-field-selective-evaluation.test.ts +0 -418
- package/tests/config.test.ts +0 -242
- package/tests/context.test.ts +0 -3141
- package/tests/default-value-create.test.ts +0 -299
- package/tests/field-hooks.test.ts +0 -410
- package/tests/field-types.test.ts +0 -1291
- package/tests/hook-context-secured.test.ts +0 -424
- package/tests/hook-pipeline.test.ts +0 -233
- package/tests/hooks.test.ts +0 -481
- package/tests/interactive-transaction.test.ts +0 -444
- package/tests/label.test.ts +0 -135
- package/tests/mcp-fields-projection-access.test.ts +0 -250
- package/tests/mcp-handler.test.ts +0 -1411
- package/tests/multi-column-validation-ordering.test.ts +0 -305
- package/tests/nav-count.test.ts +0 -189
- package/tests/needs-declared-dependencies.test.ts +0 -503
- package/tests/nested-access-and-hooks.test.ts +0 -2566
- package/tests/nested-operation-registry.test.ts +0 -231
- package/tests/nested-write-hooks.test.ts +0 -864
- package/tests/nested-write-synthetic-relation.test.ts +0 -437
- package/tests/password-type-distribution.test.ts +0 -154
- package/tests/password-types.test.ts +0 -174
- package/tests/password.test.ts +0 -263
- package/tests/plugin-engine.test.ts +0 -1155
- package/tests/prisma-errors.test.ts +0 -141
- package/tests/resolve-chain.test.ts +0 -411
- package/tests/singleton.test.ts +0 -421
- package/tests/sudo.test.ts +0 -676
- package/tests/to-one-include-access-filter.test.ts +0 -172
- package/tests/transaction-boundary-hooks.test.ts +0 -710
- package/tests/transaction-boundary-outermost.test.ts +0 -530
- package/tests/virtual-fields.test.ts +0 -421
- package/tests/with-session.test.ts +0 -243
- package/tests/write-pipeline.test.ts +0 -617
- package/tsconfig.json +0 -12
- package/tsconfig.tsbuildinfo +0 -1
- package/vitest.config.ts +0 -69
package/dist/mcp/handler.js
CHANGED
|
@@ -1,21 +1,64 @@
|
|
|
1
1
|
import * as z from 'zod';
|
|
2
|
+
import { getPluginData } from '../config/plugin-engine.js';
|
|
3
|
+
import { engineContextOf } from '../context/engine-context.js';
|
|
2
4
|
import { checkAccess } from '../access/engine.js';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
|
|
5
|
+
import { classifyRowIndependentCreateAccess } from '../access/field-access.js';
|
|
6
|
+
import { pascalToCamel } from '../lib/case-utils.js';
|
|
7
|
+
import { isRelationshipField } from '../fields/index.js';
|
|
8
|
+
import { isClientSafeError } from '../lib/client-safe-error.js';
|
|
9
|
+
import { McpToolError } from './tool-error.js';
|
|
10
|
+
import { decideAdvertisement } from './advertise.js';
|
|
11
|
+
import { McpWriteRefusedError, assertWritableData, generateFieldSchemas, ownsForeignKey, } from './field-schema.js';
|
|
12
|
+
import { listIdJsonSchema, parseListId } from '../contract/id-boundary.js';
|
|
13
|
+
import { RELATION_QUANTIFIERS, SCALAR_OPERATORS } from '../secured/operators.js';
|
|
14
|
+
import { orderByArgument, whereArgument } from './arguments.js';
|
|
15
|
+
import { coerceWhereIds, foreignKeyVisibility, idBoundaryRefusal } from './where-id-boundary.js';
|
|
16
|
+
import { McpProjectionRefusedError, generateFieldsProjectionSchema, resolveFieldsProjection, } from './projection.js';
|
|
17
|
+
const UNSAFE_SESSION_KEYS = new Set(['__proto__', 'constructor', 'prototype']);
|
|
18
|
+
/**
|
|
19
|
+
* Strips transport-level fields; userId and any custom session fields flow
|
|
20
|
+
* through to access control. A custom field resolved to `undefined` is
|
|
21
|
+
* dropped rather than passed through — `getContext` refuses a session
|
|
22
|
+
* holding `undefined` for one of its own keys (#1397), and `userId` itself
|
|
23
|
+
* is required and left untouched for that refusal to catch.
|
|
24
|
+
*/
|
|
9
25
|
function toContextSession(session) {
|
|
10
|
-
const { accessToken: _accessToken, expiresAt: _expiresAt, scopes: _scopes, ...rest } = session;
|
|
11
|
-
|
|
26
|
+
const { accessToken: _accessToken, expiresAt: _expiresAt, scopes: _scopes, userId, ...rest } = session;
|
|
27
|
+
const cleaned = { userId };
|
|
28
|
+
for (const [key, value] of Object.entries(rest)) {
|
|
29
|
+
if (value === undefined || UNSAFE_SESSION_KEYS.has(key))
|
|
30
|
+
continue;
|
|
31
|
+
cleaned[key] = value;
|
|
32
|
+
}
|
|
33
|
+
return cleaned;
|
|
12
34
|
}
|
|
13
35
|
/**
|
|
14
36
|
* MCP tools registered globally by plugins via `registerMcpTool`
|
|
15
37
|
* (stored by the plugin engine under `_pluginData.__mcpTools`).
|
|
16
38
|
*/
|
|
17
39
|
function getPluginMcpTools(config) {
|
|
18
|
-
return config
|
|
40
|
+
return getPluginData(config, '__mcpTools') ?? [];
|
|
41
|
+
}
|
|
42
|
+
function asScopeList(value) {
|
|
43
|
+
return value === undefined ? [] : typeof value === 'string' ? [value] : value;
|
|
44
|
+
}
|
|
45
|
+
function requiredCrudScopes(config,
|
|
46
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- List config generics vary per list
|
|
47
|
+
listConfig, operation) {
|
|
48
|
+
const key = operation === 'query' ? 'read' : 'write';
|
|
49
|
+
return asScopeList(listConfig.mcp?.scopes?.[key] ?? config.mcp?.scopes?.[key]);
|
|
50
|
+
}
|
|
51
|
+
function requiredCustomToolScopes(config,
|
|
52
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- List config generics vary per list
|
|
53
|
+
listConfig, customTool) {
|
|
54
|
+
return customTool.scopes ?? requiredCrudScopes(config, listConfig, 'create');
|
|
55
|
+
}
|
|
56
|
+
function missingScopes(session, required) {
|
|
57
|
+
const held = session.scopes ?? [];
|
|
58
|
+
return required.filter((scope) => !held.includes(scope));
|
|
59
|
+
}
|
|
60
|
+
function scopeRefusal(toolName, missing, id) {
|
|
61
|
+
return createErrorResultResponse(`Tool "${toolName}" requires the OAuth scope(s): ${missing.join(', ')}.`, id);
|
|
19
62
|
}
|
|
20
63
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- duck-typing across zod instances
|
|
21
64
|
function isZodSchema(schema) {
|
|
@@ -37,6 +80,22 @@ function toolInputSchemaToJson(inputSchema) {
|
|
|
37
80
|
}
|
|
38
81
|
return inputSchema;
|
|
39
82
|
}
|
|
83
|
+
function assertResourceMetadataUrl(value) {
|
|
84
|
+
let parsed;
|
|
85
|
+
try {
|
|
86
|
+
parsed = new URL(value);
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
throw new Error(`createMcpHandlers: resourceMetadataUrl "${value}" is not an absolute URL.`);
|
|
90
|
+
}
|
|
91
|
+
const hasUnsafeCharacter = Array.from(value).some((char) => {
|
|
92
|
+
const code = char.charCodeAt(0);
|
|
93
|
+
return char === '"' || char === '\\' || code < 0x20 || code === 0x7f;
|
|
94
|
+
});
|
|
95
|
+
if ((parsed.protocol !== 'https:' && parsed.protocol !== 'http:') || hasUnsafeCharacter) {
|
|
96
|
+
throw new Error('createMcpHandlers: resourceMetadataUrl must be a plain http(s) URL.');
|
|
97
|
+
}
|
|
98
|
+
}
|
|
40
99
|
/**
|
|
41
100
|
* Create MCP route handlers
|
|
42
101
|
*
|
|
@@ -46,12 +105,11 @@ function toolInputSchemaToJson(inputSchema) {
|
|
|
46
105
|
* import { createMcpHandlers } from '@opensaas/stack-core/mcp'
|
|
47
106
|
* import { createBetterAuthMcpAdapter } from '@opensaas/stack-auth/mcp'
|
|
48
107
|
* import config from '@/opensaas.config'
|
|
49
|
-
* import { auth } from '@/lib/auth'
|
|
50
108
|
* import { getContext } from '@/.opensaas/context'
|
|
51
109
|
*
|
|
52
110
|
* const { GET, POST, DELETE } = createMcpHandlers({
|
|
53
|
-
* config,
|
|
54
|
-
* getSession: createBetterAuthMcpAdapter(
|
|
111
|
+
* config: await config,
|
|
112
|
+
* getSession: createBetterAuthMcpAdapter({ resource, baseURL }),
|
|
55
113
|
* getContext
|
|
56
114
|
* })
|
|
57
115
|
*
|
|
@@ -59,7 +117,8 @@ function toolInputSchemaToJson(inputSchema) {
|
|
|
59
117
|
* ```
|
|
60
118
|
*/
|
|
61
119
|
export function createMcpHandlers(options) {
|
|
62
|
-
const { config, getSession
|
|
120
|
+
const { config, getSession } = options;
|
|
121
|
+
const getContext = async (session) => engineContextOf(await options.getContext(session));
|
|
63
122
|
if (!config.mcp?.enabled) {
|
|
64
123
|
const notEnabledHandler = async () => new Response(JSON.stringify({ error: 'MCP not enabled' }), {
|
|
65
124
|
status: 404,
|
|
@@ -68,14 +127,16 @@ export function createMcpHandlers(options) {
|
|
|
68
127
|
return { GET: notEnabledHandler, POST: notEnabledHandler, DELETE: notEnabledHandler };
|
|
69
128
|
}
|
|
70
129
|
const basePath = config.mcp.basePath || '/api/mcp';
|
|
130
|
+
if (options.resourceMetadataUrl !== undefined)
|
|
131
|
+
assertResourceMetadataUrl(options.resourceMetadataUrl);
|
|
132
|
+
const challenge = `Bearer realm="${basePath}", error="invalid_token"` +
|
|
133
|
+
(options.resourceMetadataUrl ? `, resource_metadata="${options.resourceMetadataUrl}"` : '');
|
|
71
134
|
const handler = async (req) => {
|
|
72
|
-
const session = await getSession(req.
|
|
135
|
+
const session = await getSession(req.clone());
|
|
73
136
|
if (!session) {
|
|
74
137
|
return new Response(null, {
|
|
75
138
|
status: 401,
|
|
76
|
-
headers: {
|
|
77
|
-
'WWW-Authenticate': `Bearer realm="${basePath}", error="invalid_token"`,
|
|
78
|
-
},
|
|
139
|
+
headers: { 'WWW-Authenticate': challenge },
|
|
79
140
|
});
|
|
80
141
|
}
|
|
81
142
|
try {
|
|
@@ -89,7 +150,7 @@ export function createMcpHandlers(options) {
|
|
|
89
150
|
}
|
|
90
151
|
if (body.method === 'tools/list') {
|
|
91
152
|
const context = await getContext(toContextSession(session));
|
|
92
|
-
return await handleToolsList(config, context, body.id);
|
|
153
|
+
return await handleToolsList(config, context, session, body.id);
|
|
93
154
|
}
|
|
94
155
|
if (body.method === 'tools/call') {
|
|
95
156
|
return await handleToolsCall(body.params, session, config, getContext, body.id);
|
|
@@ -104,9 +165,10 @@ export function createMcpHandlers(options) {
|
|
|
104
165
|
});
|
|
105
166
|
}
|
|
106
167
|
catch (error) {
|
|
168
|
+
console.error('[opensaas] MCP request handling failed:', error);
|
|
107
169
|
return new Response(JSON.stringify({
|
|
108
170
|
error: 'Request handling failed',
|
|
109
|
-
message:
|
|
171
|
+
message: 'Request handling failed due to an internal error.',
|
|
110
172
|
}), {
|
|
111
173
|
status: 500,
|
|
112
174
|
headers: { 'Content-Type': 'application/json' },
|
|
@@ -138,72 +200,115 @@ function handleInitialize(_params, id) {
|
|
|
138
200
|
headers: { 'Content-Type': 'application/json' },
|
|
139
201
|
});
|
|
140
202
|
}
|
|
141
|
-
|
|
203
|
+
/**
|
|
204
|
+
* The `where` argument's own description. The predicate is the Where
|
|
205
|
+
* vocabulary — the same grammar every other producer compiles to (ADR-0055) —
|
|
206
|
+
* so the schema says which operators that is rather than naming an ORM.
|
|
207
|
+
*/
|
|
208
|
+
function whereDescription(listKey) {
|
|
209
|
+
return (`Which ${listKey} rows to return, in the Where vocabulary: a field name against a value or ` +
|
|
210
|
+
`an operator object (${SCALAR_OPERATORS.join(', ')}), a relation against ` +
|
|
211
|
+
`${RELATION_QUANTIFIERS.join('/')}, and AND, OR, NOT`);
|
|
212
|
+
}
|
|
213
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- List config generics vary per list
|
|
214
|
+
function enabledToolsFor(config, listConfig) {
|
|
215
|
+
const defaultTools = config.mcp?.defaultTools || {
|
|
216
|
+
read: true,
|
|
217
|
+
create: true,
|
|
218
|
+
update: true,
|
|
219
|
+
delete: true,
|
|
220
|
+
};
|
|
221
|
+
return {
|
|
222
|
+
query: listConfig.mcp?.tools?.read ?? defaultTools.read ?? true,
|
|
223
|
+
create: listConfig.mcp?.tools?.create ?? defaultTools.create ?? true,
|
|
224
|
+
update: listConfig.mcp?.tools?.update ?? defaultTools.update ?? true,
|
|
225
|
+
delete: listConfig.mcp?.tools?.delete ?? defaultTools.delete ?? true,
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
async function listReachableOverMcp(
|
|
229
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- List config generics vary per list
|
|
230
|
+
listConfig, context) {
|
|
231
|
+
if (listConfig.mcp?.enabled === false)
|
|
232
|
+
return false;
|
|
233
|
+
return decideAdvertisement('list query access', async () => {
|
|
234
|
+
const accessResult = await checkAccess(listConfig.access?.operation?.query, {
|
|
235
|
+
session: context.session,
|
|
236
|
+
context,
|
|
237
|
+
});
|
|
238
|
+
return accessResult !== false;
|
|
239
|
+
}, false);
|
|
240
|
+
}
|
|
241
|
+
async function handleToolsList(config, context, session, id) {
|
|
142
242
|
const tools = [];
|
|
143
243
|
for (const [listKey, listConfig] of Object.entries(config.lists)) {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
// target (`relatedListIfVisible` in projection.ts applies the identical
|
|
149
|
-
// check there) — ADR-0033.
|
|
150
|
-
const queryAccess = listConfig.access?.operation?.query;
|
|
151
|
-
const accessResult = await checkAccess(queryAccess, { session: context.session, context });
|
|
152
|
-
if (accessResult === false)
|
|
244
|
+
// The tool name stays camelCase: it is the identifier an assistant has
|
|
245
|
+
// already bound to, and renaming it would break every registered client.
|
|
246
|
+
const toolKey = pascalToCamel(listKey);
|
|
247
|
+
if (!(await listReachableOverMcp(listConfig, context)))
|
|
153
248
|
continue;
|
|
154
|
-
const
|
|
155
|
-
const
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
update: true,
|
|
159
|
-
delete: true,
|
|
160
|
-
};
|
|
161
|
-
const enabledTools = {
|
|
162
|
-
read: listConfig.mcp?.tools?.read ?? defaultTools.read ?? true,
|
|
163
|
-
create: listConfig.mcp?.tools?.create ?? defaultTools.create ?? true,
|
|
164
|
-
update: listConfig.mcp?.tools?.update ?? defaultTools.update ?? true,
|
|
165
|
-
delete: listConfig.mcp?.tools?.delete ?? defaultTools.delete ?? true,
|
|
166
|
-
};
|
|
167
|
-
if (enabledTools.read) {
|
|
168
|
-
const fieldsSchema = await generateFieldsProjectionSchema(listConfig, config, context.session, context);
|
|
249
|
+
const enabledTools = enabledToolsFor(config, listConfig);
|
|
250
|
+
const permitted = (operation) => missingScopes(session, requiredCrudScopes(config, listConfig, operation)).length === 0;
|
|
251
|
+
if (enabledTools.query && permitted('query')) {
|
|
252
|
+
const fieldsSchema = await generateFieldsProjectionSchema(listKey, listConfig, config, context.session, context);
|
|
169
253
|
tools.push({
|
|
170
|
-
name: `list_${
|
|
254
|
+
name: `list_${toolKey}_query`,
|
|
171
255
|
description: `Query ${listKey} records with optional filters`,
|
|
172
256
|
inputSchema: {
|
|
173
257
|
type: 'object',
|
|
174
258
|
properties: {
|
|
175
|
-
where: { type: 'object', description:
|
|
176
|
-
take: {
|
|
259
|
+
where: { type: 'object', description: whereDescription(listKey) },
|
|
260
|
+
take: {
|
|
261
|
+
type: 'number',
|
|
262
|
+
description: 'Number of records to return (max 100; 0 returns no rows)',
|
|
263
|
+
},
|
|
177
264
|
skip: { type: 'number', description: 'Number of records to skip' },
|
|
178
|
-
orderBy: {
|
|
265
|
+
orderBy: {
|
|
266
|
+
type: 'object',
|
|
267
|
+
description: `Sort order: ${listKey} column names against "asc" or "desc"`,
|
|
268
|
+
},
|
|
179
269
|
fields: fieldsSchema,
|
|
180
270
|
},
|
|
181
271
|
},
|
|
182
272
|
});
|
|
183
273
|
}
|
|
184
|
-
if (enabledTools.create) {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
274
|
+
if (enabledTools.create && permitted('create')) {
|
|
275
|
+
// A flat, row-independent `create` denial (`access: { operation: {
|
|
276
|
+
// create: () => false } }`) refuses every call before a row is even
|
|
277
|
+
// considered — the same defect #1163 closed for a denied required
|
|
278
|
+
// field, one level up (#1355). A row-dependent rule (most plausibly one
|
|
279
|
+
// shared with `update`/`delete`) cannot be classified ahead of a real
|
|
280
|
+
// request, so it still advertises the tool.
|
|
281
|
+
const createOperationAccess = listConfig.access?.operation?.create;
|
|
282
|
+
const operationClassification = await decideAdvertisement(`${listKey}.create`, () => classifyRowIndependentCreateAccess(createOperationAccess, {
|
|
283
|
+
session: context.session,
|
|
284
|
+
context,
|
|
285
|
+
}), 'deny');
|
|
286
|
+
if (operationClassification !== 'deny') {
|
|
287
|
+
const fieldSchemas = await generateFieldSchemas(listKey, listConfig.fields, config, 'create', context.session, context);
|
|
288
|
+
if (fieldSchemas.deniedRequiredField === null) {
|
|
289
|
+
tools.push({
|
|
290
|
+
name: `list_${toolKey}_create`,
|
|
291
|
+
description: `Create a new ${listKey} record`,
|
|
292
|
+
inputSchema: {
|
|
193
293
|
type: 'object',
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
294
|
+
properties: {
|
|
295
|
+
data: {
|
|
296
|
+
type: 'object',
|
|
297
|
+
description: 'Record data with the following fields',
|
|
298
|
+
properties: fieldSchemas.properties,
|
|
299
|
+
required: fieldSchemas.required,
|
|
300
|
+
},
|
|
301
|
+
},
|
|
302
|
+
required: ['data'],
|
|
197
303
|
},
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
});
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
}
|
|
202
307
|
}
|
|
203
|
-
if (enabledTools.update) {
|
|
204
|
-
const fieldSchemas = generateFieldSchemas(listConfig.fields, 'update');
|
|
308
|
+
if (enabledTools.update && permitted('update')) {
|
|
309
|
+
const fieldSchemas = await generateFieldSchemas(listKey, listConfig.fields, config, 'update', context.session, context);
|
|
205
310
|
tools.push({
|
|
206
|
-
name: `list_${
|
|
311
|
+
name: `list_${toolKey}_update`,
|
|
207
312
|
description: `Update an existing ${listKey} record`,
|
|
208
313
|
inputSchema: {
|
|
209
314
|
type: 'object',
|
|
@@ -212,7 +317,7 @@ async function handleToolsList(config, context, id) {
|
|
|
212
317
|
type: 'object',
|
|
213
318
|
description: 'Record identifier',
|
|
214
319
|
properties: {
|
|
215
|
-
id:
|
|
320
|
+
id: listIdJsonSchema(config, listKey),
|
|
216
321
|
},
|
|
217
322
|
required: ['id'],
|
|
218
323
|
},
|
|
@@ -226,9 +331,9 @@ async function handleToolsList(config, context, id) {
|
|
|
226
331
|
},
|
|
227
332
|
});
|
|
228
333
|
}
|
|
229
|
-
if (enabledTools.delete) {
|
|
334
|
+
if (enabledTools.delete && permitted('delete')) {
|
|
230
335
|
tools.push({
|
|
231
|
-
name: `list_${
|
|
336
|
+
name: `list_${toolKey}_delete`,
|
|
232
337
|
description: `Delete a ${listKey} record`,
|
|
233
338
|
inputSchema: {
|
|
234
339
|
type: 'object',
|
|
@@ -237,7 +342,7 @@ async function handleToolsList(config, context, id) {
|
|
|
237
342
|
type: 'object',
|
|
238
343
|
description: 'Record identifier',
|
|
239
344
|
properties: {
|
|
240
|
-
id:
|
|
345
|
+
id: listIdJsonSchema(config, listKey),
|
|
241
346
|
},
|
|
242
347
|
required: ['id'],
|
|
243
348
|
},
|
|
@@ -248,6 +353,9 @@ async function handleToolsList(config, context, id) {
|
|
|
248
353
|
}
|
|
249
354
|
if (listConfig.mcp?.customTools) {
|
|
250
355
|
for (const customTool of listConfig.mcp.customTools) {
|
|
356
|
+
if (missingScopes(session, requiredCustomToolScopes(config, listConfig, customTool)).length >
|
|
357
|
+
0)
|
|
358
|
+
continue;
|
|
251
359
|
tools.push({
|
|
252
360
|
name: customTool.name,
|
|
253
361
|
description: customTool.description,
|
|
@@ -258,6 +366,8 @@ async function handleToolsList(config, context, id) {
|
|
|
258
366
|
}
|
|
259
367
|
// Tools registered globally by plugins (e.g. the RAG plugin's semantic search)
|
|
260
368
|
for (const pluginTool of getPluginMcpTools(config)) {
|
|
369
|
+
if (missingScopes(session, pluginTool.scopes ?? []).length > 0)
|
|
370
|
+
continue;
|
|
261
371
|
tools.push({
|
|
262
372
|
name: pluginTool.name,
|
|
263
373
|
description: pluginTool.description,
|
|
@@ -289,103 +399,269 @@ params, session, config, getContext, id) {
|
|
|
289
399
|
}
|
|
290
400
|
const match = toolName.match(/^list_([a-z][a-zA-Z0-9]*)_(query|create|update|delete)$/);
|
|
291
401
|
if (match) {
|
|
292
|
-
const [,
|
|
293
|
-
return await handleCrudTool(
|
|
402
|
+
const [, toolKey, operation] = match;
|
|
403
|
+
return await handleCrudTool(toolKey, operation, toolArgs, session, config, getContext, id);
|
|
294
404
|
}
|
|
295
405
|
return await handleCustomTool(toolName, toolArgs, session, config, getContext, id);
|
|
296
406
|
}
|
|
297
|
-
|
|
407
|
+
function isPlainObject(value) {
|
|
408
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
409
|
+
}
|
|
410
|
+
/** `{ connect: { id } }`, and nothing beside either key — the only shape {@link coerceConnectIds} parses. Any other shape is left alone for the write pipeline's own `MalformedRelationInputError` to refuse. */
|
|
411
|
+
function connectCriterion(value) {
|
|
412
|
+
if (!isPlainObject(value))
|
|
413
|
+
return undefined;
|
|
414
|
+
const keys = Object.keys(value);
|
|
415
|
+
if (keys.length !== 1 || keys[0] !== 'connect')
|
|
416
|
+
return undefined;
|
|
417
|
+
const criterion = value.connect;
|
|
418
|
+
if (!isPlainObject(criterion))
|
|
419
|
+
return undefined;
|
|
420
|
+
const criterionKeys = Object.keys(criterion);
|
|
421
|
+
if (criterionKeys.length !== 1 || criterionKeys[0] !== 'id')
|
|
422
|
+
return undefined;
|
|
423
|
+
return criterion;
|
|
424
|
+
}
|
|
425
|
+
/**
|
|
426
|
+
* A `data` payload's own `{ connect: { id } }` values, each at the RELATED
|
|
427
|
+
* list's own id type (ADR-0048) — the write half of the same boundary
|
|
428
|
+
* coercion `coerceWhereIds` applies to a `where.id`. The advertised schema
|
|
429
|
+
* (`fieldToJsonSchema`) already tells a well-behaved caller which type to
|
|
430
|
+
* send; this is what refuses a malformed one rather than letting it reach the
|
|
431
|
+
* reachability query as a value the target column cannot hold.
|
|
432
|
+
*
|
|
433
|
+
* Only a field that owns its foreign key can carry `connect` at all (ADR-0050
|
|
434
|
+
* refuses it everywhere else already), so every other field's value is
|
|
435
|
+
* returned unchanged. `null` (clearing the edge) and a value the write
|
|
436
|
+
* pipeline itself refuses (a malformed shape, a second key) both pass through
|
|
437
|
+
* unchanged — this only ever narrows a well-shaped `connect.id`, never widens
|
|
438
|
+
* or replaces a refusal that already exists downstream.
|
|
439
|
+
*
|
|
440
|
+
* Returns `null` when a `connect.id` names a value its related list's id
|
|
441
|
+
* column cannot hold — the caller turns that into the same generic
|
|
442
|
+
* "access denied or record not found" `where.id` already answers with.
|
|
443
|
+
*/
|
|
444
|
+
function coerceConnectIds(data, listKey,
|
|
445
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- ListConfig must accept any TypeInfo
|
|
446
|
+
listConfig, config) {
|
|
447
|
+
let coerced;
|
|
448
|
+
for (const [fieldName, fieldConfig] of Object.entries(listConfig.fields)) {
|
|
449
|
+
if (!Object.hasOwn(data, fieldName))
|
|
450
|
+
continue;
|
|
451
|
+
if (!isRelationshipField(fieldConfig))
|
|
452
|
+
continue;
|
|
453
|
+
if (!ownsForeignKey(listKey, fieldName, fieldConfig, config))
|
|
454
|
+
continue;
|
|
455
|
+
const criterion = connectCriterion(data[fieldName]);
|
|
456
|
+
if (criterion === undefined)
|
|
457
|
+
continue;
|
|
458
|
+
const relatedListKey = fieldConfig.ref.split('.')[0];
|
|
459
|
+
const parsed = parseListId(config, relatedListKey, criterion.id);
|
|
460
|
+
if (!parsed.ok)
|
|
461
|
+
return null;
|
|
462
|
+
coerced ??= { ...data };
|
|
463
|
+
coerced[fieldName] = { connect: { id: parsed.value } };
|
|
464
|
+
}
|
|
465
|
+
return coerced ?? data;
|
|
466
|
+
}
|
|
467
|
+
/**
|
|
468
|
+
* Framework-authored errors safe to hand an MCP client verbatim — everything
|
|
469
|
+
* else is an application rule's own internal detail (#1361, #1456).
|
|
470
|
+
* `DatabaseError` (and its `UniqueConstraintViolation`/`SerializationFailure`
|
|
471
|
+
* subclasses) is explicitly documented as carrying a message "safe to show a
|
|
472
|
+
* user" (ADR-0042) — the driver's own text stays on `cause`, never here.
|
|
473
|
+
*/
|
|
474
|
+
function isSafeMcpError(error) {
|
|
475
|
+
return (isClientSafeError(error) ||
|
|
476
|
+
error instanceof McpProjectionRefusedError ||
|
|
477
|
+
error instanceof McpWriteRefusedError ||
|
|
478
|
+
error instanceof McpToolError);
|
|
479
|
+
}
|
|
480
|
+
/**
|
|
481
|
+
* Redacts an error raised while serving a CRUD tool behind a generic refusal,
|
|
482
|
+
* logging the real error server-side, unless it's one of the known-safe
|
|
483
|
+
* types. Shared by `query` (whose caller-named `fields` can throw while
|
|
484
|
+
* resolving the projection), `create`/`update` (whose own result runs Field
|
|
485
|
+
* Visibility over the full row exactly like a read does, so the same
|
|
486
|
+
* throwing rule reaches the same code path there too), and `delete` (which
|
|
487
|
+
* skips Field Visibility but shares this same outer catch for whatever else
|
|
488
|
+
* a hook or the database raises).
|
|
489
|
+
*/
|
|
490
|
+
function redactMcpError(error, listKey, operationLabel, id) {
|
|
491
|
+
if (isSafeMcpError(error)) {
|
|
492
|
+
return createErrorResultResponse(error.message, id);
|
|
493
|
+
}
|
|
494
|
+
console.error(`[opensaas] MCP ${operationLabel} "${listKey}" failed:`, error);
|
|
495
|
+
return createErrorResultResponse(`${operationLabel} on "${listKey}" failed due to an internal error.`, id);
|
|
496
|
+
}
|
|
497
|
+
async function handleCrudTool(toolKey, operation,
|
|
298
498
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Tool arguments vary by operation
|
|
299
499
|
args, session, config, getContext, id) {
|
|
300
500
|
const context = await getContext(toContextSession(session));
|
|
501
|
+
const listEntry = Object.entries(config.lists).find(([candidate]) => pascalToCamel(candidate) === toolKey);
|
|
502
|
+
if (!listEntry) {
|
|
503
|
+
return createErrorResponse(`Unknown tool: list_${toolKey}_${operation}`, id);
|
|
504
|
+
}
|
|
505
|
+
const [listKey, listConfig] = listEntry;
|
|
301
506
|
try {
|
|
507
|
+
if (!enabledToolsFor(config, listConfig)[operation] ||
|
|
508
|
+
!(await listReachableOverMcp(listConfig, context))) {
|
|
509
|
+
return createErrorResponse(`Unknown tool: list_${toolKey}_${operation}`, id);
|
|
510
|
+
}
|
|
511
|
+
const missing = missingScopes(session, requiredCrudScopes(config, listConfig, operation));
|
|
512
|
+
if (missing.length > 0) {
|
|
513
|
+
return scopeRefusal(`list_${toolKey}_${operation}`, missing, id);
|
|
514
|
+
}
|
|
302
515
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Result type varies by Prisma operation
|
|
303
516
|
let result;
|
|
304
517
|
switch (operation) {
|
|
305
518
|
case 'query': {
|
|
519
|
+
if (args.take !== undefined && typeof args.take !== 'number') {
|
|
520
|
+
return createErrorResultResponse(`"${listKey}.take" must be a number.`, id);
|
|
521
|
+
}
|
|
522
|
+
if (typeof args.take === 'number' && args.take < 0) {
|
|
523
|
+
return createErrorResultResponse(`"${listKey}.take" must not be negative (reverse pagination isn't supported).`, id);
|
|
524
|
+
}
|
|
525
|
+
if (args.skip !== undefined && typeof args.skip !== 'number') {
|
|
526
|
+
return createErrorResultResponse(`"${listKey}.skip" must be a number.`, id);
|
|
527
|
+
}
|
|
528
|
+
if (typeof args.skip === 'number' && args.skip < 0) {
|
|
529
|
+
return createErrorResultResponse(`"${listKey}.skip" must not be negative.`, id);
|
|
530
|
+
}
|
|
531
|
+
let query = context.db[listKey];
|
|
306
532
|
let projection;
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
533
|
+
try {
|
|
534
|
+
if (isPlainObject(args.where)) {
|
|
535
|
+
const coercedWhere = coerceWhereIds(args.where, config, listKey, await foreignKeyVisibility(config, context.session, context));
|
|
536
|
+
if (coercedWhere === null) {
|
|
537
|
+
return createErrorResultResponse(idBoundaryRefusal('query records'), id);
|
|
538
|
+
}
|
|
539
|
+
query = query.where(whereArgument(coercedWhere, listKey));
|
|
311
540
|
}
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
projection = await resolveFieldsProjection(args.fields, listKey, listConfig, config, context.session, context);
|
|
541
|
+
else if (args.where !== undefined) {
|
|
542
|
+
query = query.where(whereArgument(args.where, listKey));
|
|
315
543
|
}
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
544
|
+
if (args.orderBy !== undefined) {
|
|
545
|
+
query = query.orderBy(orderByArgument(args.orderBy, listKey));
|
|
546
|
+
}
|
|
547
|
+
if (args.fields !== undefined) {
|
|
548
|
+
projection = await resolveFieldsProjection(args.fields, listKey, listConfig, config, context.session, context);
|
|
549
|
+
query = projection.apply(query);
|
|
321
550
|
}
|
|
551
|
+
if (args.skip !== undefined)
|
|
552
|
+
query = query.offset(args.skip);
|
|
553
|
+
const rows = await query.limit(Math.min(args.take ?? 10, 100)).all();
|
|
554
|
+
const items = projection ? projection.toWire(rows) : rows;
|
|
555
|
+
return createSuccessResponse({ items, count: items.length }, id);
|
|
556
|
+
}
|
|
557
|
+
catch (error) {
|
|
558
|
+
// A caller-named field's access rule can still throw here — a
|
|
559
|
+
// row-dependent rule cannot be classified ahead of the read
|
|
560
|
+
// (`resolveFieldsProjection` only contains rules for fields the
|
|
561
|
+
// caller did NOT ask for) — and whatever it threw is an internal
|
|
562
|
+
// detail of the application's own rule, not something to hand an
|
|
563
|
+
// external MCP client (#1361).
|
|
564
|
+
return redactMcpError(error, listKey, 'Query', id);
|
|
322
565
|
}
|
|
323
|
-
result = await context.db[dbKey].findMany({
|
|
324
|
-
where: args.where,
|
|
325
|
-
take: Math.min(args.take || 10, 100),
|
|
326
|
-
skip: args.skip,
|
|
327
|
-
orderBy: args.orderBy,
|
|
328
|
-
...(projection?.include ? { include: projection.include } : {}),
|
|
329
|
-
});
|
|
330
|
-
const items = projection
|
|
331
|
-
? result.map((item) => projectMcpResult(item, projection))
|
|
332
|
-
: result;
|
|
333
|
-
return createSuccessResponse({
|
|
334
|
-
items,
|
|
335
|
-
count: items.length,
|
|
336
|
-
}, id);
|
|
337
566
|
}
|
|
338
|
-
case 'create':
|
|
339
|
-
|
|
340
|
-
data
|
|
341
|
-
}
|
|
567
|
+
case 'create': {
|
|
568
|
+
if (!isPlainObject(args.data)) {
|
|
569
|
+
return createErrorResultResponse('`data` must be an object of field values.', id);
|
|
570
|
+
}
|
|
571
|
+
await assertWritableData(args.data, listKey, listConfig.fields, config, 'create', context.session, context);
|
|
572
|
+
// A `connect.id` naming a value its related list's id column cannot
|
|
573
|
+
// hold answers exactly as a missing row does — the same boundary
|
|
574
|
+
// coercion `where.id` gets below, applied to the write's own edges
|
|
575
|
+
// (ADR-0048, Silent failure).
|
|
576
|
+
const data = coerceConnectIds(args.data, listKey, listConfig, config);
|
|
577
|
+
if (data === null) {
|
|
578
|
+
return createErrorResultResponse('Failed to create record. Access denied or validation failed.', id);
|
|
579
|
+
}
|
|
580
|
+
result = await context.db[listKey].create({ data });
|
|
342
581
|
if (!result) {
|
|
343
582
|
return createErrorResultResponse('Failed to create record. Access denied or validation failed.', id);
|
|
344
583
|
}
|
|
345
584
|
return createSuccessResponse({ success: true, item: result }, id);
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
585
|
+
}
|
|
586
|
+
case 'update': {
|
|
587
|
+
// A malformed id answers exactly as a missing row does: shape is all
|
|
588
|
+
// the boundary can check, and "no such id" and "not yours" are the
|
|
589
|
+
// same answer everywhere else (ADR-0048, Silent failure).
|
|
590
|
+
const parsed = parseListId(config, listKey, args.where?.id);
|
|
591
|
+
if (!parsed.ok) {
|
|
592
|
+
return createErrorResultResponse(idBoundaryRefusal('update record'), id);
|
|
593
|
+
}
|
|
594
|
+
if (!isPlainObject(args.data)) {
|
|
595
|
+
return createErrorResultResponse('`data` must be an object of field values.', id);
|
|
596
|
+
}
|
|
597
|
+
await assertWritableData(args.data, listKey, listConfig.fields, config, 'update', context.session, context);
|
|
598
|
+
const data = coerceConnectIds(args.data, listKey, listConfig, config);
|
|
599
|
+
if (data === null) {
|
|
600
|
+
return createErrorResultResponse(idBoundaryRefusal('update record'), id);
|
|
601
|
+
}
|
|
602
|
+
result = await context.db[listKey].update({
|
|
603
|
+
where: { id: parsed.value },
|
|
604
|
+
data,
|
|
350
605
|
});
|
|
351
606
|
if (!result) {
|
|
352
|
-
return createErrorResultResponse('
|
|
607
|
+
return createErrorResultResponse(idBoundaryRefusal('update record'), id);
|
|
353
608
|
}
|
|
354
609
|
return createSuccessResponse({ success: true, item: result }, id);
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
610
|
+
}
|
|
611
|
+
case 'delete': {
|
|
612
|
+
const parsed = parseListId(config, listKey, args.where?.id);
|
|
613
|
+
if (!parsed.ok) {
|
|
614
|
+
return createErrorResultResponse(idBoundaryRefusal('delete record'), id);
|
|
615
|
+
}
|
|
616
|
+
result = await context.db[listKey].delete({ where: { id: parsed.value } });
|
|
359
617
|
if (!result) {
|
|
360
|
-
return createErrorResultResponse('
|
|
618
|
+
return createErrorResultResponse(idBoundaryRefusal('delete record'), id);
|
|
361
619
|
}
|
|
362
|
-
return createSuccessResponse({ success: true, deletedId:
|
|
620
|
+
return createSuccessResponse({ success: true, deletedId: parsed.value }, id);
|
|
621
|
+
}
|
|
363
622
|
default:
|
|
364
623
|
return createErrorResponse(`Unknown operation: ${operation}`, id);
|
|
365
624
|
}
|
|
366
625
|
}
|
|
367
626
|
catch (error) {
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
627
|
+
// A create/update's own returned row runs through Field Visibility
|
|
628
|
+
// exactly like a read does (no `fields`/`.select()` narrows a write's
|
|
629
|
+
// result), so a field whose `read` rule throws reaches here the same way
|
|
630
|
+
// it reaches the query path's own catch above (#1456).
|
|
631
|
+
const operationLabel = operation.charAt(0).toUpperCase() + operation.slice(1);
|
|
632
|
+
return redactMcpError(error, listKey, operationLabel, id);
|
|
373
633
|
}
|
|
374
634
|
}
|
|
375
635
|
async function handleCustomTool(toolName,
|
|
376
636
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Custom tool arguments are user-defined
|
|
377
637
|
args, session, config, getContext, id) {
|
|
378
638
|
// Find the tool: list-level custom tools first, then plugin-registered tools
|
|
639
|
+
const context = await getContext(toContextSession(session));
|
|
379
640
|
let customTool;
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
641
|
+
let owningList; // eslint-disable-line @typescript-eslint/no-explicit-any -- List config generics vary per list
|
|
642
|
+
try {
|
|
643
|
+
for (const listConfig of Object.values(config.lists)) {
|
|
644
|
+
const found = listConfig.mcp?.customTools?.find((t) => t.name === toolName);
|
|
645
|
+
if (found && (await listReachableOverMcp(listConfig, context))) {
|
|
646
|
+
customTool = found;
|
|
647
|
+
owningList = listConfig;
|
|
648
|
+
break;
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
catch (error) {
|
|
653
|
+
console.error(`[opensaas] MCP custom tool "${toolName}" access check failed:`, error);
|
|
654
|
+
return createErrorResultResponse(`Custom tool "${toolName}" failed due to an internal error.`, id);
|
|
384
655
|
}
|
|
385
656
|
customTool ??= getPluginMcpTools(config).find((t) => t.name === toolName);
|
|
386
657
|
if (!customTool) {
|
|
387
658
|
return createErrorResponse(`Unknown tool: ${toolName}`, id);
|
|
388
659
|
}
|
|
660
|
+
const missing = missingScopes(session, owningList
|
|
661
|
+
? requiredCustomToolScopes(config, owningList, customTool)
|
|
662
|
+
: (customTool.scopes ?? []));
|
|
663
|
+
if (missing.length > 0)
|
|
664
|
+
return scopeRefusal(toolName, missing, id);
|
|
389
665
|
let input = args;
|
|
390
666
|
if (isZodSchema(customTool.inputSchema)) {
|
|
391
667
|
const parsed = customTool.inputSchema.safeParse(args);
|
|
@@ -394,7 +670,6 @@ args, session, config, getContext, id) {
|
|
|
394
670
|
}
|
|
395
671
|
input = parsed.data;
|
|
396
672
|
}
|
|
397
|
-
const context = await getContext(toContextSession(session));
|
|
398
673
|
try {
|
|
399
674
|
const result = await customTool.handler({
|
|
400
675
|
input,
|
|
@@ -403,7 +678,10 @@ args, session, config, getContext, id) {
|
|
|
403
678
|
return createSuccessResponse(result, id);
|
|
404
679
|
}
|
|
405
680
|
catch (error) {
|
|
406
|
-
|
|
681
|
+
if (error instanceof McpToolError) {
|
|
682
|
+
return createErrorResultResponse(error.message, id);
|
|
683
|
+
}
|
|
684
|
+
return redactMcpError(error, toolName, 'Tool', id);
|
|
407
685
|
}
|
|
408
686
|
}
|
|
409
687
|
/**
|