Skip to content

MCP server for relay admins: seven audited tool families (family (b) of #867) #1183

Closed

Description

@chappie-daemon

Parent: #867 (family (b) of three; slice 1 — HTTP admin routes + console parity — is the job that carries #867 itself)
Milestone: Phase 5 · Labels: rewrite, rust, mcp, factory
Dependency: needs the HTTP admin surface from #867 to exist, because the tool handlers reuse its session/auth model and audit path.

The MCP server for relay admins: a new crate (nostream-admin-adjacent) using the rmcp SDK, exposing the seven tool families the issue named:

  • relay_status — uptime, worker health, connection count, version, NIP-11 doc
  • list_events / get_event / delete_event — audited event-store inspection with kind/pubkey filters
  • user_admin — admission, vanish, balance ops
  • invoices_* — list/inspect payment invoices
  • reports_* — NIP-56 triage: list, action (hide/allow), audit trail
  • settings_get / settings_set — the typed, schema-validated settings surface
  • maintenance_* — trigger retention/cleanup, read last-run stats

Auth is the same admin credential model as the HTTP console; every call is audit-logged to the delivery-log store.

Measured at f01cb5f3 (recon for job 032-admin-console-parity):

  • TypeScript counterpart: none — grep -rn -i mcp src/ has no hits, and crates/nostream-admin/src/lib.rs:19-20 says the same. This is a new surface, not a port.
  • rmcp is absent from Cargo.lock (grep -c '^name = "rmcp"' → 0).
  • The seams its tools would sit on partly exist: EventRepository, InvoiceRepository (crates/nostream-storage/src/repositories.rs:635), ReportRepository (:767), nostream-config for settings, nostreamd telemetry/liveness for status.
  • Oracle: none exists. It must be built with the crate: a tools/list snapshot plus one integration test per tool against a running relay. The repo has no JS-client test harness at all, so this is a from-scratch harness; it should reuse the in-process server pattern slice 1 establishes in crates/nostream-admin/tests/.

Estimate basis: no LOC to inherit; price it from the tool count and the harness work, not from #867's headline. Cost to be set by the scoping job from measured units in .factory/estimates.md.

Note on closing: this repository's default branch is main, so Closes #N is inert on a PR targeting rewrite/main — the issue is closed by hand with the merge sha.

Activity

  1. added
    rewrite
    rust
    mcp
    factory
    on Nov 19, 2026
  2. chappie-daemon commented on Nov 19, 2026

    @chappie-daemon
    CollaboratorAuthor

    Filed from the #867 scope gate in job 032; estimated pending its own scoping job.

  3. chappie-daemon commented on Nov 19, 2026

    @chappie-daemon
    CollaboratorAuthor

    Job opened: 033-admin-mcp-server, base rewrite/main at 9a7c3181 (the admin HTTP surface's merge), branch factory/033-admin-mcp-server. Stage: recon.

    How this job is being sized, per the board's Sizing rule and the issue's own note:

    • Split at spec time. Seven tool families plus an oracle that does not exist is more than one subsystem. The spec will name the slices, dispatch slice 1, and state what slice 1 leaves out.
    • Priced from measured units, not from [Rewrite P5] Admin console parity + admin MCP server + CLI port #867's headline. The bracket will come from the tool count, the harness work recon measures, and the rmcp version actually resolved; the line saying which of those dominates goes in the spec.
    • The oracle must assert payloads, not statuses. A tools/list snapshot plus one real call per tool against a running relay, with the response body asserted — the class of defect feat(admin): serve the console's HTTP surface from the relay's one listener #1192 fixed late (cameri/skills#317) is exactly what a status-only harness passes.
  4. chappie-daemon commented on Nov 19, 2026

    @chappie-daemon
    CollaboratorAuthor

    Spec written (slice 1). spec.md in the job folder: 418 lines, R1–R25, AC1–AC28, 33 values rows, digest fc468d9cf8d2c28a.

    The slice cut, fixed at spec time (the board's Sizing rule), each later slice with its dependency:

    1. Slice 1 (this job) — the crate, nostreamd --mcp-stdio, the token gate, the audit sink, the harness, and four tools: settings_get, settings_set, list_events, get_event.
    2. relay_status — depends on a status seam and a NIP-11 document, neither of which exists at 9a7c3181 (no total connection count anywhere; nip-parity.md:963-964).
    3. delete_event + user_admin — the store-level writes, delete_event currently audited nowhere.
    4. invoices_* + reports_* — depends on the trait change nothing writes today (Report.actionable).
    5. maintenance_* — depends on an API change: clear_old_events drops its EventPurgeCounts into a log line and publish_heartbeat writes last_run_*: None.

    The oracle is payload-asserting, the lesson from #1192's late defect (cameri/skills#317): the full tools/list snapshot with a comparator proved to reject a dropped tool and a widened schema, a real call per tool asserting the response body's fields and values, and a refusal per tool path — none of it a status check.

    Two record corrections the spec carries: the issue's "audit-logged to the delivery-log store" names a store that never held admin actions (the capture wrote a Redis sorted set; the rewrite writes admin-audit.jsonl, ADR 0014 D9), so the audit file is the sink; and the audit action union is closed at nine names, which slice 1 extends by four, adding ADR 0014 D18.

    Cost: $3.29 expected from measured units, bracket $1.97–$3.69; #860 carries the plan adjustment, because #867's $5.00 row cannot hold all five slices.

  5. chappie-daemon commented on Nov 20, 2026

    @chappie-daemon
    CollaboratorAuthor

    Job 033-admin-mcp-server — review round 2 closed CHANGES.

    At 44d03725: code PASS, security PASS, performance PASS; ux CHANGES (1), architecture CHANGES (3). The nine round-1 blocking findings are confirmed closed, each re-inverted by the code lens.

    Round 2's four blockers are all about what the surface promises versus what it does:

    • list_events silently ignored a mistyped argument name and answered unfiltered ({"kind":1} → all rows, isError:false) — a client cannot tell a typo from a criterion;
    • the stdio mode's doc still claimed 'the same repository bundle' where it composes its own, with the two wiring sites unnamed;
    • TOOL_ARGUMENTS' doc named the schema as its invariant where the code needs 'no stricter than the router's deserialiser', and the ADR repeated the stricter reading;
    • DEFAULT_PAGE_ROWS was migrated for LMDB while Postgres kept its own 500 under another name.

    Measured gains from round-1's fixes, both re-measured at the fixed head: get_event {"id":""} 10,994 → 843 µs (13×), list_events {"ids":[""]} 20,839 → 887 µs (23.5×), and a 500-row page 594,490 → 287,292 B (−51.7 %).

  6. chappie-daemon commented on Nov 20, 2026

    @chappie-daemon
    CollaboratorAuthor

    Job 033-admin-mcp-server — round 3 PASS, approver ESCALATE (money-access-identity), PR open.

    #1197

    Final head 80a631af (the changeset now says the mode is its own process). Round 3: code, security, ux and architecture all PASS; ui and performance stood down on counted reasons in review-plan.json. Oracle, run independently by the approver in a fresh target dir: 105 targets, 1560 passed / 0 failed / 6 ignored; merge-tree clean against rewrite/main.

    The approver's verdict is not about the code: every accept condition held, and it escalated because this slice puts a console session token (NOSTREAM_ADMIN_TOKEN) into a second process that grants settings read/write and event reads while declining the HTTP rate limiter — a decision for a person. Slice 2 (relay status) is the natural place to answer it with a socket-only or rate-limited shape.

  7. chappie-daemon commented on Nov 20, 2026

    @chappie-daemon
    CollaboratorAuthor

    Job 033-admin-mcp-server — slice 1 approved, PR #1197 open, merge is the owner's word.

    #1197

    Head 3c83570b. Round 8 was five PASS verdicts (ui stood down on a counted read: no rendered path in any round's delta); the approver then re-took the gate itself — 105 targets, 1582 passed / 0 failed / 6 ignored, fmt and both clippy passes clean, release build clean — and returned APPROVE after a record-only repair.

    The credential is what the operator asked for: a token document delivered by --admin-token-file (regular file, no group or other permission, at most 4 KiB, re-read on every call so the file's lifetime is the revocation) or --admin-token-fd (same checks, read once). Reads by default; settings_set needs an explicit write scope; a scope denial appends mcp.denied; NOSTREAM_ADMIN_TOKEN is retired and refuses the start.

    Cost: $8.94 against $3.29 expected — about $4.3 of that is the rework the escalation asked for, the rest eight review rounds and two approver passes. Regret line in the job record.

    Slices 2–5 remain cut in the job's spec.md; #1193 and #1194 are filed and open.

  8. chappie-daemon commented on Nov 20, 2026

    @chappie-daemon
    CollaboratorAuthor

    Merged: PR #1197 into rewrite/main at 982e6759f11da042901c6a80959dfc01f2c53f3a — slice 1 of #1183 (the admin MCP server on stdio, behind a scoped token document). Slices 2–5 stay cut in the job's spec.md and are tracked on this issue's successor scope; #1193 and #1194 remain open.

    Cost: $8.94 actual against $3.29 expected (+172 %), about $4.3 of it the operator-requested credential rework (rounds 4–8) and the rest eight review rounds plus two approver passes.

  9. 14 remaining items

  10. chappie-daemon commented on Nov 21, 2026

    @chappie-daemon
    CollaboratorAuthor

    Slice 4 opened: user_admin, the invoice reads, and reports_list. Base rewrite/main at a8cef4a5.

    033's cut put user_admin, invoices_list and invoices_get here as the families whose repository seams are complete and whose surface is absent, and left maintenance_* to slice 5 because that slice's cost is the API change rather than the tools. I am adding reports_list to this slice: 033 put both report tools in slice 3, 036 shipped the action half and recorded the read half as unowned. Now that the report store reaches the door, reports_list is a pure read over a landed route — the cheapest place it will ever sit, and leaving it for slice 5 would attach a trivial read to that slice's API break.

    Recon is running on three questions that can move the price: whether user_admin is one tool with an action enum or one per operation, whether listing reports composes from find_actionable / find_by_event_id / find_actionable_targets or needs a new trait method on both backends, and what invoices_get answers for an unknown id.

  11. chappie-daemon commented on Nov 21, 2026

    @chappie-daemon
    CollaboratorAuthor

    Slice 4 spec written: digest 62f0a2a6ceca344f, 931 lines, five tools.

    The cut as shipped in the spec, and the three calls inside it:

    • user_admin and user_get are two tools because scope is a row property. One TOOLS row would make a balance read demand a write credential or let an admission through a read-only one; a case pins the split by asserting the four reads answer under a read document and user_admin is refused once.
    • reports_list is the actionable review queue over find_actionable(limit) — no new seam. The general listing is out of scope with its measured price (15 files / +196 / −19 across six implementors), so a later slice can take it deliberately rather than inherit it.
    • The user read never calls is_vanished, because that method writes a row when it hydrates: a read must not write under a read grant, and a case asserts the store is unchanged after the call.

    invoices_list is pending-only (the only list read that exists), and invoices_get answers an unknown id as {"invoice": null}, matching get_event and reports_action. The four absent-name sites ADR 0017 left pointing at user_admin move to maintenance_run here, with a criterion counting them.

    Base measured, not assumed: 7 tools over the spawned binary, -32602 for all five names, no audit file for five refused calls; nostream-mcp 77, mcp_stdio 18, parity_lmdb 52.

  12. chappie-daemon commented on Nov 22, 2026

    @chappie-daemon
    CollaboratorAuthor

    Slice 4 approved: PR #1225, green, awaiting merge. user_admin, user_get, invoices_list, invoices_get, reports_list — five tools over the store seams the recon measured, no new trait method and no new store field.

    Round 1 ran three lenses (code, security, architecture; ux, ui and performance stood down with reasons) and took three build-side reworks:

    • the gate's first pass ran eight named inversions before writing a finding — all eight reddened, so no test-set finding came from reading this time;
    • user_row read the same store row twice; it now reads once and derives the balance, with case 18 refusing the removed read through a delegating UserRepository so the one-read invariant is pinned by a case rather than by a comment;
    • a duplicated doc sentence fmt and clippy could not see, and a build.md row naming a command that exits 2 on the installed factory version.

    The security lens measured the scope split's blast radius rather than asserting it: with user_admin's row inverted to read, an empty-scope document ran vanish, left a stored row, and wrote an ordinary audit line with no denial.

    Bench at d57ce933: 1 801 passed / 0 failed / 9 ignored, fmt and both clippy clean, release clean; store_families 18 cases each with a measured red.

    Owed and filed: #1223 (offset unbounded on a read grant, first read with a caller-chosen offset). The Postgres arms run only in CI, where a database exists.

  13. chappie-daemon commented on Nov 22, 2026

    @chappie-daemon
    CollaboratorAuthor

    Slice 4 merged: ab3626c1 on rewrite/main (2026-11-22T01:39:09Z), true merge commit. PR #1225 landed on the approver's APPROVE at a1de51c5 plus two docs-only commits: the changeset's false sentence about the user read, and reports_list's description, which invited a caller to copy the row's integer id where reports_action takes the hex event_id.

    Cost: expected $4.50, actual $3.2981 — 26.7% under. 13 sessions, 1 251 requests, 176.3M cache-read, 6.09 h summed wall. A regret line records the miss and a re-estimate to $3.30 keeps the baseline at cost_expected_usd_original.

    Why the estimate was high, which is the same lesson as slice 3 in a sharper form. The 4.50 priced a second spec round and three reworks at slice 3's rate. The second spec round cost $0.62 — a revision against a red-team list, not a cold write — and the three reworks came in at $0.05–0.10 each, because each was a doc sentence, a schema table or a test double on a branch whose gate was already warm. The one term that ran the other way was the builder: $1.08 in one 397-request session, because a five-tool build spends its budget on the snapshot and the twelve count sites rather than on new behaviour. The estimate for the next slice should price the cold build and the first spec, and treat every pass after them as a fraction of one.

    Process that earned its keep. The gate ran eight inversions named in the scoping plan before writing a single finding, and all eight reddened: slice 3's four review passes for three unprovable assertions became one pass for none. The count verifier (build-lint --worktree, from the plugin change in cameri/skills#328) ran at every build check and caught no stale count, but two record-side misses still happened — a build.md row naming a command that exits 2 on the installed version, and four numbers the post-round spec amendment outran. Both are the same class: a change to the head or to the spec must re-run the check, and the next mechanisation is to point the same verifier at spec.md.

    One incident. The AC14 inversion that moves the oracle aside left store_families.rs deleted in the worktree between two commits. An external read caught it; it was restored before any commit; the gate confirmed the file's presence in the run it recorded. The inversion is the right test, and it is one git add -A from deleting a target — builders should name paths.

  14. chappie-daemon commented on Nov 22, 2026

    @chappie-daemon
    CollaboratorAuthor

    Slice 5 (job 038-mcp-maintenance) opened on rewrite/main at ab3626c1; recon landed. Measured ground: clear_old_events drops EventPurgeCounts twice (MaintenanceService and the MaintenanceTasks trait) across exactly two implementors and 8 call sites — the storage layer already returns the counts on both backends, and no EventRepository implementor moves. The hard fact for the last-run record: the MCP server is only served in mcp_stdio::serve, which returns before the daemon's serve and composes unavailable::stores(), so the door cannot read the daemon's pass through memory — the spec chooses the record's shape and says so. Base counts: mcp 96 passed, services maintenance 6, parity_lmdb 52; both maintenance_* names answer -32602 tool not found over the real binary. Expected cost $3.50.

  15. chappie-daemon commented on Nov 22, 2026

    @chappie-daemon
    CollaboratorAuthor

    Slice 5 spec written: digest f2e63aa0b7600dd5, 777 lines, R1–R15, D1–D6, AC1–AC15. The record-shape question recon left open is settled in D3: the last-run record is process memory in AdminState, payload {"run": {ranAt, deleted, expired, retained}} and {"run": null} for never-ran — the daemon's pass is invisible to the door and the tool's description says so. D2 keeps "the same code path" honest: maintenance_run calls the purge step through MaintenanceService, the same function the MaintenanceTasks arm delegates to, because a MaintenanceRunner needs the outbox dispatcher, payments service, relay key source and hub the stdio mode does not compose. D5 retires the absent-name example to a literal no_such_tool, since after this slice no #1183 name is absent. Red-team running against ab3626c1.

  16. chappie-daemon commented on Nov 22, 2026

    @chappie-daemon
    CollaboratorAuthor

    Spec closed at digest 345410647a4ef868; build round 1 started.

    Second red-team pass (against fe52af4513cf9b3a) returned 13 proven fails-at-base, 2 declared Guards green, 0 unproven, no undeclared divergence — the first pass's AC15 is now measured, not claimed: I ran both legs at ab3626c1 through the pinned native toolchain (scripts/rust.sh cannot reach its cache from this profile): workspace 1 801 passed / 0 failed over 104 targets, release build exit 0 in 7m32s, and the per-target readings re-extracted one by one (mcp 96 = 5/6/11/10/18/23/5/18, services maintenance 6, mcp_stdio 19, admin 50 + 3). Those live in .factory/jobs/038-mcp-maintenance/base-readings.md.

    It also caught six criteria a wrong implementation could satisfy or that would not run as written — AC2's grep missing -r, AC10's tail -2 printing the Doc-tests line, AC7's audited pair writing two lines rather than one, AC8's counts satisfied by two comments (now anchored to the audit vector's rows, 12 → 14), AC12's lost old-phrase sweep in auth.rs:12, and AC6's half 2 filtering only a constant-null stub. The two-pass cap means they are recorded as orchestrator amendments under Assumptions, with the measurement that produced each, rather than sent round a third time.

  17. chappie-daemon commented on Nov 22, 2026

    @chappie-daemon
    CollaboratorAuthor

    Slice 5 build landed on branch factory/038-mcp-maintenance at 64f84448 (seven commits on ab3626c1), build gates green: build-lint exit 0, decision-coverage exit 0, static stage (clippy --all-targets --all-features) 0 findings at that sha.

    What it moved, measured rather than claimed: mcp 101 over 9 targets (96/8 at base), services maintenance 7 (6), mcp_stdio 20 (19), workspace 1 808/0 over 105 targets (1 801/0 over 104), release build green, fmt and both clippy passes clean. The seam answers counts at every layer (PassOutcome.counts: Option<EventPurgeCounts>, None on the error and timeout arms rather than zeros), the record is MaintenanceRun on process memory with replace-never-sum, and the door gained maintenance_run (Write) and maintenance_last_run (Read).

    Two spec readings the builder reported instead of quietly matching: my AC8 amendment named a path that does not exist (the vector is crates/nostream-mcp/tests/audit.rs:84-97, re-measured 12 → 14), and AC14's needle counts read 3, not 2 — the same shape TOOL_RELAY_STATUS has at base. Both corrected in the spec's amendments with the reasons attached.

    Review round 1 scoping: five lenses run (code as the gate, then security, ux, architecture, performance); ui stood down on a measured sweep of the diff's 26 paths — no rendered surface at base or head.

  18. chappie-daemon commented on Nov 22, 2026

    @chappie-daemon
    CollaboratorAuthor

    Rework 1 closed at 8e2ace82; review round 2 is a confirmation pass on architecture alone.

    Round 1 was code PASS, security PASS, ux PASS, performance PASS, architecture CHANGES, ui skipped by plan. The two findings, and how they closed:

    • Three positional counts. record_maintenance_run(deleted, expired, retained) let a deleted/expired transpose compile while all five new cases stayed green (both lenses measured the swap surviving). It now takes one EventPurgeCounts value and builds the record by field name — the old call fails with error[E0061]: this method takes 1 argument but 3 arguments were supplied.
    • ADR 0019 D3 argued from a claim its neighbours refute. D3 said a door beside a daemon is "outside the tree"; ADR 0014 D18 and 0016 D1 document that deployment, and CONFIGURATION.md examples it. D3 now says the record is this process's own, that beside a daemon {"run": null} means "this process has not run one" — a known blind spot, not a fact — and Consequences names the durable cross-process record as its successor, noting the daemon now produces the counts through PassOutcome.counts.

    A third item came from the count verifier rather than a lens: sixteen of build.md's rows quoted …-abbreviated paths and grep -n line numbers as counts. All sixteen now run as written; verify-counts.ts exits 0 with 55 quoted counts agreeing with the tree.

    The round's delta: 3 files, +26 −20 — the signature, its only call site, and the ADR. Static stage at the rework head: 0 findings. Gates re-run by the orchestrator, not taken on the builder's word: build-lint 0, decision-coverage 0, verify-counts 0, workspace 1 808/0 over 105 targets, release 0, fmt and both clippy 0.

    Process defect, recorded rather than smoothed over: I wrote round 1's round line and skipped its plan line, which blocked round 2's confirmation check until it was appended late with a note saying it arrived after the round. The line is now there and the log lints.

  19. chappie-daemon commented on Nov 22, 2026

    @chappie-daemon
    CollaboratorAuthor

    Slice 5 review closed: three rounds, all PASS, approver running at 2a116117.

    • Round 1 (at 64f84448): code PASS (whole gate at the head plus three inversions, one per criteria-bearing branch, all reddening the cases that claim them), security PASS, ux PASS, performance PASS, architecture CHANGES.
    • Rework 1 (8e2ace82): the counts became one EventPurgeCounts value — the old call now fails with error[E0061] — and ADR 0019's D3 cost was restated, since it had argued that a door beside a daemon is "outside the tree" while ADR 0014 D18 and 0016 D1 document that deployment.
    • Round 2: confirmation on architecture, CHANGES on one sentence the fix had introduced — D3 still priced the sixth key on "a value the daemon did not produce when this record was written", which PassOutcome.counts (from 5e08fdff, an ancestor of the ADR's own commit) makes false, and which :151-153 of the same ADR contradicted.
    • Rework 2 / round 3 (2a116117, one file, +5 −2): the sixth key is now priced as an amendment to ADR 0016's five-key shape plus a writer at the loop that discards run_pass's PassOutcome — "the counts are produced and dropped rather than absent". Architecture PASS; the cited lines re-verified at this head.

    Worth recording as method: the two findings that mattered most were both introduced by a fix or invisible to the test suite — a positional-count swap that all five new cases stay green through, and a cost paragraph whose premise a neighbouring ADR refutes. The confirmation rounds exist for exactly that, and they cost 0.03 each.

    Also: build.md quoted sixteen commands that could not be re-run (…-abbreviated paths, grep -n line numbers in count slots). All now run as written; verify-counts.ts exits 0 with 56 quoted counts agreeing.

  20. chappie-daemon commented on Nov 22, 2026

    @chappie-daemon
    CollaboratorAuthor

    All seven tool families are on rewrite/main as of 6d1454b122bcfb56da7ff513ec47cbbe89b1a314 (PR #1226, slice 5 of 5). Read from the merged tree's tools/list snapshot rather than from the plan — fourteen tools:

    • relay_status
    • list_events, get_event, delete_event
    • user_admin, user_get
    • invoices_list, invoices_get
    • reports_list, reports_action
    • settings_get, settings_set
    • maintenance_run, maintenance_last_run

    Slices: #867's HTTP admin surface, then relay_status (#1219), the writes (#1220), users and invoices (#1224), maintenance (#1226 on this merge).

    One known limit, stated in ADR 0019's D3 and priced in its Consequences: maintenance_last_run records this process's own runs, so a stdio door run beside a daemon answers null for passes the daemon performed. The durable cross-process record is that decision's named successor — an amendment to ADR 0016's five-key document plus a writer at the loop, which already holds the counts and discards them. It is a follow-up, not a gap in this issue.

    Every call is audit-logged with its mcp.<name> action and no count in detail, and the absent-name example retired to no_such_tool because no name in this issue is absent any more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

factorymcprewriterust

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions