@sdxc/kit 2026.10.17 → 2026.10.20
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/README.md +390 -20
- package/changelog.jsonl +1160 -1092
- package/config.schema.json +47 -1
- package/dist/cli.js +12 -0
- package/dist/commands/deploy.d.ts +23 -0
- package/dist/commands/deploy.js +167 -0
- package/dist/commands/destroy.d.ts +22 -0
- package/dist/commands/destroy.js +92 -0
- package/dist/commands/doctor.d.ts +26 -0
- package/dist/commands/doctor.js +65 -0
- package/dist/commands/initializers.d.ts +16 -0
- package/dist/commands/initializers.js +23 -0
- package/dist/commands/make.d.ts +72 -6
- package/dist/commands/make.js +127 -19
- package/dist/commands/middleware.d.ts +16 -0
- package/dist/commands/middleware.js +21 -0
- package/dist/commands/models.d.ts +18 -0
- package/dist/commands/models.js +29 -0
- package/dist/commands/notes.d.ts +17 -0
- package/dist/commands/notes.js +27 -0
- package/dist/commands/routes.d.ts +25 -0
- package/dist/commands/routes.js +50 -0
- package/dist/commands/run.d.ts +16 -0
- package/dist/commands/run.js +32 -11
- package/dist/commands/scaffold.d.ts +29 -0
- package/dist/commands/scaffold.js +33 -0
- package/dist/commands/schedule.d.ts +16 -0
- package/dist/commands/schedule.js +21 -0
- package/dist/commands/stats.d.ts +16 -0
- package/dist/commands/stats.js +21 -0
- package/dist/commands/ui/update.d.ts +6 -3
- package/dist/commands/ui/update.js +24 -7
- package/dist/commands/upgrade.d.ts +3 -1
- package/dist/commands/upgrade.js +88 -23
- package/dist/config.d.ts +18 -0
- package/dist/config.js +28 -1
- package/dist/contract.d.ts +97 -3
- package/dist/contract.js +360 -26
- package/dist/create/templates.js +3 -2
- package/dist/dependencies.d.ts +4 -1
- package/dist/dependencies.js +13 -1
- package/dist/deploy/plan.d.ts +49 -0
- package/dist/deploy/plan.js +68 -0
- package/dist/destroy.d.ts +40 -0
- package/dist/destroy.js +311 -0
- package/dist/doctor/check.d.ts +71 -0
- package/dist/doctor/check.js +53 -0
- package/dist/doctor/checks.d.ts +23 -0
- package/dist/doctor/checks.js +68 -0
- package/dist/doctor/define.d.ts +59 -0
- package/dist/doctor/define.js +16 -0
- package/dist/doctor/emails.d.ts +18 -0
- package/dist/doctor/emails.js +243 -0
- package/dist/doctor/env.d.ts +26 -0
- package/dist/doctor/env.js +88 -0
- package/dist/doctor/files.d.ts +14 -0
- package/dist/doctor/files.js +34 -0
- package/dist/doctor/fixture.d.ts +23 -0
- package/dist/doctor/fixture.js +46 -0
- package/dist/doctor/install.d.ts +17 -0
- package/dist/doctor/install.js +37 -0
- package/dist/doctor/installed.d.ts +11 -0
- package/dist/doctor/installed.js +79 -0
- package/dist/doctor/layout.d.ts +23 -0
- package/dist/doctor/layout.js +83 -0
- package/dist/doctor/migrations.d.ts +16 -0
- package/dist/doctor/migrations.js +96 -0
- package/dist/doctor/models.d.ts +13 -0
- package/dist/doctor/models.js +69 -0
- package/dist/doctor/pins.d.ts +15 -0
- package/dist/doctor/pins.js +79 -0
- package/dist/doctor/project.d.ts +58 -0
- package/dist/doctor/project.js +261 -0
- package/dist/doctor/remix.d.ts +14 -0
- package/dist/doctor/remix.js +44 -0
- package/dist/doctor/routes.d.ts +11 -0
- package/dist/doctor/routes.js +49 -0
- package/dist/doctor/typegen.d.ts +13 -0
- package/dist/doctor/typegen.js +57 -0
- package/dist/doctor/ui.d.ts +14 -0
- package/dist/doctor/ui.js +51 -0
- package/dist/initializers.d.ts +25 -0
- package/dist/initializers.js +89 -0
- package/dist/lock.d.ts +2 -2
- package/dist/make/actions.d.ts +23 -0
- package/dist/make/actions.js +82 -0
- package/dist/make/declare.d.ts +31 -3
- package/dist/make/declare.js +284 -9
- package/dist/make/email.d.ts +23 -0
- package/dist/make/email.js +111 -0
- package/dist/make/from-fields.d.ts +30 -0
- package/dist/make/from-fields.js +162 -0
- package/dist/make/from-model.d.ts +39 -0
- package/dist/make/from-model.js +161 -0
- package/dist/make/generate.d.ts +16 -5
- package/dist/make/generate.js +38 -15
- package/dist/make/guard.d.ts +35 -0
- package/dist/make/guard.js +73 -0
- package/dist/make/imports.d.ts +6 -0
- package/dist/make/imports.js +19 -0
- package/dist/make/index.d.ts +47 -4
- package/dist/make/index.js +287 -29
- package/dist/make/kinds.d.ts +29 -2
- package/dist/make/kinds.js +79 -7
- package/dist/make/mount.d.ts +25 -0
- package/dist/make/mount.js +135 -0
- package/dist/make/schema-diff.d.ts +58 -0
- package/dist/make/schema-diff.js +609 -0
- package/dist/make/schema.d.ts +76 -0
- package/dist/make/schema.js +206 -0
- package/dist/make/stubs.d.ts +7 -5
- package/dist/make/stubs.js +16 -5
- package/dist/make/test.d.ts +43 -0
- package/dist/make/test.js +149 -0
- package/dist/make/trigger.d.ts +31 -0
- package/dist/make/trigger.js +163 -0
- package/dist/models.d.ts +42 -0
- package/dist/models.js +149 -0
- package/dist/notes.d.ts +28 -0
- package/dist/notes.js +66 -0
- package/dist/reference.d.ts +27 -0
- package/dist/reference.js +103 -0
- package/dist/releases.d.ts +9 -0
- package/dist/releases.js +29 -8
- package/dist/routes/chains.d.ts +34 -0
- package/dist/routes/chains.js +95 -0
- package/dist/routes/filter.d.ts +53 -0
- package/dist/routes/filter.js +147 -0
- package/dist/routes/format.d.ts +23 -0
- package/dist/routes/format.js +123 -0
- package/dist/routes/helpers.d.ts +21 -0
- package/dist/routes/helpers.js +165 -0
- package/dist/routes/index.d.ts +56 -0
- package/dist/routes/index.js +167 -0
- package/dist/routes/modules.d.ts +116 -0
- package/dist/routes/modules.js +235 -0
- package/dist/routes/parse.d.ts +161 -0
- package/dist/routes/parse.js +621 -0
- package/dist/routes/routers.d.ts +69 -0
- package/dist/routes/routers.js +327 -0
- package/dist/scaffold/fields.d.ts +129 -0
- package/dist/scaffold/fields.js +421 -0
- package/dist/scaffold/index.d.ts +37 -0
- package/dist/scaffold/index.js +613 -0
- package/dist/scaffold/render.d.ts +51 -0
- package/dist/scaffold/render.js +332 -0
- package/dist/schedule.d.ts +45 -0
- package/dist/schedule.js +124 -0
- package/dist/stats.d.ts +37 -0
- package/dist/stats.js +126 -0
- package/dist/ui/commands.d.ts +10 -3
- package/dist/ui/commands.js +85 -15
- package/dist/ui/registry.d.ts +8 -8
- package/dist/upgrade/agents.d.ts +49 -0
- package/dist/upgrade/agents.js +110 -0
- package/dist/upgrade/changelog.d.ts +2 -2
- package/dist/upgrade/project.d.ts +4 -0
- package/dist/upgrade/project.js +11 -1
- package/dist/upgrade/prompt.d.ts +11 -0
- package/dist/upgrade/prompt.js +50 -7
- package/package.json +6 -4
- package/registry/ui/alert-dialog.json +2 -2
- package/registry/ui/attachment.json +2 -2
- package/registry/ui/calendar.json +2 -2
- package/registry/ui/color-picker.json +2 -2
- package/registry/ui/command.json +2 -2
- package/registry/ui/date-picker.json +2 -2
- package/registry/ui/date-range-picker.json +2 -2
- package/registry/ui/dialog.json +2 -2
- package/registry/ui/file-trigger.json +2 -2
- package/registry/ui/heading-scope.json +2 -2
- package/registry/ui/message-scroller.json +2 -2
- package/registry/ui/number-field.json +2 -2
- package/registry/ui/range-calendar.json +2 -2
- package/registry/ui/resizable.json +2 -2
- package/registry/ui/select.json +2 -2
- package/registry/ui/shared-element.json +2 -2
- package/stubs/controller.api.resource.stub +23 -0
- package/stubs/controller.form.stub +2 -2
- package/stubs/controller.form.test.stub +2 -2
- package/stubs/controller.resource.form.stub +67 -0
- package/stubs/controller.resource.stub +28 -0
- package/stubs/email.stub +9 -14
- package/stubs/email.test.stub +9 -9
- package/stubs/factory.stub +1 -1
- package/stubs/model.stub +3 -3
- package/stubs/policy.test.stub +34 -8
- package/stubs/scaffold.api.create.stub +34 -0
- package/stubs/scaffold.api.create.test.stub +37 -0
- package/stubs/scaffold.api.destroy.stub +34 -0
- package/stubs/scaffold.api.destroy.test.stub +44 -0
- package/stubs/scaffold.api.index.stub +23 -0
- package/stubs/scaffold.api.index.test.stub +31 -0
- package/stubs/scaffold.api.show.stub +27 -0
- package/stubs/scaffold.api.show.test.stub +41 -0
- package/stubs/scaffold.api.update.stub +44 -0
- package/stubs/scaffold.api.update.test.stub +46 -0
- package/stubs/scaffold.command.create.stub +22 -0
- package/stubs/scaffold.command.create.test.stub +30 -0
- package/stubs/scaffold.command.delete.stub +20 -0
- package/stubs/scaffold.command.delete.test.stub +39 -0
- package/stubs/scaffold.command.list.stub +18 -0
- package/stubs/scaffold.command.list.test.stub +31 -0
- package/stubs/scaffold.command.show.stub +19 -0
- package/stubs/scaffold.command.show.test.stub +37 -0
- package/stubs/scaffold.controller.destroy.stub +35 -0
- package/stubs/scaffold.controller.destroy.test.stub +65 -0
- package/stubs/scaffold.controller.edit.stub +97 -0
- package/stubs/scaffold.controller.edit.test.stub +91 -0
- package/stubs/scaffold.controller.index.stub +55 -0
- package/stubs/scaffold.controller.index.test.stub +32 -0
- package/stubs/scaffold.controller.new.stub +70 -0
- package/stubs/scaffold.controller.new.test.stub +81 -0
- package/stubs/scaffold.controller.show.stub +59 -0
- package/stubs/scaffold.controller.show.test.stub +43 -0
- package/stubs/scaffold.factory.stub +16 -0
- package/stubs/scaffold.form.stub +75 -0
- package/stubs/scaffold.mcp.create.stub +24 -0
- package/stubs/scaffold.mcp.create.test.stub +36 -0
- package/stubs/scaffold.mcp.delete.stub +31 -0
- package/stubs/scaffold.mcp.delete.test.stub +43 -0
- package/stubs/scaffold.mcp.get.stub +21 -0
- package/stubs/scaffold.mcp.get.test.stub +31 -0
- package/stubs/scaffold.mcp.list.stub +23 -0
- package/stubs/scaffold.mcp.list.test.stub +25 -0
- package/stubs/scaffold.mcp.update.stub +37 -0
- package/stubs/scaffold.mcp.update.test.stub +40 -0
- package/stubs/scaffold.migration.stub +2 -0
- package/stubs/scaffold.model.stub +35 -0
- package/stubs/scaffold.model.test.stub +25 -0
- package/stubs/scaffold.test-database.stub +33 -0
- package/stubs/scaffold.test-mcp.stub +92 -0
- package/stubs/scaffold.validator.stub +18 -0
- package/stubs/scaffold.validator.test.stub +26 -0
- package/templates/app/AGENTS.md +163 -0
- package/templates/app/CLAUDE.md +1 -0
- package/templates/app/README.md +28 -13
- package/templates/app/app/commands/console.test.ts +26 -0
- package/templates/app/app/commands/console.ts +19 -0
- package/templates/app/app/commands/db/fresh.test.ts +57 -0
- package/templates/app/app/commands/db/fresh.ts +37 -0
- package/templates/app/app/commands/db/migrate.test.ts +17 -1
- package/templates/app/app/commands/db/migrate.ts +51 -18
- package/templates/app/app/commands/db/prepare.test.ts +39 -0
- package/templates/app/app/commands/db/prepare.ts +35 -0
- package/templates/app/app/commands/db/seed.test.ts +38 -0
- package/templates/app/app/commands/db/seed.ts +26 -0
- package/templates/app/app/commands/deploy.test.ts +34 -0
- package/templates/app/app/commands/deploy.ts +18 -0
- package/templates/app/app/commands/emails/preview.test.tsx +63 -0
- package/templates/app/app/commands/emails/preview.ts +24 -0
- package/templates/app/app/commands/index.ts +57 -2
- package/templates/app/app/emails/index.ts +10 -0
- package/templates/app/app/http/middleware/access.test.ts +43 -0
- package/templates/app/app/http/middleware/access.ts +41 -0
- package/templates/app/app/http/middleware/api.ts +12 -3
- package/templates/app/app/http/middleware/page.test.ts +4 -1
- package/templates/app/app/http/middleware/page.ts +7 -5
- package/templates/app/app/initializers/cli.ts +28 -2
- package/templates/app/app/initializers/dispatcher.ts +9 -1
- package/templates/app/app/initializers/mail-transport.test.ts +27 -0
- package/templates/app/app/initializers/mail-transport.ts +26 -0
- package/templates/app/app/initializers/mail.test.ts +17 -17
- package/templates/app/app/initializers/mail.ts +15 -7
- package/templates/app/app/initializers/router.test.ts +7 -0
- package/templates/app/app/initializers/router.tsx +13 -3
- package/templates/app/app/jobs/email.test.tsx +70 -0
- package/templates/app/app/jobs/email.ts +16 -0
- package/templates/app/app/jobs/index.ts +6 -2
- package/templates/app/app/policies/abilities.ts +13 -0
- package/templates/app/app/policies/policy.test.ts +15 -0
- package/templates/app/app/policies/policy.ts +30 -0
- package/templates/app/app/services/commands.ts +30 -0
- package/templates/app/app/services/migrations.test.ts +48 -1
- package/templates/app/app/services/migrations.ts +66 -9
- package/templates/app/app/test/local-database.ts +67 -0
- package/templates/app/app/test/session.ts +28 -0
- package/templates/app/bootstrap/console.ts +13 -0
- package/templates/app/cloudflare.config.ts +3 -3
- package/templates/app/database/seed.ts +12 -0
- package/templates/app/package.json +2 -1
- package/stubs/policy.stub +0 -16
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `create_{{snake}}` tool, called over `/mcp` as a client calls it: as a member, whom
|
|
3
|
+
* `{{path}}.create` allows, and as a guest, whom it refuses.
|
|
4
|
+
*
|
|
5
|
+
* @see {@link https://sdxc.dev/docs/operations-and-testing/mcp-server}
|
|
6
|
+
* @see {@link https://sdxc.dev/docs/operations-and-testing/testing}{{header}}
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { beforeAll, describe, expect, test } from "vitest";
|
|
10
|
+
|
|
11
|
+
import { openDatabase } from "~/app/initializers/database";
|
|
12
|
+
import { {{Name}} } from "~/app/models/{{name}}";
|
|
13
|
+
import { migrate } from "~/app/test/database";
|
|
14
|
+
import { callTool } from "~/app/test/mcp";
|
|
15
|
+
|
|
16
|
+
beforeAll(migrate);
|
|
17
|
+
|
|
18
|
+
describe("create_{{snake}}", () => {
|
|
19
|
+
test("writes a {{words}} and answers it with its id", async () => {
|
|
20
|
+
let result = await callTool("create_{{snake}}", { {{jsonSample}} }, "member");
|
|
21
|
+
|
|
22
|
+
expect(result.isError).toBe(false);
|
|
23
|
+
let { id } = JSON.parse(result.text) as { id: string };
|
|
24
|
+
expect(await {{Name}}.bind({ db: openDatabase() }).find(id)).not.toBeNull();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
test("refuses a guest, writing nothing", async () => {
|
|
28
|
+
let before = await {{Name}}.bind({ db: openDatabase() }).query().all();
|
|
29
|
+
|
|
30
|
+
let result = await callTool("create_{{snake}}", { {{jsonSample}} });
|
|
31
|
+
|
|
32
|
+
let after = await {{Name}}.bind({ db: openDatabase() }).query().all();
|
|
33
|
+
expect(result.isError).toBe(true);
|
|
34
|
+
expect(after).toHaveLength(before.length);
|
|
35
|
+
});
|
|
36
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Answers `delete_{{snake}}`: deletes the {{words}} with the id and answers it as it was. An id
|
|
3
|
+
* no {{words}} has, or one `{{path}}.read` hides, is a tool error; a caller `{{path}}.delete`
|
|
4
|
+
* refuses is a forbidden call.
|
|
5
|
+
*
|
|
6
|
+
* @see {@link https://sdxc.dev/docs/operations-and-testing/mcp-server}
|
|
7
|
+
* @see {@link https://sdxc.dev/api/mcp}{{header}}
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { createTool, ForbiddenError, ToolError } from "@sdxc/mcp";
|
|
11
|
+
import { isFailure } from "@sdxc/result";
|
|
12
|
+
|
|
13
|
+
import toolset from "~/app/mcp/tools";
|
|
14
|
+
import { {{Name}} } from "~/app/models/{{name}}";
|
|
15
|
+
import abilities from "~/app/policies/abilities";
|
|
16
|
+
|
|
17
|
+
export default createTool(toolset.{{pluralKey}}.delete, async (ctx) => {
|
|
18
|
+
let model = {{Name}}.bind({ db: ctx.db });
|
|
19
|
+
let row = await model.find(ctx.input.id);
|
|
20
|
+
if (row === null || !ctx.access.can(abilities.{{path}}.read, { {{key}}: row })) {
|
|
21
|
+
throw new ToolError(`No {{words}} has the id ${ctx.input.id}; list_{{pluralSnake}} lists them.`);
|
|
22
|
+
}
|
|
23
|
+
if (!ctx.access.can(abilities.{{path}}.delete, { {{key}}: row })) {
|
|
24
|
+
throw new ForbiddenError("{{path}}.delete is not permitted");
|
|
25
|
+
}
|
|
26
|
+
let deleted = await model.delete(ctx.input.id);
|
|
27
|
+
if (isFailure(deleted)) {
|
|
28
|
+
throw new ToolError(`No {{words}} has the id ${ctx.input.id}; list_{{pluralSnake}} lists them.`);
|
|
29
|
+
}
|
|
30
|
+
return deleted.data;
|
|
31
|
+
});
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `delete_{{snake}}` tool, called over `/mcp` as a client calls it: as a member, whom
|
|
3
|
+
* `{{path}}.delete` allows, and as a guest, whom it refuses.
|
|
4
|
+
*
|
|
5
|
+
* @see {@link https://sdxc.dev/docs/operations-and-testing/mcp-server}
|
|
6
|
+
* @see {@link https://sdxc.dev/docs/operations-and-testing/testing}{{header}}
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { beforeAll, describe, expect, test } from "vitest";
|
|
10
|
+
|
|
11
|
+
import { openDatabase } from "~/app/initializers/database";
|
|
12
|
+
import { {{Name}} } from "~/app/models/{{name}}";
|
|
13
|
+
import { factories, migrate } from "~/app/test/database";
|
|
14
|
+
import { callTool } from "~/app/test/mcp";
|
|
15
|
+
import { {{Name}}Factory } from "~/database/factories/{{name}}";
|
|
16
|
+
|
|
17
|
+
beforeAll(migrate);
|
|
18
|
+
|
|
19
|
+
describe("delete_{{snake}}", () => {
|
|
20
|
+
test("deletes the {{words}} with the id", async () => {
|
|
21
|
+
let row = await factories().create({{Name}}Factory);
|
|
22
|
+
|
|
23
|
+
let result = await callTool("delete_{{snake}}", { id: row.id }, "member");
|
|
24
|
+
|
|
25
|
+
expect(result.isError).toBe(false);
|
|
26
|
+
expect(await {{Name}}.bind({ db: openDatabase() }).find(row.id)).toBeNull();
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test("reports an id no {{words}} has", async () => {
|
|
30
|
+
let result = await callTool("delete_{{snake}}", { id: "missing" }, "member");
|
|
31
|
+
|
|
32
|
+
expect(result.isError).toBe(true);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test("refuses a guest and keeps the {{words}}", async () => {
|
|
36
|
+
let row = await factories().create({{Name}}Factory);
|
|
37
|
+
|
|
38
|
+
let result = await callTool("delete_{{snake}}", { id: row.id });
|
|
39
|
+
|
|
40
|
+
expect(result.isError).toBe(true);
|
|
41
|
+
expect(await {{Name}}.bind({ db: openDatabase() }).find(row.id)).not.toBeNull();
|
|
42
|
+
});
|
|
43
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Answers `get_{{snake}}`: one {{words}} by its id, every field included. An id no {{words}} has,
|
|
3
|
+
* or one `{{path}}.read` hides, is a tool error pointing the model at `list_{{pluralSnake}}`.
|
|
4
|
+
*
|
|
5
|
+
* @see {@link https://sdxc.dev/docs/operations-and-testing/mcp-server}
|
|
6
|
+
* @see {@link https://sdxc.dev/api/mcp}{{header}}
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { createTool, ToolError } from "@sdxc/mcp";
|
|
10
|
+
|
|
11
|
+
import toolset from "~/app/mcp/tools";
|
|
12
|
+
import { {{Name}} } from "~/app/models/{{name}}";
|
|
13
|
+
import abilities from "~/app/policies/abilities";
|
|
14
|
+
|
|
15
|
+
export default createTool(toolset.{{pluralKey}}.get, async (ctx) => {
|
|
16
|
+
let row = await {{Name}}.bind({ db: ctx.db }).find(ctx.input.id);
|
|
17
|
+
if (row === null || !ctx.access.can(abilities.{{path}}.read, { {{key}}: row })) {
|
|
18
|
+
throw new ToolError(`No {{words}} has the id ${ctx.input.id}; list_{{pluralSnake}} lists them.`);
|
|
19
|
+
}
|
|
20
|
+
return row;
|
|
21
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `get_{{snake}}` tool, called over `/mcp` as a client calls it.
|
|
3
|
+
*
|
|
4
|
+
* @see {@link https://sdxc.dev/docs/operations-and-testing/mcp-server}
|
|
5
|
+
* @see {@link https://sdxc.dev/docs/operations-and-testing/testing}{{header}}
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { beforeAll, describe, expect, test } from "vitest";
|
|
9
|
+
|
|
10
|
+
import { factories, migrate } from "~/app/test/database";
|
|
11
|
+
import { callTool } from "~/app/test/mcp";
|
|
12
|
+
import { {{Name}}Factory } from "~/database/factories/{{name}}";
|
|
13
|
+
|
|
14
|
+
beforeAll(migrate);
|
|
15
|
+
|
|
16
|
+
describe("get_{{snake}}", () => {
|
|
17
|
+
test("answers the {{words}} with the id", async () => {
|
|
18
|
+
let row = await factories().create({{Name}}Factory);
|
|
19
|
+
|
|
20
|
+
let result = await callTool("get_{{snake}}", { id: row.id });
|
|
21
|
+
|
|
22
|
+
expect(result.isError).toBe(false);
|
|
23
|
+
expect(JSON.parse(result.text)).toMatchObject({ id: row.id });
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
test("reports an id no {{words}} has", async () => {
|
|
27
|
+
let result = await callTool("get_{{snake}}", { id: "missing" });
|
|
28
|
+
|
|
29
|
+
expect(result.isError).toBe(true);
|
|
30
|
+
});
|
|
31
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Answers `list_{{pluralSnake}}`: the newest {{pluralWords}} first, up to `limit`, so a model sees
|
|
3
|
+
* what exists before it reads one in full with `get_{{snake}}`. A {{words}} `{{path}}.read`
|
|
4
|
+
* hides is left out.
|
|
5
|
+
*
|
|
6
|
+
* @see {@link https://sdxc.dev/docs/operations-and-testing/mcp-server}
|
|
7
|
+
* @see {@link https://sdxc.dev/api/mcp}{{header}}
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { createTool } from "@sdxc/mcp";
|
|
11
|
+
|
|
12
|
+
import toolset from "~/app/mcp/tools";
|
|
13
|
+
import { {{Name}} } from "~/app/models/{{name}}";
|
|
14
|
+
import abilities from "~/app/policies/abilities";
|
|
15
|
+
|
|
16
|
+
export default createTool(toolset.{{pluralKey}}.list, async (ctx) => {
|
|
17
|
+
let rows = await {{Name}}.bind({ db: ctx.db })
|
|
18
|
+
.query()
|
|
19
|
+
.orderBy("created_at", "desc")
|
|
20
|
+
.limit(ctx.input.limit)
|
|
21
|
+
.all();
|
|
22
|
+
return rows.filter((row) => ctx.access.can(abilities.{{path}}.read, { {{key}}: row }));
|
|
23
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `list_{{pluralSnake}}` tool, called over `/mcp` as a client calls it.
|
|
3
|
+
*
|
|
4
|
+
* @see {@link https://sdxc.dev/docs/operations-and-testing/mcp-server}
|
|
5
|
+
* @see {@link https://sdxc.dev/docs/operations-and-testing/testing}{{header}}
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { beforeAll, describe, expect, test } from "vitest";
|
|
9
|
+
|
|
10
|
+
import { factories, migrate } from "~/app/test/database";
|
|
11
|
+
import { callTool } from "~/app/test/mcp";
|
|
12
|
+
import { {{Name}}Factory } from "~/database/factories/{{name}}";
|
|
13
|
+
|
|
14
|
+
beforeAll(migrate);
|
|
15
|
+
|
|
16
|
+
describe("list_{{pluralSnake}}", () => {
|
|
17
|
+
test("answers the {{pluralWords}} there are", async () => {
|
|
18
|
+
let row = await factories().create({{Name}}Factory);
|
|
19
|
+
|
|
20
|
+
let result = await callTool("list_{{pluralSnake}}", {});
|
|
21
|
+
|
|
22
|
+
expect(result.isError).toBe(false);
|
|
23
|
+
expect(result.text).toContain(row.id);
|
|
24
|
+
});
|
|
25
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Answers `update_{{snake}}`: changes the fields the call names on the {{words}} with the id, and
|
|
3
|
+
* answers it as saved. An id no {{words}} has, one `{{path}}.read` hides, or a write the database
|
|
4
|
+
* refuses is a tool error; a caller `{{path}}.update` refuses is a forbidden call.
|
|
5
|
+
*
|
|
6
|
+
* @see {@link https://sdxc.dev/docs/operations-and-testing/mcp-server}
|
|
7
|
+
* @see {@link https://sdxc.dev/api/mcp}{{header}}
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { NotFound } from "@sdxc/data-model";
|
|
11
|
+
import { createTool, ForbiddenError, ToolError } from "@sdxc/mcp";
|
|
12
|
+
import { isFailure } from "@sdxc/result";
|
|
13
|
+
|
|
14
|
+
import toolset from "~/app/mcp/tools";
|
|
15
|
+
import { {{Name}} } from "~/app/models/{{name}}";
|
|
16
|
+
import abilities from "~/app/policies/abilities";
|
|
17
|
+
|
|
18
|
+
export default createTool(toolset.{{pluralKey}}.update, async (ctx) => {
|
|
19
|
+
let { id, ...changes } = ctx.input;
|
|
20
|
+
let model = {{Name}}.bind({ db: ctx.db });
|
|
21
|
+
let row = await model.find(id);
|
|
22
|
+
if (row === null || !ctx.access.can(abilities.{{path}}.read, { {{key}}: row })) {
|
|
23
|
+
throw new ToolError(`No {{words}} has the id ${id}; list_{{pluralSnake}} lists them.`);
|
|
24
|
+
}
|
|
25
|
+
if (!ctx.access.can(abilities.{{path}}.update, { {{key}}: row })) {
|
|
26
|
+
throw new ForbiddenError("{{path}}.update is not permitted");
|
|
27
|
+
}
|
|
28
|
+
let updated = await model.update(id, changes);
|
|
29
|
+
if (isFailure(updated)) {
|
|
30
|
+
throw new ToolError(
|
|
31
|
+
updated.error instanceof NotFound
|
|
32
|
+
? `No {{words}} has the id ${id}; list_{{pluralSnake}} lists them.`
|
|
33
|
+
: updated.error.message,
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
return updated.data;
|
|
37
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `update_{{snake}}` tool, called over `/mcp` as a client calls it: as a member, whom
|
|
3
|
+
* `{{path}}.update` allows, and as a guest, whom it refuses.
|
|
4
|
+
*
|
|
5
|
+
* @see {@link https://sdxc.dev/docs/operations-and-testing/mcp-server}
|
|
6
|
+
* @see {@link https://sdxc.dev/docs/operations-and-testing/testing}{{header}}
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { beforeAll, describe, expect, test } from "vitest";
|
|
10
|
+
|
|
11
|
+
import { factories, migrate } from "~/app/test/database";
|
|
12
|
+
import { callTool } from "~/app/test/mcp";
|
|
13
|
+
import { {{Name}}Factory } from "~/database/factories/{{name}}";
|
|
14
|
+
|
|
15
|
+
beforeAll(migrate);
|
|
16
|
+
|
|
17
|
+
describe("update_{{snake}}", () => {
|
|
18
|
+
test("changes the fields it names and keeps the rest", async () => {
|
|
19
|
+
let row = await factories().create({{Name}}Factory);
|
|
20
|
+
|
|
21
|
+
let result = await callTool("update_{{snake}}", { id: row.id, {{changedJson}} }, "member");
|
|
22
|
+
|
|
23
|
+
expect(result.isError).toBe(false);
|
|
24
|
+
expect(JSON.parse(result.text)).toMatchObject({ id: row.id, {{changedJson}} });
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
test("reports an id no {{words}} has", async () => {
|
|
28
|
+
let result = await callTool("update_{{snake}}", { id: "missing" }, "member");
|
|
29
|
+
|
|
30
|
+
expect(result.isError).toBe(true);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test("refuses a guest", async () => {
|
|
34
|
+
let row = await factories().create({{Name}}Factory);
|
|
35
|
+
|
|
36
|
+
let result = await callTool("update_{{snake}}", { id: row.id, {{changedJson}} });
|
|
37
|
+
|
|
38
|
+
expect(result.isError).toBe(true);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The {{title}} model over the `{{table}}` table, with a column per field `sdxc scaffold` was
|
|
3
|
+
* given. Keep the columns in step with the migrations that change the table, and add the rules
|
|
4
|
+
* that keep a {{words}} consistent as callbacks.
|
|
5
|
+
*
|
|
6
|
+
* @see {@link https://sdxc.dev/docs/data-and-background-work/data-models}
|
|
7
|
+
* @see {@link https://sdxc.dev/api/data-model}{{header}}
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { TableRow } from "remix/data-table";
|
|
11
|
+
|
|
12
|
+
import { createModel } from "@sdxc/data-model";
|
|
13
|
+
import { generateUUID } from "@sdxc/uuid/v7";
|
|
14
|
+
import { column as c, table } from "remix/data-table";
|
|
15
|
+
|
|
16
|
+
/** The `{{table}}` table, as its migration creates it. */
|
|
17
|
+
export const {{key}}Table = table({
|
|
18
|
+
name: "{{table}}",
|
|
19
|
+
columns: {
|
|
20
|
+
id: c.text().primaryKey(),
|
|
21
|
+
{{columns}}
|
|
22
|
+
created_at: c.integer(),
|
|
23
|
+
updated_at: c.integer(),
|
|
24
|
+
},
|
|
25
|
+
/** `create` and `update` stamp `created_at` and `updated_at` with the database's clock. */
|
|
26
|
+
timestamps: true,
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
/** One {{words}} as it reads back from the database. */
|
|
30
|
+
export type {{Name}}Row = TableRow<typeof {{key}}Table>;
|
|
31
|
+
|
|
32
|
+
/** {{pluralTitle}}, each created with a time-ordered id; a handler reaches them as `ctx.models.{{key}}`. */
|
|
33
|
+
export const {{Name}} = createModel({{key}}Table, { generateId: generateUUID });
|
|
34
|
+
|
|
35
|
+
export default {{Name}};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The {{title}} model, writing to and reading from the `{{table}}` table its migration creates.
|
|
3
|
+
*
|
|
4
|
+
* @see {@link https://sdxc.dev/docs/data-and-background-work/data-models}
|
|
5
|
+
* @see {@link https://sdxc.dev/docs/operations-and-testing/testing}{{header}}
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { beforeAll, describe, expect, test } from "vitest";
|
|
9
|
+
|
|
10
|
+
import { openDatabase } from "~/app/initializers/database";
|
|
11
|
+
import { {{Name}} } from "~/app/models/{{name}}";
|
|
12
|
+
import { factories, migrate } from "~/app/test/database";
|
|
13
|
+
import { {{Name}}Factory } from "~/database/factories/{{name}}";
|
|
14
|
+
|
|
15
|
+
beforeAll(migrate);
|
|
16
|
+
|
|
17
|
+
describe("{{Name}}", () => {
|
|
18
|
+
test("reads back a {{words}} it created", async () => {
|
|
19
|
+
let created = await factories().create({{Name}}Factory);
|
|
20
|
+
|
|
21
|
+
let found = await {{Name}}.bind({ db: openDatabase() }).find(created.id);
|
|
22
|
+
|
|
23
|
+
expect(found).toMatchObject({ id: created.id });
|
|
24
|
+
});
|
|
25
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The database a test reads and writes: the in-memory `DB` binding with every migration in
|
|
3
|
+
* `database/migrations/` applied in name order, as `sdxc run db migrate` applies them, and
|
|
4
|
+
* factories that write through the app's own models.
|
|
5
|
+
*
|
|
6
|
+
* @see {@link https://sdxc.dev/docs/operations-and-testing/test-data}{{header}}
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { createFactories } from "@sdxc/data-model/testing";
|
|
10
|
+
import { env } from "cloudflare:workers";
|
|
11
|
+
|
|
12
|
+
import { openDatabase } from "~/app/initializers/database";
|
|
13
|
+
import registry from "~/app/models";
|
|
14
|
+
|
|
15
|
+
/** Every migration's SQL by path, bundled by Vite, so a test reads them without the file system. */
|
|
16
|
+
const MIGRATIONS = import.meta.glob<string>("/database/migrations/*.sql", {
|
|
17
|
+
query: "?raw",
|
|
18
|
+
import: "default",
|
|
19
|
+
eager: true,
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Applies every migration to the `DB` binding. Each test file starts with an empty binding, so a
|
|
24
|
+
* file runs this once, in `beforeAll`.
|
|
25
|
+
*/
|
|
26
|
+
export async function migrate(): Promise<void> {
|
|
27
|
+
for (let path of Object.keys(MIGRATIONS).sort()) await env.DB.exec(MIGRATIONS[path] ?? "");
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Factories writing through the app's models over the `DB` binding, with values that repeat run to run. */
|
|
31
|
+
export function factories() {
|
|
32
|
+
return createFactories(registry.bind({ db: openDatabase() }), { seed: 1 });
|
|
33
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calls the app's MCP tools the way a client does: a JSON-RPC `tools/call` posted to `/mcp`. A
|
|
3
|
+
* guest's call goes through the app's router, running every middleware a real call runs; a
|
|
4
|
+
* member's goes through a router binding that principal, which the API grants nobody yet.
|
|
5
|
+
*
|
|
6
|
+
* @see {@link https://sdxc.dev/docs/operations-and-testing/mcp-server}{{header}}
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { access } from "@sdxc/authz/middleware/router";
|
|
10
|
+
import { models } from "@sdxc/data-model/router";
|
|
11
|
+
import { database } from "@sdxc/database-middleware";
|
|
12
|
+
import { LATEST_PROTOCOL_VERSION, MetaKey } from "@sdxc/mcp";
|
|
13
|
+
import { createRouter } from "remix/router";
|
|
14
|
+
|
|
15
|
+
import { openDatabase } from "~/app/initializers/database";
|
|
16
|
+
import mcp from "~/app/initializers/mcp";
|
|
17
|
+
import { createWebRouter } from "~/app/initializers/router";
|
|
18
|
+
import registry from "~/app/models";
|
|
19
|
+
import abilities from "~/app/policies/abilities";
|
|
20
|
+
import policy from "~/app/policies/policy";
|
|
21
|
+
import routes from "~/routes/api";
|
|
22
|
+
|
|
23
|
+
/** Who a call is made as: a guest, as the API binds every caller, or a signed-in member. */
|
|
24
|
+
export type Caller = "guest" | "member";
|
|
25
|
+
|
|
26
|
+
/** What a call answered: its text, and whether the tool, or the protocol, reported a failure. */
|
|
27
|
+
export interface ToolCall {
|
|
28
|
+
text: string;
|
|
29
|
+
isError: boolean;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** The JSON-RPC response to a `tools/call`. */
|
|
33
|
+
interface CallResponse {
|
|
34
|
+
result?: { content?: Array<{ text?: string }>; isError?: boolean };
|
|
35
|
+
error?: { message?: string };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* A router answering `/mcp` over the app's database and models as a member, the principal the
|
|
40
|
+
* API binds once it authenticates its callers.
|
|
41
|
+
*/
|
|
42
|
+
function createMemberRouter() {
|
|
43
|
+
let router = createRouter({
|
|
44
|
+
middleware: [
|
|
45
|
+
database(openDatabase()),
|
|
46
|
+
models(registry, (ctx) => ({ db: ctx.db })),
|
|
47
|
+
access(policy, { roles: ["member"], facts: { actor: { id: "1" } }, load: [abilities] }),
|
|
48
|
+
],
|
|
49
|
+
});
|
|
50
|
+
router.map(routes.mcp, (ctx) => mcp.fetch(ctx));
|
|
51
|
+
return router;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Calls the tool `name` with `args` as `caller`. A protocol error, such as arguments the tool's
|
|
56
|
+
* schema refuses or a forbidden call, answers its message as a failure.
|
|
57
|
+
*/
|
|
58
|
+
export async function callTool(
|
|
59
|
+
name: string,
|
|
60
|
+
args: Record<string, unknown>,
|
|
61
|
+
caller: Caller = "guest",
|
|
62
|
+
): Promise<ToolCall> {
|
|
63
|
+
let router = caller === "member" ? createMemberRouter() : createWebRouter();
|
|
64
|
+
let response = await router.fetch(
|
|
65
|
+
new Request(new URL(routes.mcp.href(), "https://example.com"), {
|
|
66
|
+
method: "POST",
|
|
67
|
+
headers: {
|
|
68
|
+
"Content-Type": "application/json",
|
|
69
|
+
"MCP-Protocol-Version": LATEST_PROTOCOL_VERSION,
|
|
70
|
+
"Mcp-Method": "tools/call",
|
|
71
|
+
"Mcp-Name": name,
|
|
72
|
+
},
|
|
73
|
+
body: JSON.stringify({
|
|
74
|
+
jsonrpc: "2.0",
|
|
75
|
+
id: 1,
|
|
76
|
+
method: "tools/call",
|
|
77
|
+
params: {
|
|
78
|
+
name,
|
|
79
|
+
arguments: args,
|
|
80
|
+
_meta: {
|
|
81
|
+
[MetaKey.ProtocolVersion]: LATEST_PROTOCOL_VERSION,
|
|
82
|
+
[MetaKey.ClientInfo]: { name: "test", version: "1.0.0" },
|
|
83
|
+
[MetaKey.ClientCapabilities]: {},
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
}),
|
|
87
|
+
}),
|
|
88
|
+
);
|
|
89
|
+
let body = (await response.json()) as CallResponse;
|
|
90
|
+
if (body.error !== undefined) return { text: body.error.message ?? "", isError: true };
|
|
91
|
+
return { text: body.result?.content?.[0]?.text ?? "", isError: body.result?.isError === true };
|
|
92
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The {{words}} fields the new and edit forms submit, validated before a create or an update
|
|
3
|
+
* writes them. Each field matches a column of the {{Name}} model, so a valid submission is a
|
|
4
|
+
* complete row.
|
|
5
|
+
*
|
|
6
|
+
* @see {@link https://sdxc.dev/docs/building-remix-apps/forms-and-params}
|
|
7
|
+
* @see {@link https://sdxc.dev/api/validate}{{header}}
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
{{schemaImports}}
|
|
11
|
+
|
|
12
|
+
/** The {{words}} fields, as the form's action receives them; an unticked box reads `false`. */
|
|
13
|
+
export const {{Name}}Schema = f.object({
|
|
14
|
+
{{schemaFields}}
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
/** A validated {{words}} submission, ready for `create` or `update`. */
|
|
18
|
+
export type {{Name}}Input = s.InferOutput<typeof {{Name}}Schema>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The {{words}} form's validation.
|
|
3
|
+
*
|
|
4
|
+
* @see {@link https://sdxc.dev/docs/building-remix-apps/forms-and-params}
|
|
5
|
+
* @see {@link https://sdxc.dev/docs/operations-and-testing/testing}{{header}}
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { isFailure, isSuccess } from "@sdxc/result";
|
|
9
|
+
import { validate } from "@sdxc/validate";
|
|
10
|
+
import { describe, expect, test } from "vitest";
|
|
11
|
+
|
|
12
|
+
import { {{Name}}Schema } from "~/app/http/validators/{{name}}";
|
|
13
|
+
|
|
14
|
+
describe("{{Name}}Schema", () => {
|
|
15
|
+
test("accepts a complete submission", async () => {
|
|
16
|
+
let form = new URLSearchParams({ {{formSample}} });
|
|
17
|
+
|
|
18
|
+
expect(isSuccess(await validate(form, {{Name}}Schema))).toBe(true);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
test("refuses a submission with a value its field cannot take", async () => {
|
|
22
|
+
let form = new URLSearchParams({ {{invalidForm}} });
|
|
23
|
+
|
|
24
|
+
expect(isFailure(await validate(form, {{Name}}Schema))).toBe(true);
|
|
25
|
+
});
|
|
26
|
+
});
|