Skip to content

feat: add logging #35

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 3 commits into from
Apr 10, 2025
Merged

feat: add logging #35

merged 3 commits into from
Apr 10, 2025

Conversation

nirinchev
Copy link
Collaborator

@nirinchev nirinchev commented Apr 9, 2025

This adds logging to disk as well as sending log messages to the client via the logging capability.

The reason why I believe it's valuable to do both is that sometimes client logs can be noisy (e.g. Claude logs a bunch of error messages related to the fact that we don't provide prompts or resources).

@fmenezes
Copy link
Collaborator

@nirinchev
Copy link
Collaborator Author

Yes, I wanted to integrate that as well, but got pretty late last night, so decided to leave it for today 😅 I still think it'd be valuable to both send the logs to the client, but also store them on disk.

@nirinchev nirinchev marked this pull request as ready for review April 10, 2025 10:42
@nirinchev nirinchev requested a review from fmenezes April 10, 2025 10:44
@fmenezes
Copy link
Collaborator

If you want to add it to disk we run the risk of adding to too many logs needing to implement log rotation, where to you want to send the logs to? Should we truncate?

@nirinchev
Copy link
Collaborator Author

@fmenezes I'm using https://github.com/mongodb-js/devtools-shared/tree/main/packages/mongodb-log-writer for writing the logs on disk. It's the same package we use in mongosh and Compass and it implements log cleanup based on retention policy and storage limits. Right now, I've hardcoded some default values, but once we get to #21, we'd be able to expose them as config options for users to tweak.

Comment on lines +24 to +33
function getLocalDataPath() {
if (process.platform === "win32") {
const appData = process.env.APPDATA;
const localAppData = process.env.LOCALAPPDATA ?? process.env.APPDATA;
if (localAppData && appData) {
return path.join(localAppData, "mongodb", "mongodb-mcp");
}
}

return path.join(os.homedir(), ".mongodb", "mongodb-mcp");
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is the same parent folder as the one we use for mongosh/compass.

Comment on lines +108 to +112
retentionDays: 30,
onwarn: console.warn,
onerror: console.error,
gzip: false,
retentionGB: 1,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Defaulting to 30 day retention or 1 gb of storage. We'll want to expose these as config options at a later point.

@nirinchev nirinchev merged commit d72c835 into main Apr 10, 2025
1 check passed
@nirinchev nirinchev deleted the ni/logging branch April 10, 2025 10:56
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.

2 participants