Skip to content

AI / MCP integration ​

See package manager commands and troubleshooting for pnpm 11/12 and npm usage.

SwallowKit provides a machine-readable CLI (swallowkit machine) and a bundled MCP stdio server (swallowkit-mcp) so coding agents can operate through official generators, inspectors, and validators instead of guessing raw filesystem edits.

For guidance on using SwallowKit throughout discovery, specification, planning, implementation, verification, and review, see the Coding agent guide.

Architecture ​

The integration surface is intentionally layered:

  1. Human CLI: interactive prompts, colored logs, human-readable guidance
  2. Machine CLI: swallowkit machine ... with deterministic JSON output
  3. MCP runtime: swallowkit-mcp, a thin stdio adapter over the machine CLI
  4. Project manifest: .swallowkit/project.json, the framework-owned project metadata used for inspection and validation

This keeps framework logic in SwallowKit itself while making AI integrations explicit and predictable.

Machine CLI ​

Use the machine interface when an agent needs structured project data or needs to invoke the official generators without interactive prompts.

Inspection ​

bash
npx swallowkit machine inspect project
npx swallowkit machine inspect entities
npx swallowkit machine inspect routes
bash
pnpm exec swallowkit machine inspect project
pnpm exec swallowkit machine inspect entities
pnpm exec swallowkit machine inspect routes

These commands return framework-owned metadata such as:

  • project manifest source
  • entities and schema metadata
  • generated BFF / Functions route mappings
  • connectors, auth, and architecture metadata

Validation ​

bash
npx swallowkit machine validate project
bash
pnpm exec swallowkit machine validate project

Validation returns structured violations for:

  • config errors
  • naming issues
  • missing generated artifacts
  • missing required files/directories
  • forbidden dependencies across SwallowKit layers

Generation ​

bash
npx swallowkit machine plan model todo --overwrite never
npx swallowkit machine apply model --plan <planId>
npx swallowkit machine generate scaffold todo --api-only
bash
pnpm exec swallowkit machine plan model todo --overwrite never
pnpm exec swallowkit machine apply model --plan <planId>
pnpm exec swallowkit machine generate scaffold todo --api-only

Generation stays non-interactive and returns JSON describing created or updated artifacts.

Plan / Apply ​

A two-phase flow that lets agents preview changes before changing generated targets. This is the recommended path for autonomous loops.

bash
npx swallowkit machine plan scaffold todo --api-only
npx swallowkit machine apply scaffold --plan <planId>
# Only after approval to overwrite the reported conflicts
npx swallowkit machine apply scaffold --plan <planId> --approve
bash
pnpm exec swallowkit machine plan scaffold todo --api-only
pnpm exec swallowkit machine apply scaffold --plan <planId>
# Only after approval to overwrite the reported conflicts
pnpm exec swallowkit machine apply scaffold --plan <planId> --approve
  • plan scaffold leaves generated targets unchanged; it returns the files that would be created / updated / overwritten, plus any conflicts. Plans are stored in .swallowkit/state/plans/ and referenced by planId.
  • apply scaffold --plan <planId> rejects the plan with stale-plan (status: "blocked") if any planned file changed after planning.
  • Overwriting a managed file that was hand-edited after generation returns approval-required (status: "requires-human") and requires an explicit --approve.
  • C# / Python OpenAPI and native schema artifacts are included in plans and participate in stale-plan detection, conflict checks, approval, and the artifact ledger. Planning does not invoke external tools or the network; validation and environment bootstrap with NSwag or datamodel-code-generator run only during apply, as a pre-flight step before any file is written. If validation fails (for example, the .NET SDK is missing), apply fails without modifying the project.
  • plan auth --provider <p> / apply auth follow the same two-phase flow (custom-jwt / swa / external-token / none; use --scheme to add a named scheme).

Provision (Plan / Apply, approval always required) ​

