-
Notifications
You must be signed in to change notification settings - Fork 330
feat: Add logging handler to MCP Server #415
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
Conversation
…ges sent/received
Hey @halter73, @stephentoub, Would you mind to take a look in this PR, please? |
Thanks for your time on this. My feedback is basically the same feedback I left on the issue, so I would lean towards closing this PR until we design a full middleware layer that allows you to intercept and modify requests and responses perhaps short-circuiting the inner layers entirely. Given that functionality, a lot of this seems redundant. And a lot of this still seems redundant given we have structured logging and otel metrics.
With #447 merged, you can now capture any exceptions from tool calls by implementing an ILoggerProvider as demonstrated in ToolCallError_LogsErrorMessage. I don't think it makes sense to add new try/catches to log things like this PR does, but wherever we already catch user-unhandled exceptions, we should absolutely log these as an error using ILogger. csharp-sdk/tests/ModelContextProtocol.Tests/Server/McpServerToolTests.cs Lines 419 to 422 in adb2098
Furthermore, a lot of this could already be achieved with a delegating ITransport. It's not the simplest thing to set up, but it's already possible. Maybe we could add a I'm interested in what @stephentoub and @eiriktsarpalis think too. If we do go forward on this, I do have thoughts about where we invoke the log handler, whether it needs to be a delegate, what properties belong on the context and what should be settable, etc., but I don't want to waste time on those things if we ultimately decide to close this PR. |
Hey @halter73, @eiriktsarpalis, thanks for you considerations on this PR. I'll close this PR, then. |
Thank you regardless! |
This change aims to add the possibility to receive events from the MCP Server context, allowing you to log information about given requests/responses and possible exceptions that might have been thrown by tools/prompts and resources right before they're handled and sent as formal responses to the Client.
Motivation and Context
Based on #359 request, we've created a proposal for letting the developers to access specific message events that could help troubleshooting possible problems when calling MCP resources at the server.
How Has This Been Tested?
We're currently testing this version generating observability outputs to troubleshoot MCP Tool calls, allowing us to monitor possible unhandled exceptions that might occur and which parameters generated faulty scenarios.
Breaking Changes
There's no breaking changes associated with this change. This feature is meant to be fully optional.
Types of changes
Checklist