Skip to content

imcp2-deploy 5/6: the MCP tools, served from the local server - #232

Closed
raymondk wants to merge 1 commit into
deploy-2b-uploadsfrom
deploy-3-mcp-tools
Closed

raymondk wants to merge 1 commit into
deploy-2b-uploadsfrom
deploy-3-mcp-tools

Conversation

@raymondk

@raymondk raymondk commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The MCP tools over the pipeline, the handler that serves them beside the core surface, and imcp2-local composing them.

icp_deploy_bundle takes a bundle, the environment name, and optionally the canister-id mapping an earlier deploy returned. It answers with the status, the mapping to pass back next time, the canisters created and a per-phase log, as structured content under a declared output schema. A failed or interrupted run still reports every canister it created.

  • One call, as long as the deploy. Each phase is forwarded to the client as it completes: a progress notification when the request carried a progress token, else a logging message. Cancelling the call interrupts the deploy at its next step.
  • One bundle source per server. A server that sits with the project takes bundle_path; one the agent cannot hand a file to takes bundle_upload, the id of an upload received through imcp2-deploy 4/6: receive a bundle by upload ticket #247's store. Each server lists the one argument it takes and refuses the other before anything is read, so a server reached over the network reads no path a caller names.
  • One deploy per session, and a cap on how many run at once across sessions (one, unless the server says otherwise). Past either the call is refused, not queued, since a queued deploy's mapping would be stale by the time it ran.
  • Who deploys. Calls are signed as the user's developer principal: their default Internet Identity account at the origin the icp CLI links to. It is not the management identity the canister lifecycle tools act as.

icp_cycles_balance reports that principal and its cycles balance. icp_deploy_guide returns the deploy skill, which is also served as skill://deploy-with-mcp, for a client that reads no resources. icp_deploy_upload mints an upload ticket and is listed only by a server with an upload store; nothing mounts one until #243.

WithDeploy<H> serves an inner handler's tools with the deploy tools beside them, the skill next to the inner resources, and puts a DEPLOYING paragraph in the place of core's "no tool here deploys" paragraph (DEPLOYS_ELSEWHERE).

imcp2-local wraps WithDeploy<IcTools>, takes the bundle by path, keeps each deploy's working directory under the OS's local data directory, and refuses to start without one.

What changed in this PR at the re-cut

Review so far

  • sea-snake asked how runs are isolated between users. Each deploy has a working directory of its own, readable by its owner alone, and the mapping a deploy starts from is the one its own call passed in.
  • sea-snake noted that a skill served only as a resource does not reach every agent. icp_deploy_guide returns it as a tool result.
  • aterga's comments on imcp2-deploy 6/6: serve the deploy tools on the hosted server, with the bundle uploaded on a ticket #243 about the instructions and the skill are addressed here, where that text now lives: deploying is not presented as an exception; the DEPLOYING paragraph is about a third of its former length; the instructions, the icp_cycles_balance description and the skill no longer name cli.id.ai or CLI identity commands; the slot count is not in the instructions; the skill treats the canister ids as a file to pass in and write back unchanged; the instructions point to the guide once.
  • Open, from aterga on imcp2-deploy 6/6: serve the deploy tools on the hosted server, with the bundle uploaded on a ticket #243: a mitigation for one client holding every deploy slot, and whether the guide should exist as both a skill resource and a tool.

Changes

  • crates/imcp2-deploy/src/lib.rs (868 lines of code, 276 of tests), src/server.rs, static/skills/deploy-with-mcp.md; Cargo.toml adds rmcp, serde, http, url.
  • imcp2-core: cycles_balance_of split out of cycles_balance; DEPLOYS_ELSEWHERE exported.
  • crates/imcp2-local: server.rs, main.rs, Cargo.toml, README.

Testing

  • cargo build --locked --workspace --all-targets
  • cargo test --locked --workspace --all-targets
  • cargo fmt --all -- --check

Tested: each kind of server accepts its bundle argument and refuses the other, and lists the one it takes; the request's defaults, its parsed ids, and the rejections that name a bad mode, id or subnet; a relative deploy directory made absolute; the tool list; the human-readable result; the skill document's shape. The local server's round-trip tests cover the deploy tools in its listing and the skill among its resources.

