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:
- Human CLI: interactive prompts, colored logs, human-readable guidance
- Machine CLI:
swallowkit machine ...with deterministic JSON output - MCP runtime:
swallowkit-mcp, a thin stdio adapter over the machine CLI - 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
npx swallowkit machine inspect project
npx swallowkit machine inspect entities
npx swallowkit machine inspect routespnpm exec swallowkit machine inspect project
pnpm exec swallowkit machine inspect entities
pnpm exec swallowkit machine inspect routesThese 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
npx swallowkit machine validate projectpnpm exec swallowkit machine validate projectValidation returns structured violations for:
- config errors
- naming issues
- missing generated artifacts
- missing required files/directories
- forbidden dependencies across SwallowKit layers
Generation
npx swallowkit machine plan model todo --overwrite never
npx swallowkit machine apply model --plan <planId>
npx swallowkit machine generate scaffold todo --api-onlypnpm exec swallowkit machine plan model todo --overwrite never
pnpm exec swallowkit machine apply model --plan <planId>
pnpm exec swallowkit machine generate scaffold todo --api-onlyGeneration 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.
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> --approvepnpm 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> --approveplan scaffoldleaves 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 byplanId.apply scaffold --plan <planId>rejects the plan withstale-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 authfollow the same two-phase flow (custom-jwt/swa/external-token/none; use--schemeto add a named scheme).
Provision (Plan / Apply, approval always required)
npx swallowkit machine plan provision -g my-rg --location japaneast --swa-location eastasia
npx swallowkit machine apply provision --plan <planId> --approvepnpm exec swallowkit machine plan provision -g my-rg --location japaneast --swa-location eastasia
pnpm exec swallowkit machine apply provision --plan <planId> --approveplan provisionanalyzes 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 andaz login; unavailable az produces an offline preview that cannot be applied.--what-ifadditionally 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 provisionrefuses to run without an--approvethat 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). Inspectstatus,outcomeandnextActions: Running/Accepted isin-progress, unreadable state isunknown, and Succeeded without finished tags/ledger ispartial, not complete. machine inspect provision --plan <runId> [--wait-seconds 300]/swallowkit_inspect_provisionis read-only. After renewed human approval,apply provision --plan <runId> --approve/swallowkit_apply_provisionresumes 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
npx swallowkit machine inspect boundaries
npx swallowkit machine inspect infrapnpm exec swallowkit machine inspect boundaries
pnpm exec swallowkit machine inspect infrainspect boundariesreturns the responsibility boundary between AI free-form authoring and SwallowKit's deterministic generation as a machine-readable contract. Each ownership maps to azone(deterministic/ai-authored/shared) and aneditPolicy(regenerate-via-plan-apply/free-edit/edit-outside-markers/never-hand-edit); paths not in the ledger resolve through prefix-basedconventionRules. Agents should consult this contract before editing and route changes todeterministicareas through plan/apply.inspect infraparses the Bicep assets underinfra/(params / modules / outputs / container wiring) without calling Azure. A scaffold-generated container that is not wired intomain.bicepis reported as acontainer-not-wiredwarning.
Artifact / Drift Inspection
npx swallowkit machine inspect artifacts
npx swallowkit machine inspect driftpnpm exec swallowkit machine inspect artifacts
pnpm exec swallowkit machine inspect driftinspect artifactsreturns the generated-artifact ledger (.swallowkit/artifacts.json) with ownership (managed/generated-once/user-owned/extension-point/metadata) and modified / missing flags.inspect driftdetects 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 arepairAction.
Verify / Explain
npx swallowkit machine verify project
npx swallowkit machine verify project --checks structure,drift
npx swallowkit machine explain failure
npx swallowkit machine explain failure --check typecheckpnpm 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 typecheckverify projectdefaults tostructure,drift,typecheck, andbackend-build, returning evidence andsuggestedActions. 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: truemeans 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).--checksalso acceptsbuild/lint/test, which run the matching package.json script when present (and are skipped otherwise).- Custom checks defined under
verify.checksinswallowkit.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 failurereturns 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
{
"ok": true,
"command": "inspect-project",
"status": "complete",
"data": {
"manifestSource": "file",
"manifest": {}
}
}Failure
{
"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.
| status | meaning |
|---|---|
complete | Operation finished; proceed to the next step |
in-progress | Unresolved issues remain (e.g. failed verify checks); keep fixing |
blocked | A precondition broke (e.g. stale-plan, not-a-swallowkit-project); redo the previous step |
requires-human | Human judgement or approval is required (e.g. approval-required) |
failed | The 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 rootstale-plan(blocked) — planned files changed after planning; re-planplan-not-found(blocked) — the plan is missing or corrupted; re-planapproval-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:
initcreate-modelscaffoldadd-connectoradd-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:
npx swallowkit-mcppnpm exec swallowkit-mcpThe server exposes explicit tools only:
swallowkit_inspect_projectswallowkit_inspect_entitiesswallowkit_inspect_routesswallowkit_inspect_artifactsswallowkit_inspect_boundariesswallowkit_inspect_driftswallowkit_inspect_infraswallowkit_validate_projectswallowkit_generate_modelswallowkit_plan_modelswallowkit_plan_model_infrastructureswallowkit_apply_modelswallowkit_add_model_migrationswallowkit_scaffold_modelswallowkit_plan_scaffoldswallowkit_apply_scaffoldswallowkit_plan_authswallowkit_apply_authswallowkit_plan_provisionswallowkit_apply_provisionswallowkit_inspect_provisionswallowkit_verify_projectswallowkit_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:
{
"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.jsonservers - 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:
initkeepslatestunless the SwallowKit version used for init is newer than the publishedlatest(for example2.0.0-alpha.3whilelatestis1.1.2). ThenSWALLOWKIT_MCP_VERSIONis pinned to that version.- A launcher started as
latest(or without a version) compares itself with the project-installedswallowkitby semantic-version precedence. When the project is newer, it hands the session to the project's ownswallowkit-mcp. Oncelatestcatches up (for example2.0.0versus2.0.0-alpha.3),latestis used again. - An explicit
SWALLOWKIT_MCP_VERSIONother thanlatestis always honored. A pinned server warns withmcp-older-than-projectwhen it is older than the project, and withmcp-pin-outdatedwhen the publishedlatesthas caught up with the pin. - Every MCP response includes
metadata.swallowkitVersionandmetadata.mcp(version,requestedVersion,projectVersion,selection,delegated,delegatedFrom). Version warnings appear inmetadata.warningstogether withnextActions. swallowkit configure-mcp [--version auto|latest|<semver>]changes only the version in.mcp.json.auto(default) selectslatestunless 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).
| Skill | Use for |
|---|---|
swallowkit-add-model | adding a model / CRUD feature (plan/apply/verify loop) |
swallowkit-modify-model | changing an existing schema and resolving drift |
swallowkit-verify-repair | the verify-and-repair convergence loop |
swallowkit-provision | Azure provisioning (always via human approval) |
For agents without skills support, the same runbooks live in .swallowkit/workflows/ and are referenced from AGENTS.md.
Recommended Usage
- 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:
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 --approveResponsibility boundary principles:
| zone | Edit policy | Examples |
|---|---|---|
deterministic | Never hand-edit; regenerate via plan/apply | Tracked generated CRUD/BFF files; baseline Bicep |
ai-authored | AI / developers write freely | Custom pages not registered as generated artifacts, custom lib/ code, unapplied migrations |
shared | Follow the path-specific rule | shared/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.