bash
npx swallowkit machine plan provision -g my-rg --location japaneast --swa-location eastasia
npx swallowkit machine apply provision --plan <planId> --approve
bash
pnpm exec swallowkit machine plan provision -g my-rg --location japaneast --swa-location eastasia
pnpm exec swallowkit machine apply provision --plan <planId> --approve
  • plan provision analyzes local Bicep and reads the Azure subscription/resource-group/migration state when az is available. It creates no resources, but online planning requires Azure connectivity and az login; unavailable az produces an offline preview that cannot be applied.
  • --what-if additionally reads Azure deployment change evidence; it does not apply resources.
  • Provisioning creates billable resources, so the plan always reports requiresApproval: true (status: "requires-human"). apply provision refuses to run without an --approve that reflects explicit human consent.
  • Apply saves a pre-write execution checkpoint, submits Bicep once with --no-wait, and bounded-polls the original deployment (default 300 seconds; --wait-seconds 0-3600). Inspect status, outcome and nextActions: Running/Accepted is in-progress, unreadable state is unknown, and Succeeded without finished tags/ledger is partial, not complete.
  • machine inspect provision --plan <runId> [--wait-seconds 300] / swallowkit_inspect_provision is read-only. After renewed human approval, apply provision --plan <runId> --approve / swallowkit_apply_provision resumes the same checkpoint without re-submitting attempted deployments. Retain .swallowkit/state/provision/; never reconcile/cancel/delete to repair waiting or bookkeeping. Ctrl+C may leave Azure running.
  • Older untracked baselines can use plan provision --resume-deployment <name> with the original target/regions. ARM template and non-secure parameters must match local files; otherwise recovery blocks. Diagnostics redact secrets and omit deployment output values. See the recovery guide.

Responsibility Boundary / Infra Inspection ​

bash
npx swallowkit machine inspect boundaries
npx swallowkit machine inspect infra
bash
pnpm exec swallowkit machine inspect boundaries
pnpm exec swallowkit machine inspect infra
  • inspect boundaries returns the responsibility boundary between AI free-form authoring and SwallowKit's deterministic generation as a machine-readable contract. Each ownership maps to a zone (deterministic / ai-authored / shared) and an editPolicy (regenerate-via-plan-apply / free-edit / edit-outside-markers / never-hand-edit); paths not in the ledger resolve through prefix-based conventionRules. Agents should consult this contract before editing and route changes to deterministic areas through plan/apply.
  • inspect infra parses the Bicep assets under infra/ (params / modules / outputs / container wiring) without calling Azure. A scaffold-generated container that is not wired into main.bicep is reported as a container-not-wired warning.

Artifact / Drift Inspection ​

bash
npx swallowkit machine inspect artifacts
npx swallowkit machine inspect drift
bash
pnpm exec swallowkit machine inspect artifacts
pnpm exec swallowkit machine inspect drift
  • inspect artifacts returns the generated-artifact ledger (.swallowkit/artifacts.json) with ownership (managed / generated-once / user-owned / extension-point / metadata) and modified / missing flags.
  • inspect drift detects schema changes (schema-drift), manual edits (artifact-modified), missing files (artifact-missing), generator version differences (generator-drift), and manifest divergence (manifest-drift). Every finding includes a repairAction.

Verify / Explain ​

bash
npx swallowkit machine verify project
npx swallowkit machine verify project --checks structure,drift
npx swallowkit machine explain failure
npx swallowkit machine explain failure --check typecheck
bash
pnpm exec swallowkit machine verify project
pnpm exec swallowkit machine verify project --checks structure,drift
pnpm exec swallowkit machine explain failure
pnpm exec swallowkit machine explain failure --check typecheck
  • verify project defaults to structure, drift, typecheck, and backend-build, returning evidence and suggestedActions. Its structure check also requires each persistent model to have a current registered Cosmos container migration or a matching baseline-owned container; connectors and referenced helper schemas are excluded. This checks local definitions, not Azure deployment state. The backend check compiles C#/TypeScript Functions and checks Python syntax (not imports/types). Missing toolchains are skipped with a reason; summary.done: true means no failures, not that skipped checks, runtime behavior, or Azure provisioning were verified. For production builds too, use --checks "structure,drift,typecheck,backend-build,build" (quote CSV in PowerShell).
  • --checks also accepts build / lint / test, which run the matching package.json script when present (and are skipped otherwise).
  • Custom checks defined under verify.checks in swallowkit.config.json (e.g. { "id": "smoke-api", "command": "node scripts/smoke.js" }) are added to the default set. Ids must match ^[a-z][a-z0-9-]*$ and must not clash with built-in ids.
  • explain failure returns the evidence and repair actions for the failing checks from the most recent verify run.

Response Shape ​

All machine commands write a single JSON document to stdout.

Success ​

json
{
  "ok": true,
  "command": "inspect-project",
  "status": "complete",
  "data": {
    "manifestSource": "file",
    "manifest": {}
  }
}

