Skip to content

chore: allow logging unredacted messages MCP-103 #420

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 6, 2025
Merged

Conversation

nirinchev
Copy link
Collaborator

@nirinchev nirinchev commented Aug 4, 2025

Proposed changes

This is a refactoring of the logger interface to allow consumers to opt out of the automatic redacting logic. It enables a blanket opt out or opting out for specific logger type(s).

This should only be used where the messages are safe to log or where not logging the unredacted messages makes the logs meaningless. The impetus for this change is logging by the HTTP transport, which would otherwise log things like Server started on http://<ip-address>:3000.

This is related to MCP-103, but not addressing the core of the issue.

Checklist

@Copilot Copilot AI review requested due to automatic review settings August 4, 2025 12:49
@nirinchev nirinchev requested a review from a team as a code owner August 4, 2025 12:49
Copilot

This comment was marked as outdated.

@nirinchev nirinchev marked this pull request as draft August 4, 2025 12:50
@nirinchev nirinchev requested a review from Copilot August 4, 2025 12:59
Copy link
Contributor

@Copilot Copilot AI left a comment

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 refactors the logger interface to allow consumers to opt out of automatic redaction logic by introducing a noRedaction option. The change enables either a blanket opt-out or selective opt-out for specific logger types, addressing cases where redaction makes logs meaningless (e.g., HTTP transport startup messages).

  • Migrated all logger calls from positional parameters to object-based payloads
  • Added noRedaction configuration option to control redaction behavior per logger type
  • Updated logger base class to handle redaction logic based on logger type and consumer preferences

Reviewed Changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/common/logger.ts Core logger refactoring with new LogPayload interface and redaction control logic
src/transports/streamableHttp.ts Updated logger calls to object format, added noRedaction: true for server startup message
src/tools/tool.ts Migrated logger calls to object format with selective noRedaction flags
src/telemetry/telemetry.ts Updated telemetry logging to use new object-based logger interface
src/server.ts Converted server initialization logging to new format
src/index.ts Updated main function logging to use object-based payloads
src/common/sessionStore.ts Migrated session management logging to new format
src/common/session.ts Updated session lifecycle logging to object format
src/resources/resource.ts Converted resource update logging to new interface
src/tools/mongodb/mongodbTool.ts Updated MongoDB tool logging to object format
src/tools/atlas/connect/connectCluster.ts Migrated Atlas cluster connection logging with selective redaction control
src/tools/atlas/atlasTool.ts Updated Atlas tool argument parsing logging
src/common/atlas/cluster.ts Converted cluster inspection logging to new format
src/common/atlas/apiClient.ts Updated API client logging to object-based interface
src/common/atlas/accessListUtils.ts Migrated access list utility logging to new format
src/transports/stdio.ts Updated stdio transport logging to object format

@nirinchev nirinchev marked this pull request as ready for review August 4, 2025 15:53
@nirinchev nirinchev changed the title chore: allow logging unredacted messages chore: allow logging unredacted messages MCP-103 Aug 5, 2025
@coveralls
Copy link
Collaborator

Pull Request Test Coverage Report for Build 16779406063

Details

  • 161 of 291 (55.33%) changed or added relevant lines in 16 files are covered.
  • 7 unchanged lines in 4 files lost coverage.
  • Overall coverage decreased (-0.4%) to 81.424%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/common/atlas/accessListUtils.ts 12 15 80.0%
src/common/atlas/cluster.ts 0 5 0.0%
src/common/logger.ts 52 57 91.23%
src/tools/atlas/atlasTool.ts 0 5 0.0%
src/tools/mongodb/mongodbTool.ts 0 5 0.0%
src/transports/stdio.ts 0 5 0.0%
src/telemetry/telemetry.ts 32 38 84.21%
src/tools/tool.ts 17 23 73.91%
src/common/session.ts 0 10 0.0%
src/tools/atlas/connect/connectCluster.ts 22 32 68.75%
Files with Coverage Reduction New Missed Lines %
src/common/session.ts 1 84.55%
src/telemetry/telemetry.ts 1 89.82%
src/common/sessionStore.ts 2 54.72%
src/common/logger.ts 3 91.19%
Totals Coverage Status
Change from base Build 16779162520: -0.4%
Covered Lines: 3485
Relevant Lines: 4240

💛 - Coveralls

@nirinchev
Copy link
Collaborator Author

The coverage reduction is just a result of reformatting of the logger calls (multiline vs single line).

id: MongoLogId;
context: string;
message: string;
noRedaction?: boolean | LoggerType | LoggerType[];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: i find no variables difficult to read and prone to difficult statements over the code. Not super used to a single variable having so many different types too. WDYT about the below?

Suggested change
noRedaction?: boolean | LoggerType | LoggerType[];
redaction?: {
enabled: boolean;
exceptFor?: LoggerType[];
};

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree - I also tend to prefer positively-named variables - in this case, I chose the negative because I want all messages to be redacted by default. If we had this as redaction/redacted, the implication would be that if we don't explicitly specify redaction: true, messages would be unredacted.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point, I threw this into an LLM and got another suggestion

 redaction?: {
        mode: "auto" | "force" | "skip";
        skipFor?: LoggerType[];
    };

but I think it still adds another complexity type w/ the modes, so feel free to ignore since I don't have a strong opinion

@nirinchev nirinchev merged commit 53ac631 into main Aug 6, 2025
17 of 18 checks passed
@nirinchev nirinchev deleted the ni/logger-changes branch August 6, 2025 17:18
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.

3 participants