Skip to content

feat(admin): serve the admin MCP server on stdio (#1183, slice 1) - #1197

Merged
cameri merged 24 commits into
rewrite/mainfrom
factory/033-admin-mcp-server
Nov 20, 2026
Merged

cameri merged 24 commits into
rewrite/mainfrom
factory/033-admin-mcp-server

Conversation

@chappie-daemon

@chappie-daemon chappie-daemon commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Slice 1 of #1183: an MCP admin server over stdio, with a credential of its own.

The credential

  • A token document, not a console session: {"scopes": ["write"]} — scopes optional, the key
    set closed, an unknown scope refuses the load.
  • Delivered by --admin-token-file PATH (a regular file with no group or other permission, at most
    4 KiB, re-read on every call, so deleting or rewriting it is the revocation) or
    --admin-token-fd N (the same checks on the descriptor, read once — the process's lifetime).
  • Reads (settings_get, list_events, get_event) are what a token gets by default;
    settings_set needs write.
  • NOSTREAM_ADMIN_TOKEN is retired: set it and the mode refuses to start, naming the variable.
    A console session token has no path in — the session-key check is not consulted here.

What ships

crates/nostream-mcp and nostreamd --mcp-stdio serve four tools over stdio, in a process of
their own over the same config directory (ADR 0012 D9 puts a second process on one store
directory outside its contract, and the store is not wired for either mode yet). Every dispatched
call appends one line to <config>/admin-audit.jsonl under mcp.<tool>; a scope denial appends
mcp.denied with {tool, scope} and no argument values; a credential refusal appends nothing.
ADR 0014 D18 (the surface, the audit table) and D19 (this credential) record the decisions.

Slices 2–5 (relay status, delete/user admin, invoices and reports, maintenance) are cut in the
job's spec.md and discussed on #1183.

Why the credential changed

The first approved tree used a console session token in an environment variable. It was escalated
rather than merged — an env var is readable at /proc/<pid>/environ, inherited by every child, and
that token carried settings write into a second process with no rate limiter in front of it. The
operator's answer was "narrow the credential"; this is that build, and the escalation is the reason
the diff is larger than the four tools.

Verification

cargo test --workspace --all-features — 105 targets, 1582 passed, 0 failed, 6 ignored (the six
need a Postgres URL), re-taken independently by the approver. cargo fmt --all --check clean, both
clippy passes clean (-D warnings, and the strict deny-set on lib+bins), release build clean.
mcp_stdio 15, auth 11, tool_payloads 23, tools_list 5, audit 4, nostream-admin 155.

Eight review rounds; every blocking finding was fixed with a case that fails at the previous head, and
the load-bearing ones were:

  • the audit table was a _ => false a fifth tool could bypass — now a const table the dispatch
    cannot avoid, with a case over rmcp's own tool list;
  • list_events answered unfiltered to a mistyped argument name — an unknown key is now refused,
    naming the accepted set;
  • every page crossed the wire twice (48.3 % duplicate, 594,490 B → 287,292 B);
  • {"id":""} cost 8,153 µs over 20,000 keys — criteria are validated to the wire's 4-hex floor
    before any store read (10,994 → 843 µs);
  • the scope requirement and the audit column each failed open for a tool the table did not carry —
    one conjunction (row && router.has_route) now decides both, and a route-less row is refused;
  • the token document's read was unbounded (/proc/self/environ read whole, a rewrite accepted with
    metadata ≤ 4 KiB) — take(cap + 1) plus a reserved buffer (a 4 KiB read: −3.36 µs, 2 reads not 9).

Known, filed separately

Closes #1183 is absent on purpose: the repository's default branch is main, so a Closes line on
a PR into rewrite/main closes nothing; #1183 is closed by hand when the slice merges.

@changeset-bot

changeset-bot Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 3c83570

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 0 packages

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai

coderabbitai Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 4fb29902-9f1f-40ac-9e86-878cee20076d

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@socket-security

socket-security Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addedcargo/​rmcp@​3.11.087100100100100

View full report

@greptile-apps

greptile-apps Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[High impact] The PR appears safe to merge; no new blocking issue was found.

Summary

Adds four admin MCP tools over stdin/stdout, with a separate scoped credential and audit records.

  • Admin MCP calls can read and update settings.
  • Admin MCP calls can list events or look up one event.
  • A scoped token controls MCP calls and their audit records.
  • nostreamd can serve the admin MCP tools over stdio.

No new actionable issues were found. Tests were inspected, not run.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Tool call] --> B{Admin enabled and credential accepted?}
  B -->|No| C[Return refusal]
  B -->|Yes| D{Table entry and live route?}
  D -->|No| E[Return tool not found]
  D -->|Yes| F{Scope allows call?}
  F -->|No| G[Record denial and return Forbidden]
  F -->|Yes| H[Record dispatch when arguments parse]
  H --> I[Call tool]
Loading

Reviews (8) · Last reviewed commit: "docs(admin): say what D18's refusal asks..." · Reviewed by Greptile

Comment thread crates/nostream-mcp/src/server.rs Resolved
@chappie-daemon

Copy link
Copy Markdown
Collaborator Author

Hosted-review triage: the P2 on truncated is confirmed in the code (server.rs:358 counts surviving rows after collect_records drops vanished ones) and filed as #1198 with the fix direction — the marker should come from the store's own page, not from what survived. It is an edge that needs a concurrent delete inside one read, so it does not hold this PR.

A page's size is the slots the store spent. collect_records drops
StreamedEvent::Vanished, which is the store's signal that a selected key was
removed before its value was read (a replacement hard-deletes the row it
supersedes, a retention pass removes a soft-deleted one), so a full page that
lost a row answered 499 rows with truncated: false while another matching row
remained unread. collect_page returns the rows and the slots beside them, the
tool derives the marker from the slots, and a case drives a real page whose
second selected slot vanished.
greptile-apps[bot]
greptile-apps Bot previously approved these changes Nov 20, 2026
@greptile-apps
greptile-apps Bot dismissed their stale review November 20, 2026 12:21

Dismissed because a newer commit was pushed; Greptile will re-review the current head.

Comment thread crates/nostreamd/src/main.rs Resolved
greptile-apps[bot]
greptile-apps Bot previously approved these changes Nov 20, 2026
@greptile-apps
greptile-apps Bot dismissed their stale review November 20, 2026 12:55

Dismissed because a newer commit was pushed; Greptile will re-review the current head.

greptile-apps[bot]
greptile-apps Bot previously approved these changes Nov 20, 2026
@greptile-apps
greptile-apps Bot dismissed their stale review November 20, 2026 14:27

Dismissed because a newer commit was pushed; Greptile will re-review the current head.

greptile-apps[bot]
greptile-apps Bot previously approved these changes Nov 20, 2026
@greptile-apps
greptile-apps Bot dismissed their stale review November 20, 2026 15:08

Dismissed because a newer commit was pushed; Greptile will re-review the current head.

@cameri
cameri merged commit 982e675 into rewrite/main Nov 20, 2026
18 checks passed
@cameri
cameri deleted the factory/033-admin-mcp-server branch November 20, 2026 16:20
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.

2 participants