Skip to content

chore: Dockerfile at repo root + CI build/push to GHCR - #2

Merged
aterga merged 2 commits into
mainfrom
feat/icp-mcp-server
Jun 16, 2026
Merged

aterga merged 2 commits into
mainfrom
feat/icp-mcp-server

Conversation

@aterga

@aterga aterga commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator

Follow-up to #1, which was merged before these two commits landed:

  • Move the Dockerfile to the repo root so docker build . works without -f (the build context was already the root; COPY paths are unchanged).
  • Add a GitHub Actions workflow that builds the linux/amd64 image and pushes it to ghcr.io/aterga/icp-mcp-server using the built-in GITHUB_TOKEN. Merging this to the default branch publishes the :latest tag.

Tests

CI built and pushed the image successfully on the branch (:feat-icp-mcp-server, :sha-76080f8).

aterga and others added 2 commits June 16, 2026 16:56
The build context was already the repo root, so this only changes the
file's location (no -f flag needed) — COPY paths are unchanged.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Add a workflow that builds the linux/amd64 image and pushes it to
ghcr.io/<owner>/icp-mcp-server using the built-in GITHUB_TOKEN, so the
deployable image is produced in CI without a local Docker build. Update
the README accordingly.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@aterga
aterga merged commit d06de2e into main Jun 16, 2026
1 check passed
@aterga
aterga deleted the feat/icp-mcp-server branch June 16, 2026 15:13
aterga added a commit that referenced this pull request Jul 17, 2026
…origin for OQL reads (Tiers 0–1) (#61)

* Make per-app reads self-correcting: surface auth as the missing ingredient (Tiers 0-1)

Anonymous per-app reads come back empty because the data is gated by the
caller's principal, and nothing in the old tool surface signalled that
authentication — not "no data" — was the missing ingredient. An agent asked a
"my data in this app" question would read empty, guess bespoke method/entity
names, and thrash before stumbling onto passing the app_url. This reworks the
return payloads, error messages, capability flags, and the server-instructions
playbook so the authenticated path is the obvious one and an empty read is
self-explaining.

Tier 0
 #1 Empty reads now carry an auth signal. get_canister_oql_schema,
    run_canister_oql_query, and call_canister query results always echo
    is_anonymous (alongside acted_as_principal / derived_for_origin). When a read
    is anonymous AND empty, they append a note: empty here most likely means "not
    authenticated as your account", so re-run adding the origin. Computed only
    from local facts (anonymous && empty) — never by probing whether
    authenticated data exists — and the origin stays a placeholder the agent
    fills, never one guessed via app_url_default.

Tier 1
 #2 Rewrote the server-instructions playbook: open_app FIRST for a named app; a
    "my/our…" question is an authenticated read (pass the origin); anonymous
    per-app reads usually return empty and that's an auth artifact; call
    get_canister_api_doc only when candid says it's available; oql:true => reads
    via the OQL tools, call_canister is updates-only. Dropped the old
    "discover_app_canisters first" / "get_canister_api_doc FIRST" advice.
 #3 open_app / discover_app_canisters now probe each app-owned canister's Candid
    once (enrich_capabilities) and attach oql / api_doc_available flags plus a
    caller-gated data-access note bound to the resolved derivation_origin. Scoped
    by is_app_data_candidate to the app's own data canisters — never
    II/NNS/ledger/frontend — per the origin-resolution trust boundary.
 #4 get_canister_candid reports api_doc_available, computed with the same
    predicate get_canister_api_doc uses, so the api-doc call is gated on it.
 #5 The call_canister OQL-rejection message names the replacement path
    (icp_oql_guide -> get_canister_oql_schema -> run_canister_oql_query) and the
    auth hint (pass the origin for the user's own data).
 #6 get_canister_api_doc returns a structured result in every case
    (available/expected/retry/next), distinguishing an expected absence from an
    unreachable canister instead of one opaque error.
 #7 run_canister_oql_query validates the query's start entity on an empty result
    (validate-on-empty, not preflight) by re-reading the schema for the SAME
    principal, returning valid_entities + a did_you_mean repair (booking ->
    bookings). Hard-validates start only.
 #8 get_canister_oql_schema emits a ready-to-run run_canister_oql_query example
    per entity, each preserving the identity the schema was read under so copying
    one doesn't silently drop to anonymous.
 #9 Rewrote the OQL tool descriptions (guide->schema->query; entity names are
    often plural and differ from Candid; my-data => pass origin) and the OQL primer.

Tests cover the new pure helpers (empty detection, entity extraction,
did_you_mean, examples, conservative empty-reply detection, app-data-candidate
scoping) and the enriched OQL-rejection message. Tier 2 (auto-authenticated
reads / open_app_as_me) is left to a follow-up.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HRpq9CvXFNhkr2roH7j22d

* Address adversarial review: fix empty-diagnosis on error paths, app_url mis-hints, unparsed-reply note

Folds in the confirmed findings from an adversarial review of the Tier 0-1 diff
(4 dimensions x per-finding verification). No high-severity findings; the
security-guardrail dimension found nothing.

 - diagnose_empty_oql now takes an EmptyContext. On a FAILED result (trap / OQL
   error arm) it emits ONLY the #7 unknown-`start` repair, never the "came back
   empty => likely not authenticated" / "no entities here" notes — those describe
   an EMPTY result and would contradict a genuine error message. (Previously an
   anonymous query with a valid start that ERRORED got a misleading re-authenticate
   hint.)
 - diagnose_empty_oql distinguishes a FAILED schema re-read (entities: None) from a
   schema that genuinely lists no entities (Some([])), so a transient schema-read
   failure on an authenticated empty-table result no longer mislabels it "this
   account sees no entities" — it falls back to the benign "0 rows" note.
 - Dropped the "(or app_url)" hint for the OQL read tools in three places (the
   open_app data-access handle, the open_app description, and the server-instructions
   MY/OUR block): get_canister_oql_schema / run_canister_oql_query take only
   `derivation_origin`; `app_url` is call_canister's. Offering it sent the agent to
   a param those tools silently ignore -> an anonymous empty read.
 - The OQL Unrecognized-result arm now carries a structured `note` ("not an empty
   result; raw reply is in the text block"), so a structured-only consumer doesn't
   misread a non-tabular reply as "no data".
 - Fixed the candid_reply_is_empty doc to match the implementation: it recognizes
   `variant { none }` only; an explicit `variant { err = … }` is a real error, not
   "empty" (with a test assertion locking that contract in).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HRpq9CvXFNhkr2roH7j22d

* Build OQL example query with serde_json so untrusted entity names are escaped

Addresses a Copilot review comment on PR #61: oql_query_examples built the
example `query` JSON string with format!, so a schema entity name containing a
quote or backslash — the schema is canister-supplied, hence untrusted — would
produce invalid JSON in the (advisory) example. Build the query object via
serde_json::json!(...).to_string() instead, which escapes it. Added a test with
a quoted entity name asserting both the args and the inner query string parse as
valid JSON and the name round-trips.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HRpq9CvXFNhkr2roH7j22d

* Require an origin for OQL reads: disable anonymous per-app reads for now

Per maintainer direction, replace the soft "anonymous empty read" auth note on
the OQL read tools with a hard precondition: get_canister_oql_schema and
run_canister_oql_query now REJECT a call with no derivation_origin, since they
read per-app data gated by the caller's principal (an anonymous read is signed as
2vxsx-fae and returns nothing useful). The rejection names what to pass and points
at open_app / resolve_app so the agent recovers in one step. A hard reject can't
be misread as "no data" the way an empty result can.

Rationale for no anonymous escape hatch: authenticating never hurts a public read
— the canister serves the request regardless of principal, so a caller with no
account there simply isn't blocked. So there's no case that needs anonymous.

Scope:
 - Applies to the two OQL read tools only (the definitively caller-gated per-app
   data surface). The guards are a two-line origin.is_none() check, so re-enabling
   anonymous later is a trivial revert — the is_anonymous field and the empty-read
   diagnostics are left intact and simply aren't reached while the guards stand.
 - call_canister stays permissive (keeps its soft empty-read note): it's the
   general-purpose tool used for genuinely public canisters like ledgers, where
   there's often no app origin to pass and hard-blocking would break common public
   reads for no gain.
 - Public-metadata tools (get_canister_candid, get_canister_api_doc,
   discover_app_canisters, resolve_app) are unaffected — they read public data and
   take no origin.

Updated the OQL tool descriptions, the server-instructions playbook, the
get_canister_candid OQL note, open_app's description + data-access note, and the
OQL primer to say the OQL reads REQUIRE the origin (not "anonymous comes back
empty"). Added a test that the rejection message is actionable.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HRpq9CvXFNhkr2roH7j22d

* Sync README with the tool changes (capability flags, structured api-doc, require-origin OQL reads)

The README tool table + flow drifted from the code. Brought them current:
 - get_canister_candid now advertises both `oql` and `api_doc_available` flags.
 - get_canister_api_doc is call-only-when-available and returns a structured
   available/expected/retry/next result (not "call first for an unfamiliar app").
 - get_canister_oql_schema / run_canister_oql_query now REQUIRE derivation_origin
   (anonymous per-app reads are rejected for now); noted the per-entity examples
   and the empty-result start validation / did_you_mean.
 - open_app / discover_app_canisters now report per-canister oql/api_doc_available
   capability flags + the caller-gated data-access note.
 - Typical flow + OQL section updated to say the OQL read tools require the origin
   while public metadata and call_canister public reads stay anonymous.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HRpq9CvXFNhkr2roH7j22d

---------

Co-authored-by: Claude <noreply@anthropic.com>
blind-oracle added a commit that referenced this pull request Nov 10, 2026
aterga pushed a commit that referenced this pull request Dec 4, 2026
Copilot's second review found eight more issues, all High, all real and all
reproduced before fixing. Seven are ways past the guard; counting the first
round, nine in total:

  cat <<EOF with $(gh api ...)   an unquoted body is expanded, so it runs
  <<'END-DOC'                    delimiter normalised to ENDDOC, so the
                                 terminator never matched and the rest of
                                 the command was swallowed
  x=$((1<<2))                    arithmetic read as a heredoc on "2"
  /bin/bash <<'EOF'              the interpreter check wanted a bare name
  cat <<'EOF' | bash             it looked only before the operator
  gh  pr ready                   the pattern matched a single space
  gh pr ready 1 --undo; gh api   --undo anywhere exempted the whole line
  repos/$REPO/pulls/$PR/...      no literal target, so no target was found
  repos/{owner}/{repo}/...       likewise

Every one is the same bug: the guard defaulted to ALLOW whenever it failed to
understand something. Shell is not a regular language, so patching each case
in turn only buys time until the tenth.

The default is now inverted. The question is no longer "does this promote?"
but "can I prove this promotes nothing I have not checked?":

  * text that mentions no promotion exits silently, as before;
  * anything promotion-shaped defaults to DENY;
  * a heredoc body is dropped only when the delimiter is quoted, there is no
    pipe, and the command owning it is PROVEN not to execute its input --
    cat, tee, dd, git. Naming the dangerous interpreters instead would mean
    enumerating bash, sh, python3, perl, node ... and the first one forgotten
    is the next bypass, which is how /bin/bash got through;
  * every promotion must resolve to a literal owner/repo/number. Counting
    promotions against resolvable targets is what makes this hold when an
    unresolvable one sits beside a resolvable one.

Also from the review:

  * .claude/settings.json drops its `if: Bash(gh *)` filter. It reads the
    start of the command string, so the hook was never invoked for
    `bash -c 'gh api ...'` -- a command it can judge perfectly well. The
    offline tests could not catch this, since they invoke the script directly.
  * pr-gates.sh: ci_green passed when the only check present was `skipped`,
    which happens when the draft-review workflow reports before CI registers
    anything. It now counts checks that actually ran, and
    PR_GATES_REQUIRED_CHECKS can pin names that must have reported.
  * The two-target test ran against a stub that blocked BOTH pull requests,
    so it passed whether the guard checked both or only the first -- the
    regression it existed to catch. It now uses a stub that passes #1 and
    blocks #2, confirmed by making the guard check only the first and
    watching the case go red.
  * The skill documented the {owner}/{repo} form, which the guard now denies.

Suites: 36 guard cases (was 16), 45 gate cases (was 41).

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VP2vTFTrLpdUDpcNfWdouN
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.

1 participant