Failure ​

json
{
  "ok": false,
  "command": "generate-scaffold",
  "status": "failed",
  "error": {
    "code": "internal-error",
    "message": "..."
  }
}

Terminal State ​

Every machine command returns a status that autonomous loops can use as a termination signal.

statusmeaning
completeOperation finished; proceed to the next step
in-progressUnresolved issues remain (e.g. failed verify checks); keep fixing
blockedA precondition broke (e.g. stale-plan, not-a-swallowkit-project); redo the previous step
requires-humanHuman judgement or approval is required (e.g. approval-required)
failedThe operation itself failed

Successful responses may also include nextActions suggesting the next command to run.

Key guardrail error codes:

  • not-a-swallowkit-project (blocked) — a write command ran outside a project; move to the project root
  • stale-plan (blocked) — planned files changed after planning; re-plan
  • plan-not-found (blocked) — the plan is missing or corrupted; re-plan
  • approval-required (requires-human) — overwrites/provisioning need human approval; a guardrail, not an error

Project Manifest ​

SwallowKit keeps project semantics in .swallowkit/project.json.

The manifest is synchronized after framework-owned mutations such as:

  • init
  • create-model
  • scaffold
  • add-connector
  • add-auth

Inspection and validation use this manifest as the primary project map. If it is missing, SwallowKit reconstructs metadata from the current project structure.

MCP Server ​

Use the bundled stdio MCP server when your agent platform supports MCP tools:

bash
npx swallowkit-mcp
bash
pnpm exec swallowkit-mcp

The server exposes explicit tools only:

  • swallowkit_inspect_project
  • swallowkit_inspect_entities
  • swallowkit_inspect_routes
  • swallowkit_inspect_artifacts
  • swallowkit_inspect_boundaries
  • swallowkit_inspect_drift
  • swallowkit_inspect_infra
  • swallowkit_validate_project
  • swallowkit_generate_model
  • swallowkit_plan_model
  • swallowkit_plan_model_infrastructure
  • swallowkit_apply_model
  • swallowkit_add_model_migration
  • swallowkit_scaffold_model
  • swallowkit_plan_scaffold
  • swallowkit_apply_scaffold
  • swallowkit_plan_auth
  • swallowkit_apply_auth
  • swallowkit_plan_provision
  • swallowkit_apply_provision
  • swallowkit_inspect_provision
  • swallowkit_verify_project
  • swallowkit_explain_failure

The MCP layer does not implement framework logic on its own. It delegates each tool call to the machine CLI. swallowkit_generate_model registers a container migration for newly created non-connector models. swallowkit_add_model_migration is the schema-preserving backfill for hand-written models; dryRun lists concrete migration/manifest writes without writing. Its refreshPending option is opt-in and performs read-only Azure migration-tag and deployment-history checks against the specified resource group before a pending definition may be refreshed. For a plan/apply backfill of a hand-written schema, use swallowkit_plan_model_infrastructure and pass its reviewed planId to swallowkit_apply_model; this preserves the schema and fingerprints all planned migration, manifest, and artifact-ledger writes. For previewable persistent-model generation, use swallowkit_plan_model and apply its reviewed planId with swallowkit_apply_model; the preview includes the schema, shared export, migration, manifest, and artifact ledger.

Generated Project Bootstrap ​

swallowkit init writes a project-scoped .mcp.json file at the repository root. It resolves and launches the latest SwallowKit MCP entrypoint on each start; set SWALLOWKIT_MCP_VERSION in the file to pin a version.

Example shape:

json
{
  "mcpServers": {
    "swallowkit": {
      "command": "pnpm",
      "args": ["--package", "swallowkit@${SWALLOWKIT_MCP_VERSION}", "dlx", "swallowkit-mcp"],
      "env": { "SWALLOWKIT_MCP_VERSION": "latest" },
      "cwd": "."
    }
  }
}

Practical behavior:

  • Claude Code can load project-scoped MCP servers from .mcp.json
  • GitHub Copilot CLI can also discover workspace .mcp.json servers
  • Other agents / Codex-style runtimes can reuse the same launcher when their MCP client supports project-level config; otherwise they should use the machine CLI fallback

