Skip to content

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:

pip install aisketcher
claude mcp add aisketcher -- aisketcher mcp --workspace-dir .
# Optional: add --preset mlx-flux2-klein-edit@1 --backend mlx on Apple Silicon
pip install aisketcher
codex mcp add aisketcher -- aisketcher mcp --workspace-dir .
# Or add [mcp_servers.aisketcher] command = "aisketcher", args = ["mcp", "--workspace-dir", "."]
pip install aisketcher
# Add to ~/.copilot/mcp-config.json:
# {"mcpServers":{"aisketcher":{"command":"aisketcher","args":["mcp","--workspace-dir","."]}}}

Full JSON / TOML configuration snippets

If you manage MCP servers in config files instead of CLI commands:

{
  "mcpServers": {
    "aisketcher": {
      "command": "aisketcher",
      "args": [
        "mcp",
        "--preset", "dreamshaper-canny@1",
        "--workspace-dir", "."
      ]
    }
  }
}
[mcp_servers.aisketcher]
command = "aisketcher"
args = ["mcp", "--preset", "dreamshaper-canny@1", "--workspace-dir", "."]

You can also invoke the module directly via python -m aisketcher.mcp_server.

CLI flags

aisketcher mcp [OPTIONS]
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-dir is configured, resolve_workspace_path() resolves every image_path, output_dir, and manifest_path relative to the workspace root and rejects .. traversal, null bytes, or symlinks that escape the workspace tree.
  • Offline by default: allow_downloads defaults to False (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-downloads only when you want tool calls to download curated, SHA-256-verified presets.
  • Manifest integrity before mutation or replay: Both aisketcher_vary_candidate and aisketcher_inspect_manifest verify all recorded file SHA-256 digests and the canonical recipe_sha256 before loading any image or generating variations.
  • Stdout protocol isolation: While dispatching tool calls, run_stdio_server() redirects Python stdout to stderr so progress logs or third-party warnings cannot corrupt newline-delimited JSON-RPC frames on stdout.
  • Safe overwrites: overwrite defaults to False, 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):

  1. 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
      }
    }
    
  2. Vary the chosen candidate with structure locked via aisketcher_vary_candidate:

    {
      "name": "aisketcher_vary_candidate",
      "arguments": {
        "manifest_path": "studies/scout-01/manifest.json",
        "candidate_index": 0,
        "output_dir": "studies/vary-01",
        "strength": "subtle",
        "lock_structure": true,
        "outputs": 2
      }
    }
    
  3. Verify hashes and lineage via aisketcher_inspect_manifest:

    {
      "name": "aisketcher_inspect_manifest",
      "arguments": {
        "manifest_path": "studies/vary-01/manifest.json"
      }
    }
    

    Check that "valid": true and "recipe_hash_valid": true.

  4. 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@1 and mlx-flux2-klein-edit@1 4-bit/8-bit), strict replay passed with zero drift across the complete scout-and-vary workflow.

Next