Add MCP notifications/message for log streaming to clients#3484
Open
anushakolan wants to merge 6 commits intomainfrom
Open
Add MCP notifications/message for log streaming to clients#3484anushakolan wants to merge 6 commits intomainfrom
anushakolan wants to merge 6 commits intomainfrom
Conversation
Aniruddh25
reviewed
May 1, 2026
| // For MCP stdio mode, add the MCP logger provider to send logs as notifications | ||
| if (runMcpStdio) | ||
| { | ||
| logging.AddProvider(new McpLoggerProvider(McpNotificationWriter, LogLevelProvider.ShouldLog)); |
Collaborator
There was a problem hiding this comment.
how do you ensure other LogLevelProviders dont get added when in stdio mode?
Aniruddh25
reviewed
May 1, 2026
|
|
||
| var notification = new | ||
| { | ||
| jsonrpc = "2.0", |
Collaborator
There was a problem hiding this comment.
define a constant that represents 2.0 protocol, so it can be changed in one shot.
Aniruddh25
reviewed
May 1, 2026
| /// </remarks> | ||
| private static string ConvertToMcpLevel(LogLevel logLevel) | ||
| { | ||
| return logLevel switch |
Collaborator
There was a problem hiding this comment.
Doesnt McpStdioServer or somewhere else we already define such conversion levels? Can we reuse that?
Aniruddh25
reviewed
May 1, 2026
| } | ||
|
|
||
| [TestMethod] | ||
| public void McpLogger_BeginScope_ReturnsNonNullDisposable() |
Collaborator
There was a problem hiding this comment.
this is a trivial test can be skipped. since we dont even use the scope.
Aniruddh25
previously approved these changes
May 1, 2026
Collaborator
Aniruddh25
left a comment
There was a problem hiding this comment.
Left some suggestions for code reuse.
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.
Why make this change?
Enables MCP clients (like MCP Inspector, Claude Desktop, VS Code Copilot) to receive real-time log output via MCP
notifications/message.Related: #3274 (depends on PR #3419)
What is this change?
When
logging/setLevelis called with a level other than "none", logs are sent to MCP clients as JSON-RPC notifications:{ "jsonrpc": "2.0", "method": "notifications/message", "params": { "level": "info", "logger": "Azure.DataApiBuilder.Service.Startup", "data": "Starting Data API builder..." } }New files:
McpLogNotificationWriter.cs- Writes logs as MCP notifications to stdoutMcpLogger.cs/McpLoggerProvider.cs- ILogger implementation for .NET logging pipelineMcpLogNotificationTests.cs- Unit tests (8 tests)Modified files:
Program.cs- RegistersMcpNotificationWriterandMcpLoggerProviderfor MCP modeMcpStdioServer.cs- Enables notifications whenlogging/setLevelis calledHow was this tested?
logging/setLevelis sentNote
This PR targets
dev/anushakolan/set-log-level(PR #3419) as it depends on thelogging/setLevelimplementation.