Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .changeset/mcp-users-invoices.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
---

feat(mcp): five store-family tools — `user_admin`, `user_get`, the invoice reads and `reports_list`

`user_admin` carries the four decisions an operator makes about one pubkey — `admit`, `revoke`,
`vanish` and `unvanish` — as one closed action enum, and `user_get` reads the same row and its
balance under a document that grants nothing: the scope is a property of the `TOOLS` row, so one
tool would have made a balance read cost a `write` document or an admission reachable with a
read-only one. The read path is one `find_by_pubkey` with the balance taken from the row it
answers, never `is_vanished`, which hydrates a live kind-62 and stores a row — so `user_get` never
writes.

`invoices_list` is the store's pending walk, oldest first, paged by `offset` and `limit`;
`invoices_get` takes the invoice's own opaque id verbatim and answers a miss as
`{"invoice": null}`, as `get_event` answers an unknown event id. `reports_list` is the review
queue over `find_actionable`: the reports still actionable, newest first, with no offset — a full
listing would be one new trait method on six implementors and is left for a slice that takes it
deliberately.

The two list tools share the door's one page bound (500, the default and the ceiling), and the
events' page size now goes through the same function. The audit vocabulary gains five `mcp.*`
names, each carrying `{"tool": …}` and nothing else. `docs/rewrite/decisions/0018-users-invoices-and-report-reads.md`
records the seven decisions. Rust only: no published package changes.
7 changes: 4 additions & 3 deletions CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ The following environment variables can be set:
## The admin MCP mode (`--mcp-stdio`)

`nostreamd --mcp-stdio` serves the admin MCP server (`settings_get`, `settings_set`,
`list_events`, `get_event`, `delete_event`, `reports_action`) on stdin/stdout and exits when stdin
`list_events`, `get_event`, `relay_status`, `delete_event`, `reports_action`, `reports_list`,
`user_admin`, `user_get`, `invoices_list` and `invoices_get`) on stdin/stdout and exits when stdin
closes. It binds no socket,
opens no store of its own, and writes its log lines to **stderr** so nothing but JSON-RPC crosses
stdout.
Expand All @@ -96,8 +97,8 @@ The document is JSON, and `scopes` is optional:

