@opensaas/stack-core 0.43.0 → 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 +2720 -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 -16
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +105 -51
- 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 -74
- package/dist/context/nested-operations.d.ts.map +0 -1
- package/dist/context/nested-operations.js +0 -847
- 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 -1470
- 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 -192
- 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 -3146
- 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 -317
- 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
|
@@ -1,1411 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
|
2
|
-
import * as z from 'zod'
|
|
3
|
-
import { createMcpHandlers } from '../src/mcp/handler.js'
|
|
4
|
-
import type { OpenSaasConfig } from '../src/config/types.js'
|
|
5
|
-
import type { AccessContext } from '../src/access/types.js'
|
|
6
|
-
import type { McpSession, McpSessionProvider } from '../src/mcp/types.js'
|
|
7
|
-
import { HashedPassword } from '../src/utils/password.js'
|
|
8
|
-
import {
|
|
9
|
-
AccessScopeDepthExceededError,
|
|
10
|
-
RelationFilterAccessDeniedError,
|
|
11
|
-
} from '../src/access/errors.js'
|
|
12
|
-
|
|
13
|
-
describe('MCP Handler', () => {
|
|
14
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
15
|
-
let mockPrisma: any
|
|
16
|
-
let config: OpenSaasConfig
|
|
17
|
-
let getContext: (session?: { userId: string }) => AccessContext
|
|
18
|
-
let mockGetSession: McpSessionProvider
|
|
19
|
-
|
|
20
|
-
beforeEach(() => {
|
|
21
|
-
// Mock Prisma client
|
|
22
|
-
mockPrisma = {
|
|
23
|
-
post: {
|
|
24
|
-
findMany: vi.fn(),
|
|
25
|
-
create: vi.fn(),
|
|
26
|
-
update: vi.fn(),
|
|
27
|
-
delete: vi.fn(),
|
|
28
|
-
},
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// Sample config with MCP enabled
|
|
32
|
-
config = {
|
|
33
|
-
db: {
|
|
34
|
-
provider: 'postgresql',
|
|
35
|
-
url: 'postgresql://localhost:5432/test',
|
|
36
|
-
},
|
|
37
|
-
mcp: {
|
|
38
|
-
enabled: true,
|
|
39
|
-
basePath: '/api/mcp',
|
|
40
|
-
},
|
|
41
|
-
lists: {
|
|
42
|
-
Post: {
|
|
43
|
-
fields: {
|
|
44
|
-
title: { type: 'text', validation: { isRequired: true } },
|
|
45
|
-
content: { type: 'text' },
|
|
46
|
-
},
|
|
47
|
-
access: {
|
|
48
|
-
operation: {
|
|
49
|
-
query: () => true,
|
|
50
|
-
create: ({ session }) => !!session,
|
|
51
|
-
update: ({ session }) => !!session,
|
|
52
|
-
delete: ({ session }) => !!session,
|
|
53
|
-
},
|
|
54
|
-
},
|
|
55
|
-
},
|
|
56
|
-
},
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// Mock getContext function
|
|
60
|
-
getContext = vi.fn((session?: { userId: string }) => ({
|
|
61
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
62
|
-
db: mockPrisma as any,
|
|
63
|
-
session: session || null,
|
|
64
|
-
prisma: mockPrisma,
|
|
65
|
-
}))
|
|
66
|
-
|
|
67
|
-
// Mock session provider
|
|
68
|
-
mockGetSession = vi.fn(async () => ({
|
|
69
|
-
userId: 'user-123',
|
|
70
|
-
scopes: ['read', 'write'],
|
|
71
|
-
}))
|
|
72
|
-
})
|
|
73
|
-
|
|
74
|
-
describe('createMcpHandlers', () => {
|
|
75
|
-
it('should create GET, POST, DELETE handlers', () => {
|
|
76
|
-
const handlers = createMcpHandlers({ config, getSession: mockGetSession, getContext })
|
|
77
|
-
|
|
78
|
-
expect(handlers.GET).toBeDefined()
|
|
79
|
-
expect(handlers.POST).toBeDefined()
|
|
80
|
-
expect(handlers.DELETE).toBeDefined()
|
|
81
|
-
expect(typeof handlers.GET).toBe('function')
|
|
82
|
-
expect(typeof handlers.POST).toBe('function')
|
|
83
|
-
expect(typeof handlers.DELETE).toBe('function')
|
|
84
|
-
})
|
|
85
|
-
|
|
86
|
-
it('should return 404 when MCP is not enabled', async () => {
|
|
87
|
-
const disabledConfig = { ...config, mcp: { enabled: false } }
|
|
88
|
-
const handlers = createMcpHandlers({
|
|
89
|
-
config: disabledConfig,
|
|
90
|
-
getSession: mockGetSession,
|
|
91
|
-
getContext,
|
|
92
|
-
})
|
|
93
|
-
|
|
94
|
-
const request = new Request('http://localhost/api/mcp', {
|
|
95
|
-
method: 'POST',
|
|
96
|
-
headers: { 'Content-Type': 'application/json' },
|
|
97
|
-
body: JSON.stringify({ method: 'initialize' }),
|
|
98
|
-
})
|
|
99
|
-
|
|
100
|
-
const response = await handlers.POST(request)
|
|
101
|
-
expect(response.status).toBe(404)
|
|
102
|
-
|
|
103
|
-
const data = await response.json()
|
|
104
|
-
expect(data.error).toBe('MCP not enabled')
|
|
105
|
-
})
|
|
106
|
-
|
|
107
|
-
it('should return 401 when session is not provided', async () => {
|
|
108
|
-
const noSessionProvider: McpSessionProvider = vi.fn(async () => null)
|
|
109
|
-
const handlers = createMcpHandlers({
|
|
110
|
-
config,
|
|
111
|
-
getSession: noSessionProvider,
|
|
112
|
-
getContext,
|
|
113
|
-
})
|
|
114
|
-
|
|
115
|
-
const request = new Request('http://localhost/api/mcp', {
|
|
116
|
-
method: 'POST',
|
|
117
|
-
headers: { 'Content-Type': 'application/json' },
|
|
118
|
-
body: JSON.stringify({ method: 'initialize' }),
|
|
119
|
-
})
|
|
120
|
-
|
|
121
|
-
const response = await handlers.POST(request)
|
|
122
|
-
expect(response.status).toBe(401)
|
|
123
|
-
expect(response.headers.get('WWW-Authenticate')).toContain('Bearer')
|
|
124
|
-
})
|
|
125
|
-
})
|
|
126
|
-
|
|
127
|
-
describe('initialize method', () => {
|
|
128
|
-
it('should handle initialize request', async () => {
|
|
129
|
-
const handlers = createMcpHandlers({ config, getSession: mockGetSession, getContext })
|
|
130
|
-
|
|
131
|
-
const request = new Request('http://localhost/api/mcp', {
|
|
132
|
-
method: 'POST',
|
|
133
|
-
headers: { 'Content-Type': 'application/json' },
|
|
134
|
-
body: JSON.stringify({
|
|
135
|
-
jsonrpc: '2.0',
|
|
136
|
-
id: 1,
|
|
137
|
-
method: 'initialize',
|
|
138
|
-
params: {},
|
|
139
|
-
}),
|
|
140
|
-
})
|
|
141
|
-
|
|
142
|
-
const response = await handlers.POST(request)
|
|
143
|
-
expect(response.status).toBe(200)
|
|
144
|
-
|
|
145
|
-
const data = await response.json()
|
|
146
|
-
expect(data.jsonrpc).toBe('2.0')
|
|
147
|
-
expect(data.id).toBe(1)
|
|
148
|
-
expect(data.result.protocolVersion).toBe('2024-11-05')
|
|
149
|
-
expect(data.result.capabilities.tools).toBeDefined()
|
|
150
|
-
expect(data.result.serverInfo.name).toBe('opensaas-mcp-server')
|
|
151
|
-
})
|
|
152
|
-
})
|
|
153
|
-
|
|
154
|
-
describe('notifications/initialized method', () => {
|
|
155
|
-
it('should handle initialized notification with 204 response', async () => {
|
|
156
|
-
const handlers = createMcpHandlers({ config, getSession: mockGetSession, getContext })
|
|
157
|
-
|
|
158
|
-
const request = new Request('http://localhost/api/mcp', {
|
|
159
|
-
method: 'POST',
|
|
160
|
-
headers: { 'Content-Type': 'application/json' },
|
|
161
|
-
body: JSON.stringify({
|
|
162
|
-
jsonrpc: '2.0',
|
|
163
|
-
method: 'notifications/initialized',
|
|
164
|
-
}),
|
|
165
|
-
})
|
|
166
|
-
|
|
167
|
-
const response = await handlers.POST(request)
|
|
168
|
-
expect(response.status).toBe(204)
|
|
169
|
-
})
|
|
170
|
-
})
|
|
171
|
-
|
|
172
|
-
describe('tools/list method', () => {
|
|
173
|
-
it('should list all CRUD tools for enabled lists', async () => {
|
|
174
|
-
const handlers = createMcpHandlers({ config, getSession: mockGetSession, getContext })
|
|
175
|
-
|
|
176
|
-
const request = new Request('http://localhost/api/mcp', {
|
|
177
|
-
method: 'POST',
|
|
178
|
-
headers: { 'Content-Type': 'application/json' },
|
|
179
|
-
body: JSON.stringify({
|
|
180
|
-
jsonrpc: '2.0',
|
|
181
|
-
id: 1,
|
|
182
|
-
method: 'tools/list',
|
|
183
|
-
}),
|
|
184
|
-
})
|
|
185
|
-
|
|
186
|
-
const response = await handlers.POST(request)
|
|
187
|
-
expect(response.status).toBe(200)
|
|
188
|
-
|
|
189
|
-
const data = await response.json()
|
|
190
|
-
expect(data.result.tools).toBeDefined()
|
|
191
|
-
expect(Array.isArray(data.result.tools)).toBe(true)
|
|
192
|
-
|
|
193
|
-
const toolNames = data.result.tools.map((t: { name: string }) => t.name)
|
|
194
|
-
expect(toolNames).toContain('list_post_query')
|
|
195
|
-
expect(toolNames).toContain('list_post_create')
|
|
196
|
-
expect(toolNames).toContain('list_post_update')
|
|
197
|
-
expect(toolNames).toContain('list_post_delete')
|
|
198
|
-
})
|
|
199
|
-
|
|
200
|
-
it('should exclude disabled tools', async () => {
|
|
201
|
-
const configWithDisabledTools = {
|
|
202
|
-
...config,
|
|
203
|
-
lists: {
|
|
204
|
-
Post: {
|
|
205
|
-
...config.lists.Post,
|
|
206
|
-
mcp: {
|
|
207
|
-
tools: {
|
|
208
|
-
read: true,
|
|
209
|
-
create: true,
|
|
210
|
-
update: false,
|
|
211
|
-
delete: false,
|
|
212
|
-
},
|
|
213
|
-
},
|
|
214
|
-
},
|
|
215
|
-
},
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
const handlers = createMcpHandlers({
|
|
219
|
-
config: configWithDisabledTools,
|
|
220
|
-
getSession: mockGetSession,
|
|
221
|
-
getContext,
|
|
222
|
-
})
|
|
223
|
-
|
|
224
|
-
const request = new Request('http://localhost/api/mcp', {
|
|
225
|
-
method: 'POST',
|
|
226
|
-
headers: { 'Content-Type': 'application/json' },
|
|
227
|
-
body: JSON.stringify({
|
|
228
|
-
jsonrpc: '2.0',
|
|
229
|
-
id: 1,
|
|
230
|
-
method: 'tools/list',
|
|
231
|
-
}),
|
|
232
|
-
})
|
|
233
|
-
|
|
234
|
-
const response = await handlers.POST(request)
|
|
235
|
-
const data = await response.json()
|
|
236
|
-
|
|
237
|
-
const toolNames = data.result.tools.map((t: { name: string }) => t.name)
|
|
238
|
-
expect(toolNames).toContain('list_post_query')
|
|
239
|
-
expect(toolNames).toContain('list_post_create')
|
|
240
|
-
expect(toolNames).not.toContain('list_post_update')
|
|
241
|
-
expect(toolNames).not.toContain('list_post_delete')
|
|
242
|
-
})
|
|
243
|
-
|
|
244
|
-
it('should include custom tools', async () => {
|
|
245
|
-
const configWithCustomTools = {
|
|
246
|
-
...config,
|
|
247
|
-
lists: {
|
|
248
|
-
Post: {
|
|
249
|
-
...config.lists.Post,
|
|
250
|
-
mcp: {
|
|
251
|
-
customTools: [
|
|
252
|
-
{
|
|
253
|
-
name: 'publishPost',
|
|
254
|
-
description: 'Publish a post',
|
|
255
|
-
inputSchema: {
|
|
256
|
-
type: 'object' as const,
|
|
257
|
-
properties: { postId: { type: 'string' } },
|
|
258
|
-
},
|
|
259
|
-
handler: vi.fn(),
|
|
260
|
-
},
|
|
261
|
-
],
|
|
262
|
-
},
|
|
263
|
-
},
|
|
264
|
-
},
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
const handlers = createMcpHandlers({
|
|
268
|
-
config: configWithCustomTools,
|
|
269
|
-
getSession: mockGetSession,
|
|
270
|
-
getContext,
|
|
271
|
-
})
|
|
272
|
-
|
|
273
|
-
const request = new Request('http://localhost/api/mcp', {
|
|
274
|
-
method: 'POST',
|
|
275
|
-
headers: { 'Content-Type': 'application/json' },
|
|
276
|
-
body: JSON.stringify({
|
|
277
|
-
jsonrpc: '2.0',
|
|
278
|
-
id: 1,
|
|
279
|
-
method: 'tools/list',
|
|
280
|
-
}),
|
|
281
|
-
})
|
|
282
|
-
|
|
283
|
-
const response = await handlers.POST(request)
|
|
284
|
-
const data = await response.json()
|
|
285
|
-
|
|
286
|
-
const toolNames = data.result.tools.map((t: { name: string }) => t.name)
|
|
287
|
-
expect(toolNames).toContain('publishPost')
|
|
288
|
-
})
|
|
289
|
-
})
|
|
290
|
-
|
|
291
|
-
describe('tools/call method - CRUD operations', () => {
|
|
292
|
-
it('should execute query operation', async () => {
|
|
293
|
-
const mockResults = [
|
|
294
|
-
{ id: '1', title: 'Post 1', content: 'Content 1' },
|
|
295
|
-
{ id: '2', title: 'Post 2', content: 'Content 2' },
|
|
296
|
-
]
|
|
297
|
-
mockPrisma.post.findMany.mockResolvedValue(mockResults)
|
|
298
|
-
|
|
299
|
-
const handlers = createMcpHandlers({ config, getSession: mockGetSession, getContext })
|
|
300
|
-
|
|
301
|
-
const request = new Request('http://localhost/api/mcp', {
|
|
302
|
-
method: 'POST',
|
|
303
|
-
headers: { 'Content-Type': 'application/json' },
|
|
304
|
-
body: JSON.stringify({
|
|
305
|
-
jsonrpc: '2.0',
|
|
306
|
-
id: 1,
|
|
307
|
-
method: 'tools/call',
|
|
308
|
-
params: {
|
|
309
|
-
name: 'list_post_query',
|
|
310
|
-
arguments: {
|
|
311
|
-
where: {},
|
|
312
|
-
take: 10,
|
|
313
|
-
},
|
|
314
|
-
},
|
|
315
|
-
}),
|
|
316
|
-
})
|
|
317
|
-
|
|
318
|
-
const response = await handlers.POST(request)
|
|
319
|
-
expect(response.status).toBe(200)
|
|
320
|
-
|
|
321
|
-
const data = await response.json()
|
|
322
|
-
expect(data.result.content[0].type).toBe('text')
|
|
323
|
-
|
|
324
|
-
const result = JSON.parse(data.result.content[0].text)
|
|
325
|
-
expect(result.items).toEqual(mockResults)
|
|
326
|
-
expect(result.count).toBe(2)
|
|
327
|
-
expect(mockPrisma.post.findMany).toHaveBeenCalledWith({
|
|
328
|
-
where: {},
|
|
329
|
-
take: 10,
|
|
330
|
-
skip: undefined,
|
|
331
|
-
orderBy: undefined,
|
|
332
|
-
})
|
|
333
|
-
})
|
|
334
|
-
|
|
335
|
-
// Regression test (issue #907 / ADR-0029): a bare `JSON.stringify` throws
|
|
336
|
-
// `TypeError: Do not know how to serialize a BigInt` on a bigInt() field's
|
|
337
|
-
// value. This must respond successfully, rendering the value as a decimal
|
|
338
|
-
// string — the field's MCP wire representation.
|
|
339
|
-
it('should serialize a bigint field value as a decimal string instead of throwing', async () => {
|
|
340
|
-
const mockResults = [{ id: '1', title: 'Post 1', occurredAtMs: 9007199254740993n }]
|
|
341
|
-
mockPrisma.post.findMany.mockResolvedValue(mockResults)
|
|
342
|
-
|
|
343
|
-
const handlers = createMcpHandlers({ config, getSession: mockGetSession, getContext })
|
|
344
|
-
|
|
345
|
-
const request = new Request('http://localhost/api/mcp', {
|
|
346
|
-
method: 'POST',
|
|
347
|
-
headers: { 'Content-Type': 'application/json' },
|
|
348
|
-
body: JSON.stringify({
|
|
349
|
-
jsonrpc: '2.0',
|
|
350
|
-
id: 1,
|
|
351
|
-
method: 'tools/call',
|
|
352
|
-
params: {
|
|
353
|
-
name: 'list_post_query',
|
|
354
|
-
arguments: { where: {}, take: 10 },
|
|
355
|
-
},
|
|
356
|
-
}),
|
|
357
|
-
})
|
|
358
|
-
|
|
359
|
-
const response = await handlers.POST(request)
|
|
360
|
-
expect(response.status).toBe(200)
|
|
361
|
-
|
|
362
|
-
const data = await response.json()
|
|
363
|
-
expect(data.result.content[0].text).toContain('"occurredAtMs": "9007199254740993"')
|
|
364
|
-
|
|
365
|
-
const result = JSON.parse(data.result.content[0].text)
|
|
366
|
-
expect(result.items[0].occurredAtMs).toBe('9007199254740993')
|
|
367
|
-
})
|
|
368
|
-
|
|
369
|
-
// Regression test (issue #965): the response's JSON.stringify replacer runs
|
|
370
|
-
// AFTER toJSON, so it can't intercept a HashedPassword that leaks its hash
|
|
371
|
-
// from toJSON — the redaction has to live in HashedPassword itself.
|
|
372
|
-
it('should not leak a bcrypt hash for a password field in the query response', async () => {
|
|
373
|
-
const hash = '$2b$04$q5yvruv7NaUYCQvV.UGzf.92.dpteicGq5MoSHYNWqzIm.bsIIJrW'
|
|
374
|
-
const mockResults = [{ id: '1', title: 'Post 1', password: new HashedPassword(hash) }]
|
|
375
|
-
mockPrisma.post.findMany.mockResolvedValue(mockResults)
|
|
376
|
-
|
|
377
|
-
const handlers = createMcpHandlers({ config, getSession: mockGetSession, getContext })
|
|
378
|
-
|
|
379
|
-
const request = new Request('http://localhost/api/mcp', {
|
|
380
|
-
method: 'POST',
|
|
381
|
-
headers: { 'Content-Type': 'application/json' },
|
|
382
|
-
body: JSON.stringify({
|
|
383
|
-
jsonrpc: '2.0',
|
|
384
|
-
id: 1,
|
|
385
|
-
method: 'tools/call',
|
|
386
|
-
params: {
|
|
387
|
-
name: 'list_post_query',
|
|
388
|
-
arguments: { where: {}, take: 10 },
|
|
389
|
-
},
|
|
390
|
-
}),
|
|
391
|
-
})
|
|
392
|
-
|
|
393
|
-
const response = await handlers.POST(request)
|
|
394
|
-
expect(response.status).toBe(200)
|
|
395
|
-
|
|
396
|
-
const data = await response.json()
|
|
397
|
-
const responseBody = data.result.content[0].text
|
|
398
|
-
expect(responseBody).not.toContain(hash)
|
|
399
|
-
|
|
400
|
-
const result = JSON.parse(responseBody)
|
|
401
|
-
expect(result.items[0].password).toEqual({ isSet: true })
|
|
402
|
-
})
|
|
403
|
-
|
|
404
|
-
it('should execute create operation', async () => {
|
|
405
|
-
const mockResult = { id: '1', title: 'New Post', content: 'New Content' }
|
|
406
|
-
mockPrisma.post.create.mockResolvedValue(mockResult)
|
|
407
|
-
|
|
408
|
-
const handlers = createMcpHandlers({ config, getSession: mockGetSession, getContext })
|
|
409
|
-
|
|
410
|
-
const request = new Request('http://localhost/api/mcp', {
|
|
411
|
-
method: 'POST',
|
|
412
|
-
headers: { 'Content-Type': 'application/json' },
|
|
413
|
-
body: JSON.stringify({
|
|
414
|
-
jsonrpc: '2.0',
|
|
415
|
-
id: 1,
|
|
416
|
-
method: 'tools/call',
|
|
417
|
-
params: {
|
|
418
|
-
name: 'list_post_create',
|
|
419
|
-
arguments: {
|
|
420
|
-
data: { title: 'New Post', content: 'New Content' },
|
|
421
|
-
},
|
|
422
|
-
},
|
|
423
|
-
}),
|
|
424
|
-
})
|
|
425
|
-
|
|
426
|
-
const response = await handlers.POST(request)
|
|
427
|
-
expect(response.status).toBe(200)
|
|
428
|
-
|
|
429
|
-
const data = await response.json()
|
|
430
|
-
const result = JSON.parse(data.result.content[0].text)
|
|
431
|
-
expect(result.success).toBe(true)
|
|
432
|
-
expect(result.item).toEqual(mockResult)
|
|
433
|
-
expect(mockPrisma.post.create).toHaveBeenCalledWith({
|
|
434
|
-
data: { title: 'New Post', content: 'New Content' },
|
|
435
|
-
})
|
|
436
|
-
})
|
|
437
|
-
|
|
438
|
-
it('should execute update operation', async () => {
|
|
439
|
-
const mockResult = { id: '1', title: 'Updated Post', content: 'Updated Content' }
|
|
440
|
-
mockPrisma.post.update.mockResolvedValue(mockResult)
|
|
441
|
-
|
|
442
|
-
const handlers = createMcpHandlers({ config, getSession: mockGetSession, getContext })
|
|
443
|
-
|
|
444
|
-
const request = new Request('http://localhost/api/mcp', {
|
|
445
|
-
method: 'POST',
|
|
446
|
-
headers: { 'Content-Type': 'application/json' },
|
|
447
|
-
body: JSON.stringify({
|
|
448
|
-
jsonrpc: '2.0',
|
|
449
|
-
id: 1,
|
|
450
|
-
method: 'tools/call',
|
|
451
|
-
params: {
|
|
452
|
-
name: 'list_post_update',
|
|
453
|
-
arguments: {
|
|
454
|
-
where: { id: '1' },
|
|
455
|
-
data: { title: 'Updated Post' },
|
|
456
|
-
},
|
|
457
|
-
},
|
|
458
|
-
}),
|
|
459
|
-
})
|
|
460
|
-
|
|
461
|
-
const response = await handlers.POST(request)
|
|
462
|
-
expect(response.status).toBe(200)
|
|
463
|
-
|
|
464
|
-
const data = await response.json()
|
|
465
|
-
const result = JSON.parse(data.result.content[0].text)
|
|
466
|
-
expect(result.success).toBe(true)
|
|
467
|
-
expect(result.item).toEqual(mockResult)
|
|
468
|
-
})
|
|
469
|
-
|
|
470
|
-
it('should execute delete operation', async () => {
|
|
471
|
-
const mockResult = { id: '1', title: 'Deleted Post', content: 'Deleted Content' }
|
|
472
|
-
mockPrisma.post.delete.mockResolvedValue(mockResult)
|
|
473
|
-
|
|
474
|
-
const handlers = createMcpHandlers({ config, getSession: mockGetSession, getContext })
|
|
475
|
-
|
|
476
|
-
const request = new Request('http://localhost/api/mcp', {
|
|
477
|
-
method: 'POST',
|
|
478
|
-
headers: { 'Content-Type': 'application/json' },
|
|
479
|
-
body: JSON.stringify({
|
|
480
|
-
jsonrpc: '2.0',
|
|
481
|
-
id: 1,
|
|
482
|
-
method: 'tools/call',
|
|
483
|
-
params: {
|
|
484
|
-
name: 'list_post_delete',
|
|
485
|
-
arguments: {
|
|
486
|
-
where: { id: '1' },
|
|
487
|
-
},
|
|
488
|
-
},
|
|
489
|
-
}),
|
|
490
|
-
})
|
|
491
|
-
|
|
492
|
-
const response = await handlers.POST(request)
|
|
493
|
-
expect(response.status).toBe(200)
|
|
494
|
-
|
|
495
|
-
const data = await response.json()
|
|
496
|
-
const result = JSON.parse(data.result.content[0].text)
|
|
497
|
-
expect(result.success).toBe(true)
|
|
498
|
-
expect(result.deletedId).toBe('1')
|
|
499
|
-
})
|
|
500
|
-
|
|
501
|
-
it('should limit query results to max 100', async () => {
|
|
502
|
-
mockPrisma.post.findMany.mockResolvedValue([])
|
|
503
|
-
|
|
504
|
-
const handlers = createMcpHandlers({ config, getSession: mockGetSession, getContext })
|
|
505
|
-
|
|
506
|
-
const request = new Request('http://localhost/api/mcp', {
|
|
507
|
-
method: 'POST',
|
|
508
|
-
headers: { 'Content-Type': 'application/json' },
|
|
509
|
-
body: JSON.stringify({
|
|
510
|
-
jsonrpc: '2.0',
|
|
511
|
-
id: 1,
|
|
512
|
-
method: 'tools/call',
|
|
513
|
-
params: {
|
|
514
|
-
name: 'list_post_query',
|
|
515
|
-
arguments: {
|
|
516
|
-
take: 200, // Request more than max
|
|
517
|
-
},
|
|
518
|
-
},
|
|
519
|
-
}),
|
|
520
|
-
})
|
|
521
|
-
|
|
522
|
-
await handlers.POST(request)
|
|
523
|
-
|
|
524
|
-
expect(mockPrisma.post.findMany).toHaveBeenCalledWith({
|
|
525
|
-
where: undefined,
|
|
526
|
-
take: 100, // Should be limited to 100
|
|
527
|
-
skip: undefined,
|
|
528
|
-
orderBy: undefined,
|
|
529
|
-
})
|
|
530
|
-
})
|
|
531
|
-
|
|
532
|
-
it('should handle access denied by returning error', async () => {
|
|
533
|
-
mockPrisma.post.create.mockResolvedValue(null) // Simulates access denial
|
|
534
|
-
|
|
535
|
-
const handlers = createMcpHandlers({ config, getSession: mockGetSession, getContext })
|
|
536
|
-
|
|
537
|
-
const request = new Request('http://localhost/api/mcp', {
|
|
538
|
-
method: 'POST',
|
|
539
|
-
headers: { 'Content-Type': 'application/json' },
|
|
540
|
-
body: JSON.stringify({
|
|
541
|
-
jsonrpc: '2.0',
|
|
542
|
-
id: 1,
|
|
543
|
-
method: 'tools/call',
|
|
544
|
-
params: {
|
|
545
|
-
name: 'list_post_create',
|
|
546
|
-
arguments: {
|
|
547
|
-
data: { title: 'Test' },
|
|
548
|
-
},
|
|
549
|
-
},
|
|
550
|
-
}),
|
|
551
|
-
})
|
|
552
|
-
|
|
553
|
-
const response = await handlers.POST(request)
|
|
554
|
-
expect(response.status).toBe(200)
|
|
555
|
-
|
|
556
|
-
const data = await response.json()
|
|
557
|
-
expect(data.error).toBeUndefined()
|
|
558
|
-
expect(data.result.isError).toBe(true)
|
|
559
|
-
expect(data.result.content[0].text).toContain('Access denied')
|
|
560
|
-
})
|
|
561
|
-
})
|
|
562
|
-
|
|
563
|
-
describe('tools/call method - custom tools', () => {
|
|
564
|
-
it('should execute custom tool handler', async () => {
|
|
565
|
-
const customHandler = vi.fn(async () => ({ published: true }))
|
|
566
|
-
|
|
567
|
-
const configWithCustomTools = {
|
|
568
|
-
...config,
|
|
569
|
-
lists: {
|
|
570
|
-
Post: {
|
|
571
|
-
...config.lists.Post,
|
|
572
|
-
mcp: {
|
|
573
|
-
customTools: [
|
|
574
|
-
{
|
|
575
|
-
name: 'publishPost',
|
|
576
|
-
description: 'Publish a post',
|
|
577
|
-
inputSchema: {
|
|
578
|
-
type: 'object' as const,
|
|
579
|
-
properties: { postId: { type: 'string' } },
|
|
580
|
-
},
|
|
581
|
-
handler: customHandler,
|
|
582
|
-
},
|
|
583
|
-
],
|
|
584
|
-
},
|
|
585
|
-
},
|
|
586
|
-
},
|
|
587
|
-
}
|
|
588
|
-
|
|
589
|
-
const handlers = createMcpHandlers({
|
|
590
|
-
config: configWithCustomTools,
|
|
591
|
-
getSession: mockGetSession,
|
|
592
|
-
getContext,
|
|
593
|
-
})
|
|
594
|
-
|
|
595
|
-
const request = new Request('http://localhost/api/mcp', {
|
|
596
|
-
method: 'POST',
|
|
597
|
-
headers: { 'Content-Type': 'application/json' },
|
|
598
|
-
body: JSON.stringify({
|
|
599
|
-
jsonrpc: '2.0',
|
|
600
|
-
id: 1,
|
|
601
|
-
method: 'tools/call',
|
|
602
|
-
params: {
|
|
603
|
-
name: 'publishPost',
|
|
604
|
-
arguments: {
|
|
605
|
-
postId: 'post-123',
|
|
606
|
-
},
|
|
607
|
-
},
|
|
608
|
-
}),
|
|
609
|
-
})
|
|
610
|
-
|
|
611
|
-
const response = await handlers.POST(request)
|
|
612
|
-
expect(response.status).toBe(200)
|
|
613
|
-
|
|
614
|
-
expect(customHandler).toHaveBeenCalledWith({
|
|
615
|
-
input: { postId: 'post-123' },
|
|
616
|
-
context: expect.any(Object),
|
|
617
|
-
})
|
|
618
|
-
|
|
619
|
-
const data = await response.json()
|
|
620
|
-
const result = JSON.parse(data.result.content[0].text)
|
|
621
|
-
expect(result.published).toBe(true)
|
|
622
|
-
})
|
|
623
|
-
|
|
624
|
-
it('should handle unknown tool name', async () => {
|
|
625
|
-
const handlers = createMcpHandlers({ config, getSession: mockGetSession, getContext })
|
|
626
|
-
|
|
627
|
-
const request = new Request('http://localhost/api/mcp', {
|
|
628
|
-
method: 'POST',
|
|
629
|
-
headers: { 'Content-Type': 'application/json' },
|
|
630
|
-
body: JSON.stringify({
|
|
631
|
-
jsonrpc: '2.0',
|
|
632
|
-
id: 1,
|
|
633
|
-
method: 'tools/call',
|
|
634
|
-
params: {
|
|
635
|
-
name: 'unknown_tool',
|
|
636
|
-
arguments: {},
|
|
637
|
-
},
|
|
638
|
-
}),
|
|
639
|
-
})
|
|
640
|
-
|
|
641
|
-
const response = await handlers.POST(request)
|
|
642
|
-
expect(response.status).toBe(400)
|
|
643
|
-
|
|
644
|
-
const data = await response.json()
|
|
645
|
-
expect(data.error.message).toContain('Unknown tool')
|
|
646
|
-
})
|
|
647
|
-
|
|
648
|
-
it('should return a custom tool input schema validation failure as a tool result', async () => {
|
|
649
|
-
const configWithCustomTools = {
|
|
650
|
-
...config,
|
|
651
|
-
lists: {
|
|
652
|
-
Post: {
|
|
653
|
-
...config.lists.Post,
|
|
654
|
-
mcp: {
|
|
655
|
-
customTools: [
|
|
656
|
-
{
|
|
657
|
-
name: 'publishPost',
|
|
658
|
-
description: 'Publish a post',
|
|
659
|
-
inputSchema: z.object({ postId: z.string() }),
|
|
660
|
-
handler: vi.fn(),
|
|
661
|
-
},
|
|
662
|
-
],
|
|
663
|
-
},
|
|
664
|
-
},
|
|
665
|
-
},
|
|
666
|
-
}
|
|
667
|
-
|
|
668
|
-
const handlers = createMcpHandlers({
|
|
669
|
-
config: configWithCustomTools,
|
|
670
|
-
getSession: mockGetSession,
|
|
671
|
-
getContext,
|
|
672
|
-
})
|
|
673
|
-
|
|
674
|
-
const request = new Request('http://localhost/api/mcp', {
|
|
675
|
-
method: 'POST',
|
|
676
|
-
headers: { 'Content-Type': 'application/json' },
|
|
677
|
-
body: JSON.stringify({
|
|
678
|
-
jsonrpc: '2.0',
|
|
679
|
-
id: 1,
|
|
680
|
-
method: 'tools/call',
|
|
681
|
-
params: {
|
|
682
|
-
name: 'publishPost',
|
|
683
|
-
arguments: {},
|
|
684
|
-
},
|
|
685
|
-
}),
|
|
686
|
-
})
|
|
687
|
-
|
|
688
|
-
const response = await handlers.POST(request)
|
|
689
|
-
expect(response.status).toBe(200)
|
|
690
|
-
|
|
691
|
-
const data = await response.json()
|
|
692
|
-
expect(data.error).toBeUndefined()
|
|
693
|
-
expect(data.result.isError).toBe(true)
|
|
694
|
-
expect(data.result.content[0].text).toContain('Invalid params')
|
|
695
|
-
})
|
|
696
|
-
|
|
697
|
-
it('should return a thrown custom tool error as a tool result', async () => {
|
|
698
|
-
const configWithCustomTools = {
|
|
699
|
-
...config,
|
|
700
|
-
lists: {
|
|
701
|
-
Post: {
|
|
702
|
-
...config.lists.Post,
|
|
703
|
-
mcp: {
|
|
704
|
-
customTools: [
|
|
705
|
-
{
|
|
706
|
-
name: 'publishPost',
|
|
707
|
-
description: 'Publish a post',
|
|
708
|
-
inputSchema: {
|
|
709
|
-
type: 'object' as const,
|
|
710
|
-
properties: { postId: { type: 'string' } },
|
|
711
|
-
},
|
|
712
|
-
handler: vi.fn(async () => {
|
|
713
|
-
throw new Error('cannot publish an already-published post')
|
|
714
|
-
}),
|
|
715
|
-
},
|
|
716
|
-
],
|
|
717
|
-
},
|
|
718
|
-
},
|
|
719
|
-
},
|
|
720
|
-
}
|
|
721
|
-
|
|
722
|
-
const handlers = createMcpHandlers({
|
|
723
|
-
config: configWithCustomTools,
|
|
724
|
-
getSession: mockGetSession,
|
|
725
|
-
getContext,
|
|
726
|
-
})
|
|
727
|
-
|
|
728
|
-
const request = new Request('http://localhost/api/mcp', {
|
|
729
|
-
method: 'POST',
|
|
730
|
-
headers: { 'Content-Type': 'application/json' },
|
|
731
|
-
body: JSON.stringify({
|
|
732
|
-
jsonrpc: '2.0',
|
|
733
|
-
id: 1,
|
|
734
|
-
method: 'tools/call',
|
|
735
|
-
params: {
|
|
736
|
-
name: 'publishPost',
|
|
737
|
-
arguments: { postId: 'post-123' },
|
|
738
|
-
},
|
|
739
|
-
}),
|
|
740
|
-
})
|
|
741
|
-
|
|
742
|
-
const response = await handlers.POST(request)
|
|
743
|
-
expect(response.status).toBe(200)
|
|
744
|
-
|
|
745
|
-
const data = await response.json()
|
|
746
|
-
expect(data.error).toBeUndefined()
|
|
747
|
-
expect(data.result.isError).toBe(true)
|
|
748
|
-
expect(data.result.content[0].text).toContain('cannot publish an already-published post')
|
|
749
|
-
})
|
|
750
|
-
})
|
|
751
|
-
|
|
752
|
-
describe('error handling', () => {
|
|
753
|
-
it('should handle invalid method', async () => {
|
|
754
|
-
const handlers = createMcpHandlers({ config, getSession: mockGetSession, getContext })
|
|
755
|
-
|
|
756
|
-
const request = new Request('http://localhost/api/mcp', {
|
|
757
|
-
method: 'POST',
|
|
758
|
-
headers: { 'Content-Type': 'application/json' },
|
|
759
|
-
body: JSON.stringify({
|
|
760
|
-
jsonrpc: '2.0',
|
|
761
|
-
id: 1,
|
|
762
|
-
method: 'invalid/method',
|
|
763
|
-
}),
|
|
764
|
-
})
|
|
765
|
-
|
|
766
|
-
const response = await handlers.POST(request)
|
|
767
|
-
expect(response.status).toBe(400)
|
|
768
|
-
|
|
769
|
-
const data = await response.json()
|
|
770
|
-
expect(data.error.code).toBe(-32601)
|
|
771
|
-
expect(data.error.message).toBe('Method not found')
|
|
772
|
-
})
|
|
773
|
-
|
|
774
|
-
it('should handle missing tool name in tools/call', async () => {
|
|
775
|
-
const handlers = createMcpHandlers({ config, getSession: mockGetSession, getContext })
|
|
776
|
-
|
|
777
|
-
const request = new Request('http://localhost/api/mcp', {
|
|
778
|
-
method: 'POST',
|
|
779
|
-
headers: { 'Content-Type': 'application/json' },
|
|
780
|
-
body: JSON.stringify({
|
|
781
|
-
jsonrpc: '2.0',
|
|
782
|
-
id: 1,
|
|
783
|
-
method: 'tools/call',
|
|
784
|
-
params: {
|
|
785
|
-
arguments: {},
|
|
786
|
-
},
|
|
787
|
-
}),
|
|
788
|
-
})
|
|
789
|
-
|
|
790
|
-
const response = await handlers.POST(request)
|
|
791
|
-
expect(response.status).toBe(400)
|
|
792
|
-
|
|
793
|
-
const data = await response.json()
|
|
794
|
-
expect(data.error.message).toContain('Tool name required')
|
|
795
|
-
})
|
|
796
|
-
|
|
797
|
-
it('should handle operation errors gracefully', async () => {
|
|
798
|
-
mockPrisma.post.findMany.mockRejectedValue(new Error('Database error'))
|
|
799
|
-
|
|
800
|
-
const handlers = createMcpHandlers({ config, getSession: mockGetSession, getContext })
|
|
801
|
-
|
|
802
|
-
const request = new Request('http://localhost/api/mcp', {
|
|
803
|
-
method: 'POST',
|
|
804
|
-
headers: { 'Content-Type': 'application/json' },
|
|
805
|
-
body: JSON.stringify({
|
|
806
|
-
jsonrpc: '2.0',
|
|
807
|
-
id: 1,
|
|
808
|
-
method: 'tools/call',
|
|
809
|
-
params: {
|
|
810
|
-
name: 'list_post_query',
|
|
811
|
-
arguments: {},
|
|
812
|
-
},
|
|
813
|
-
}),
|
|
814
|
-
})
|
|
815
|
-
|
|
816
|
-
const response = await handlers.POST(request)
|
|
817
|
-
expect(response.status).toBe(200)
|
|
818
|
-
|
|
819
|
-
const data = await response.json()
|
|
820
|
-
expect(data.error).toBeUndefined()
|
|
821
|
-
expect(data.result.isError).toBe(true)
|
|
822
|
-
expect(data.result.content[0].text).toContain('Database error')
|
|
823
|
-
})
|
|
824
|
-
|
|
825
|
-
it('should return a relation-filter access-denial error as a tool result naming the relation and related list', async () => {
|
|
826
|
-
mockPrisma.post.findMany.mockRejectedValue(
|
|
827
|
-
new RelationFilterAccessDeniedError('Post', 'author', 'User'),
|
|
828
|
-
)
|
|
829
|
-
|
|
830
|
-
const handlers = createMcpHandlers({ config, getSession: mockGetSession, getContext })
|
|
831
|
-
|
|
832
|
-
const request = new Request('http://localhost/api/mcp', {
|
|
833
|
-
method: 'POST',
|
|
834
|
-
headers: { 'Content-Type': 'application/json' },
|
|
835
|
-
body: JSON.stringify({
|
|
836
|
-
jsonrpc: '2.0',
|
|
837
|
-
id: 1,
|
|
838
|
-
method: 'tools/call',
|
|
839
|
-
params: {
|
|
840
|
-
name: 'list_post_query',
|
|
841
|
-
arguments: { where: { author: { is: {} } } },
|
|
842
|
-
},
|
|
843
|
-
}),
|
|
844
|
-
})
|
|
845
|
-
|
|
846
|
-
const response = await handlers.POST(request)
|
|
847
|
-
expect(response.status).toBe(200)
|
|
848
|
-
|
|
849
|
-
const data = await response.json()
|
|
850
|
-
expect(data.error).toBeUndefined()
|
|
851
|
-
expect(data.result.isError).toBe(true)
|
|
852
|
-
expect(data.result.content[0].text).toContain('Post.author')
|
|
853
|
-
expect(data.result.content[0].text).toContain('User')
|
|
854
|
-
})
|
|
855
|
-
|
|
856
|
-
it('should return a depth-exceeded error as a tool result worded as a cost refusal', async () => {
|
|
857
|
-
mockPrisma.post.findMany.mockRejectedValue(
|
|
858
|
-
new AccessScopeDepthExceededError('Post', 'author', 3),
|
|
859
|
-
)
|
|
860
|
-
|
|
861
|
-
const handlers = createMcpHandlers({ config, getSession: mockGetSession, getContext })
|
|
862
|
-
|
|
863
|
-
const request = new Request('http://localhost/api/mcp', {
|
|
864
|
-
method: 'POST',
|
|
865
|
-
headers: { 'Content-Type': 'application/json' },
|
|
866
|
-
body: JSON.stringify({
|
|
867
|
-
jsonrpc: '2.0',
|
|
868
|
-
id: 1,
|
|
869
|
-
method: 'tools/call',
|
|
870
|
-
params: {
|
|
871
|
-
name: 'list_post_query',
|
|
872
|
-
arguments: {},
|
|
873
|
-
},
|
|
874
|
-
}),
|
|
875
|
-
})
|
|
876
|
-
|
|
877
|
-
const response = await handlers.POST(request)
|
|
878
|
-
expect(response.status).toBe(200)
|
|
879
|
-
|
|
880
|
-
const data = await response.json()
|
|
881
|
-
expect(data.error).toBeUndefined()
|
|
882
|
-
expect(data.result.isError).toBe(true)
|
|
883
|
-
expect(data.result.content[0].text).toContain('Post.author')
|
|
884
|
-
expect(data.result.content[0].text).toContain('cost limit')
|
|
885
|
-
})
|
|
886
|
-
})
|
|
887
|
-
|
|
888
|
-
describe('session integration', () => {
|
|
889
|
-
it('should pass session to getContext', async () => {
|
|
890
|
-
const mockSession: McpSession = {
|
|
891
|
-
userId: 'user-456',
|
|
892
|
-
scopes: ['admin'],
|
|
893
|
-
}
|
|
894
|
-
|
|
895
|
-
const sessionProvider: McpSessionProvider = vi.fn(async () => mockSession)
|
|
896
|
-
const mockGetContext = vi.fn((session?: { userId: string }) => ({
|
|
897
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
898
|
-
db: mockPrisma as any,
|
|
899
|
-
session: session || null,
|
|
900
|
-
prisma: mockPrisma,
|
|
901
|
-
}))
|
|
902
|
-
|
|
903
|
-
mockPrisma.post.findMany.mockResolvedValue([])
|
|
904
|
-
|
|
905
|
-
const handlers = createMcpHandlers({
|
|
906
|
-
config,
|
|
907
|
-
getSession: sessionProvider,
|
|
908
|
-
getContext: mockGetContext,
|
|
909
|
-
})
|
|
910
|
-
|
|
911
|
-
const request = new Request('http://localhost/api/mcp', {
|
|
912
|
-
method: 'POST',
|
|
913
|
-
headers: { 'Content-Type': 'application/json' },
|
|
914
|
-
body: JSON.stringify({
|
|
915
|
-
jsonrpc: '2.0',
|
|
916
|
-
id: 1,
|
|
917
|
-
method: 'tools/call',
|
|
918
|
-
params: {
|
|
919
|
-
name: 'list_post_query',
|
|
920
|
-
arguments: {},
|
|
921
|
-
},
|
|
922
|
-
}),
|
|
923
|
-
})
|
|
924
|
-
|
|
925
|
-
await handlers.POST(request)
|
|
926
|
-
|
|
927
|
-
expect(mockGetContext).toHaveBeenCalledWith({ userId: 'user-456' })
|
|
928
|
-
})
|
|
929
|
-
})
|
|
930
|
-
})
|
|
931
|
-
|
|
932
|
-
// Coverage for issue #851 / ADR-0033: the `query` tool's `fields` projection
|
|
933
|
-
// argument, its generated per-session schema, and `tools/list` becoming
|
|
934
|
-
// per-session. Uses the same lightweight mocked-`context.db` harness as the
|
|
935
|
-
// suite above — these tests exercise the MCP-layer translation (schema
|
|
936
|
-
// shape, `fields` → `include` translation, response projection) rather than
|
|
937
|
-
// the real access-control engine, which is covered separately in
|
|
938
|
-
// `mcp-fields-projection-access.test.ts` against a real `getContext`.
|
|
939
|
-
describe('MCP Handler — fields projection (#851)', () => {
|
|
940
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
941
|
-
let mockPrisma: any
|
|
942
|
-
let config: OpenSaasConfig
|
|
943
|
-
let getContext: (session?: { userId: string }) => AccessContext
|
|
944
|
-
let mockGetSession: McpSessionProvider
|
|
945
|
-
|
|
946
|
-
beforeEach(() => {
|
|
947
|
-
mockPrisma = {
|
|
948
|
-
user: { findMany: vi.fn() },
|
|
949
|
-
comment: { findMany: vi.fn() },
|
|
950
|
-
post: { findMany: vi.fn() },
|
|
951
|
-
secret: { findMany: vi.fn() },
|
|
952
|
-
draft: { findMany: vi.fn() },
|
|
953
|
-
category: { findMany: vi.fn() },
|
|
954
|
-
}
|
|
955
|
-
|
|
956
|
-
config = {
|
|
957
|
-
db: { provider: 'postgresql', url: 'postgresql://localhost:5432/test' },
|
|
958
|
-
mcp: { enabled: true, basePath: '/api/mcp' },
|
|
959
|
-
lists: {
|
|
960
|
-
User: {
|
|
961
|
-
fields: {
|
|
962
|
-
name: { type: 'text' },
|
|
963
|
-
email: { type: 'text' },
|
|
964
|
-
},
|
|
965
|
-
access: { operation: { query: () => true } },
|
|
966
|
-
},
|
|
967
|
-
Comment: {
|
|
968
|
-
fields: {
|
|
969
|
-
text: { type: 'text' },
|
|
970
|
-
approved: { type: 'checkbox' },
|
|
971
|
-
// Field-level read denied — used to prove a nested `where`/
|
|
972
|
-
// `orderBy` can't name a field this session cannot read.
|
|
973
|
-
internalNote: { type: 'text', access: { read: () => false } },
|
|
974
|
-
post: { type: 'relationship', ref: 'Post.comments' },
|
|
975
|
-
},
|
|
976
|
-
access: { operation: { query: () => true } },
|
|
977
|
-
},
|
|
978
|
-
Post: {
|
|
979
|
-
fields: {
|
|
980
|
-
title: { type: 'text' },
|
|
981
|
-
content: { type: 'text' },
|
|
982
|
-
author: { type: 'relationship', ref: 'User' },
|
|
983
|
-
comments: { type: 'relationship', ref: 'Comment.post', many: true },
|
|
984
|
-
// Field-level read denied on the RELATIONSHIP FIELD ITSELF —
|
|
985
|
-
// distinct from a related list's operation-level access — used
|
|
986
|
-
// to prove `count` can't bypass it.
|
|
987
|
-
restrictedComments: {
|
|
988
|
-
type: 'relationship',
|
|
989
|
-
ref: 'Comment',
|
|
990
|
-
many: true,
|
|
991
|
-
access: { read: () => false },
|
|
992
|
-
},
|
|
993
|
-
secretInfo: { type: 'relationship', ref: 'Secret' },
|
|
994
|
-
draftRef: { type: 'relationship', ref: 'Draft' },
|
|
995
|
-
},
|
|
996
|
-
access: { operation: { query: () => true } },
|
|
997
|
-
},
|
|
998
|
-
// Denies query access outright — must vanish from `tools/list` as a
|
|
999
|
-
// tool owner AND from `Post`'s `fields` schema as a relation target.
|
|
1000
|
-
Secret: {
|
|
1001
|
-
fields: { value: { type: 'text' } },
|
|
1002
|
-
access: { operation: { query: () => false } },
|
|
1003
|
-
},
|
|
1004
|
-
// MCP-disabled — same double omission as `Secret`, different cause.
|
|
1005
|
-
Draft: {
|
|
1006
|
-
fields: { title: { type: 'text' } },
|
|
1007
|
-
access: { operation: { query: () => true } },
|
|
1008
|
-
mcp: { enabled: false },
|
|
1009
|
-
},
|
|
1010
|
-
// Self-referential — the schema must terminate at depth 2 rather
|
|
1011
|
-
// than recursing forever.
|
|
1012
|
-
Category: {
|
|
1013
|
-
fields: {
|
|
1014
|
-
name: { type: 'text' },
|
|
1015
|
-
parent: { type: 'relationship', ref: 'Category.children' },
|
|
1016
|
-
children: { type: 'relationship', ref: 'Category.parent', many: true },
|
|
1017
|
-
},
|
|
1018
|
-
access: { operation: { query: () => true } },
|
|
1019
|
-
},
|
|
1020
|
-
},
|
|
1021
|
-
}
|
|
1022
|
-
|
|
1023
|
-
getContext = vi.fn((session?: { userId: string }) => ({
|
|
1024
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1025
|
-
db: mockPrisma as any,
|
|
1026
|
-
session: session || null,
|
|
1027
|
-
prisma: mockPrisma,
|
|
1028
|
-
}))
|
|
1029
|
-
|
|
1030
|
-
mockGetSession = vi.fn(async () => ({ userId: 'user-123' }))
|
|
1031
|
-
})
|
|
1032
|
-
|
|
1033
|
-
async function listTools() {
|
|
1034
|
-
const handlers = createMcpHandlers({ config, getSession: mockGetSession, getContext })
|
|
1035
|
-
const request = new Request('http://localhost/api/mcp', {
|
|
1036
|
-
method: 'POST',
|
|
1037
|
-
headers: { 'Content-Type': 'application/json' },
|
|
1038
|
-
body: JSON.stringify({ jsonrpc: '2.0', id: 1, method: 'tools/list' }),
|
|
1039
|
-
})
|
|
1040
|
-
const response = await handlers.POST(request)
|
|
1041
|
-
const data = await response.json()
|
|
1042
|
-
return data.result.tools as Array<{ name: string; inputSchema: Record<string, unknown> }>
|
|
1043
|
-
}
|
|
1044
|
-
|
|
1045
|
-
async function callQuery(
|
|
1046
|
-
name: string,
|
|
1047
|
-
args: Record<string, unknown>,
|
|
1048
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1049
|
-
): Promise<any> {
|
|
1050
|
-
const handlers = createMcpHandlers({ config, getSession: mockGetSession, getContext })
|
|
1051
|
-
const request = new Request('http://localhost/api/mcp', {
|
|
1052
|
-
method: 'POST',
|
|
1053
|
-
headers: { 'Content-Type': 'application/json' },
|
|
1054
|
-
body: JSON.stringify({
|
|
1055
|
-
jsonrpc: '2.0',
|
|
1056
|
-
id: 1,
|
|
1057
|
-
method: 'tools/call',
|
|
1058
|
-
params: { name, arguments: args },
|
|
1059
|
-
}),
|
|
1060
|
-
})
|
|
1061
|
-
const response = await handlers.POST(request)
|
|
1062
|
-
return response.json()
|
|
1063
|
-
}
|
|
1064
|
-
|
|
1065
|
-
describe('generated `fields` schema on tools/list', () => {
|
|
1066
|
-
it('advertises scalars as booleans and relations as nested selectors', async () => {
|
|
1067
|
-
const tools = await listTools()
|
|
1068
|
-
const postQuery = tools.find((t) => t.name === 'list_post_query')!
|
|
1069
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1070
|
-
const fieldsSchema = (postQuery.inputSchema.properties as any).fields
|
|
1071
|
-
|
|
1072
|
-
expect(fieldsSchema.properties.title).toMatchObject({ type: 'boolean' })
|
|
1073
|
-
expect(fieldsSchema.properties.content).toMatchObject({ type: 'boolean' })
|
|
1074
|
-
|
|
1075
|
-
// To-one: nested `fields` only, required, no where/orderBy/take/skip/count.
|
|
1076
|
-
expect(fieldsSchema.properties.author.required).toEqual(['fields'])
|
|
1077
|
-
const authorFields = fieldsSchema.properties.author.properties.fields.properties
|
|
1078
|
-
expect(authorFields.name).toMatchObject({ type: 'boolean' })
|
|
1079
|
-
expect(authorFields.email).toMatchObject({ type: 'boolean' })
|
|
1080
|
-
expect(fieldsSchema.properties.author.properties.where).toBeUndefined()
|
|
1081
|
-
|
|
1082
|
-
// To-many: fields optional, plus where/orderBy/take/skip/count.
|
|
1083
|
-
expect(fieldsSchema.properties.comments.required).toBeUndefined()
|
|
1084
|
-
const commentFields = fieldsSchema.properties.comments.properties.fields.properties
|
|
1085
|
-
expect(commentFields.text).toMatchObject({ type: 'boolean' })
|
|
1086
|
-
expect(commentFields.approved).toMatchObject({ type: 'boolean' })
|
|
1087
|
-
expect(fieldsSchema.properties.comments.properties.where).toBeDefined()
|
|
1088
|
-
expect(fieldsSchema.properties.comments.properties.orderBy).toBeDefined()
|
|
1089
|
-
expect(fieldsSchema.properties.comments.properties.take).toBeDefined()
|
|
1090
|
-
expect(fieldsSchema.properties.comments.properties.skip).toBeDefined()
|
|
1091
|
-
expect(fieldsSchema.properties.comments.properties.count).toEqual({
|
|
1092
|
-
type: 'boolean',
|
|
1093
|
-
description: expect.any(String),
|
|
1094
|
-
})
|
|
1095
|
-
})
|
|
1096
|
-
|
|
1097
|
-
it('omits a relation whose target list denies query access', async () => {
|
|
1098
|
-
const tools = await listTools()
|
|
1099
|
-
const postQuery = tools.find((t) => t.name === 'list_post_query')!
|
|
1100
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1101
|
-
const fieldsSchema = (postQuery.inputSchema.properties as any).fields
|
|
1102
|
-
expect(fieldsSchema.properties.secretInfo).toBeUndefined()
|
|
1103
|
-
})
|
|
1104
|
-
|
|
1105
|
-
it('omits a relation whose target list has mcp.enabled: false', async () => {
|
|
1106
|
-
const tools = await listTools()
|
|
1107
|
-
const postQuery = tools.find((t) => t.name === 'list_post_query')!
|
|
1108
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1109
|
-
const fieldsSchema = (postQuery.inputSchema.properties as any).fields
|
|
1110
|
-
expect(fieldsSchema.properties.draftRef).toBeUndefined()
|
|
1111
|
-
})
|
|
1112
|
-
|
|
1113
|
-
it('terminates a self-referential relationship at depth 2 (no relation fields at level 2)', async () => {
|
|
1114
|
-
const tools = await listTools()
|
|
1115
|
-
const categoryQuery = tools.find((t) => t.name === 'list_category_query')!
|
|
1116
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1117
|
-
const fieldsSchema = (categoryQuery.inputSchema.properties as any).fields
|
|
1118
|
-
|
|
1119
|
-
// Only scalars (plus the always-present system fields) — no `parent`/
|
|
1120
|
-
// `children` at this depth, which is what actually terminates the
|
|
1121
|
-
// self-reference.
|
|
1122
|
-
const parentFields = fieldsSchema.properties.parent.properties.fields.properties
|
|
1123
|
-
expect(Object.keys(parentFields).sort()).toEqual(['createdAt', 'id', 'name', 'updatedAt'])
|
|
1124
|
-
expect(parentFields.name).toMatchObject({ type: 'boolean' })
|
|
1125
|
-
|
|
1126
|
-
const childrenFields = fieldsSchema.properties.children.properties.fields.properties
|
|
1127
|
-
expect(Object.keys(childrenFields).sort()).toEqual(['createdAt', 'id', 'name', 'updatedAt'])
|
|
1128
|
-
expect(childrenFields.name).toMatchObject({ type: 'boolean' })
|
|
1129
|
-
})
|
|
1130
|
-
})
|
|
1131
|
-
|
|
1132
|
-
describe('tools/list is per-session', () => {
|
|
1133
|
-
it('omits all four CRUD tools for a list whose query access denies the session', async () => {
|
|
1134
|
-
const tools = await listTools()
|
|
1135
|
-
const toolNames = tools.map((t) => t.name)
|
|
1136
|
-
expect(toolNames).not.toContain('list_secret_query')
|
|
1137
|
-
expect(toolNames).not.toContain('list_secret_create')
|
|
1138
|
-
expect(toolNames).not.toContain('list_secret_update')
|
|
1139
|
-
expect(toolNames).not.toContain('list_secret_delete')
|
|
1140
|
-
})
|
|
1141
|
-
|
|
1142
|
-
it('omits all four CRUD tools for a list with mcp.enabled: false', async () => {
|
|
1143
|
-
const tools = await listTools()
|
|
1144
|
-
const toolNames = tools.map((t) => t.name)
|
|
1145
|
-
expect(toolNames).not.toContain('list_draft_query')
|
|
1146
|
-
})
|
|
1147
|
-
})
|
|
1148
|
-
|
|
1149
|
-
describe('query dispatch with `fields`', () => {
|
|
1150
|
-
it('selects only scalar fields, issuing no `include`', async () => {
|
|
1151
|
-
mockPrisma.post.findMany.mockResolvedValue([{ id: '1', title: 'Hello', content: 'World' }])
|
|
1152
|
-
|
|
1153
|
-
const data = await callQuery('list_post_query', { fields: { title: true } })
|
|
1154
|
-
|
|
1155
|
-
expect(mockPrisma.post.findMany).toHaveBeenCalledWith(
|
|
1156
|
-
expect.not.objectContaining({ include: expect.anything() }),
|
|
1157
|
-
)
|
|
1158
|
-
const result = JSON.parse(data.result.content[0].text)
|
|
1159
|
-
expect(result.items).toEqual([{ id: '1', title: 'Hello' }])
|
|
1160
|
-
})
|
|
1161
|
-
|
|
1162
|
-
it('selects a to-one relation with nested fields', async () => {
|
|
1163
|
-
mockPrisma.post.findMany.mockResolvedValue([
|
|
1164
|
-
{ id: '1', title: 'Hello', author: { id: 'u1', name: 'Ada', email: 'ada@example.com' } },
|
|
1165
|
-
])
|
|
1166
|
-
|
|
1167
|
-
const data = await callQuery('list_post_query', {
|
|
1168
|
-
fields: { title: true, author: { fields: { name: true } } },
|
|
1169
|
-
})
|
|
1170
|
-
|
|
1171
|
-
expect(mockPrisma.post.findMany).toHaveBeenCalledWith(
|
|
1172
|
-
expect.objectContaining({ include: { author: true } }),
|
|
1173
|
-
)
|
|
1174
|
-
const result = JSON.parse(data.result.content[0].text)
|
|
1175
|
-
expect(result.items).toEqual([{ id: '1', title: 'Hello', author: { id: 'u1', name: 'Ada' } }])
|
|
1176
|
-
})
|
|
1177
|
-
|
|
1178
|
-
it('honours nested where/orderBy/take/skip on a to-many relation, applying the default take ceiling when omitted', async () => {
|
|
1179
|
-
mockPrisma.post.findMany.mockResolvedValue([{ id: '1', comments: [] }])
|
|
1180
|
-
|
|
1181
|
-
await callQuery('list_post_query', {
|
|
1182
|
-
fields: {
|
|
1183
|
-
comments: {
|
|
1184
|
-
fields: { text: true },
|
|
1185
|
-
where: { approved: { equals: true } },
|
|
1186
|
-
orderBy: { text: 'asc' },
|
|
1187
|
-
skip: 2,
|
|
1188
|
-
},
|
|
1189
|
-
},
|
|
1190
|
-
})
|
|
1191
|
-
|
|
1192
|
-
expect(mockPrisma.post.findMany).toHaveBeenCalledWith(
|
|
1193
|
-
expect.objectContaining({
|
|
1194
|
-
include: {
|
|
1195
|
-
comments: {
|
|
1196
|
-
where: { approved: { equals: true } },
|
|
1197
|
-
orderBy: { text: 'asc' },
|
|
1198
|
-
take: 5,
|
|
1199
|
-
skip: 2,
|
|
1200
|
-
},
|
|
1201
|
-
},
|
|
1202
|
-
}),
|
|
1203
|
-
)
|
|
1204
|
-
})
|
|
1205
|
-
|
|
1206
|
-
it('clamps a nested take above the hard cap', async () => {
|
|
1207
|
-
mockPrisma.post.findMany.mockResolvedValue([{ id: '1', comments: [] }])
|
|
1208
|
-
|
|
1209
|
-
await callQuery('list_post_query', {
|
|
1210
|
-
fields: { comments: { fields: { text: true }, take: 9999 } },
|
|
1211
|
-
})
|
|
1212
|
-
|
|
1213
|
-
expect(mockPrisma.post.findMany).toHaveBeenCalledWith(
|
|
1214
|
-
expect.objectContaining({
|
|
1215
|
-
include: { comments: { take: 50 } },
|
|
1216
|
-
}),
|
|
1217
|
-
)
|
|
1218
|
-
})
|
|
1219
|
-
|
|
1220
|
-
it('requests a to-many count in place of its rows', async () => {
|
|
1221
|
-
// The relation is still named in the include, fetched with the SAME
|
|
1222
|
-
// real rows a `fields`-and-`count` request would get (never a
|
|
1223
|
-
// synthetic `take: 0`, which would make field-visibility's read-access
|
|
1224
|
-
// check see a permanently-empty relation) — see projectMcpResult's doc
|
|
1225
|
-
// comment. The rows themselves are simply never added to
|
|
1226
|
-
// `fieldSelection`, so they never reach the projected output.
|
|
1227
|
-
mockPrisma.post.findMany.mockResolvedValue([
|
|
1228
|
-
{ id: '1', comments: [{ text: 'hi' }], _count: { comments: 7 } },
|
|
1229
|
-
])
|
|
1230
|
-
|
|
1231
|
-
const data = await callQuery('list_post_query', {
|
|
1232
|
-
fields: { comments: { count: true } },
|
|
1233
|
-
})
|
|
1234
|
-
|
|
1235
|
-
expect(mockPrisma.post.findMany).toHaveBeenCalledWith(
|
|
1236
|
-
expect.objectContaining({
|
|
1237
|
-
include: { comments: { take: 5 }, _count: { select: { comments: true } } },
|
|
1238
|
-
}),
|
|
1239
|
-
)
|
|
1240
|
-
const result = JSON.parse(data.result.content[0].text)
|
|
1241
|
-
expect(result.items).toEqual([{ id: '1', comments: 7 }])
|
|
1242
|
-
})
|
|
1243
|
-
|
|
1244
|
-
it('requests a to-many count alongside its rows', async () => {
|
|
1245
|
-
mockPrisma.post.findMany.mockResolvedValue([
|
|
1246
|
-
{ id: '1', comments: [{ text: 'hi' }], _count: { comments: 7 } },
|
|
1247
|
-
])
|
|
1248
|
-
|
|
1249
|
-
const data = await callQuery('list_post_query', {
|
|
1250
|
-
fields: { comments: { fields: { text: true }, count: true } },
|
|
1251
|
-
})
|
|
1252
|
-
|
|
1253
|
-
expect(mockPrisma.post.findMany).toHaveBeenCalledWith(
|
|
1254
|
-
expect.objectContaining({
|
|
1255
|
-
include: {
|
|
1256
|
-
comments: { take: 5 },
|
|
1257
|
-
_count: { select: { comments: true } },
|
|
1258
|
-
},
|
|
1259
|
-
}),
|
|
1260
|
-
)
|
|
1261
|
-
const result = JSON.parse(data.result.content[0].text)
|
|
1262
|
-
expect(result.items).toEqual([{ id: '1', comments: { items: [{ text: 'hi' }], count: 7 } }])
|
|
1263
|
-
})
|
|
1264
|
-
|
|
1265
|
-
it('refuses an unadvertised field name as an isError tool result', async () => {
|
|
1266
|
-
const data = await callQuery('list_post_query', { fields: { madeUpField: true } })
|
|
1267
|
-
|
|
1268
|
-
expect(data.error).toBeUndefined()
|
|
1269
|
-
expect(data.result.isError).toBe(true)
|
|
1270
|
-
expect(data.result.content[0].text).toContain('madeUpField')
|
|
1271
|
-
})
|
|
1272
|
-
|
|
1273
|
-
it('refuses a relation named two levels deep as an isError tool result', async () => {
|
|
1274
|
-
const data = await callQuery('list_post_query', {
|
|
1275
|
-
fields: { comments: { fields: { post: true } } },
|
|
1276
|
-
})
|
|
1277
|
-
|
|
1278
|
-
expect(data.error).toBeUndefined()
|
|
1279
|
-
expect(data.result.isError).toBe(true)
|
|
1280
|
-
expect(data.result.content[0].text).toContain('post')
|
|
1281
|
-
})
|
|
1282
|
-
|
|
1283
|
-
it('refuses a relation field selected with `true` instead of a selector object', async () => {
|
|
1284
|
-
const data = await callQuery('list_post_query', { fields: { author: true } })
|
|
1285
|
-
|
|
1286
|
-
expect(data.result.isError).toBe(true)
|
|
1287
|
-
})
|
|
1288
|
-
|
|
1289
|
-
it('refuses a scalar field selected with a non-true value', async () => {
|
|
1290
|
-
const data = await callQuery('list_post_query', { fields: { title: 'yes' } })
|
|
1291
|
-
|
|
1292
|
-
expect(data.result.isError).toBe(true)
|
|
1293
|
-
})
|
|
1294
|
-
|
|
1295
|
-
it('refuses a relation whose target list denies query access', async () => {
|
|
1296
|
-
const data = await callQuery('list_post_query', {
|
|
1297
|
-
fields: { secretInfo: { fields: { value: true } } },
|
|
1298
|
-
})
|
|
1299
|
-
|
|
1300
|
-
expect(data.result.isError).toBe(true)
|
|
1301
|
-
})
|
|
1302
|
-
|
|
1303
|
-
it('always returns id, even when the projection never names it', async () => {
|
|
1304
|
-
mockPrisma.post.findMany.mockResolvedValue([{ id: '1', title: 'Hello' }])
|
|
1305
|
-
|
|
1306
|
-
const data = await callQuery('list_post_query', { fields: { title: true } })
|
|
1307
|
-
|
|
1308
|
-
const result = JSON.parse(data.result.content[0].text)
|
|
1309
|
-
expect(result.items).toEqual([{ id: '1', title: 'Hello' }])
|
|
1310
|
-
})
|
|
1311
|
-
|
|
1312
|
-
it('accepts id/createdAt/updatedAt as explicitly selectable system fields', async () => {
|
|
1313
|
-
mockPrisma.post.findMany.mockResolvedValue([
|
|
1314
|
-
{ id: '1', title: 'Hello', createdAt: 't1', updatedAt: 't2' },
|
|
1315
|
-
])
|
|
1316
|
-
|
|
1317
|
-
const data = await callQuery('list_post_query', {
|
|
1318
|
-
fields: { id: true, createdAt: true, updatedAt: true },
|
|
1319
|
-
})
|
|
1320
|
-
|
|
1321
|
-
const result = JSON.parse(data.result.content[0].text)
|
|
1322
|
-
expect(result.items).toEqual([{ id: '1', createdAt: 't1', updatedAt: 't2' }])
|
|
1323
|
-
})
|
|
1324
|
-
|
|
1325
|
-
it('refuses a malformed nested where/take/orderBy/skip/count with a clear message rather than an opaque Prisma error', async () => {
|
|
1326
|
-
const badWhere = await callQuery('list_post_query', {
|
|
1327
|
-
fields: { comments: { fields: { text: true }, where: 'not-an-object' } },
|
|
1328
|
-
})
|
|
1329
|
-
expect(badWhere.result.isError).toBe(true)
|
|
1330
|
-
expect(badWhere.result.content[0].text).toContain('where')
|
|
1331
|
-
|
|
1332
|
-
const badTake = await callQuery('list_post_query', {
|
|
1333
|
-
fields: { comments: { fields: { text: true }, take: 'lots' } },
|
|
1334
|
-
})
|
|
1335
|
-
expect(badTake.result.isError).toBe(true)
|
|
1336
|
-
expect(badTake.result.content[0].text).toContain('take')
|
|
1337
|
-
|
|
1338
|
-
const badCount = await callQuery('list_post_query', {
|
|
1339
|
-
fields: { comments: { count: 'yes' } },
|
|
1340
|
-
})
|
|
1341
|
-
expect(badCount.result.isError).toBe(true)
|
|
1342
|
-
expect(badCount.result.content[0].text).toContain('count')
|
|
1343
|
-
})
|
|
1344
|
-
|
|
1345
|
-
it('refuses a negative nested take rather than allowing reverse-pagination to bypass the row cap', async () => {
|
|
1346
|
-
const data = await callQuery('list_post_query', {
|
|
1347
|
-
fields: { comments: { fields: { text: true }, take: -100000 } },
|
|
1348
|
-
})
|
|
1349
|
-
|
|
1350
|
-
expect(data.result.isError).toBe(true)
|
|
1351
|
-
expect(data.result.content[0].text).toContain('take')
|
|
1352
|
-
expect(mockPrisma.post.findMany).not.toHaveBeenCalled()
|
|
1353
|
-
})
|
|
1354
|
-
|
|
1355
|
-
it('refuses a nested where naming a field-level-denied field on the related list', async () => {
|
|
1356
|
-
const data = await callQuery('list_post_query', {
|
|
1357
|
-
fields: {
|
|
1358
|
-
comments: { fields: { text: true }, where: { internalNote: { equals: 'x' } } },
|
|
1359
|
-
},
|
|
1360
|
-
})
|
|
1361
|
-
|
|
1362
|
-
expect(data.result.isError).toBe(true)
|
|
1363
|
-
expect(data.result.content[0].text).toContain('internalNote')
|
|
1364
|
-
expect(mockPrisma.post.findMany).not.toHaveBeenCalled()
|
|
1365
|
-
})
|
|
1366
|
-
|
|
1367
|
-
it('refuses a nested orderBy naming an undeclared field on the related list', async () => {
|
|
1368
|
-
const data = await callQuery('list_post_query', {
|
|
1369
|
-
fields: {
|
|
1370
|
-
comments: { fields: { text: true }, orderBy: { bogusField: 'asc' } },
|
|
1371
|
-
},
|
|
1372
|
-
})
|
|
1373
|
-
|
|
1374
|
-
expect(data.result.isError).toBe(true)
|
|
1375
|
-
expect(data.result.content[0].text).toContain('bogusField')
|
|
1376
|
-
})
|
|
1377
|
-
|
|
1378
|
-
it('names a count-only relation in the include with real rows (never a synthetic take: 0) so field-visibility can evaluate its own read access against the true value', async () => {
|
|
1379
|
-
mockPrisma.post.findMany.mockResolvedValue([
|
|
1380
|
-
{ id: '1', restrictedComments: [{ text: 'hi' }], _count: { restrictedComments: 3 } },
|
|
1381
|
-
])
|
|
1382
|
-
|
|
1383
|
-
await callQuery('list_post_query', { fields: { restrictedComments: { count: true } } })
|
|
1384
|
-
|
|
1385
|
-
expect(mockPrisma.post.findMany).toHaveBeenCalledWith(
|
|
1386
|
-
expect.objectContaining({
|
|
1387
|
-
include: expect.objectContaining({ restrictedComments: { take: 5 } }),
|
|
1388
|
-
}),
|
|
1389
|
-
)
|
|
1390
|
-
})
|
|
1391
|
-
|
|
1392
|
-
// This mocked harness bypasses the real `filterReadableFields`, so it
|
|
1393
|
-
// can only simulate the outcome (a denied relation key absent from the
|
|
1394
|
-
// row `context.db` returns) rather than exercise the real per-row
|
|
1395
|
-
// access check — see `mcp-fields-projection-access.test.ts`'s
|
|
1396
|
-
// "suppresses a relation count denied by the relationship field's own
|
|
1397
|
-
// access" for the end-to-end version through the real pipeline.
|
|
1398
|
-
it('suppresses a count whose relation key is absent from the row (what a field-visibility denial produces)', async () => {
|
|
1399
|
-
mockPrisma.post.findMany.mockResolvedValue([
|
|
1400
|
-
{ id: '1', _count: { restrictedComments: 3 } }, // no `restrictedComments` key
|
|
1401
|
-
])
|
|
1402
|
-
|
|
1403
|
-
const data = await callQuery('list_post_query', {
|
|
1404
|
-
fields: { restrictedComments: { count: true } },
|
|
1405
|
-
})
|
|
1406
|
-
|
|
1407
|
-
const result = JSON.parse(data.result.content[0].text)
|
|
1408
|
-
expect(result.items).toEqual([{ id: '1' }])
|
|
1409
|
-
})
|
|
1410
|
-
})
|
|
1411
|
-
})
|