Repository navigation
Audit Trail
memory-journal-mcp includes a high-throughput, symlink-hardened JSONL audit logging subsystem (src/audit/) that records mutating tool invocations, team operations, sensitive resource reads, identity context, timing, and token estimates. Mutating and privileged scopes (write, admin, team, audit) are always logged when enabled, while general read tools are opt-in via --audit-reads.
Enable audit logging via CLI flags, environment variables, or the startup configuration file (memory-journal.config.{json,yaml}).
# Enable JSONL audit logging to a rotating file
memory-journal-mcp --audit-log ./logs/mcp-audit.jsonl
# Also log read-scoped tools and allow up to 20 MB per log file
memory-journal-mcp --audit-log ./logs/mcp-audit.jsonl --audit-reads --audit-log-max-size 20971520
# Disable argument redaction (include tool input parameters in entries)
memory-journal-mcp --audit-log ./logs/mcp-audit.jsonl --no-audit-redact| CLI Flag | Environment Variable | Config Key (JSON/YAML) | Default | Description |
|---|---|---|---|---|
--audit-log <path> |
AUDIT_LOG_PATH |
auditLog |
disabled | Absolute/relative JSONL file path, or stderr for container streaming |
--audit-redact / --no-audit-redact
|
AUDIT_REDACT |
auditRedact |
true (redacted) |
Omit tool input args from written entries by default |
--audit-reads |
AUDIT_READS |
auditReads |
false |
Also log read-scoped tool invocations |
--audit-log-max-size <bytes> |
AUDIT_LOG_MAX_SIZE |
auditLogMaxSize |
10485760 (10 MB) |
Max file size before rotation (min: 1024 bytes via CLI/env; 0 disables rotation programmatically only) |
Note
auditLog, auditRedact, auditReads, and auditLogMaxSize in memory-journal.config.{json,yaml} are startup-only settings (not hot-reloaded on file change). Both the server and the offline CLI subcommand memory-journal-mcp admin audit read AUDIT_LOG_PATH with MEMORY_JOURNAL_AUDIT_LOG as a fallback.
For Docker, Kubernetes, and container orchestrators where platform drivers capture standard error, pass --audit-log stderr (AUDIT_LOG_PATH=stderr):
docker run --rm -p 3000:3000 \
-e AUDIT_LOG_PATH=stderr \
-e ALLOWED_IO_ROOTS=/app/data \
-e MCP_AUTH_TOKEN="<strong-random-secret>" \
-v ./data:/app/data \
writenotenow/memory-journal-mcp:latest \
--transport http --port 3000 --server-host 0.0.0.0 \
--database /app/data/memory_journal.dbAlternatively, bind-mount a log directory (-v ./logs:/var/log/memory-journal) with --audit-log /var/log/memory-journal/mcp-audit.jsonl when shipping logs with Grafana Alloy or Datadog Agent (see examples/observability/).
Each line written to the audit log is a self-contained JSON object (AuditEntry, src/audit/types.ts):
{
"timestamp": "2026-05-30T14:22:10.412Z",
"requestId": "aud-m2x9k1p-9f4a21c8",
"sessionId": "b7c4e910-3a2d-4e9b-9c21-1f8e7d6c5b4a",
"tool": "create_entry",
"category": "write",
"scope": "write",
"user": "alice@example.com",
"scopes": ["read", "write", "audit"],
"durationMs": 4,
"success": true,
"tokenEstimate": 185,
"workspaceId": "my-repo",
"projectNumber": 1
}| Field | Type | Description |
|---|---|---|
timestamp |
string |
ISO 8601 UTC timestamp of the invocation |
requestId |
string |
Unique correlation ID (aud-<timestamp-base36>-<8-hex>, or denied-<timestamp-ms> for denied-access records) |
sessionId |
string? |
HTTP/SSE transport session ID when present |
tool |
string |
MCP tool name or resource/prompt audit target identifier |
category |
'read' | 'write' | 'admin' | 'team' | 'audit' |
Operation category mapped from required OAuth scope |
scope |
string |
Required OAuth scope (read, write, admin, team, audit) |
user |
string | null |
OAuth sub claim when authenticated, or null when auth is not enabled |
scopes |
string[] |
Granted OAuth scopes on the caller's token ([] when unauthenticated) |
durationMs |
number |
Execution duration in milliseconds |
success |
boolean |
true if execution succeeded; false on exception or { success: false }
|
error |
string? |
Sanitized error message (present only when success === false) |
args |
object? |
Scrubbed tool input arguments (omitted when AUDIT_REDACT=true, default) |
tokenEstimate |
number? |
Estimated response token count (~2.8β4.0 bytes/token by content type) |
workspaceId |
string? |
Resolved multi-tenant workspace ID associated with the call |
projectNumber |
number? |
Resolved project number associated with the call |
AuditInterceptor (src/audit/interceptor.ts) classifies every operation by its required scope and sensitive-resource sensitivity:
| Operation / Scope | Examples | Logged? | Notes |
|---|---|---|---|
write |
create_entry, link_entries, import_markdown
|
β Always | Recorded with identity, timing, token estimate, and workspace/project scope |
admin |
update_entry, run_auto_prune, merge_tags, team_merge_tags, backup_journal, restore_backup, update_configuration, admin prompts |
β Always | Always captured including failures |
team |
team_create_entry, team_link_entries, memory://team/*, team prompts |
β Always | Both team mutations and sensitive memory://team/* / memory://insights/team-collaboration reads |
audit |
search_audit_log, memory://audit, memory://metrics/users
|
β Always | Auditing and sensitive user/log reads are always recorded |
read (standard) |
search_entries, get_recent_entries, get_entry_by_id, standard resources |
β‘ Opt-in (--audit-reads) |
Disabled by default to keep audit logs compact and low-noise |
-
Default Redacted (
AUDIT_REDACT=true): Tool inputargsare omitted from audit entries by default so entry bodies, search queries, and credentials never leak into log streams. -
Unredacted Opt-In (
--no-audit-redact/AUDIT_REDACT=false): Includes scrubbedargs(capped at2048chars per value after a4096-char pre-scrub slice, with sensitive secret keys stripped byscrubAuditArgs()).
When audit logging is active, agents with the audit scope (in authenticated deployments) can read memory://audit (text/plain YAML) over stdio or HTTP. It streams backward from EOF in 64 KB chunks (O(1) chunk buffer) until up to 50 most recent entries are collected (or start-of-file is reached) and returns the session_summary alongside them:
audit_log: ./logs/mcp-audit.jsonl
entries_shown: 2
as_of: 2026-05-30T14:22:15.000Z
session_summary:
total_tokens: 412
total_duration_ms: 19
error_count: 0
dropped_count: 0
redact_mode: true
- timestamp: 2026-05-30T14:22:10.412Z
tool: "create_entry"
scope: write
category: write
duration_ms: 4
success: true
token_estimate: 185You can also scope the resource query with URI parameters:
memory://audit?workspace_id=my-repomemory://audit?project_number=1memory://audit?workspace_id=my-repo&project_number=1
When the admin tool group is active (requires audit, admin, or full scope under OAuth), query historical recordsβincluding rotated .1β.5 archivesβvia search_audit_log:
| Parameter | Type | Default | Description |
|---|---|---|---|
tool_name |
string |
β | Filter by exact MCP tool name |
user |
string |
β | Filter by OAuth sub user identifier |
date_range |
{ start?: string, end?: string } |
β | Filter by ISO 8601 start/end timestamps |
status |
boolean |
β |
true for successful calls, false for failures (success alias accepted) |
category |
'read' | 'write' | 'admin' | 'team' | 'audit' |
β | Filter by operation category |
limit |
integer (1β1000) |
100 |
Maximum matching entries to return (newest first) |
workspace_id |
string |
β | Filter by workspace (* disables workspace filtering) |
project_number |
integer |
β | Filter by project number |
From the command line without starting an MCP session, inspect logs via:
MEMORY_JOURNAL_AUDIT_LOG=./logs/mcp-audit.jsonl memory-journal-mcp admin audit --limit 25AuditLogger (src/audit/audit-logger.ts, src/audit/audit-file-helpers.ts) is non-blocking and non-throwing so log I/O never stalls MCP tool responses:
-
Async Ring Buffering: Buffers up to
50entries (BUFFER_HIGH_WATER) or100ms(FLUSH_INTERVAL_MS), then flushes sequentially and drains cleanly on shutdown. -
Size-Based Rotation: Automatically rotates when the active log exceeds
10 MB(DEFAULT_AUDIT_LOG_MAX_SIZE_BYTES, configurable via--audit-log-max-size/AUDIT_LOG_MAX_SIZE; CLI/env enforces a minimum of1024bytes, while0disables rotation programmatically only), retaining5archive generations (.1through.5). -
Bounded Line Size (
256 KB): Serialized entries are hard-capped at262,144bytes (MAX_AUDIT_LINE_BYTES)βtruncating oversized errors/args safely so backward search (1 MBchunk skip ceiling) never skips malformed lines. -
Symlink & Special-File Protection: Validates paths with
lstat()and opens files usingO_NOFOLLOWto prevent symlink-following attacks against log paths. -
Health Visibility:
memory://healthreports liveauditstatus (ok,degraded,unknown) anddroppedCountif disk flushes ever fail.
Unlike relational DDL MCP servers (such as mysql-mcp) that create per-DDL schema snapshots (.snapshot.json.gz), memory-journal-mcp provides database-level SQLite backups for point-in-time recovery across destructive journal operations:
-
backup_journalβ Create a consistent snapshot of the SQLite journal database -
list_backupsβ Inspect available backup files, timestamps, and sizes -
restore_backupβ Restore from a backup (automatically creates a pre-restore safety backup before overwriting) -
cleanup_backupsβ Enforce retention limits on old backups -
Pre-Prune Protection β Live
run_auto_pruneexecutions create a safety backup automatically before modifying or deleting entries
See Maintenance & Optimization and Tools Reference for usage details.
| Platform | Collection Method | Notes |
|---|---|---|
| Grafana Loki | Grafana Alloy (examples/observability/alloy-config.alloy) |
Tail mcp-audit.jsonl with tail_from_end = true + file_watch on WSL2 9p; Loki mem_limit: 512m + GOMEMLIMIT=400MiB
|
| Datadog | File tailing (conf.d) or container labels (com.datadoghq.ad.logs) |
Promote success, tool, category, and scope attributes; avoid duplicate autodiscovery |
| Elastic / ELK | Filebeat filestream JSON parser |
Parse timestamp and structured fields natively |
| Splunk | Universal Forwarder or HTTP Event Collector (JSON) | Route --audit-log stderr or bind-mounted JSONL directly |
| CloudWatch Logs | Docker awslogs log driver (--audit-log stderr) |
Native JSONL line indexing in AWS CloudWatch Logs Insights |
| Fluentd / Fluent Bit |
tail input + json parser |
Works seamlessly for both file mounts and container stderr
|
When OAuth 2.1 (--oauth-enabled) or Bearer authentication is active, every audit entry records:
-
user: Authenticatedclaims.subidentifier (ornullwhen unauthenticated) -
scopes: Array of granted scopes from the token -
sessionId,workspaceId, andprojectNumber: Transport and multi-tenant scope correlation across multi-agent deployments
-
Observability β Prometheus
/metrics, Grafana, Loki, Datadog, andmemory://metrics/*resources - Configuration β CLI flags, environment variables, and startup config options
-
HTTP Transport β OAuth 2.1, Bearer auth,
/metrics, and rate limiting -
Resources β
memory://audit,memory://health, andmemory://metrics/*details -
Maintenance & Optimization β SQLite backups,
run_auto_prune, and database health - Team Collaboration β Team database RBAC and team audit coverage
- Deployment β Production container and Docker Compose patterns
Tip
Value Proposition: Persistent project memory for AI agents, so decisions and history stay available across sessions.
- Quick Start
- Installation
- Configuration
- CLI Reference
- HTTP Transport
- Tool Filtering
- Code Mode
- Tools Reference
- Performance
- Capacity Planning
- Architecture
- Observability
- Audit Trail
- Maintenance & Optimization
- Deployment
- Schema
- Team Collaboration