| Document | What it may call |
|---|---|
| `{}` or `{ "scopes": [] }` | The read tools: `settings_get`, `list_events`, `get_event`. |
| `{ "scopes": ["write"] }` | The read tools, and the three that change something: `settings_set`, `delete_event` (soft-deletes **any author's** stored event by id — there is no per-author restriction, the holder of the token is the operator) and `reports_action` (sets the relay-wide NIP-56 filter for the target an actionable report names). |
| `{}` or `{ "scopes": [] }` | The read tools: `settings_get`, `list_events`, `get_event`, `relay_status`, `user_get`, `invoices_list`, `invoices_get` and `reports_list`. |
| `{ "scopes": ["write"] }` | The read tools, and the four that change something: `settings_set`, `delete_event` (soft-deletes **any author's** stored event by id — there is no per-author restriction, the holder of the token is the operator), `reports_action` (sets the relay-wide NIP-56 filter for the target an actionable report names) and `user_admin` (admits, revokes, vanishes and unvanishes one pubkey). |

`write` is the only accepted scope, and an unknown name — a typo, or a document from another tool
— refuses to start rather than being narrowed silently. A call the document's scopes deny is
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/nostream-mcp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ repository.workspace = true
description = "The admin MCP server: the tool router, the credential gate and the audit sink"

[dependencies]
chrono.workspace = true
nostream-admin.workspace = true
nostream-config.workspace = true
nostream-core.workspace = true
Expand Down
6 changes: 3 additions & 3 deletions crates/nostream-mcp/src/credential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use serde::Deserialize;

use crate::error::McpError;

/// The one scope beyond reading: the right to call `settings_set` (R28).
/// The one scope beyond reading: the right to call the four tools that write (R28).
pub const SCOPE_WRITE: &str = "write";

/// The scopes a token document may name, as a refusal states them.
Expand Down Expand Up @@ -57,14 +57,14 @@ pub const MAX_TOKEN_DOCUMENT_BYTES: u64 = 4 * 1024;
/// The scopes a token document grants.
///
/// Reading is not a scope: every accepted document reads (R28). `write` is the one name a
/// document may add, and it is what makes `settings_set` callable.
/// document may add, and it is what makes the four writes callable.
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
pub struct Scopes {
write: bool,
}

impl Scopes {
/// The grant a document with no `scopes` carries: the four read tools.
/// The grant a document with no `scopes` carries: the eight read tools.
pub fn read_only() -> Self {
Self::default()
}
Expand Down
20 changes: 11 additions & 9 deletions crates/nostream-mcp/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! `nostream-mcp` owns the admin MCP server: the tool router, the seven tools, the credential
//! `nostream-mcp` owns the admin MCP server: the tool router, the twelve tools, the credential
//! and its scopes, and the audit sink.
//!
//! It owns no transport and no socket. `nostreamd --mcp-stdio` serves this server on
Expand All @@ -24,8 +24,8 @@
//! `nostream-admin` (used here, not re-implemented);
//! - the settings merge, validation, redaction and the guided catalogue — `nostream-config`;
//! - the event store and the repositories — `nostream-storage`;
//! - every tool family outside this surface: `user_admin`, `invoices_*` and `maintenance_*` are
//! later slices of #1183.
//! - every tool family outside this surface: `maintenance_run` and `maintenance_last_run` are
//! slice 5 of #1183.

mod credential;
mod error;
Expand All @@ -36,10 +36,12 @@ pub use credential::{
};
pub use error::McpError;
pub use server::{
AUDIT_DENIED, AdminMcp, DeleteEventArgs, FORBIDDEN, GetEventArgs, ListEventsArgs,
MAX_FILTER_TERMS, MAX_ROWS_PER_PAGE, MCP_INSTRUCTIONS, MCP_SERVER_NAME, NOT_FOUND,
OUTCOME_ALREADY_DELETED, OUTCOME_DELETED, OUTCOME_NOT_DELETEABLE, OUTCOME_NOT_FOUND,
ReportAction, ReportsActionArgs, Requires, SettingsSetArgs, TOOL_DELETE_EVENT, TOOL_GET_EVENT,
TOOL_LIST_EVENTS, TOOL_RELAY_STATUS, TOOL_REPORTS_ACTION, TOOL_SETTINGS_GET, TOOL_SETTINGS_SET,
TOOLS, Tool, UNAUTHORIZED, arguments_parse, audit_action, required_scope,
AUDIT_DENIED, AdminMcp, DeleteEventArgs, FORBIDDEN, GetEventArgs, InvoicesGetArgs,
InvoicesListArgs, ListEventsArgs, MAX_FILTER_TERMS, MAX_ROWS_PER_PAGE, MCP_INSTRUCTIONS,
MCP_SERVER_NAME, NOT_FOUND, OUTCOME_ALREADY_DELETED, OUTCOME_DELETED, OUTCOME_NOT_DELETEABLE,
OUTCOME_NOT_FOUND, ReportAction, ReportsActionArgs, ReportsListArgs, Requires, SettingsSetArgs,
TOOL_DELETE_EVENT, TOOL_GET_EVENT, TOOL_INVOICES_GET, TOOL_INVOICES_LIST, TOOL_LIST_EVENTS,
TOOL_RELAY_STATUS, TOOL_REPORTS_ACTION, TOOL_REPORTS_LIST, TOOL_SETTINGS_GET,
TOOL_SETTINGS_SET, TOOL_USER_ADMIN, TOOL_USER_GET, TOOLS, Tool, UNAUTHORIZED, UserAction,
UserAdminArgs, UserGetArgs, arguments_parse, audit_action, required_scope,
};
Loading
Loading