Skip to content

Identity tools take derivation_origin only (drop app_url) — resolve once, reuse - #64

Merged
aterga merged 2 commits into
mainfrom
claude/mcp-connector-tool-discovery-si0bx7
Jul 17, 2026
Merged

aterga merged 2 commits into
mainfrom
claude/mcp-connector-tool-discovery-si0bx7

Conversation

@aterga

@aterga aterga commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator

Follow-up to the guessed-domain work (#57). Makes the identity-bearing tools identify an app one way — by its canonical derivation_origin, resolved once — instead of also accepting a website app_url that the stateless server re-resolves on every call.

Change

  • call_canister, get_app_principal, list_app_accounts: the app_url parameter is removed; they take only derivation_origin.
  • run_canister_oql_query / get_canister_oql_schema: already derivation_origin-only; deliberately not extended with app_url (this reverses the earlier "uniformity via app_url" idea in favor of uniformity via derivation_origin).
  • open_app / resolve_app are unchanged — resolving a name/URL to the derivation origin is their job, and they still run the guessed-domain gate.

Why

A derivation origin is a stable per-app value. On a stateless server, accepting a URL on every identity call re-resolved it (a network round-trip) each time, and offering two ways to identify an app invites an agent down the inefficient path. Now the app is resolved once (open_app/resolve_app return the derivation_origin) and that origin is reused across calls — one obvious contract, zero repeated resolution. In practice the origin is already in hand: you call open_app/discover_app_canisters to get the canister id anyway, and open_app returns the derivation origin alongside it.

Safety

The guessed-domain gate is unaffected — it lives at the resolver step (open_app/resolve_app), which is on the critical path (you must resolve to get the canister id). derivation_origin stays trusted verbatim (ungated) — the deliberate escape hatch for custom / non-IC-hosted II origins — so this opens no new hole (a fabricated derivation_origin was always ungated); it removes a gated shortcut in exchange for efficiency and a single contract. Prompt steering + the derivation_origin field description continue to say "get it from open_app/resolve_app, never guess."

Mechanical fallout

resolve_identity_target is now derivation_origin-only and synchronous; IdentityTarget drops the (already dead-code) application_origin field; identity_annotation drops its now-unreachable app_url_default branch; derivation_origin_source on these tools is always "explicit" (the declared/known/app_url_default sources are reported by the resolver tools). Tool descriptions, arg schemas, the server instructions, and the README are updated; the old app_url-path unit tests are retargeted to clean_app_url.

Note: breaking change to call_canister/get_app_principal/list_app_accounts signatures (the domain alias for derivation_origin is retained). Fine for the MVP/preview surface.

Tests

Full suite: 119 passed, 0 failed locally (offline unit + live discovery/identity). The tool count is unchanged (26).

🤖 Generated with Claude Code

https://claude.ai/code/session_01NDKdKM6Nhp3z8xxJEDqToh


Generated by Claude Code

Follow-up to the guessed-domain work (#57). The identity-bearing tools no
longer accept an `app_url` to auto-resolve — they take ONLY
`derivation_origin`:

- call_canister, get_app_principal, list_app_accounts: `app_url` removed.
- run_canister_oql_query / get_canister_oql_schema were already
  derivation_origin-only; NOT extended with app_url (the earlier
  "uniformity via app_url" idea, reversed).

Rationale: a derivation origin is a STABLE per-app value, and the server
is stateless, so accepting a URL on every call re-resolved it (a network
round-trip) every time — and having two ways to identify an app invites
the inefficient path. Now the app is resolved ONCE via open_app /
resolve_app (which run the guessed-domain gate and return the derivation
origin) and that origin is reused across calls. One obvious way in;
zero repeated resolution.

The guessed-domain gate is unaffected: it lives at the resolver step
(open_app/resolve_app), which is on the critical path anyway (you resolve
to get the canister id). `derivation_origin` remains trusted verbatim
(ungated) — that's the deliberate escape hatch — so this opens no new
hole (a fabricated derivation_origin was always ungated); it removes a
gated shortcut in favor of efficiency + a single contract.

resolve_identity_target is now derivation_origin-only and synchronous;
IdentityTarget drops the unused application_origin field; identity_annotation
drops its now-unreachable app_url_default branch; derivation_origin_source
on these tools is always "explicit" (the declared/known/app_url_default
sources are reported by the resolver tools). Tool descriptions, arg
schemas, server instructions, and README updated; app_url-path unit tests
retargeted to clean_app_url. Full suite: 119 passed.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NDKdKM6Nhp3z8xxJEDqToh

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.

Pull request overview

This PR simplifies the “act as user at app” tool surface by removing the app_url identity path and requiring callers to use the app’s canonical derivation_origin (resolved once via open_app/resolve_app) across identity-bearing operations, avoiding repeated URL resolution on a stateless server.

Changes:

  • Removed app_url from call_canister, get_app_principal, and list_app_accounts, and made resolve_identity_target derivation-origin-only and synchronous.
  • Updated tool descriptions/server instructions and identity annotations to reflect the derivation-origin-only contract.
  • Retargeted/updated tests and README documentation to match the new API surface.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
src/main.rs Drops app_url identity resolution, updates tool docs/instructions, and refactors resolve_identity_target + related tests.
src/identities.rs Updates identity tool argument/output docs to be derivation-origin-only and removes app_url fields from argument structs.
src/calls.rs Removes app_url from call_canister args and updates output field documentation accordingly.
README.md Updates public documentation to describe the derivation-origin-only identity flow and tool signatures.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/identities.rs Resolved
Comment thread src/identities.rs Resolved
…rincipal/list_app_accounts

These two tools always act as an app account — they errored at runtime
when derivation_origin was omitted — but modeling it as Option<String>
with #[serde(default)] advertised it as OPTIONAL in the generated MCP
schema, so a client/model could omit it and only hit the requirement at
call time. It's now a required `String` (keeping the `domain` alias), so
the schema marks it required and validation fails up front. Handlers pass
Some(derivation_origin) into resolve_identity_target.

call_canister keeps Option<String> — there, omitting it is a valid
anonymous call.

Full suite: 119 passed.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NDKdKM6Nhp3z8xxJEDqToh
@aterga
aterga marked this pull request as ready for review July 17, 2026 08:29
Copilot AI review requested due to automatic review settings July 17, 2026 08:29
@aterga
aterga merged commit 4be4081 into main Jul 17, 2026
1 check passed

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.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

Comment thread src/main.rs
Comment on lines +496 to 501
// `derivation_origin` is a required String here, so this always yields a
// target (never the anonymous None) unless it fails validation.
let target = match resolve_identity_target(Some(derivation_origin)) {
Ok(Some(t)) => t,
Ok(None) => return Ok(err("provide `derivation_origin` or `app_url` to identify the app".into())),
Ok(None) => return Ok(err("`derivation_origin` must not be empty".into())),
Err(e) => return Ok(err(e)),
Comment thread src/main.rs
Comment on lines +551 to 556
// `derivation_origin` is a required String here, so this always yields a
// target (never the anonymous None) unless it fails validation.
let target = match resolve_identity_target(Some(derivation_origin)) {
Ok(Some(t)) => t,
Ok(None) => return Ok(err("provide `derivation_origin` or `app_url` to identify the app".into())),
Ok(None) => return Ok(err("`derivation_origin` must not be empty".into())),
Err(e) => return Ok(err(e)),
aterga pushed a commit that referenced this pull request Jul 17, 2026
Main advanced to 88984cb, notably #64 "Identity tools take derivation_origin
only (drop app_url)", which overlapped this branch's changes. Reconciliation:

 - README tools table (the only textual conflict): kept this branch's rows for
   get_canister_candid (oql + api_doc_available flags) and get_canister_api_doc
   (structured available/expected/retry/next), and took main's rows for
   call_canister / get_app_principal / list_app_accounts (app_url dropped —
   derivation_origin only).
 - main.rs / calls.rs auto-merged textually but had semantic staleness from the
   app_url drop, fixed here: the call_canister empty-read note hint, open_app's
   "Next:" text, and the server-instructions MY/OUR block no longer offer app_url
   for the identity tools; the is_anonymous doc comment dropped its app_url mention.
 - This branch's require-origin guards on the OQL read tools, capability-flag
   enrichment, and empty-read diagnostics all survive alongside main's resolve-once
   restructure.

cargo build + cargo test --all-targets pass (124 tests); no conflict markers, no
stale identity-tool app_url references remain.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Claude-Session: https://claude.ai/code/session_01HRpq9CvXFNhkr2roH7j22d
aterga pushed a commit that referenced this pull request Jul 28, 2026
Rebased onto main after #64 (identity tools take derivation_origin only),
reconciliation is now carried by #66, so this narrows to the non-auth
improvements that main still lacks:

- call_canister: document the candid? arg; state the OQL query-call
  rejection accurately (fires when get_canister_candid reports oql: true,
  not on any OQL canister).
- discover: reframe open_app as the one-call entry point; note the domain
  argument accepts a domain or URL.
- App Connect: add the SSRF-hardening note (CWE-918), scoped precisely
  (user-supplied fetches are address-pinned; dashboard/registry enrichment
  uses the redirect guard only).
- OQL: define the CWE-674 guard (1 MiB / 128-depth pre-parse check over
  textual Candid; the OQL query path is JSON and only shares the size cap).
- Creating canisters: correct the CMC recovery hint (re-notify with the
  same arguments; the block index alone is not enough).
- Run/Deploy: self-contained binary via include_str!; OAUTH_CLIENTS_FILE is
  always used (default oauth-clients.json, read on startup, best-effort
  write), needs a writable path; graceful SIGTERM/SIGINT drain; landing page.
- Try it: fix the stateless plain-JSON example (drop the SSE parsing and
  session-id dance, show the bearer token, label the read anonymous).
- Domain identities: correct the stale custom-derivation-origin note (the
  app_url path resolves declared/known origins via resolve_app; only a raw
  derivation_origin is used verbatim).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Claude-Session: https://claude.ai/code/session_014T9N8USDfNK5yzznPGg7Ym
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