Skip to content

mcp: Add example of using Middleware for logging purposes #58

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

Conversation

rwjblue-glean
Copy link
Contributor

Motivation and Context

I needed to implement some logging for our experimental server that we are building out using the SDK, and figured I could propose an example that might make it easier for folks in the future.

For #33

How Has This Been Tested?

Implemented a small number of tests to ensure that the example continues to function over time.

Breaking Changes

N/A

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

@rwjblue-glean rwjblue-glean force-pushed the rwjblue/logging-middleware branch from 22d44b4 to d87030f Compare June 26, 2025 23:44
Copy link
Contributor

@jba jba left a comment

Choose a reason for hiding this comment

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

This should be a Go documentation example, not a separate program. See mcp/example_progress_test.go.

You won't need a lot of test infrastructure in that case. I would disable time output, and use the "// Output:" feature of examples for some very basic testing.
src/cmd/go/alldocs.go

If that doesn't work out for some reason, let me know and I'll reconsider.

@rwjblue-glean
Copy link
Contributor Author

Thank you @jba for taking a look! I will work on updating this evening.

@rwjblue-glean rwjblue-glean force-pushed the rwjblue/logging-middleware branch from d87030f to accdc47 Compare July 16, 2025 22:24
@rwjblue-glean
Copy link
Contributor Author

Sorry for the delay here @jba (I was out on vacation, and this slipped between the cracks); I've updated as you requested please take a look when you have time.

@rwjblue-glean rwjblue-glean requested a review from jba July 16, 2025 22:27
Copy link
Contributor

@jba jba left a comment

Choose a reason for hiding this comment

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

Looks awesome! Some minor tweaks.

@rwjblue-glean rwjblue-glean requested a review from jba July 17, 2025 14:10
Copy link
Contributor

@jba jba left a comment

Choose a reason for hiding this comment

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

Thanks a lot!

@jba jba merged commit dd49b70 into modelcontextprotocol:main Jul 17, 2025
3 checks passed
@rwjblue-glean rwjblue-glean deleted the rwjblue/logging-middleware branch July 17, 2025 15:37
@rwjblue-glean
Copy link
Contributor Author

Thank you for all of your help @jba!

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