Skip to content

Default audit output to chrondb plus stdout#99

Merged
avelino merged 3 commits into
mainfrom
avelino/issue-98
May 20, 2026
Merged

Default audit output to chrondb plus stdout#99
avelino merged 3 commits into
mainfrom
avelino/issue-98

Conversation

@avelino

@avelino avelino commented May 19, 2026

Copy link
Copy Markdown
Owner

Audit entries used to land only in chrondb. The pod log showed just generic tracing events, so seeing actual call records meant opening a second shell with mcp logs.

Added file+stdout and file+stderr variants on AuditOutput that write to chrondb and mirror each entry as JSON on the chosen stream. The mirror runs before the db write so entries stay visible even when the db write fails. Default is now file+stdout. Stdio transport falls back to file+stderr so the JSON-RPC channel stays clean

fixed: #98

Audit entries used to land only in chrondb. The pod log showed just generic tracing events, so seeing actual call records meant opening a second shell with `mcp logs`.

Added `file+stdout` and `file+stderr` variants on `AuditOutput` that write to chrondb and mirror each entry as JSON on the chosen stream. The mirror runs before the db write so entries stay visible even when the db write fails. Default is now `file+stdout`. Stdio transport falls back to `file+stderr` so the JSON-RPC channel stays clean

fixed: #98

Signed-off-by: Avelino <31996+avelino@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 19, 2026 22:42

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 implements a dual-sink audit output mode so audit entries can be persisted to ChronDB while also being visible immediately in container/terminal logs, and updates the default audit output accordingly.

Changes:

  • Adds file+stdout / file+stderr audit output modes and a writes_to_file() helper.
  • Mirrors audit entries to stdout/stderr (before DB write) while still persisting to ChronDB.
  • Updates stdio mode to redirect file+stdoutfile+stderr to keep the JSON-RPC channel clean, and updates docs/env var handling.

Reviewed changes

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

Show a summary per file
File Description
src/serve/stdio.rs Redirects stdout and file+stdout audit outputs to stderr variants under stdio transport; switches DB init to writes_to_file().
src/serve/http.rs Switches DB init gating to writes_to_file().
src/main.rs Switches shared DB init gating to writes_to_file().
src/config.rs Extends MCP_AUDIT_OUTPUT env parsing to accept file+stdout / file+stderr.
src/audit.rs Introduces new AuditOutput variants, changes default to file+stdout, implements mirroring + persistence, and adds tests.
docs/reference/environment-variables.md Documents new audit output modes and new default.
docs/howto/kubernetes.md Updates Kubernetes guidance for new default and dual-sink option.
docs/howto/docker.md Updates Docker guidance for new default and dual-sink option.
docs/guides/audit-logging.md Updates audit logging guide with output mode matrix and stdio caveat.

Comment thread src/audit.rs Outdated
Comment thread src/audit.rs Outdated
Comment thread src/audit.rs Outdated
Comment thread src/config.rs Outdated
The previous default of FileAndStdout in main also affected CLI subcommands (`mcp roam ...`, `mcp gh ...`), interleaving audit JSON with command output and breaking pipelines like `mcp ... | jq`. The audit writer also called `pool.acquire()` per entry and used `println!` directly, causing log floods on a disabled pool and buffered output on container stdout.

Global default is now `File`. `mcp serve` calls a new `AuditOutput::promote_for_serve(ctx)` that turns `File` into `FileAndStdout` (HTTP) or `FileAndStderr` (stdio), preserving any explicit user value. The writer caches the chrondb handle once at startup, runs in mirror-only mode if acquire fails, and writes through a locked `writeln! + flush()` so entries reach the log driver in real time. `FromStr for AuditOutput` removes the duplicated env-var parsing between `audit.rs` and `config.rs`. Eleven new tests cover the promotion rule, FromStr edge cases, writeln+flush ordering and disabled-pool mode.

Signed-off-by: Avelino <31996+avelino@users.noreply.github.com>

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 9 out of 9 changed files in this pull request and generated 9 comments.

Comment thread src/serve/http.rs Outdated
Comment thread src/serve/stdio.rs Outdated
Comment thread docs/reference/environment-variables.md Outdated
Comment thread docs/guides/audit-logging.md Outdated
Comment thread docs/howto/docker.md Outdated
Comment thread docs/howto/kubernetes.md
Comment thread src/audit.rs Outdated
Comment thread src/audit.rs Outdated
Comment thread src/audit.rs Outdated
Signed-off-by: Avelino <31996+avelino@users.noreply.github.com>
@avelino
avelino merged commit db31884 into main May 20, 2026
9 checks passed
@avelino
avelino deleted the avelino/issue-98 branch May 20, 2026 09:42
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.

Audit logging: default to dual-sink (chrondb + stdout) so entries are visible without mcp logs

2 participants