@rfc0/patty 0.0.0-stage → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +214 -2
- package/dist/adapters/access-tokens.js +7 -0
- package/dist/adapters/accounts.js +37 -0
- package/dist/adapters/auth.js +11 -0
- package/dist/adapters/bills.js +32 -0
- package/dist/adapters/budgets.js +29 -0
- package/dist/adapters/categories.js +32 -0
- package/dist/adapters/client-grants.js +7 -0
- package/dist/adapters/credit-cards.js +33 -0
- package/dist/adapters/currencies.js +2 -0
- package/dist/adapters/currency-rates.js +18 -0
- package/dist/adapters/dashboards.js +43 -0
- package/dist/adapters/demo.js +13 -0
- package/dist/adapters/instance-settings.js +7 -0
- package/dist/adapters/invites.js +7 -0
- package/dist/adapters/recurring.js +55 -0
- package/dist/adapters/sessions.js +7 -0
- package/dist/adapters/settings.js +4 -0
- package/dist/adapters/setup-codes.js +7 -0
- package/dist/adapters/tags.js +9 -0
- package/dist/adapters/transactions.js +95 -0
- package/dist/adapters/users.js +7 -0
- package/dist/common/build-version.js +5 -0
- package/dist/common/errors.js +118 -0
- package/dist/common/net.js +71 -0
- package/dist/common/result.js +7 -0
- package/dist/composition/auth.js +106 -0
- package/dist/composition/boot.js +27 -0
- package/dist/composition/cli.js +86 -0
- package/dist/composition/demo/seed.js +92 -0
- package/dist/composition/demo/shell.js +107 -0
- package/dist/composition/export.js +89 -0
- package/dist/composition/http.js +110 -0
- package/dist/composition/import.js +55 -0
- package/dist/composition/lazy-modules.js +2 -0
- package/dist/composition/runtime.js +115 -0
- package/dist/composition/sign-in/interpreter.js +154 -0
- package/dist/composition/sign-in/server.js +36 -0
- package/dist/composition/sign-in/wiring.js +23 -0
- package/dist/composition/stdio.js +69 -0
- package/dist/config.js +136 -0
- package/dist/controllers/account/account.js +88 -0
- package/dist/controllers/account/transaction.js +119 -0
- package/dist/controllers/account/transfer.js +34 -0
- package/dist/controllers/aggregate.js +40 -0
- package/dist/controllers/auth/access-tokens.js +61 -0
- package/dist/controllers/auth/grants.js +136 -0
- package/dist/controllers/auth/key-export.js +20 -0
- package/dist/controllers/auth/owner.js +80 -0
- package/dist/controllers/auth/password.js +35 -0
- package/dist/controllers/auth/session.js +50 -0
- package/dist/controllers/auth/step-up.js +8 -0
- package/dist/controllers/auth/users.js +183 -0
- package/dist/controllers/budgets.js +87 -0
- package/dist/controllers/categories.js +67 -0
- package/dist/controllers/correlations.js +112 -0
- package/dist/controllers/credit-card/bill.js +105 -0
- package/dist/controllers/credit-card/credit-card.js +129 -0
- package/dist/controllers/credit-card/transaction.js +181 -0
- package/dist/controllers/currencies.js +1 -0
- package/dist/controllers/currency-rates.js +40 -0
- package/dist/controllers/dashboards.js +68 -0
- package/dist/controllers/demo/seed.js +31 -0
- package/dist/controllers/demo/tour.js +12 -0
- package/dist/controllers/deps.js +6 -0
- package/dist/controllers/instance.js +6 -0
- package/dist/controllers/merchants.js +12 -0
- package/dist/controllers/recurring.js +70 -0
- package/dist/controllers/resolve.js +37 -0
- package/dist/controllers/settings.js +47 -0
- package/dist/controllers/status.js +19 -0
- package/dist/controllers/summary.js +21 -0
- package/dist/controllers/tags.js +19 -0
- package/dist/controllers/transaction/bulk.js +6 -0
- package/dist/controllers/transaction/core.js +49 -0
- package/dist/controllers/transaction/read.js +28 -0
- package/dist/diplomat/auth/credentials.js +58 -0
- package/dist/diplomat/auth/sign-in-store.js +18 -0
- package/dist/diplomat/cli/commands/auth.js +100 -0
- package/dist/diplomat/cli/commands/db.js +72 -0
- package/dist/diplomat/cli/commands/demo.js +68 -0
- package/dist/diplomat/cli/commands/key.js +119 -0
- package/dist/diplomat/cli/commands/login.js +151 -0
- package/dist/diplomat/cli/commands/setup.js +132 -0
- package/dist/diplomat/cli/commands/users.js +123 -0
- package/dist/diplomat/cli/commands.js +61 -0
- package/dist/diplomat/cli/export-file.js +37 -0
- package/dist/diplomat/cli/import-file.js +44 -0
- package/dist/diplomat/cli/io.js +61 -0
- package/dist/diplomat/cli/key-export-approval.js +37 -0
- package/dist/diplomat/cli/messages.js +96 -0
- package/dist/diplomat/cli/prompt.js +74 -0
- package/dist/diplomat/cli/terminal.js +81 -0
- package/dist/diplomat/client-config/clients.js +150 -0
- package/dist/diplomat/client-config/merge.js +41 -0
- package/dist/diplomat/db/bootstrap.js +98 -0
- package/dist/diplomat/db/database-files.js +147 -0
- package/dist/diplomat/db/driver.js +167 -0
- package/dist/diplomat/db/effects.js +101 -0
- package/dist/diplomat/db/engine.js +9 -0
- package/dist/diplomat/db/export.js +22 -0
- package/dist/diplomat/db/file-lock.js +82 -0
- package/dist/diplomat/db/key-lock.js +14 -0
- package/dist/diplomat/db/locale-cache.js +23 -0
- package/dist/diplomat/db/migration-barrier.js +57 -0
- package/dist/diplomat/db/migration-journal.js +18 -0
- package/dist/diplomat/db/migration-lock.js +15 -0
- package/dist/diplomat/db/migrations.js +11 -0
- package/dist/diplomat/db/present.js +17 -0
- package/dist/diplomat/db/queries/aggregate-whitelist.js +35 -0
- package/dist/diplomat/db/queries/filters.js +59 -0
- package/dist/diplomat/db/queries/fts.js +18 -0
- package/dist/diplomat/db/queries/scope.js +8 -0
- package/dist/diplomat/db/queries/transaction-select.js +26 -0
- package/dist/diplomat/db/queries/tx-predicates.js +13 -0
- package/dist/diplomat/db/repos/access-tokens.js +27 -0
- package/dist/diplomat/db/repos/accounts.js +91 -0
- package/dist/diplomat/db/repos/bills.js +93 -0
- package/dist/diplomat/db/repos/budgets.js +72 -0
- package/dist/diplomat/db/repos/categories.js +53 -0
- package/dist/diplomat/db/repos/client-grants.js +67 -0
- package/dist/diplomat/db/repos/correlations.js +66 -0
- package/dist/diplomat/db/repos/credit-cards.js +67 -0
- package/dist/diplomat/db/repos/currencies.js +8 -0
- package/dist/diplomat/db/repos/currency-rates.js +40 -0
- package/dist/diplomat/db/repos/dashboards.js +123 -0
- package/dist/diplomat/db/repos/health.js +12 -0
- package/dist/diplomat/db/repos/instance-settings.js +14 -0
- package/dist/diplomat/db/repos/instance.js +58 -0
- package/dist/diplomat/db/repos/invites.js +43 -0
- package/dist/diplomat/db/repos/merchants.js +121 -0
- package/dist/diplomat/db/repos/recurring.js +29 -0
- package/dist/diplomat/db/repos/sessions.js +19 -0
- package/dist/diplomat/db/repos/settings.js +41 -0
- package/dist/diplomat/db/repos/setup-codes.js +28 -0
- package/dist/diplomat/db/repos/sub-categories.js +67 -0
- package/dist/diplomat/db/repos/tags.js +51 -0
- package/dist/diplomat/db/repos/transaction-tags.js +57 -0
- package/dist/diplomat/db/repos/transactions.js +163 -0
- package/dist/diplomat/db/repos/users.js +47 -0
- package/dist/diplomat/db/safety-copy.js +87 -0
- package/dist/diplomat/db/schema.js +348 -0
- package/dist/diplomat/db/seed/categories.js +112 -0
- package/dist/diplomat/db/seed/currencies.js +9 -0
- package/dist/diplomat/db/seed/demo/br.js +98 -0
- package/dist/diplomat/db/seed/demo/co.js +89 -0
- package/dist/diplomat/db/seed/demo/index.js +12 -0
- package/dist/diplomat/db/seed/demo/mx.js +90 -0
- package/dist/diplomat/db/seed/demo/shared.js +39 -0
- package/dist/diplomat/db/seed/demo/us.js +90 -0
- package/dist/diplomat/db/seed/merchant-rules.js +188 -0
- package/dist/diplomat/db/sqlite-errors.js +40 -0
- package/dist/diplomat/db/tenancy-integrity.js +45 -0
- package/dist/diplomat/db/version-guard.js +16 -0
- package/dist/diplomat/http/auth-pages.js +41 -0
- package/dist/diplomat/http/auth-paths.js +46 -0
- package/dist/diplomat/http/bearer.js +15 -0
- package/dist/diplomat/http/connect-pages.js +51 -0
- package/dist/diplomat/http/context.js +17 -0
- package/dist/diplomat/http/cookies.js +27 -0
- package/dist/diplomat/http/form-pages.js +38 -0
- package/dist/diplomat/http/hooks/auth.js +106 -0
- package/dist/diplomat/http/hooks/demo-marker.js +59 -0
- package/dist/diplomat/http/openapi.js +73 -0
- package/dist/diplomat/http/principal.js +1 -0
- package/dist/diplomat/http/rate-limiter.js +78 -0
- package/dist/diplomat/http/remedy.js +26 -0
- package/dist/diplomat/http/respond.js +50 -0
- package/dist/diplomat/http/routes/account.js +226 -0
- package/dist/diplomat/http/routes/aggregate.js +28 -0
- package/dist/diplomat/http/routes/auth.js +105 -0
- package/dist/diplomat/http/routes/budget.js +34 -0
- package/dist/diplomat/http/routes/category.js +109 -0
- package/dist/diplomat/http/routes/connect.js +124 -0
- package/dist/diplomat/http/routes/credit-card.js +263 -0
- package/dist/diplomat/http/routes/currency-rates.js +60 -0
- package/dist/diplomat/http/routes/currency.js +16 -0
- package/dist/diplomat/http/routes/dashboard.js +93 -0
- package/dist/diplomat/http/routes/invite.js +63 -0
- package/dist/diplomat/http/routes/recurring.js +65 -0
- package/dist/diplomat/http/routes/settings.js +38 -0
- package/dist/diplomat/http/routes/summary.js +23 -0
- package/dist/diplomat/http/routes/system.js +29 -0
- package/dist/diplomat/http/routes/tag.js +51 -0
- package/dist/diplomat/http/routes/tokens.js +72 -0
- package/dist/diplomat/http/routes/transaction.js +55 -0
- package/dist/diplomat/http/routes/transfer.js +35 -0
- package/dist/diplomat/http/routes/ui.js +110 -0
- package/dist/diplomat/http/routes/users.js +156 -0
- package/dist/diplomat/http/routes/well-known.js +26 -0
- package/dist/diplomat/http/routes.js +85 -0
- package/dist/diplomat/http/session.js +34 -0
- package/dist/diplomat/http/token-pages.js +75 -0
- package/dist/diplomat/http/ui-files.js +21 -0
- package/dist/diplomat/http/user-pages.js +93 -0
- package/dist/diplomat/mcp/annotations.js +8 -0
- package/dist/diplomat/mcp/auth-info.js +20 -0
- package/dist/diplomat/mcp/context.js +14 -0
- package/dist/diplomat/mcp/definition.js +3 -0
- package/dist/diplomat/mcp/gate.js +15 -0
- package/dist/diplomat/mcp/instructions.js +19 -0
- package/dist/diplomat/mcp/prompts.js +125 -0
- package/dist/diplomat/mcp/register.js +12 -0
- package/dist/diplomat/mcp/remedy.js +17 -0
- package/dist/diplomat/mcp/resources.js +93 -0
- package/dist/diplomat/mcp/respond.js +20 -0
- package/dist/diplomat/mcp/route.js +62 -0
- package/dist/diplomat/mcp/scopes.js +53 -0
- package/dist/diplomat/mcp/server.js +26 -0
- package/dist/diplomat/mcp/shared.js +5 -0
- package/dist/diplomat/mcp/stdio-session.js +94 -0
- package/dist/diplomat/mcp/stdio.js +23 -0
- package/dist/diplomat/mcp/tool-name.js +59 -0
- package/dist/diplomat/mcp/tools/account.js +218 -0
- package/dist/diplomat/mcp/tools/aggregate.js +32 -0
- package/dist/diplomat/mcp/tools/budget.js +99 -0
- package/dist/diplomat/mcp/tools/category.js +103 -0
- package/dist/diplomat/mcp/tools/correlations.js +70 -0
- package/dist/diplomat/mcp/tools/credit-card.js +239 -0
- package/dist/diplomat/mcp/tools/currency-rates.js +62 -0
- package/dist/diplomat/mcp/tools/dashboard.js +75 -0
- package/dist/diplomat/mcp/tools/index.js +31 -0
- package/dist/diplomat/mcp/tools/recurring.js +62 -0
- package/dist/diplomat/mcp/tools/summary.js +30 -0
- package/dist/diplomat/mcp/tools/system.js +83 -0
- package/dist/diplomat/mcp/tools/tag.js +48 -0
- package/dist/diplomat/mcp/tools/transaction.js +53 -0
- package/dist/diplomat/mcp/tools/transfer.js +28 -0
- package/dist/diplomat/mcp/tour.js +87 -0
- package/dist/logic/account.js +79 -0
- package/dist/logic/aggregate.js +37 -0
- package/dist/logic/auth/bearer.js +35 -0
- package/dist/logic/auth/grant.js +126 -0
- package/dist/logic/auth/key-export.js +10 -0
- package/dist/logic/auth/keychain.js +3 -0
- package/dist/logic/auth/message.js +22 -0
- package/dist/logic/auth/origin.js +57 -0
- package/dist/logic/auth/owner.js +22 -0
- package/dist/logic/auth/password.js +3 -0
- package/dist/logic/auth/redact.js +25 -0
- package/dist/logic/auth/revoke.js +28 -0
- package/dist/logic/auth/scope.js +17 -0
- package/dist/logic/auth/session.js +30 -0
- package/dist/logic/auth/sign-in-flow.js +305 -0
- package/dist/logic/auth/time.js +2 -0
- package/dist/logic/auth/token.js +74 -0
- package/dist/logic/auth/user-plans.js +84 -0
- package/dist/logic/auth/users.js +78 -0
- package/dist/logic/balance.js +2 -0
- package/dist/logic/bill.js +74 -0
- package/dist/logic/budget.js +78 -0
- package/dist/logic/category.js +37 -0
- package/dist/logic/classify.js +21 -0
- package/dist/logic/correlations.js +147 -0
- package/dist/logic/credit-card.js +2 -0
- package/dist/logic/currency-rate.js +69 -0
- package/dist/logic/dashboard.js +40 -0
- package/dist/logic/demo/database.js +30 -0
- package/dist/logic/demo/plan.js +308 -0
- package/dist/logic/demo/tour.js +33 -0
- package/dist/logic/export-destination.js +12 -0
- package/dist/logic/key-import.js +15 -0
- package/dist/logic/locale.js +5 -0
- package/dist/logic/localize.js +12 -0
- package/dist/logic/merchant.js +31 -0
- package/dist/logic/migration.js +1 -0
- package/dist/logic/money.js +12 -0
- package/dist/logic/period.js +45 -0
- package/dist/logic/persistence.js +48 -0
- package/dist/logic/recurring.js +51 -0
- package/dist/logic/resolve.js +44 -0
- package/dist/logic/summary.js +29 -0
- package/dist/logic/tag.js +13 -0
- package/dist/logic/transaction.js +197 -0
- package/dist/main.js +42 -0
- package/dist/models/account.js +197 -0
- package/dist/models/aggregate.js +61 -0
- package/dist/models/auth/bearer.js +11 -0
- package/dist/models/auth/entity.js +17 -0
- package/dist/models/auth/errors.js +42 -0
- package/dist/models/auth/grant.js +58 -0
- package/dist/models/auth/key-export.js +11 -0
- package/dist/models/auth/message.js +50 -0
- package/dist/models/auth/mode.js +7 -0
- package/dist/models/auth/origin.js +16 -0
- package/dist/models/auth/owner.js +36 -0
- package/dist/models/auth/password.js +24 -0
- package/dist/models/auth/principal.js +26 -0
- package/dist/models/auth/redact.js +4 -0
- package/dist/models/auth/scope.js +9 -0
- package/dist/models/auth/session.js +19 -0
- package/dist/models/auth/sign-in-flow.js +102 -0
- package/dist/models/auth/sign-in.js +41 -0
- package/dist/models/auth/time.js +5 -0
- package/dist/models/auth/token.js +50 -0
- package/dist/models/auth/users.js +52 -0
- package/dist/models/bill.js +55 -0
- package/dist/models/budget.js +106 -0
- package/dist/models/category.js +52 -0
- package/dist/models/client-config.js +18 -0
- package/dist/models/correlations.js +215 -0
- package/dist/models/credit-card.js +156 -0
- package/dist/models/currency-rate.js +83 -0
- package/dist/models/dashboard.js +54 -0
- package/dist/models/database.js +16 -0
- package/dist/models/date.js +8 -0
- package/dist/models/demo/core.js +58 -0
- package/dist/models/demo/tour.js +41 -0
- package/dist/models/encryption-key.js +2 -0
- package/dist/models/error.js +13 -0
- package/dist/models/export.js +9 -0
- package/dist/models/id.js +2 -0
- package/dist/models/instance.js +7 -0
- package/dist/models/key-import.js +6 -0
- package/dist/models/locale.js +25 -0
- package/dist/models/merchant.js +12 -0
- package/dist/models/money.js +14 -0
- package/dist/models/package.js +12 -0
- package/dist/models/page.js +56 -0
- package/dist/models/persistence.js +1 -0
- package/dist/models/prompts.js +5 -0
- package/dist/models/recurring.js +54 -0
- package/dist/models/remedy.js +17 -0
- package/dist/models/resolution.js +1 -0
- package/dist/models/startup.js +7 -0
- package/dist/models/summary.js +24 -0
- package/dist/models/tag.js +14 -0
- package/dist/models/tenancy.js +10 -0
- package/dist/models/transaction-tag.js +6 -0
- package/dist/models/transaction.js +275 -0
- package/dist/wire/db/access-tokens.js +1 -0
- package/dist/wire/db/accounts.js +7 -0
- package/dist/wire/db/aggregate.js +16 -0
- package/dist/wire/db/bills.js +14 -0
- package/dist/wire/db/budgets.js +33 -0
- package/dist/wire/db/categories.js +14 -0
- package/dist/wire/db/client-grants.js +1 -0
- package/dist/wire/db/correlations.js +49 -0
- package/dist/wire/db/credit-cards.js +1 -0
- package/dist/wire/db/currencies.js +1 -0
- package/dist/wire/db/currency-rates.js +1 -0
- package/dist/wire/db/dashboards.js +1 -0
- package/dist/wire/db/instance-settings.js +1 -0
- package/dist/wire/db/invites.js +1 -0
- package/dist/wire/db/merchants.js +18 -0
- package/dist/wire/db/recurring.js +19 -0
- package/dist/wire/db/sessions.js +1 -0
- package/dist/wire/db/settings.js +1 -0
- package/dist/wire/db/setup-codes.js +1 -0
- package/dist/wire/db/tags.js +1 -0
- package/dist/wire/db/tenancy.js +1 -0
- package/dist/wire/db/transactions.js +89 -0
- package/dist/wire/db/users.js +1 -0
- package/dist/wire/in/accounts.js +26 -0
- package/dist/wire/in/aggregate.js +10 -0
- package/dist/wire/in/auth.js +107 -0
- package/dist/wire/in/bills.js +11 -0
- package/dist/wire/in/budgets.js +11 -0
- package/dist/wire/in/categories.js +9 -0
- package/dist/wire/in/cli.js +106 -0
- package/dist/wire/in/coerce.js +6 -0
- package/dist/wire/in/common.js +17 -0
- package/dist/wire/in/credit-cards.js +16 -0
- package/dist/wire/in/currency-rates.js +8 -0
- package/dist/wire/in/period.js +7 -0
- package/dist/wire/in/recurring.js +6 -0
- package/dist/wire/in/settings.js +5 -0
- package/dist/wire/in/summary.js +5 -0
- package/dist/wire/in/tags.js +2 -0
- package/dist/wire/in/transactions.js +31 -0
- package/dist/wire/out/bills.js +9 -0
- package/dist/wire/out/budgets.js +10 -0
- package/dist/wire/out/client-config.js +2 -0
- package/dist/wire/out/common.js +4 -0
- package/dist/wire/out/credit-cards.js +15 -0
- package/dist/wire/out/currency-rates.js +11 -0
- package/dist/wire/out/errors.js +58 -0
- package/dist/wire/out/recurring.js +6 -0
- package/dist/wire/out/status.js +10 -0
- package/dist/wire/out/summary.js +9 -0
- package/dist/wire/out/transactions.js +52 -0
- package/drizzle/0000_futuristic_umar.sql +124 -0
- package/drizzle/0001_fts5_search.sql +23 -0
- package/drizzle/0002_rename_graph_to_history.sql +7 -0
- package/drizzle/0003_lyrical_hairball.sql +2 -0
- package/drizzle/0004_misty_ikaris.sql +7 -0
- package/drizzle/0005_credit-liability-accounts.sql +14 -0
- package/drizzle/0006_smart_aqueduct.sql +1 -0
- package/drizzle/0007_add_dashboards.sql +5 -0
- package/drizzle/0008_yummy_madripoor.sql +1 -0
- package/drizzle/0009_version_groundwork.sql +9 -0
- package/drizzle/0010_category_merchant_association_cascade.sql +16 -0
- package/drizzle/0011_dashboard_id_normalization.sql +16 -0
- package/drizzle/0012_hot_the_spike.sql +12 -0
- package/drizzle/0013_recurring_rules_merchant.sql +1 -0
- package/drizzle/0014_dashboard_source_discriminator.sql +17 -0
- package/drizzle/0015_currencies_decimals.sql +1 -0
- package/drizzle/0016_unusual_zaran.sql +13 -0
- package/drizzle/0017_premium_blur.sql +1 -0
- package/drizzle/0018_auth_identity.sql +39 -0
- package/drizzle/0019_access_tokens.sql +16 -0
- package/drizzle/0020_stdio_sign_in.sql +27 -0
- package/drizzle/0021_tenancy_data.sql +289 -0
- package/drizzle/0022_user_management.sql +17 -0
- package/drizzle/0023_instance_settings_row.sql +2 -0
- package/drizzle/0024_credentials_changed_at.sql +2 -0
- package/drizzle/0025_instance_kind.sql +2 -0
- package/drizzle/0026_demo_seeded_at.sql +2 -0
- package/drizzle/0027_demo_country.sql +2 -0
- package/drizzle/0028_reset_sign_ins.sql +2 -0
- package/drizzle/meta/0000_snapshot.json +894 -0
- package/drizzle/meta/0003_snapshot.json +910 -0
- package/drizzle/meta/0004_snapshot.json +951 -0
- package/drizzle/meta/0005_snapshot.json +991 -0
- package/drizzle/meta/0006_snapshot.json +998 -0
- package/drizzle/meta/0007_snapshot.json +1029 -0
- package/drizzle/meta/0008_snapshot.json +1049 -0
- package/drizzle/meta/0009_snapshot.json +1121 -0
- package/drizzle/meta/0010_snapshot.json +1121 -0
- package/drizzle/meta/0011_snapshot.json +1136 -0
- package/drizzle/meta/0012_snapshot.json +1227 -0
- package/drizzle/meta/0013_snapshot.json +1247 -0
- package/drizzle/meta/0014_snapshot.json +1267 -0
- package/drizzle/meta/0015_snapshot.json +1275 -0
- package/drizzle/meta/0016_snapshot.json +1371 -0
- package/drizzle/meta/0017_snapshot.json +1392 -0
- package/drizzle/meta/0018_snapshot.json +1603 -0
- package/drizzle/meta/0019_snapshot.json +1713 -0
- package/drizzle/meta/0020_snapshot.json +1904 -0
- package/drizzle/meta/0021_snapshot.json +2186 -0
- package/drizzle/meta/0022_snapshot.json +2311 -0
- package/drizzle/meta/0023_snapshot.json +2311 -0
- package/drizzle/meta/0024_snapshot.json +2318 -0
- package/drizzle/meta/0025_snapshot.json +2326 -0
- package/drizzle/meta/0026_snapshot.json +2333 -0
- package/drizzle/meta/0027_snapshot.json +2340 -0
- package/drizzle/meta/0028_snapshot.json +2340 -0
- package/drizzle/meta/_journal.json +209 -0
- package/package.json +106 -4
- package/skills/dashboard-building/SKILL.md +201 -0
- package/skills/patty-tour/SKILL.md +34 -0
- package/ui/app.css +758 -0
- package/ui/app.js +543 -0
- package/ui/connect-result.html +16 -0
- package/ui/connect.html +53 -0
- package/ui/dashboards/accounts.html +3189 -0
- package/ui/dashboards/budget.html +1734 -0
- package/ui/dashboards/cards.html +4032 -0
- package/ui/dashboards/categories.html +4694 -0
- package/ui/dashboards/comparative.html +2475 -0
- package/ui/dashboards/dashboards.html +839 -0
- package/ui/dashboards/overview.html +2405 -0
- package/ui/dashboards/pending.html +2973 -0
- package/ui/dashboards/projections.html +2528 -0
- package/ui/dashboards/tags.html +1365 -0
- package/ui/invite.html +44 -0
- package/ui/login.html +26 -0
- package/ui/money.js +175 -0
- package/ui/setup.html +29 -0
- package/ui/shell.html +96 -0
- package/ui/token-created.html +24 -0
- package/ui/tokens.html +58 -0
- package/ui/user-invited.html +27 -0
- package/ui/users.html +60 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import * as R from 'remeda';
|
|
2
|
+
import { hasScope } from '../../logic/auth/scope.js';
|
|
3
|
+
import { WRITE_SCOPE } from '../../models/auth/scope.js';
|
|
4
|
+
import { AccessTokenKind, DEFAULT_TOKEN_EXPIRY, TOKEN_EXPIRY_DAYS, TOKEN_NAME_MAX_LENGTH, TokenAccess, TokenExpiry, TokenStatus, } from '../../models/auth/token.js';
|
|
5
|
+
import { ACCESS_LABEL, errorBlock, escapeHtml, fillTemplate, formatMinute } from './auth-pages.js';
|
|
6
|
+
import { TOKENS_PATH, UI_APP_CSS_PATH, UI_ROOT_PATH, USERS_PATH } from './auth-paths.js';
|
|
7
|
+
import { readCached, UI_ROOT } from './ui-files.js';
|
|
8
|
+
const TOKENS_TEMPLATE_PATH = `${UI_ROOT}/tokens.html`;
|
|
9
|
+
const TOKEN_CREATED_TEMPLATE_PATH = `${UI_ROOT}/token-created.html`;
|
|
10
|
+
const NOT_YET = '—';
|
|
11
|
+
// Only a token minted before ADR-034 §6 can have no expiry; it still works until revoked, and the list says so.
|
|
12
|
+
const LEGACY_NO_EXPIRY_LABEL = 'No expiry (legacy)';
|
|
13
|
+
const expiryLabel = (expiry) => `in ${TOKEN_EXPIRY_DAYS[expiry]} days`;
|
|
14
|
+
const option = (value, label, selected = false) => `<option value="${escapeHtml(value)}"${selected ? ' selected' : ''}>${escapeHtml(label)}</option>`;
|
|
15
|
+
const accessOptions = () => TokenAccess.options.map((access) => option(access, ACCESS_LABEL[access])).join('');
|
|
16
|
+
const expiryOptions = () => R.pipe(TokenExpiry.options, R.sortBy((expiry) => TOKEN_EXPIRY_DAYS[expiry]), R.map((expiry) => option(expiry, expiryLabel(expiry), expiry === DEFAULT_TOKEN_EXPIRY))).join('');
|
|
17
|
+
const SCOPE_LABEL = { read: 'read only', write: 'read + write' };
|
|
18
|
+
const when = (iso, fallback) => (iso === null ? fallback : formatMinute(iso));
|
|
19
|
+
const accessOf = (token) => hasScope(token.scopes, WRITE_SCOPE) ? SCOPE_LABEL.write : SCOPE_LABEL.read;
|
|
20
|
+
const revokeForm = (token) => token.status === TokenStatus.enum.active
|
|
21
|
+
? `<form method="post" action="${TOKENS_PATH}/${escapeHtml(token.id)}/revoke">` +
|
|
22
|
+
`<button type="submit" class="token-revoke" aria-label="Revoke ${escapeHtml(token.name)}">Revoke</button></form>`
|
|
23
|
+
: '';
|
|
24
|
+
const row = (token) => '<tr>' +
|
|
25
|
+
`<td>${escapeHtml(token.name)}</td>` +
|
|
26
|
+
`<td><code>${escapeHtml(token.prefix)}…</code></td>` +
|
|
27
|
+
`<td>${accessOf(token)}</td>` +
|
|
28
|
+
`<td>${when(token.createdAt, NOT_YET)}</td>` +
|
|
29
|
+
`<td>${when(token.lastUsedAt, NOT_YET)}</td>` +
|
|
30
|
+
`<td>${when(token.expiresAt, LEGACY_NO_EXPIRY_LABEL)}</td>` +
|
|
31
|
+
`<td class="token-status-${token.status}">${token.status}</td>` +
|
|
32
|
+
`<td>${revokeForm(token)}</td>` +
|
|
33
|
+
'</tr>';
|
|
34
|
+
const signInRow = (signIn) => '<tr>' +
|
|
35
|
+
// The client name is whatever the spawning program reported about itself.
|
|
36
|
+
`<td>${escapeHtml(signIn.clientName ?? signIn.name)}</td>` +
|
|
37
|
+
`<td>${escapeHtml(signIn.profile ?? '')}</td>` +
|
|
38
|
+
`<td>${accessOf(signIn)}</td>` +
|
|
39
|
+
`<td>${when(signIn.createdAt, NOT_YET)}</td>` +
|
|
40
|
+
`<td>${when(signIn.expiresAt, LEGACY_NO_EXPIRY_LABEL)}</td>` +
|
|
41
|
+
`<td>${when(signIn.lastUsedAt, NOT_YET)}</td>` +
|
|
42
|
+
`<td class="token-status-${signIn.status}">${signIn.status}</td>` +
|
|
43
|
+
`<td>${revokeForm(signIn)}</td>` +
|
|
44
|
+
'</tr>';
|
|
45
|
+
const signInsTable = (signIns) => signIns.length === 0
|
|
46
|
+
? '<p class="auth-hint">No Claude sign-ins yet.</p>'
|
|
47
|
+
: '<div class="tokens-scroll"><table class="tokens-table"><thead><tr>' +
|
|
48
|
+
'<th>Client</th><th>Profile</th><th>Access</th><th>Signed in</th><th>Expires</th><th>Last used</th><th>Status</th><th></th>' +
|
|
49
|
+
`</tr></thead><tbody>${signIns.map(signInRow).join('')}</tbody></table></div>`;
|
|
50
|
+
const table = (tokens) => tokens.length === 0
|
|
51
|
+
? '<p class="auth-hint">No access tokens yet.</p>'
|
|
52
|
+
: '<div class="tokens-scroll"><table class="tokens-table"><thead><tr>' +
|
|
53
|
+
'<th>Name</th><th>Token</th><th>Access</th><th>Created</th><th>Last used</th><th>Expires</th><th>Status</th><th></th>' +
|
|
54
|
+
`</tr></thead><tbody>${tokens.map(row).join('')}</tbody></table></div>`;
|
|
55
|
+
const usersLink = (show) => (show ? `<a href="${USERS_PATH}">Users</a> · ` : '');
|
|
56
|
+
export const renderTokensPage = async (fields) => fillTemplate(await readCached(TOKENS_TEMPLATE_PATH), {
|
|
57
|
+
stylesheet: UI_APP_CSS_PATH,
|
|
58
|
+
action: TOKENS_PATH,
|
|
59
|
+
dashboards: UI_ROOT_PATH,
|
|
60
|
+
usersLink: usersLink(fields.showUsersLink),
|
|
61
|
+
nameMaxLength: String(TOKEN_NAME_MAX_LENGTH),
|
|
62
|
+
accessOptions: accessOptions(),
|
|
63
|
+
expiryOptions: expiryOptions(),
|
|
64
|
+
tokens: table(R.filter(fields.tokens, (token) => token.kind === AccessTokenKind.enum.pat)),
|
|
65
|
+
signIns: signInsTable(R.filter(fields.tokens, (token) => token.kind === AccessTokenKind.enum.stdio)),
|
|
66
|
+
error: errorBlock(fields.error),
|
|
67
|
+
});
|
|
68
|
+
/** The one place the plaintext token is ever rendered. */
|
|
69
|
+
export const renderTokenCreatedPage = async (fields) => fillTemplate(await readCached(TOKEN_CREATED_TEMPLATE_PATH), {
|
|
70
|
+
stylesheet: UI_APP_CSS_PATH,
|
|
71
|
+
name: escapeHtml(fields.summary.name),
|
|
72
|
+
access: accessOf(fields.summary),
|
|
73
|
+
token: escapeHtml(fields.token),
|
|
74
|
+
tokensPath: TOKENS_PATH,
|
|
75
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import { fileURLToPath } from 'node:url';
|
|
3
|
+
// Resolved relative to this module's own file location (not process.cwd()) so it works
|
|
4
|
+
// identically under `tsx src/...` (dev) and `node dist/...` (published package) — same pattern as
|
|
5
|
+
// diplomat/db/bootstrap.ts's DEFAULT_MIGRATIONS_FOLDER. src/diplomat/http/ui-files.ts and its
|
|
6
|
+
// compiled dist/diplomat/http/ui-files.js are both 3 levels below the package root.
|
|
7
|
+
export const HTML_CONTENT_TYPE = 'text/html; charset=utf-8';
|
|
8
|
+
export const UI_ROOT = fileURLToPath(new URL('../../../ui', import.meta.url));
|
|
9
|
+
// The files under ui/ are fixed package assets — never rewritten at runtime — so the first read of
|
|
10
|
+
// each is cached in memory for the life of the process; only a *successful* read is cached (never
|
|
11
|
+
// a rejected promise), so a transient read error doesn't wedge every later request into repeating
|
|
12
|
+
// the same failure. `cache-control: no-cache` governs the browser's cache, not this one.
|
|
13
|
+
const fileContentCache = new Map();
|
|
14
|
+
export const readCached = async (path) => {
|
|
15
|
+
const cached = fileContentCache.get(path);
|
|
16
|
+
if (cached !== undefined)
|
|
17
|
+
return cached;
|
|
18
|
+
const content = await readFile(path, 'utf-8');
|
|
19
|
+
fileContentCache.set(path, content);
|
|
20
|
+
return content;
|
|
21
|
+
};
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import * as R from 'remeda';
|
|
2
|
+
import { PASSWORD_MIN_LENGTH } from '../../models/auth/password.js';
|
|
3
|
+
import { UserRole } from '../../models/auth/owner.js';
|
|
4
|
+
import { INVITE_TTL_HOURS, SignInCap, UserAction, UserStatus, } from '../../models/auth/users.js';
|
|
5
|
+
import { errorBlock, escapeHtml, fillTemplate, formatMinute } from './auth-pages.js';
|
|
6
|
+
import { INVITE_PATH, TOKENS_PATH, UI_APP_CSS_PATH, UI_ROOT_PATH, userActionUrl, USERS_CAP_PATH, USERS_PATH, } from './auth-paths.js';
|
|
7
|
+
import { readCached, UI_ROOT } from './ui-files.js';
|
|
8
|
+
const USERS_TEMPLATE_PATH = `${UI_ROOT}/users.html`;
|
|
9
|
+
const INVITED_TEMPLATE_PATH = `${UI_ROOT}/user-invited.html`;
|
|
10
|
+
const INVITE_TEMPLATE_PATH = `${UI_ROOT}/invite.html`;
|
|
11
|
+
const NEVER = '—';
|
|
12
|
+
const UNNAMED = '(not set up yet)';
|
|
13
|
+
const ROLE_LABEL = {
|
|
14
|
+
admin: 'Administrator — manages users',
|
|
15
|
+
member: 'Member — their own finances only',
|
|
16
|
+
};
|
|
17
|
+
const CAP_LABEL = { '24h': '24 hours', '7d': '7 days', '30d': '30 days' };
|
|
18
|
+
const option = (value, label, selected = false) => `<option value="${escapeHtml(value)}"${selected ? ' selected' : ''}>${escapeHtml(label)}</option>`;
|
|
19
|
+
const roleOptions = (selected) => UserRole.options.map((role) => option(role, ROLE_LABEL[role], role === selected)).join('');
|
|
20
|
+
const capOptions = (selected) => SignInCap.options.map((cap) => option(cap, CAP_LABEL[cap], cap === selected)).join('');
|
|
21
|
+
const when = (iso, fallback = NEVER) => (iso === null ? fallback : formatMinute(iso));
|
|
22
|
+
const passwordField = (label) => `<input name="password" type="password" autocomplete="current-password" placeholder="Your password" ` +
|
|
23
|
+
`aria-label="${escapeHtml(label)}" required />`;
|
|
24
|
+
const actionForm = (user, action, button, fields = '') => `<form method="post" action="${userActionUrl(user.id, action)}">${fields}` +
|
|
25
|
+
`<button type="submit" class="token-revoke">${escapeHtml(button)}</button></form>`;
|
|
26
|
+
const nameOf = (user) => user.username ?? UNNAMED;
|
|
27
|
+
const stepUpForm = (user, action, button) => actionForm(user, action, button, passwordField(`Your password to ${button.toLowerCase()} ${nameOf(user)}`));
|
|
28
|
+
const roleForm = (user) => actionForm(user, UserAction.enum.role, 'Set role', `<select name="role" aria-label="Role of ${escapeHtml(nameOf(user))}">${roleOptions(user.role)}</select>` +
|
|
29
|
+
passwordField(`Your password to change the role of ${nameOf(user)}`));
|
|
30
|
+
// Typed by the status, so a new status cannot exist without its actions.
|
|
31
|
+
const ACTIONS = {
|
|
32
|
+
invited: (user) => stepUpForm(user, UserAction.enum.reissue, 'Reissue invite') + stepUpForm(user, UserAction.enum.disable, 'Disable'),
|
|
33
|
+
active: (user) => roleForm(user) +
|
|
34
|
+
stepUpForm(user, UserAction.enum.reissue, 'Reset password') +
|
|
35
|
+
stepUpForm(user, UserAction.enum.disable, 'Disable'),
|
|
36
|
+
disabled: (user) => stepUpForm(user, UserAction.enum.enable, 'Enable'),
|
|
37
|
+
};
|
|
38
|
+
const statusCell = (user) => user.status === UserStatus.enum.invited && user.inviteExpiresAt !== null
|
|
39
|
+
? `invited (expires ${formatMinute(user.inviteExpiresAt)})`
|
|
40
|
+
: user.status;
|
|
41
|
+
const row = (user) => `<tr data-user="${escapeHtml(nameOf(user))}">` +
|
|
42
|
+
`<td>${escapeHtml(nameOf(user))}</td>` +
|
|
43
|
+
`<td>${user.role}</td>` +
|
|
44
|
+
`<td class="user-status-${user.status}">${statusCell(user)}</td>` +
|
|
45
|
+
`<td>${when(user.createdAt)}</td>` +
|
|
46
|
+
`<td>${when(user.lastLoginAt)}</td>` +
|
|
47
|
+
`<td class="user-actions">${ACTIONS[user.status](user)}</td>` +
|
|
48
|
+
'</tr>';
|
|
49
|
+
const table = (users) => '<div class="tokens-scroll"><table class="tokens-table"><thead><tr>' +
|
|
50
|
+
'<th>Username</th><th>Role</th><th>Status</th><th>Created</th><th>Last login</th><th></th>' +
|
|
51
|
+
`</tr></thead><tbody>${R.map(users, row).join('')}</tbody></table></div>`;
|
|
52
|
+
export const renderUsersPage = async (fields) => fillTemplate(await readCached(USERS_TEMPLATE_PATH), {
|
|
53
|
+
stylesheet: UI_APP_CSS_PATH,
|
|
54
|
+
tokensPath: TOKENS_PATH,
|
|
55
|
+
dashboards: UI_ROOT_PATH,
|
|
56
|
+
inviteAction: USERS_PATH,
|
|
57
|
+
capAction: USERS_CAP_PATH,
|
|
58
|
+
inviteHours: String(INVITE_TTL_HOURS),
|
|
59
|
+
roleOptions: roleOptions(UserRole.enum.member),
|
|
60
|
+
capOptions: capOptions(fields.cap),
|
|
61
|
+
users: table(fields.users),
|
|
62
|
+
error: errorBlock(fields.error),
|
|
63
|
+
});
|
|
64
|
+
const linkBlock = (link) => link === null ? '' : `<p>Link</p><p class="token-secret" data-testid="invite-link">${escapeHtml(link)}</p>`;
|
|
65
|
+
const consequenceOf = (issued) => {
|
|
66
|
+
const { sessionsEnded, tokensRevoked } = issued.revoked;
|
|
67
|
+
return sessionsEnded + tokensRevoked === 0
|
|
68
|
+
? 'They choose their own password; you never see it.'
|
|
69
|
+
: `Their password is gone and ${sessionsEnded} session(s) and ${tokensRevoked} token(s) or sign-in(s) ended; ` +
|
|
70
|
+
'this invite is the only way back in.';
|
|
71
|
+
};
|
|
72
|
+
/** The one place an invite's code and link are ever rendered. `link` is null when the instance cannot name its own
|
|
73
|
+
* origin (set `PUBLIC_URL`); the code can still be typed at the invite page. */
|
|
74
|
+
export const renderInvitedPage = async (fields) => fillTemplate(await readCached(INVITED_TEMPLATE_PATH), {
|
|
75
|
+
stylesheet: UI_APP_CSS_PATH,
|
|
76
|
+
heading: escapeHtml(fields.heading),
|
|
77
|
+
username: escapeHtml(fields.issued.user.username ?? UNNAMED),
|
|
78
|
+
role: fields.issued.user.role,
|
|
79
|
+
consequence: escapeHtml(consequenceOf(fields.issued)),
|
|
80
|
+
expiresAt: formatMinute(fields.issued.expiresAt),
|
|
81
|
+
link: linkBlock(fields.link),
|
|
82
|
+
code: escapeHtml(fields.issued.code),
|
|
83
|
+
invitePath: INVITE_PATH,
|
|
84
|
+
usersPath: USERS_PATH,
|
|
85
|
+
});
|
|
86
|
+
/** The claim page. `code` is whatever the link carried (escaped); never the password. */
|
|
87
|
+
export const renderInvitePage = async (fields) => fillTemplate(await readCached(INVITE_TEMPLATE_PATH), {
|
|
88
|
+
stylesheet: UI_APP_CSS_PATH,
|
|
89
|
+
action: INVITE_PATH,
|
|
90
|
+
code: escapeHtml(fields.code),
|
|
91
|
+
passwordMinLength: String(PASSWORD_MIN_LENGTH),
|
|
92
|
+
error: errorBlock(fields.error),
|
|
93
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The MCP tool annotations every `registerTool` call declares (ADR-033 §3). `readOnlyHint` is the single
|
|
3
|
+
* source of a tool's scope — `logic/auth/scope.ts`'s `scopeOfTool`: read-only → `patty:read`, anything else →
|
|
4
|
+
* `patty:write` — and clients use the same hint to decide how freely to run a tool. A tool that changes
|
|
5
|
+
* anything (including a read-then-write like `apply_due_recurring`) is `MUTATING`.
|
|
6
|
+
*/
|
|
7
|
+
export const READ_ONLY = { readOnlyHint: true };
|
|
8
|
+
export const MUTATING = { readOnlyHint: false };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { PrincipalSchema } from '../../models/auth/principal.js';
|
|
2
|
+
import { PAT_CLIENT_ID_PREFIX } from '../../models/auth/token.js';
|
|
3
|
+
/**
|
|
4
|
+
* The SDK's `AuthInfo` for a request's principal, handed to the transport as `req.raw.auth` and echoed back to
|
|
5
|
+
* every tool as `extra.authInfo` (the gate reads it). `token` is the access token's id — never the secret, which this
|
|
6
|
+
* process only ever sees as a hash — and `clientId` names how the caller authenticated. `extra` carries the rest of the
|
|
7
|
+
* principal, so `principalOf` can rebuild it whole.
|
|
8
|
+
*/
|
|
9
|
+
export const authInfoOf = (principal) => ({
|
|
10
|
+
token: principal.tokenId ?? principal.via,
|
|
11
|
+
clientId: principal.tokenId === undefined ? principal.via : `${PAT_CLIENT_ID_PREFIX}${principal.tokenId}`,
|
|
12
|
+
scopes: principal.scopes,
|
|
13
|
+
extra: { userId: principal.userId, role: principal.role, via: principal.via, tokenId: principal.tokenId },
|
|
14
|
+
});
|
|
15
|
+
/** The inverse of `authInfoOf`, decoded at this boundary: `null` for anything that is not a whole principal, so a
|
|
16
|
+
* malformed `authInfo` is refused rather than trusted. */
|
|
17
|
+
export const principalOf = (authInfo) => {
|
|
18
|
+
const decoded = PrincipalSchema.safeParse({ ...authInfo.extra, scopes: authInfo.scopes });
|
|
19
|
+
return decoded.success ? decoded.data : null;
|
|
20
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { scopedFor } from '../../controllers/deps.js';
|
|
2
|
+
import { LOG_PREFIX } from '../../models/package.js';
|
|
3
|
+
export const MISSING_CALLER_MESSAGE = `${LOG_PREFIX} an MCP callback reached user data without an authenticated principal`;
|
|
4
|
+
/** Throws without a principal rather than defaulting to anyone. */
|
|
5
|
+
export const callerOf = (extra) => {
|
|
6
|
+
const principal = extra?.principal;
|
|
7
|
+
if (principal === undefined)
|
|
8
|
+
throw new Error(MISSING_CALLER_MESSAGE);
|
|
9
|
+
return principal;
|
|
10
|
+
};
|
|
11
|
+
export const createMcpContext = (tenancy, version) => ({
|
|
12
|
+
version,
|
|
13
|
+
as: (extra) => scopedFor(tenancy, callerOf(extra)),
|
|
14
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { authErrors } from '../../models/auth/errors.js';
|
|
3
|
+
import { OWNER_PRINCIPAL } from '../../models/auth/principal.js';
|
|
4
|
+
import { principalOf } from './auth-info.js';
|
|
5
|
+
export const GateKind = z.enum(['granted', 'refused', 'not_signed_in']);
|
|
6
|
+
/** HTTP: the edge authenticated the request and handed the principal to the transport as `req.auth`. */
|
|
7
|
+
export const authInfoGate = async (extra) => {
|
|
8
|
+
const authInfo = extra?.authInfo;
|
|
9
|
+
const principal = authInfo === undefined ? null : principalOf(authInfo);
|
|
10
|
+
return principal === null
|
|
11
|
+
? { kind: GateKind.enum.refused, error: authErrors.unauthenticated }
|
|
12
|
+
: { kind: GateKind.enum.granted, principal };
|
|
13
|
+
};
|
|
14
|
+
/** `PATTY_AUTH=disabled`: every request is the owner, holding every scope. */
|
|
15
|
+
export const ownerGate = async () => ({ kind: GateKind.enum.granted, principal: OWNER_PRINCIPAL });
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { isDemoInstance } from '../../models/instance.js';
|
|
2
|
+
import { Locale } from '../../models/locale.js';
|
|
3
|
+
import { PRODUCT_NAME } from '../../models/package.js';
|
|
4
|
+
export const MCP_SERVER_NAME = 'patty';
|
|
5
|
+
/** What a client is told when it connects to a demo database, in the demo's language. The `patty` server name is
|
|
6
|
+
* the real install's. */
|
|
7
|
+
export const DEMO_SERVER_INSTRUCTIONS = {
|
|
8
|
+
[Locale.enum.en]: `This ${PRODUCT_NAME} server is a DEMO: its data is sample data, not the person's finances. ` +
|
|
9
|
+
'Say so once, when you start working with it. Never record, import or change anything here as if it were the ' +
|
|
10
|
+
`person's real money; for their real finances use the \`${MCP_SERVER_NAME}\` server instead.`,
|
|
11
|
+
[Locale.enum.pt]: `Este servidor ${PRODUCT_NAME} é uma DEMO: os dados são de exemplo, não as finanças da pessoa. ` +
|
|
12
|
+
'Diga isso uma vez, ao começar a trabalhar com ele. Nunca registre, importe ou altere nada aqui como se fosse ' +
|
|
13
|
+
`o dinheiro real da pessoa; para as finanças reais use o servidor \`${MCP_SERVER_NAME}\`.`,
|
|
14
|
+
[Locale.enum.es]: `Este servidor ${PRODUCT_NAME} es una DEMO: sus datos son de ejemplo, no las finanzas de la persona. ` +
|
|
15
|
+
'Dilo una sola vez, al empezar a trabajar con él. Nunca registres, importes ni cambies nada aquí como si fuera ' +
|
|
16
|
+
`el dinero real de la persona; para sus finanzas reales usa el servidor \`${MCP_SERVER_NAME}\`.`,
|
|
17
|
+
};
|
|
18
|
+
/** Sent at initialize only for a demo database; a standard one sends none. */
|
|
19
|
+
export const serverInstructions = ({ kind, locale }) => isDemoInstance(kind) ? DEMO_SERVER_INSTRUCTIONS[locale] : undefined;
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { PeriodSchema } from '../../models/date.js';
|
|
3
|
+
import { getTourContext } from '../../controllers/demo/tour.js';
|
|
4
|
+
import { ImportStatementSource, PromptName } from '../../models/prompts.js';
|
|
5
|
+
import { definePrompt } from './definition.js';
|
|
6
|
+
import { tourPromptText } from './tour.js';
|
|
7
|
+
import { ToolName } from './tool-name.js';
|
|
8
|
+
import { PRODUCT_NAME } from '../../models/package.js';
|
|
9
|
+
const T = ToolName.enum;
|
|
10
|
+
/** Guided-workflow MCP prompts (Feature Design 019) — orchestration text; the *model* executes the tools the text
|
|
11
|
+
* instructs it to call. Only `tour` reads the database (through `controllers/demo/tour.ts`). The trivial date
|
|
12
|
+
* formatting below stays local rather than reusing `logic/period.ts`'s private `pad`. */
|
|
13
|
+
const pad = (n) => String(n).padStart(2, '0');
|
|
14
|
+
/** Shared by monthly_review/budget_checkup: both are scoped to one calendar month. The MCP prompt
|
|
15
|
+
* protocol always sends string arguments (GetPromptRequest.arguments is Record<string, string>),
|
|
16
|
+
* so each field coerces to a number before validating through PeriodSchema's own bounds — reusing
|
|
17
|
+
* them rather than restating "1-12"/"2000-2100" as a second pair of literals. */
|
|
18
|
+
export const PeriodPromptArgsSchema = {
|
|
19
|
+
month: z.coerce
|
|
20
|
+
.number()
|
|
21
|
+
.pipe(PeriodSchema.shape.month)
|
|
22
|
+
.optional()
|
|
23
|
+
.describe('Month (1-12) — default: the current month'),
|
|
24
|
+
year: z.coerce
|
|
25
|
+
.number()
|
|
26
|
+
.pipe(PeriodSchema.shape.year)
|
|
27
|
+
.optional()
|
|
28
|
+
.describe('Calendar year — default: the current year'),
|
|
29
|
+
};
|
|
30
|
+
export const ImportStatementPromptArgsSchema = {
|
|
31
|
+
source: ImportStatementSource.optional().describe('"card" or "account" — omit to ask the user which kind of statement they have'),
|
|
32
|
+
};
|
|
33
|
+
/** Resolves the effective review period: an omitted month or year falls back to `now`'s, so
|
|
34
|
+
* passing only one of the two (e.g. just a past year) still anchors the other to today. */
|
|
35
|
+
export const resolvePromptPeriod = (args, now) => ({
|
|
36
|
+
month: args.month ?? now.getMonth() + 1,
|
|
37
|
+
year: args.year ?? now.getFullYear(),
|
|
38
|
+
});
|
|
39
|
+
const formatPeriod = ({ month, year }) => `${pad(month)}/${year}`;
|
|
40
|
+
const CURRENCY_RULE = 'Group every figure by currency and never sum across currencies — BRL and USD are always reported separately.';
|
|
41
|
+
export const monthlyReviewPromptText = (period) => `You are reviewing the user's finances for ${formatPeriod(period)}. Call ${T.get_spending_summary}, ` +
|
|
42
|
+
`${T.find_correlations} with analysis "spending_shifts", then "budget_fit", then "recurring_candidates" ` +
|
|
43
|
+
`(all scoped to month ${period.month} year ${period.year}), and ${T.get_budget_status} for the same period. ` +
|
|
44
|
+
'Then write a brief, prose review — no raw table dumps: per-currency income/expenses/balance; the 2-3 ' +
|
|
45
|
+
'biggest category shifts vs the baseline and a plausible driver for each; which budgets are over or have ' +
|
|
46
|
+
`slack; and any recurring-payment candidates worth turning into a rule via ${T.create_recurring}. ${CURRENCY_RULE}`;
|
|
47
|
+
export const budgetCheckupPromptText = (period) => `You are checking the user's budgets for ${formatPeriod(period)}. Call ${T.get_budget_status} and ` +
|
|
48
|
+
`${T.find_correlations} with analysis "budget_fit" (both scoped to month ${period.month} year ${period.year}). ` +
|
|
49
|
+
'Report which budgets are on track, over, or generous; surface each suggestedLimit; and flag any ' +
|
|
50
|
+
'unbudgeted category with a significant, established spend pattern. Offer to apply a suggestion — with ' +
|
|
51
|
+
`the user's say-so, call ${T.update_budget} (existing budget) or ${T.create_budget} (unbudgeted category) with the ` +
|
|
52
|
+
`suggested limit. ${CURRENCY_RULE}`;
|
|
53
|
+
const describeStatementSource = (source) => {
|
|
54
|
+
if (source === ImportStatementSource.enum.card) {
|
|
55
|
+
return `The statement is a credit-card statement — use ${T.import_card_statement}.`;
|
|
56
|
+
}
|
|
57
|
+
if (source === ImportStatementSource.enum.account) {
|
|
58
|
+
return `The statement is a bank/wallet account statement — use ${T.import_account_statement}.`;
|
|
59
|
+
}
|
|
60
|
+
return (`Ask the user whether this is a credit-card statement (${T.import_card_statement}) or a bank/wallet ` +
|
|
61
|
+
`account statement (${T.import_account_statement}) before importing.`);
|
|
62
|
+
};
|
|
63
|
+
export const importStatementPromptText = (source) => 'Ask the user to paste the statement text (or CSV lines) they want to import. ' +
|
|
64
|
+
`${describeStatementSource(source)} After importing, report the created / duplicate / needs_review / ` +
|
|
65
|
+
'error counts, then walk each needs_review item with the user one at a time so they can confirm or ' +
|
|
66
|
+
'correct its category before moving on.';
|
|
67
|
+
const periodPrompt = (text) => async ({ month, year }, { deps }) => ({
|
|
68
|
+
messages: [
|
|
69
|
+
{
|
|
70
|
+
role: 'user',
|
|
71
|
+
content: { type: 'text', text: text(resolvePromptPeriod({ month, year }, deps.clock())) },
|
|
72
|
+
},
|
|
73
|
+
],
|
|
74
|
+
});
|
|
75
|
+
const monthlyReviewPrompt = definePrompt({
|
|
76
|
+
name: PromptName.enum.monthly_review,
|
|
77
|
+
config: {
|
|
78
|
+
title: 'Monthly financial review',
|
|
79
|
+
description: 'Synthesize a per-currency monthly review: spending summary, the biggest shifts vs baseline, ' +
|
|
80
|
+
'budget fit, and recurring-payment candidates worth automating.',
|
|
81
|
+
argsSchema: PeriodPromptArgsSchema,
|
|
82
|
+
},
|
|
83
|
+
handle: periodPrompt(monthlyReviewPromptText),
|
|
84
|
+
});
|
|
85
|
+
const budgetCheckupPrompt = definePrompt({
|
|
86
|
+
name: PromptName.enum.budget_checkup,
|
|
87
|
+
config: {
|
|
88
|
+
title: 'Budget checkup',
|
|
89
|
+
description: 'Report which budgets are on track, over, or generous, surface suggested limits and unbudgeted ' +
|
|
90
|
+
'significant spend, and offer to apply the suggestions.',
|
|
91
|
+
argsSchema: PeriodPromptArgsSchema,
|
|
92
|
+
},
|
|
93
|
+
handle: periodPrompt(budgetCheckupPromptText),
|
|
94
|
+
});
|
|
95
|
+
const importStatementPrompt = definePrompt({
|
|
96
|
+
name: PromptName.enum.import_statement,
|
|
97
|
+
config: {
|
|
98
|
+
title: 'Import a statement',
|
|
99
|
+
description: 'Walk the user through pasting a card or account statement, importing it, and confirming any ' +
|
|
100
|
+
'needs_review items.',
|
|
101
|
+
argsSchema: ImportStatementPromptArgsSchema,
|
|
102
|
+
},
|
|
103
|
+
handle: async ({ source }) => ({
|
|
104
|
+
messages: [{ role: 'user', content: { type: 'text', text: importStatementPromptText(source) } }],
|
|
105
|
+
}),
|
|
106
|
+
});
|
|
107
|
+
/** Takes no arguments: the demo's language, country and trip come from the database (Feature Design 022 §6). */
|
|
108
|
+
const tourPrompt = definePrompt({
|
|
109
|
+
name: PromptName.enum.tour,
|
|
110
|
+
config: {
|
|
111
|
+
title: `Tour of the ${PRODUCT_NAME} demo`,
|
|
112
|
+
description: 'A six-step guided tour of the demo (balances, last month, budgets, a statement import, tagging the seeded ' +
|
|
113
|
+
'trip and building a dashboard, then installing for real). On a real database it only says how to start the demo.',
|
|
114
|
+
},
|
|
115
|
+
handle: async (_args, { deps }) => ({
|
|
116
|
+
messages: [{ role: 'user', content: { type: 'text', text: tourPromptText(await getTourContext(deps)) } }],
|
|
117
|
+
}),
|
|
118
|
+
});
|
|
119
|
+
/** Guided-workflow prompts (Feature Design 019, 022) — few and cross-domain, one module (ADR-025). */
|
|
120
|
+
export const promptDefinitions = [
|
|
121
|
+
monthlyReviewPrompt,
|
|
122
|
+
budgetCheckupPrompt,
|
|
123
|
+
importStatementPrompt,
|
|
124
|
+
tourPrompt,
|
|
125
|
+
];
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one registrar (ADR-025): registers any list of definitions on `server`. `server.registerTool/Resource/Prompt`
|
|
3
|
+
* are the scope-guarded ones (`guardScopes`), so a definition cannot be registered around the guard; each callback asks
|
|
4
|
+
* `ctx.as` for the caller's scoped dependencies, built from the principal the guard put on `extra`.
|
|
5
|
+
*/
|
|
6
|
+
export const registerDefinitions = (server, ctx, definitions) => {
|
|
7
|
+
definitions.prompts.forEach(({ name, config, handle }) => config.argsSchema
|
|
8
|
+
? server.registerPrompt(name, { ...config, argsSchema: config.argsSchema }, (args, extra) => handle(args, ctx.as(extra), ctx))
|
|
9
|
+
: server.registerPrompt(name, config, (extra) => handle({}, ctx.as(extra), ctx)));
|
|
10
|
+
definitions.resources.forEach(({ name, uri, config, read }) => server.registerResource(name, uri, config, (resourceUri, extra) => read(resourceUri, ctx.as(extra), ctx)));
|
|
11
|
+
definitions.tools.forEach(({ name, config, handle }) => server.registerTool(name, config, (args, extra) => handle(args, ctx.as(extra), ctx)));
|
|
12
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { withRemedyHint } from '../../common/errors.js';
|
|
2
|
+
import { ToolName } from './tool-name.js';
|
|
3
|
+
/** The MCP tool that performs each domain operation a rejected call is told to use instead. */
|
|
4
|
+
const REMEDY_TOOL = {
|
|
5
|
+
pay_bill: ToolName.enum.pay_bill,
|
|
6
|
+
revert_bill_payment: ToolName.enum.revert_bill_payment,
|
|
7
|
+
create_credit_card: ToolName.enum.create_credit_card,
|
|
8
|
+
update_credit_card: ToolName.enum.update_credit_card,
|
|
9
|
+
delete_credit_card: ToolName.enum.delete_credit_card,
|
|
10
|
+
update_account_transaction: ToolName.enum.update_account_transaction,
|
|
11
|
+
update_card_transaction: ToolName.enum.update_card_transaction,
|
|
12
|
+
delete_account_transaction: ToolName.enum.delete_account_transaction,
|
|
13
|
+
delete_card_transaction: ToolName.enum.delete_card_transaction,
|
|
14
|
+
};
|
|
15
|
+
export const remedyHint = (remedy) => `use ${REMEDY_TOOL[remedy]}`;
|
|
16
|
+
/** The error as an MCP reply shows it: a `remedy` becomes `hint: "use <tool>"`. */
|
|
17
|
+
export const withToolHint = (error) => withRemedyHint(error, remedyHint);
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { listAccounts } from '../../controllers/account/account.js';
|
|
2
|
+
import { listCategories } from '../../controllers/categories.js';
|
|
3
|
+
import { listCurrencies } from '../../controllers/currencies.js';
|
|
4
|
+
import { listExchangeRates } from '../../controllers/currency-rates.js';
|
|
5
|
+
import { topMerchants } from '../../controllers/merchants.js';
|
|
6
|
+
import { listCreditCards } from '../../controllers/credit-card/credit-card.js';
|
|
7
|
+
import { listTags } from '../../controllers/tags.js';
|
|
8
|
+
import { DEFAULT_TOP_MERCHANTS_LIMIT } from '../../models/merchant.js';
|
|
9
|
+
import { jsonResource } from './respond.js';
|
|
10
|
+
import { PRODUCT_NAME } from '../../models/package.js';
|
|
11
|
+
const openapiDescription = 'OpenAPI 3.0 document for the REST API (GET /api/openapi.json mirrors this). ' +
|
|
12
|
+
'Read this before generating fetch() calls against /api endpoints (ADR-013).';
|
|
13
|
+
const openApiResource = (openApiDocument) => ({
|
|
14
|
+
name: 'openapi',
|
|
15
|
+
uri: 'patty://openapi',
|
|
16
|
+
config: { title: `${PRODUCT_NAME} OpenAPI contract`, description: openapiDescription, mimeType: 'application/json' },
|
|
17
|
+
read: async (uri) => jsonResource(uri, openApiDocument),
|
|
18
|
+
});
|
|
19
|
+
const categoriesDescription = 'Top-level categories with locale-resolved display names and kind (expense/income/both) — the same ' +
|
|
20
|
+
'data list_categories returns. Read this to resolve a category name before classifying a transaction, ' +
|
|
21
|
+
'without a tool round-trip.';
|
|
22
|
+
const categoriesResource = {
|
|
23
|
+
name: 'categories',
|
|
24
|
+
uri: 'patty://categories',
|
|
25
|
+
config: { title: 'Category taxonomy', description: categoriesDescription, mimeType: 'application/json' },
|
|
26
|
+
read: async (uri, { deps }) => jsonResource(uri, await listCategories(deps)),
|
|
27
|
+
};
|
|
28
|
+
const accountsDescription = 'All accounts with name, type, and currency — the same data list_accounts returns. Read this to ' +
|
|
29
|
+
'resolve an account name without a tool round-trip.';
|
|
30
|
+
const accountsResource = {
|
|
31
|
+
name: 'accounts',
|
|
32
|
+
uri: 'patty://accounts',
|
|
33
|
+
config: { title: 'Accounts', description: accountsDescription, mimeType: 'application/json' },
|
|
34
|
+
read: async (uri, { deps }) => jsonResource(uri, await listAccounts(deps)),
|
|
35
|
+
};
|
|
36
|
+
const currenciesDescription = 'All currencies (fiat and crypto) with symbol and decimals — the same data GET /api/currencies returns. ' +
|
|
37
|
+
"Read this to format an amount correctly: crypto codes (USDC, BTC) aren't ISO 4217, so a generic currency " +
|
|
38
|
+
'formatter must use the symbol + decimals given here instead of assuming 2 decimal places.';
|
|
39
|
+
const currenciesResource = {
|
|
40
|
+
name: 'currencies',
|
|
41
|
+
uri: 'patty://currencies',
|
|
42
|
+
config: { title: 'Currencies', description: currenciesDescription, mimeType: 'application/json' },
|
|
43
|
+
read: async (uri, { deps }) => jsonResource(uri, await listCurrencies(deps)),
|
|
44
|
+
};
|
|
45
|
+
const exchangeRatesDescription = 'All cached exchange rates, each with its own as_of — the same data list_exchange_rates returns. ' +
|
|
46
|
+
`${PRODUCT_NAME} never fetches rates itself (local-first, ADR-026); read this to see which pairs are ` +
|
|
47
|
+
'cached and how fresh they are before deciding whether to refresh via set_exchange_rate(s).';
|
|
48
|
+
const exchangeRatesResource = {
|
|
49
|
+
name: 'exchange-rates',
|
|
50
|
+
uri: 'patty://exchange-rates',
|
|
51
|
+
config: { title: 'Exchange rates', description: exchangeRatesDescription, mimeType: 'application/json' },
|
|
52
|
+
read: async (uri, { deps }) => jsonResource(uri, await listExchangeRates(deps)),
|
|
53
|
+
};
|
|
54
|
+
const tagsResource = {
|
|
55
|
+
name: 'tags',
|
|
56
|
+
uri: 'patty://tags',
|
|
57
|
+
config: {
|
|
58
|
+
title: 'Tags',
|
|
59
|
+
description: 'All tags — the same data list_tags returns. Read this to resolve a tag name without a tool round-trip.',
|
|
60
|
+
mimeType: 'application/json',
|
|
61
|
+
},
|
|
62
|
+
read: async (uri, { deps }) => jsonResource(uri, await listTags(deps)),
|
|
63
|
+
};
|
|
64
|
+
const creditCardsDescription = 'All credit cards — the same data list_credit_cards returns. Read this to resolve a card name without ' +
|
|
65
|
+
'a tool round-trip.';
|
|
66
|
+
const creditCardsResource = {
|
|
67
|
+
name: 'credit-cards',
|
|
68
|
+
uri: 'patty://credit-cards',
|
|
69
|
+
config: { title: 'Credit cards', description: creditCardsDescription, mimeType: 'application/json' },
|
|
70
|
+
read: async (uri, { deps }) => jsonResource(uri, await listCreditCards(deps)),
|
|
71
|
+
};
|
|
72
|
+
const merchantsTopDescription = `The ${DEFAULT_TOP_MERCHANTS_LIMIT} merchants with the most effective, non-transfer transactions, each ` +
|
|
73
|
+
'with the category it is most often classified into — the vocabulary of merchants the user actually ' +
|
|
74
|
+
'deals with (e.g. "iFood → Alimentação"), by transaction frequency (not spend). Not a money report: no ' +
|
|
75
|
+
'per-currency amounts. categoryName is null for a merchant whose transactions are all uncategorized.';
|
|
76
|
+
const merchantsTopResource = {
|
|
77
|
+
name: 'merchants-top',
|
|
78
|
+
uri: 'patty://merchants/top',
|
|
79
|
+
config: { title: 'Top merchants', description: merchantsTopDescription, mimeType: 'application/json' },
|
|
80
|
+
read: async (uri, { deps }) => jsonResource(uri, await topMerchants(deps)),
|
|
81
|
+
};
|
|
82
|
+
/** The reference resources (Feature Design 018) plus the OpenAPI document — few and cross-domain, so one module rather
|
|
83
|
+
* than one per domain (ADR-025). The OpenAPI document is the one definition that needs context: it is built once. */
|
|
84
|
+
export const resourceDefinitions = (openApiDocument) => [
|
|
85
|
+
openApiResource(openApiDocument),
|
|
86
|
+
categoriesResource,
|
|
87
|
+
accountsResource,
|
|
88
|
+
currenciesResource,
|
|
89
|
+
exchangeRatesResource,
|
|
90
|
+
tagsResource,
|
|
91
|
+
creditCardsResource,
|
|
92
|
+
merchantsTopResource,
|
|
93
|
+
];
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { withToolHint } from './remedy.js';
|
|
2
|
+
/** Shared MCP tool response helpers (ADR-025) — one implementation for every tool module. */
|
|
3
|
+
export const json = (value) => ({
|
|
4
|
+
content: [{ type: 'text', text: JSON.stringify(value, null, 2) }],
|
|
5
|
+
});
|
|
6
|
+
export const jsonError = (e) => ({
|
|
7
|
+
content: [{ type: 'text', text: JSON.stringify({ error: withToolHint(e) }, null, 2) }],
|
|
8
|
+
isError: true,
|
|
9
|
+
});
|
|
10
|
+
/** A plain-text tool error — for an instruction a person must read (sign in), not a structured `AppError`. */
|
|
11
|
+
export const textError = (message) => ({
|
|
12
|
+
content: [{ type: 'text', text: message }],
|
|
13
|
+
isError: true,
|
|
14
|
+
});
|
|
15
|
+
export const fromResult = (result) => result.match(json, jsonError);
|
|
16
|
+
/** Shared by every static-URI JSON resource (`patty://openapi` and the Feature Design 018
|
|
17
|
+
* reference resources) — one `contents` entry, `application/json`, pretty-printed. */
|
|
18
|
+
export const jsonResource = (uri, value) => ({
|
|
19
|
+
contents: [{ uri: uri.href, mimeType: 'application/json', text: JSON.stringify(value, null, 2) }],
|
|
20
|
+
});
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { isInitializeRequest } from '@modelcontextprotocol/sdk/types.js';
|
|
2
|
+
import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
|
|
3
|
+
import { instanceFactsOf } from '../../controllers/instance.js';
|
|
4
|
+
import { hasScope, requiredMcpScope } from '../../logic/auth/scope.js';
|
|
5
|
+
import { MCP_PATH } from '../../models/auth/bearer.js';
|
|
6
|
+
import { authErrors } from '../../models/auth/errors.js';
|
|
7
|
+
import { READ_SCOPE } from '../../models/auth/scope.js';
|
|
8
|
+
import { rejectWithChallenge } from '../http/bearer.js';
|
|
9
|
+
import '../http/principal.js';
|
|
10
|
+
import { authInfoOf } from './auth-info.js';
|
|
11
|
+
import { authInfoGate } from './gate.js';
|
|
12
|
+
import { buildMcpServer } from './server.js';
|
|
13
|
+
import { toolScopesOf } from './scopes.js';
|
|
14
|
+
/**
|
|
15
|
+
* Stateless MCP over streamable HTTP: a fresh server+transport per request.
|
|
16
|
+
* Claude clients connect to POST /mcp.
|
|
17
|
+
*
|
|
18
|
+
* Authorization (ADR-033 §3): the auth hook has already authenticated the request and checked the route-level
|
|
19
|
+
* `read` scope (config below). A `preHandler` then reads the parsed JSON-RPC body and, for a `tools/call` of a
|
|
20
|
+
* write tool (any message, if the SDK is given a batch), demands `patty:write` — a short token gets a 403
|
|
21
|
+
* `insufficient_scope` challenge before any tool runs. The principal then travels to the tools as `req.raw.auth`
|
|
22
|
+
* (the SDK's `AuthInfo`), where `scopes.ts` checks it again.
|
|
23
|
+
*/
|
|
24
|
+
// Only `initialize` carries the server instructions, so only it reads the marker: a ping or a tool call must not
|
|
25
|
+
// fail because that read did.
|
|
26
|
+
const instanceForInitialize = async (tenancy, body) => [body].flat().some(isInitializeRequest) ? instanceFactsOf(tenancy) : undefined;
|
|
27
|
+
export const registerMcpRoute = (app, tenancy, version, publicUrl) => {
|
|
28
|
+
const scopeGuard = { gate: authInfoGate };
|
|
29
|
+
// Built once, only to learn which scope each tool needs; the per-request server below is identical.
|
|
30
|
+
const catalog = buildMcpServer(tenancy, version, scopeGuard);
|
|
31
|
+
const toolScopes = toolScopesOf(catalog);
|
|
32
|
+
app.post(MCP_PATH, {
|
|
33
|
+
config: { scope: READ_SCOPE },
|
|
34
|
+
preHandler: async (req, reply) => {
|
|
35
|
+
const required = requiredMcpScope(req.body, (name) => toolScopes.get(name));
|
|
36
|
+
const principal = req.principal;
|
|
37
|
+
if (principal && hasScope(principal.scopes, required))
|
|
38
|
+
return undefined;
|
|
39
|
+
const error = principal ? authErrors.insufficientScope(required) : authErrors.unauthenticated;
|
|
40
|
+
return rejectWithChallenge(req, reply, publicUrl, error);
|
|
41
|
+
},
|
|
42
|
+
}, async (req, reply) => {
|
|
43
|
+
const server = buildMcpServer(tenancy, version, scopeGuard, await instanceForInitialize(tenancy, req.body));
|
|
44
|
+
const transport = new StreamableHTTPServerTransport({
|
|
45
|
+
sessionIdGenerator: undefined,
|
|
46
|
+
enableJsonResponse: true,
|
|
47
|
+
});
|
|
48
|
+
// The SDK reads the caller's AuthInfo from `req.auth` and passes it to every tool as `extra.authInfo`.
|
|
49
|
+
if (req.principal)
|
|
50
|
+
req.raw.auth = authInfoOf(req.principal);
|
|
51
|
+
reply.hijack();
|
|
52
|
+
await server.connect(transport);
|
|
53
|
+
await transport.handleRequest(req.raw, reply.raw, req.body);
|
|
54
|
+
reply.raw.on('close', () => {
|
|
55
|
+
void transport.close();
|
|
56
|
+
void server.close();
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
// Stateless mode: no SSE stream or session to manage.
|
|
60
|
+
app.get(MCP_PATH, async (_req, reply) => reply.status(405).send({ error: 'method_not_allowed' }));
|
|
61
|
+
app.delete(MCP_PATH, async (_req, reply) => reply.status(405).send({ error: 'method_not_allowed' }));
|
|
62
|
+
};
|