Default audit output to chrondb plus stdout#99
Merged
Conversation
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>
There was a problem hiding this comment.
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+stderraudit output modes and awrites_to_file()helper. - Mirrors audit entries to stdout/stderr (before DB write) while still persisting to ChronDB.
- Updates stdio mode to redirect
file+stdout→file+stderrto 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. |
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>
Signed-off-by: Avelino <31996+avelino@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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+stdoutandfile+stderrvariants onAuditOutputthat 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 nowfile+stdout. Stdio transport falls back tofile+stderrso the JSON-RPC channel stays cleanfixed: #98