Skip to content

Deploy tools 4/6: the MCP tools, and the local server serving them - #257

Closed
raymondk wants to merge 1 commit into
deploy-core-3-pipelinefrom
deploy-core-4-tools-local
Closed

raymondk wants to merge 1 commit into
deploy-core-3-pipelinefrom
deploy-core-4-tools-local

Conversation

@raymondk

Copy link
Copy Markdown
Contributor

Fourth of six. Stacked on the deploy pipeline PR.

What this PR adds

The MCP tools (imcp2_core::deploy::IcDeployTools, mounted beside the core surface by WithDeploy):

  • icp_deploy_bundle: deploys a bundle as the user, creating the canisters the given mapping does not name and upgrading those it does, reporting each phase as it completes.
  • icp_cycles_balance: the balance those deploys draw on, and the principal that holds it.
  • icp_deploy_upload: mints an upload ticket, on a server that takes bundles that way.
  • icp_deploy_guide: returns the skill that walks an agent through the loop (also served as a resource).

Rules the tools enforce:

  • A server takes the bundle one way. On the user's machine it reads the path the agent names; a server that cannot see the user's disk takes an upload and reads no path. Each lists only the argument it accepts.
  • One deploy per session, and a cap across sessions, in slots a process can share between endpoints. Past either, a deploy is refused, not queued.
  • A stopping server begins no deploy and interrupts running ones.
  • Each call's fate (refused and why, or how it ended and how long it held its slot) is reported to an observer, for a server to count.

imcp2-local serves them, signing as the user's default Internet Identity account at https://cli.id.ai, the principal icp identity link web links the CLI to.

Open questions carried over from #243

A reviewer raised these on the old PR and they were not answered. They apply to code in this PR:

  1. Why ship a skill at all? Shouldn't the tools be self-documenting, and who consumes the file? (thread)
  2. Should the canister-id mapping be presented as opaque "app development metadata", so the agent stores it as a blob and doesn't inspect it? (thread)
  3. Why is the deploy guide available twice (as a tool and as a resource), and can the duplication be avoided? (thread)

These are design decisions I have not made on the author's behalf.

Testing

Argument handling for both kinds of server, the tool listing, slot sharing, stop propagation, outcome classification, and the local server's composition.

🤖 Generated with Claude Code

https://claude.ai/code/session_01XSXgo38kH12wagL3rstXfV

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Missing shutdown cancellation and deployment draining risk losing recovery IDs after cycles are spent, while blocked log forwarding can retain deployment slots and prevent shutdown from completing.

6 open issues
What changed in this PR

Exposes the existing deployment pipeline through shared MCP tools and enables deployment in imcp2-local, signing as the user’s default account at https://cli.id.ai.

Changes:

  • Adds deployment, balance, upload-ticket, and guide tools with bundle validation, shared concurrency limits, cancellation, and outcome reporting.
  • Composes deploy tools and resources alongside the core and local login surfaces.
  • Documents the deployment workflow and expands local integration tests.
File Description
crates/​imcp2-local/​src/​server.rs Composes deploy tools with core and login handlers; extends integration tests.
crates/​imcp2-local/​src/​main.rs Enables local deployment and configures its working directory.
crates/​imcp2-local/​README.md Documents deployment, signing identity, progress, and recovery.
crates/​imcp2-core/​static/​skills/​deploy-with-mcp.md Adds agent guidance for bundling, deploying, and saving canister mappings.
crates/​imcp2-core/​src/​tools.rs Extracts the core deployment disclaimer for replacement by composed servers.
crates/​imcp2-core/​src/​management.rs Extracts a reusable cycles-balance query for a supplied principal.
crates/​imcp2-core/​src/​lib.rs Exports balance helpers and the deployment disclaimer.
crates/​imcp2-core/​src/​deploy/​server.rs Adds the shared handler for deploy tools, resources, and instructions.
crates/​imcp2-core/​src/​deploy/​observe.rs Defines deploy refusal and completion observer events.
crates/​imcp2-core/​src/​deploy/​mod.rs Implements MCP tools, argument validation, slot management, and progress forwarding.

