MCP server for design and coding agents¶
AIsketcher 0.5.0 ships a zero-dependency Model Context Protocol (MCP) stdio
server (aisketcher mcp) built solely on the Python standard library and
AIsketcher core. It speaks newline-delimited JSON-RPC 2.0 over stdio
(negotiating MCP protocol versions 2024-11-05 and 2025-03-26) so coding and
design agents can prepare sketches, scout deterministic seeds, vary a chosen
candidate with structure locks, inspect SHA-256 manifests, and run strict replay
without adding an external MCP SDK dependency.
3-line setup¶
Install AIsketcher once, then register aisketcher mcp with your client:
Full JSON / TOML configuration snippets¶
If you manage MCP servers in config files instead of CLI commands:
You can also invoke the module directly via python -m aisketcher.mcp_server.
CLI flags¶
| Flag | Default | Description |
|---|---|---|
--preset |
dreamshaper-canny@1 |
Default curated preset when a tool call omits preset |
--backend |
auto |
Default backend (auto, fake, diffusers, mlx) |
--device |
auto |
Execution device (auto, cuda, mps, mlx, cpu) |
--cache-dir |
platform cache | Optional local model cache directory |
--workspace-dir |
unset | Restrict all input/output/manifest file paths to this directory tree |
--allow-downloads |
false (off) |
Permit downloading pinned curated presets when absent from local cache |
On Apple Silicon with aisketcher[mlx]==0.5.0 installed, pass
--preset mlx-flux2-klein-edit@1 --backend mlx to default tool calls to the
native MLX backend. For model-free CI or agent smoke testing, pass
--backend fake.
Tool catalog (6 tools)¶
Every tool rejects unknown properties (additionalProperties: false) and returns
both JSON text content and structuredContent.
| Tool | Required arguments | Key optional arguments | Returns |
|---|---|---|---|
aisketcher_list_presets |
(none) | (none) | default_preset, default_backend, allow_downloads, and all curated presets with install state, byte sizes, control mode, steps, guidance, scheduler, and pinned models |
aisketcher_prepare_sketch |
image_path |
max_side (64..4096, default 1024), canny_low (0..254), canny_high (1..255) |
original_size, prepared_size, source_sha256, control_sha256, canny, and diagnostics |
aisketcher_explore_seeds |
image_path, prompt, output_dir |
preset, backend (auto/fake/diffusers/mlx), outputs (1..8, default 4), seed_mode (scout/locked/explicit), seed, seeds, structure (loose/balanced/faithful), profile, negative_prompt, steps, guidance_scale, control_strength, canny_low, canny_high, max_side, overwrite |
study_id, manifest_path, recipe_sha256, preset, backend, seed_plan, candidates (id, seed, path, scores), and contact_sheet_path |
aisketcher_vary_candidate |
manifest_path, output_dir |
candidate_id or candidate_index, strength (subtle/balanced/bold, default subtle), lock_structure (default true), outputs (1..8, default 4), seed_mode, seed, seeds, backend, overwrite |
study_id, parent_id, manifest_path, recipe_sha256, preset, backend, seed_plan, lineage, candidates, and contact_sheet_path |
aisketcher_inspect_manifest |
manifest_path |
(none) | valid, manifest_path, run_id, schema, kind, backend, preset, recipe_sha256, computed_recipe_sha256, recipe_hash_valid, verified_files, seed_plan, selection, lineage, and candidates |
aisketcher_replay_manifest |
manifest_path |
output_dir, mode (strict/compatible, default strict), backend, overwrite |
study_id, mode, backend, preset, verified_files, drift, warnings, exact_candidate_match, recipe_sha256, candidates (with hash_matches_original), and exported_manifest_path |
manifest_path accepts either the path to a manifest.json file or an exported
study directory containing manifest.json.
Security and containment model¶
The MCP server enforces strict defaults designed for autonomous tool use:
- Workspace path containment: When
--workspace-diris configured,resolve_workspace_path()resolves everyimage_path,output_dir, andmanifest_pathrelative to the workspace root and rejects..traversal, null bytes, or symlinks that escape the workspace tree. - Offline by default:
allow_downloadsdefaults toFalse(local_files_only=True). A model that is not already installed and verified in the local cache fails closed instead of triggering an unexpected multi-GB transfer during an agent turn. Pass--allow-downloadsonly when you want tool calls to download curated, SHA-256-verified presets. - Manifest integrity before mutation or replay: Both
aisketcher_vary_candidateandaisketcher_inspect_manifestverify all recorded file SHA-256 digests and the canonicalrecipe_sha256before loading any image or generating variations. - Stdout protocol isolation: While dispatching tool calls,
run_stdio_server()redirects Python stdout tostderrso progress logs or third-party warnings cannot corrupt newline-delimited JSON-RPC frames onstdout. - Safe overwrites:
overwritedefaults toFalse, and even when enabled, AIsketcher only replaces an existing canonical AIsketcher export directory.
End-to-end replay verification example¶
The sequence below runs completely offline (and works identically with real
local presets once installed, or with "backend": "fake" for fast CI checks):
-
Scout four deterministic directions via
aisketcher_explore_seeds:{ "name": "aisketcher_explore_seeds", "arguments": { "image_path": "sketch.png", "prompt": "A playful miniature fantasy kingdom made of layered paper craft", "output_dir": "studies/scout-01", "preset": "dreamshaper-canny@1", "seed_mode": "explicit", "seeds": [6764547109648557242, 6854547109648557242, 6634547109688557242, 6764547109648557243], "canny_low": 140, "canny_high": 160 } } -
Vary the chosen candidate with structure locked via
aisketcher_vary_candidate: -
Verify hashes and lineage via
aisketcher_inspect_manifest:{ "name": "aisketcher_inspect_manifest", "arguments": { "manifest_path": "studies/vary-01/manifest.json" } }Check that
"valid": trueand"recipe_hash_valid": true. -
Verify deterministic strict replay via
aisketcher_replay_manifest:{ "name": "aisketcher_replay_manifest", "arguments": { "manifest_path": "studies/vary-01/manifest.json", "mode": "strict" } }Confirm
"drift": []and inspect per-candidate"hash_matches_original"results. On Apple M6 (dreamshaper-canny@1andmlx-flux2-klein-edit@14-bit/8-bit), strict replay passed with zero drift across the complete scout-and-vary workflow.
Next¶
- Configure Apple Silicon MLX presets in Apple Silicon MLX.
- Read the export and replay contract.
- Inspect the model decision guide.