The generated instruction files (AGENTS.md, CLAUDE.md, .github/copilot-instructions.md) explicitly tell agents to prefer MCP tools when available and fall back to swallowkit machine ... when they are not. The launcher uses the project package manager: pnpm for pnpm projects, or npx --yes --package swallowkit@${SWALLOWKIT_MCP_VERSION} swallowkit-mcp for npm projects. Network access is needed when the selected version is not cached. MCP intentionally defaults to latest; normal project commands use the locally installed CLI.

MCP version selection ​

latest is intentional: projects created with older releases still receive the current stable tools. A prerelease project can be newer than latest, so SwallowKit applies these rules:

  • init keeps latest unless the SwallowKit version used for init is newer than the published latest (for example 2.0.0-alpha.3 while latest is 1.1.2). Then SWALLOWKIT_MCP_VERSION is pinned to that version.
  • A launcher started as latest (or without a version) compares itself with the project-installed swallowkit by semantic-version precedence. When the project is newer, it hands the session to the project's own swallowkit-mcp. Once latest catches up (for example 2.0.0 versus 2.0.0-alpha.3), latest is used again.
  • An explicit SWALLOWKIT_MCP_VERSION other than latest is always honored. A pinned server warns with mcp-older-than-project when it is older than the project, and with mcp-pin-outdated when the published latest has caught up with the pin.
  • Every MCP response includes metadata.swallowkitVersion and metadata.mcp (version, requestedVersion, projectVersion, selection, delegated, delegatedFrom). Version warnings appear in metadata.warnings together with nextActions.
  • swallowkit configure-mcp [--version auto|latest|<semver>] changes only the version in .mcp.json. auto (default) selects latest unless the project is newer.

Delegation only works when the latest release itself contains it. Until such a stable release is published, the pin written by init or configure-mcp keeps prerelease projects on their own version. Generated instructions also tell agents to use swallowkit machine ... whenever MCP reports an older version than the project.

Agent Skills (agentskills.io standard) ​

init also generates the autonomous-loop runbooks as skills in the Agent Skills open-standard format under .github/skills/. Skills-aware agents (GitHub Copilot in VS Code / CLI / cloud agent, and others) keep only the frontmatter name / description resident and load the body on demand when the task matches (progressive disclosure).

SkillUse for
swallowkit-add-modeladding a model / CRUD feature (plan/apply/verify loop)
swallowkit-modify-modelchanging an existing schema and resolving drift
swallowkit-verify-repairthe verify-and-repair convergence loop
swallowkit-provisionAzure provisioning (always via human approval)

For agents without skills support, the same runbooks live in .swallowkit/workflows/ and are referenced from AGENTS.md.

  • Use inspect first to understand the SwallowKit project structure
  • Perform write operations in two phases: plan → (review) → apply
  • Run verify after applying; on failure use explain failure to get evidence, fix, and re-verify
  • Use validate / inspect drift before or after generation to detect framework rule violations and divergence
  • Use generate / apply instead of editing framework-owned (managed) artifacts by hand
  • Keep custom logic in application files, but let SwallowKit own generated structure and metadata

Typical autonomous loop:

text
inspect project → plan scaffold → apply scaffold --plan <id> → verify project
   └ on failure: explain failure → fix → verify project (repeat)
   └ on approval-required: ask a human → apply scaffold --approve

Responsibility boundary principles:

zoneEdit policyExamples
deterministicNever hand-edit; regenerate via plan/applyTracked generated CRUD/BFF files; baseline Bicep
ai-authoredAI / developers write freelyCustom pages not registered as generated artifacts, custom lib/ code, unapplied migrations
sharedFollow the path-specific ruleshared/index.ts allows manual exports (no markers); Python functions/function_app.py requires edits outside registration markers

Convention rules are resolved for the configured backend.language: C# and TypeScript backends have no registration file, so no backend marker rule is reported. Baseline infra/ files are deterministic because infra/migrations/manifest.json records their checksums; add infrastructure as new migrations instead.

Fetch the contract with inspect boundaries (or swallowkit_inspect_boundaries) before editing, and replace direct edits to deterministic areas with model edits followed by plan/apply.

Authentication data in machine/MCP output ​

inspect project and the corresponding MCP project inspection return canonical auth.schemes and auth.authorization.policies. Legacy single-provider configuration appears as the default scheme, and public appears as anonymous. Validation diagnostics include the full configuration path and a suggested correction; consumers must never reinterpret an invalid or missing policy as anonymous.

Released under the MIT License.