Repository navigation
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
Critical upload-lifecycle and quota-accounting flaws can delete directories still used by workers and allow concurrent uploads or retained records to bypass resource limits.
6 open issues
Reject a zero extracted-bytes limit · New Account for retained interrupted-upload storage · New Keep the directory lock alive through background work · New Validate the canonical deploy path during construction · New Stop in-progress uploads during graceful shutdown · New Decouple archive and extracted-size limits · New
What changed in this PR
Integrates the existing core deploy tools into the hosted MCP server. Embedders opt in with McpServer::with_deploy; the bundled binary always enables them.
Changes:
- Adds ticket-authenticated uploads and streamed deploy progress, with cancellation when clients disconnect.
- Shares deploy limits, storage, directory locking, cleanup, and shutdown state across endpoints.
- Adds binary configuration, integration tests, and deployment documentation.
| File | Description |
|---|---|
src/main.rs |
Configures shared deploy state and coordinates shutdown. |
src/lib.rs |
Adds optional deploy integration and lifecycle hooks. |
src/deploy.rs |
Implements upload routing, progress streaming, shared state, and tests. |
src/auth.rs |
Adds a test-only bearer-token helper. |
README.md |
Documents hosted deployment behavior and configuration. |
deploy/native/README.md |
Documents operational limits, upload timeouts, and recovery records. |
deploy/native/imcp2.service |
Updates shutdown comments; service settings are unchanged. |
Cargo.toml |
Adds streaming support and deploy-test dependencies. |
Cargo.lock |
Updates the root package’s dependency entries. |
Review effort: Max
| /// | ||
| /// Also an error: an entry of [`DeployConfig::allowed_plugins`] that is | ||
| /// not a sha256. A list read wrong is not run with. | ||
| pub fn new(config: &DeployConfig, state_dir: &Path) -> std::io::Result<Self> { |
| /// One sweep; see [`Self::spawn_sweeper`]. | ||
| fn sweep(&self) { | ||
| self.uploads.sweep(); | ||
| let removed = imcp2_core::deploy::remove_old_deploy_records(&self.dir, DEPLOY_RECORD_TTL); |
| json: service(transport.clone().with_json_response(true)), | ||
| sse: service(transport.with_json_response(false)), | ||
| uploads, | ||
| _owned: deploys._owned.clone(), |
Comment on lines
+239
to
+240
| let dir = state_dir.join("deploys"); | ||
| let owned = own_directory(&dir)?; |
Comment on lines
+501
to
+504
| let reader = tokio_util::io::StreamReader::new( | ||
| request.into_body().into_data_stream().map_err(std::io::Error::other), | ||
| ); | ||
| let received = mcp.uploads.receive(&ticket, declared, reader).await; |
Comment on lines
+150
to
+153
| anyhow::ensure!( | ||
| config.max_upload_bytes <= config.max_extracted_bytes, | ||
| "MCP_DEPLOY_MAX_UPLOAD_BYTES ({}) must be at most MCP_DEPLOY_MAX_EXTRACTED_BYTES ({}): \ | ||
| an archive is never larger than what it extracts to", |
This was referenced Nov 19, 2026
raymondk
marked this pull request as draft
November 19, 2026 03:12
raymondk
force-pushed
the
deploy-core-5-remote
branch
from
November 19, 2026 04:06
c86a53f to
ca65db1
Compare
raymondk
force-pushed
the
deploy-core-5-remote
branch
from
November 19, 2026 15:59
ca65db1 to
193629e
Compare
…loaded on a ticket
The deploy tools on the `imcp2` server, for an embedder that turns them on
(`McpServer::with_deploy`); the bundled binary always does.
- **How the bundle arrives.** `icp_deploy_upload` mints a ticket inside an
authenticated call, and the archive is `PUT` to `{mcp_path}/deploy/upload`
on it. The route is outside the bearer gate — the ticket is its
authentication — and the body is extracted as it arrives: 413 at the
byte that takes the archive, or what it extracts to, past its limit, and
422 for what is not a bundle or carries a sync plugin the server does
not run. The deploy tool here refuses a path: the server opens no file a
caller names.
- **A deploy call is answered as an event stream**, so each phase reaches
the client before the result; every other request keeps the plain JSON
answer. A client that goes away stops its deploy.
- **One deploy state for the process** (`Deploys`): the slots, the upload
store and the word that the server is stopping are shared by every
endpoint. It locks its directory, so a second server over the same
state directory is refused rather than clearing the first one's
uploads; clears what a killed process left; and sweeps what has lapsed.
- **Stopping.** `Deploys::stop` before the drain tells running deploys to
end and refuses new ones, and `Deploys::stopped` waits, bounded, for
them to have ended: a deploy waiting on a canister call whose client
has gone holds no connection for a drain to wait on. The server's own
`spawn_session_reaper` and `shutdown` cover the sweeper and the stop for
an embedder that does nothing more.
- **Configuration** is `DeployConfig`: deploys at once, the archive and
extracted limits, the budget for every bundle held, and the sync plugins
run besides the ones the server knows. The library reads no environment
variable; the bundled binary maps `MCP_DEPLOY_*` onto it and refuses to
start on values that contradict one another.
Co-Authored-By: Claude Fable 5.2 <[email protected]>
Claude-Session: https://claude.ai/code/session_01XSXgo38kH12wagL3rstXfV
raymondk
force-pushed
the
deploy-core-5-remote
branch
from
November 19, 2026 16:21
193629e to
cd5bd52
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Fifth of six. Stacked on the tools PR.
What this PR adds
The deploy tools on the
imcp2server. An embedder turns them on withMcpServer::with_deploy; the bundled binary always serves them.PUT {mcp_path}/deploy/uploadon a ticket fromicp_deploy_upload. The route is outside the bearer gate, since the ticket is its authentication. The body is extracted as it arrives:413when the archive or its extracted size passes its limit,422when it is not a bundle or carries a sync plugin the server does not run. The deploy tool here refuses a path.Deploys). Slots, the upload store and the stopping signal are shared by every endpoint. It locks its directory, so a second server over the same state directory is refused instead of clearing the first one's uploads.Deploys::stop()before the drain,Deploys::stopped().awaitafter it, thenshutdown(). The second call matters because a deploy whose client has gone holds no connection for a drain to wait on.spawn_session_reaperandshutdowncover the sweeper and the stop for an embedder that does nothing more.DeployConfig. The library reads no environment variables; the bundled binary mapsMCP_DEPLOY_*onto it and refuses to start on contradictory values.Behaviour change for the bundled binary
It now always serves the deploy tools. There is no cargo feature and no runtime switch. Anyone running the
imcp2binary gets the upload endpoint and deploy tools, behind Internet Identity sign-in and the limits above.What the deploy tools hold in memory
On a RAM-backed state directory, the upload store's budget is the bound: by default one 128 MiB bundle per concurrent deploy plus one, so 384 MiB with the default of two deploys. A running deploy also reads one module at a time onto the heap.
Open question carried over from #243
A reviewer asked whether the upload works through the IC gateways (thread). I have not tested it there. Things to check on the gateway side: any request-body size limit or timeout in front of the MCP routes, and that a streamed
PUTbody is passed through unbuffered.For the gateway's integration
Deploys::newreturns aResult; it fails when another server owns the state directory or an allowed-plugin entry is not a SHA-256.Testing
The whole loop through the router (ticket, upload, refusals, deploy as an event stream), shared state across two endpoints, the directory lock, the lifecycle hooks, the bounded shutdown wait, and configuration parsing. Not tested: a real HTTP client's view of an upload stopped mid-body, and a restart during a real deploy.
🤖 Generated with Claude Code
https://claude.ai/code/session_01XSXgo38kH12wagL3rstXfV