Review effort: Max

Comment on lines +193 to +195
let deploy = IcDeployTools::new(identities.clone(), slot.resolver())
.deploys_in(&data.join("imcp2-local").join("deploys"))
.map_err(anyhow::Error::msg)?;
None,
),
Some((uploads, _)) => {
let taken = match uploads.take(&bundle, &sid).await {
let result = deploy_bundle(identity, request, watch).instrument(span.clone()).await;
// The sender went with the run; the forwarder ends once it has
// delivered what is left.
let _ = forwarder.await;
let minted = uploads.mint(&sid).await;
let output = UploadTicketOutput {
curl: format!(
"curl -fsS -T <bundle.tar.gz> -H '{TICKET_HEADER}: {}' '{url}'",
Comment on lines +37 to +40
- A signed-in session with the "Actions & questions" access level. If a
tool answers that it needs an authenticated session, call `authenticate`,
have the user open the returned id.ai link, then retry. Check with
`auth_status`.
Comment on lines +59 to +80
This builds every canister, then writes a gzipped tar archive holding the
built wasms, the plugins the sync steps need, and a rewritten `icp.yaml`
whose build steps reference the bundled wasms, pinned by sha256. The bundle
is self-contained: the server needs no toolchain to deploy it.

Rules that matter here:

- Use an absolute output path outside any directory a canister syncs (a
frontend's `dist/`, for example), or the archive would include itself.
- Only `plugin` sync steps can be replayed from a bundle. A canister with a
`script` sync step cannot be bundled; the CLI says so.
- A server that deploys for others runs only the sync plugins it knows: the
released plugins that upload a frontend's assets, each known by the hash
of its module. A bundle whose canister is synced by any other plugin — a
build of your own, a release the server has not been told of — is refused
on the upload (`422`) or by the deploy, and the refusal lists the hashes
the server runs. That is not something to retry or work around: tell the
user, who can switch the project to a listed plugin release and bundle
again, or deploy with a server of their own (`imcp2-local`, or `icp
deploy`), which runs whatever the project brings.
- The bundle is built for the environments the manifest declares. Pick the
one you will deploy in step 2 now, and build with the matching settings.
- **The tools** (`imcp2_core::deploy::IcDeployTools`, mounted beside the
  core surface by `WithDeploy`): `icp_deploy_bundle` deploys a bundle to
  the Internet Computer as the user, every phase of `icp deploy`, creating
  the canisters the given mapping does not name and upgrading those it
  does, and reports each phase as it completes; `icp_cycles_balance`
  reports the balance those deploys create canisters from, and the
  principal that holds it; `icp_deploy_upload` mints an upload ticket, on
  a server that takes its bundles that way; `icp_deploy_guide` returns the
  skill that walks an agent through the loop (also a resource).
- **One way in per server.** A server on the project's machine reads the
  bundle at the path the agent names; one the agent cannot hand a file to
  takes an upload, and reads no path a caller gives it. Each lists the one
  argument it takes.
- **Bounded.** One deploy per session, and so many at once across sessions
  in slots a process can share between its endpoints: past either a deploy
  is refused, not queued. A server that is stopping begins none and
  interrupts those running, and can wait for them to have ended.
- **Observable.** What became of each deploy call — refused, and why; or
  how it ended, and how long it held its slot — is told to an observer,
  for a server to count: the call itself is one request among many to the
  transport that carries it.
- **imcp2-local serves them**, signing as the user's default Internet
  Identity account at `https://cli.id.ai`, the principal `icp identity
  link web` links the CLI to, with each deploy's directory under the
  user's local data directory.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Claude-Session: https://claude.ai/code/session_01XSXgo38kH12wagL3rstXfV
@raymondk
raymondk force-pushed the deploy-core-4-tools-local branch from 3835cbd to 7ebe764 Compare November 19, 2026 16:21
@aterga aterga closed this Nov 19, 2026
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.

3 participants