feat(mcp): add structured audit logging for tool invocations#322
Open
DeryFerd wants to merge 2 commits into
Open
feat(mcp): add structured audit logging for tool invocations#322DeryFerd wants to merge 2 commits into
DeryFerd wants to merge 2 commits into
Conversation
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.
Problem
The MCP server infrastructure was running tools silently. When a tool was invoked, there was no record of which tool, what arguments were passed, how long it took, or whether it succeeded. That made debugging integration issues tedious — you had to add temporary log statements or reproduce the scenario while watching the network tab.
This PR adds structured audit logging around every MCP tool invocation.
What changed in
backend/mcp/servers/helper.tssanitizeArgs()— a helper that takes a tool's argument object and returns a redacted copy. It scrubs values for known sensitive keys (apiKey,token,secret,password,credential,key) and truncates any string longer than 200 characters. The idea is to make logs useful for debugging without accidentally leaking credentials into log files.Two log points wrapped around each tool call:
The timing uses
performance.now()for sub-millisecond precision, rounded to one decimal place.What this enables
What it does not do
This is purely a logging change. No behavior is altered — tools execute exactly as they did before, return the same results, and fail with the same errors. The only difference is that there is now a record of what happened.
Risk
Minimal. The
sanitizeArgsfunction is best-effort — it checks exact key names, so a credential passed under a nonstandard key would still appear in logs. But covering the common cases covers the vast majority of real usage. The redaction set can be extended later if needed.Validation
bun build --no-bundle backend/mcp/servers/helper.ts— compiles cleanbun run lint— no new warningsdebug('mcp-tool')channel behavior