Not covered: the Internet Identity round trip that mints the deploy delegation, and an on-chain deploy (see #231).

The stack

Six stacked PRs that bring icp deploy to the MCP servers through the icp CLI's own project library. Re-cut on 2026-11-18 so that each file arrives once, in the form it has at the top; the tree at the top is unchanged from before the re-cut, rebased onto current main.

PR What
1 #230 The crate and the icp-project host for an untrusted bundle
2 #246 Signing: canister calls over ic-agent, an identity that refreshes
3 #231 The deploy pipeline, its events and its interruption
4 #247 The upload-ticket store
5 #232 The MCP tools, and the local server serving them
6 #243 The hosted server serving them

#242 (streamed phases, interruption) and #245 (one bundle source per server, crates.io) are closed: their changes are folded into the PRs above.

Checklist

  • I have read the Contributing guidelines.
  • Docs (README / comments) updated for any user-visible change.
  • No secrets, credentials, or internal-only information are included.

🤖 Generated with Claude Code

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

Concurrent deployments or retries after an interrupted response can create duplicate funded canisters; balance checks may use the wrong network, and revoked grants may continue signing.

6 open issues
What changed in this PR

Completes the three-part deployment integration by exposing bundle deployment and cycles-balance tools through the local MCP server, while keeping deployment dependencies out of the published core crates.

Changes:

  • Adds authenticated deployment tools with validated inputs, structured results, and refreshing signing identities.
  • Composes the tools and deployment skill into the local server, with expanded MCP round-trip tests.
  • Documents the bundle–deploy–save-mapping workflow and exposes reusable core balance helpers.
File Description
crates/​imcp2-local/​src/​server.rs Routes deployment tools, serves the skill, and extends integration tests.
crates/​imcp2-local/​src/​main.rs Constructs and wires the deployment tool group.
crates/​imcp2-local/​README.md Documents deployment inputs, identities, and mapping persistence.
crates/​imcp2-local/​Cargo.toml Adds the deployment crate dependency.
crates/​imcp2-deploy/​static/​skills/​deploy-with-mcp.md Adds agent guidance for bundling, deploying, and saving IDs.
crates/​imcp2-deploy/​src/​lib.rs Implements tool schemas, validation, authorization, and results.
crates/​imcp2-deploy/​src/​identity.rs Adds delegation refresh during long-running deployments.
crates/​imcp2-core/​src/​management.rs Extracts a balance helper for an explicit principal and agent.
crates/​imcp2-core/​src/​lib.rs Exports balance helpers and their result type.
crates/​imcp2-core/​src/​identities.rs Makes identity-specific agent construction public.
Cargo.lock Records the local server’s deployment dependency.

Review effort: Balanced

Comment thread crates/imcp2-deploy/src/identity.rs Resolved
Comment thread crates/imcp2-deploy/src/lib.rs Resolved
Comment thread crates/imcp2-deploy/src/lib.rs Resolved
Comment thread crates/imcp2-deploy/src/lib.rs Resolved
Comment thread crates/imcp2-deploy/src/identity.rs Resolved
Comment thread crates/imcp2-deploy/src/lib.rs Resolved
Copilot AI balanced review requested due to automatic review settings November 3, 2026 20:34

Copilot AI left a comment

Copy link
Copy Markdown

Comment thread crates/imcp2-deploy/src/lib.rs Resolved
Comment thread crates/imcp2-local/src/server.rs Resolved
Comment thread crates/imcp2-deploy/src/lib.rs Resolved
Comment thread crates/imcp2-local/src/server.rs Resolved
Copilot AI balanced review requested due to automatic review settings November 3, 2026 23:42

Copilot AI left a comment

Copy link
Copy Markdown

Comment thread crates/imcp2-deploy/src/deploy.rs Resolved
Comment thread crates/imcp2-deploy/src/deploy.rs Resolved
Comment thread crates/imcp2-deploy/src/lib.rs Outdated
Ok(id) => id,
Err(e) => return Ok(err(e)),
};
match deploy_bundle(identity, request).await {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Still open: the runner builds its own engine and store (icp-sync-plugin), so the limiter belongs upstream, and host_for's doc records the gap. Refusing sync steps until then would refuse the asset canister a bundle is deployed for. Left open until the runner has one.

Comment thread crates/imcp2-local/src/main.rs Resolved
@raymondk
raymondk marked this pull request as draft November 4, 2026 00:17

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

The deployment guide overstates compatibility protection because the upstream check skips comparison when deployed Candid metadata is unreadable; qualify the guarantee and advise separate verification in that case.

2 open issues
3 resolved since last review

Review effort: Balanced

Comment on lines +125 to +128
Canisters named in `canister_ids` are upgraded with the Candid compatibility
check; an incompatible interface change fails the deploy before any code is
replaced. Pass `skip_candid_check: true` only when the user has accepted the
break. `mode` (default `auto`; `install`, `reinstall`, `upgrade`),
Copilot AI balanced review requested due to automatic review settings November 18, 2026 02:00
@raymondk
raymondk removed this pull request from stack #233 November 18, 2026 02:01
@raymondk
raymondk changed the base branch from deploy-2-pipeline to deploy-2b-uploads November 18, 2026 02:01
@raymondk
raymondk added this pull request to stack #248 November 18, 2026 02:02
@raymondk raymondk changed the title imcp2-deploy 3/3: serve icp_deploy_bundle and icp_cycles_balance from the local MCP server imcp2-deploy 5/6: the MCP tools, served from the local server Nov 18, 2026

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.

🔵 Needs a closer look

Unbounded stored and in-flight uploads let one authorized session exhaust disk space, while cancellation and restarts can leave orphaned archives that cleanup never removes.

2 open issues

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 18, 2026 03:17
…icp_cycles_balance, icp_deploy_guide

`IcDeployTools` is the tool group over the pipeline, and `WithDeploy` the
handler that serves it beside the core surface. A deploy is signed as the
user's developer principal, runs as one blocking call that reports each
phase as it completes (a progress notification, or a log message for a
client that sent no token), and is interrupted when the call is cancelled.
One deploy runs per session, and a server caps how many run at once;
past either a deploy is refused, not queued. Each deploy's working
directory is its owner's alone, under a directory the server names.

A server takes the bundle one way and lists that argument alone: a path on
a server that sits with the project, an upload on one that does not. The
upload side (`icp_deploy_upload`, on the store from the previous change) is
here with the rest of the tool group; nothing mounts it until the hosted
server does.

The deploy skill is served as `skill://deploy-with-mcp` and returned by
`icp_deploy_guide` for a client that reads no resources.

imcp2-local composes the group always, takes the bundle by path, and
refuses to start without a local data directory for deploy records.

Co-Authored-By: Claude Fable 5.2 <[email protected]>

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

The test cleanup can destroy pre-existing files by recursively deleting the working directory’s entire state folder, and the guide misstates hosted authentication recovery and compatibility-check guarantees.

4 open issues

Review effort: Balanced

Comment on lines +1049 to +1055
let tools = tools().deploys_in(std::path::Path::new("state/deploys")).unwrap();
let dir = tools.deploys_dir.clone().unwrap();
assert!(dir.is_absolute(), "{dir}");
let cwd = std::env::current_dir().unwrap().canonicalize().unwrap();
assert_eq!(dir.as_std_path(), cwd.join("state/deploys"));
assert!(dir.is_dir(), "made now, not on first use");
std::fs::remove_dir_all(cwd.join("state")).unwrap();
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`.
Copilot AI balanced review requested due to automatic review settings November 18, 2026 03:31

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.

🔵 Needs a closer look

A test recursively deletes the working directory’s entire state folder, risking destruction of pre-existing files unrelated to the test.

4 open issues

Review effort: Balanced

@raymondk

Copy link
Copy Markdown
Contributor Author

Superseded by the stack #254 → #259, which carries the same code in six PRs from main, with the deploy tools living in imcp2-core instead of a separate crate. The MCP tools and the local server are in #257.

@raymondk raymondk 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