Skip to content

Add write operations (create/update/delete) for Kontena schemas and entries#39

Merged
sutisnamulyana merged 1 commit into
mainfrom
claude/vibrant-lovelace-wqpj3
May 22, 2026
Merged

Add write operations (create/update/delete) for Kontena schemas and entries#39
sutisnamulyana merged 1 commit into
mainfrom
claude/vibrant-lovelace-wqpj3

Conversation

@sutisnamulyana
Copy link
Copy Markdown
Member

Summary

Extends the Kontena CLI and MCP tool surface from read-only inspection to full CRUD operations. Adds support for creating, updating, and deleting both schemas and entries, plus publish/unpublish workflows for collection entries.

Key Changes

CLI Commands (packages/sawala/src/commands/kontena.ts)

  • Schema CRUD: Added schema create, schema update <slugOrId>, and schema delete <slugOrId> commands
    • Support --file and --data options for input payloads
    • --dry-run flag to validate without writing
    • Confirmation prompt for destructive operations (skippable with --yes)
  • Entry CRUD: Added entry create <schemaSlug>, entry update <schemaSlug> <slugOrId>, and entry delete <schemaSlug> <slugOrId> commands
    • Automatic schema type detection (single vs collection) via transparent fetchSchemaType() helper
    • Routes to correct /content/{single,collection}/... endpoints based on schema type
    • --publish flag to set status='published' on create/update
    • entry publish <schemaSlug> <slugOrId> and entry unpublish <schemaSlug> <slugOrId> convenience commands
  • Updated command descriptions to reflect read+write capability

Input/Output Utilities (packages/sawala/src/lib/io.ts)

  • New readJsonInput(path): Reads JSON from file or stdin (-)
  • New confirmOrThrow(question): TTY-aware confirmation prompt for destructive operations
  • New resolveInputPayload(opts): Unified handler for --data and --file options

MCP Tools (packages/sawala-mcp/src/tools/)

Added 8 new tool definitions:

  • kontenaCreateSchemaTool: POST schema to /schemas
  • kontenaUpdateSchemaTool: PUT schema patch to /schemas/<slugOrId>
  • kontenaDeleteSchemaTool: DELETE schema (requires confirm: true)
  • kontenaCreateEntryTool: POST entry with transparent schema-type routing
  • kontenaUpdateEntryTool: PUT entry patch with optional publish flag
  • kontenaDeleteEntryTool: DELETE entry (requires confirm: true)
  • kontenaPublishEntryTool: Publish collection entry (idempotent)
  • kontenaUnpublishEntryTool: Unpublish collection entry (idempotent)

All MCP tools include proper Zod validation, destructive/idempotent annotations, and error handling.

Tests

  • Comprehensive test coverage for all new CLI commands in packages/sawala/test/kontena.test.ts
  • Unit tests for all new MCP tools in packages/sawala-mcp/test/tools/
  • Tests verify correct HTTP methods, URL routing, payload handling, and schema-type detection

Notable Implementation Details

  • Schema type inference: Entry mutations transparently fetch the schema first to determine whether to use /content/single/ or /content/collection/ routes, hiding wire-protocol asymmetry from users
  • Confirmation safety: Destructive operations (delete) refuse to run in non-TTY environments without --yes, preventing accidental data loss in scripts
  • Idempotent publish/unpublish: Separate convenience tools for publish/unpublish that are marked as idempotent in MCP annotations
  • PUT semantics: Schema and entry updates use PUT replacement semantics (not PATCH)
  • MCP annotations: All tools properly annotated with readOnlyHint, destructiveHint, idempotentHint, and irreversibleHint for host-level safety warnings

https://claude.ai/code/session_01MuNb39Fg1kz7xDNfD8ehhe

…blish)

Adds the create/update/delete + publish workflow on top of the existing
read-only kontena CLI and MCP surfaces. Three milestones in one PR:

* CLI: `sawala kontena schema {create,update,delete}` and
  `sawala kontena entry {create,update,delete,publish,unpublish}`.
  Body is supplied via `--file <path>` (or `-` for stdin) or inline
  `--data <json>`. Destructive verbs prompt on a TTY and refuse in
  non-TTY mode without `--yes`. Both create/update support `--dry-run`
  for round-trip-free validation.

* MCP: eight new tools mirroring the CLI verbs. Delete tools require
  `confirm: true` in the input to guard against empty-payload accidents
  and carry `destructiveHint`/`irreversibleHint` for host UIs. Entry
  CRUD transparently fetches the schema first to route single vs
  collection — schema type stays an implementation detail of the
  worker, not the tool surface.

* Shared helpers: new `packages/sawala/src/lib/io.ts` with
  `readJsonInput`, `confirmOrThrow`, and `resolveInputPayload` so the
  CLI verbs share a single I/O convention.

The publish/unpublish verbs target collection schemas; for single-type
schemas, callers use `update --publish` with the locale in the patch.
@sutisnamulyana sutisnamulyana merged commit 9522f14 into main May 22, 2026
1 check passed
sutisnamulyana pushed a commit that referenced this pull request May 22, 2026
PR #39 merged without a changeset, so the release workflow tried to
republish the existing 0.1.2 of both `@sawala/cli` and `@sawala/mcp`.
This bumps both to a `minor` (new feature surface).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants