Skip to content

[azsdk-cli] Log to MCP clients over json-rpc instead of stdout#13475

Merged
benbp merged 6 commits intoAzure:mainfrom
benbp:benbp/mcp-progress
Jan 13, 2026
Merged

[azsdk-cli] Log to MCP clients over json-rpc instead of stdout#13475
benbp merged 6 commits intoAzure:mainfrom
benbp:benbp/mcp-progress

Conversation

@benbp
Copy link
Member

@benbp benbp commented Jan 6, 2026

resolves #11804
fixes #13422

This PR leverages the MCP logging utility and MCP SDK logging to route output from components back to the MCP client via json-rpc. Previously we were sending back all server log messages over stderr to avoid the misleading failed to parse message log prefix from MCP clients, but it was still confusing because all logs would show up as [server stderr]. With this update logs will show up in a normal format prefixed by the category name.

Aside from visual cleanup, the intent of this change is to also give some feedback to the user when there are long-running process operations going on. The internal process helper forwards stdout by default, so with this change that output now gets sent via MCP logging. In the future we could also consider building in first class support for the MCP progress utility, but I think to start this will be sufficient.

Example mcp client logging output when running an external process:

2026-01-09 15:15:36.281 [info] Running command [pwsh -File /tmp/azsdk_example_c55940.ps1 foobar2] in /home/ben/ai/projects/mcp-progress/tools/azsdk-cli/Azure.Sdk.Tools.Cli
2026-01-09 15:15:36.287 [info] --------------------------------------------------------------------------------
2026-01-09 15:15:37.014 [info] [azsdk_example_c55940.ps1] 1: foobar2
2026-01-09 15:15:38.028 [info] [azsdk_example_c55940.ps1] 2: foobar2
2026-01-09 15:15:39.795 [error] [azsdk_example_c55940.ps1] �[31;1mWrite-Error: �[31;1mTest error message, no failure�[0m
2026-01-09 15:15:40.796 [info] [azsdk_example_c55940.ps1] 3: foobar2
2026-01-09 15:15:40.833 [info] --------------------------------------------------------------------------------
2026-01-09 15:15:40.859 [info] Server (azsdk 0.5.12.0), Client (Visual Studio Code 1.106.3) method 'tools/call' request handler completed.

@github-actions github-actions bot added the azsdk-cli Issues related to Azure/azure-sdk-tools::tools/azsdk-cli label Jan 6, 2026
@benbp benbp force-pushed the benbp/mcp-progress branch 3 times, most recently from 294bf72 to eb46983 Compare January 6, 2026 21:04
@benbp benbp added the Central-EngSys This issue is owned by the Engineering System team. label Jan 6, 2026
@benbp benbp moved this from 🤔 Triage to 🔬 Dev in PR in Azure SDK EngSys 📆🎇 Jan 6, 2026
@benbp benbp marked this pull request as ready for review January 6, 2026 22:05
Copilot AI review requested due to automatic review settings January 6, 2026 22:05
@benbp benbp requested a review from a team as a code owner January 6, 2026 22:05
@benbp benbp self-assigned this Jan 6, 2026
@benbp benbp marked this pull request as draft January 6, 2026 22:06
Copy link
Contributor

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 introduces MCP (Model Context Protocol) compatible logging infrastructure to the azsdk-cli tool. The changes enable proper logging when running in MCP server mode by registering custom loggers that route log messages through the MCP protocol instead of standard console output.

Key changes:

  • Added new MCP logging infrastructure with context accessor, logger provider, and hosted service
  • Integrated MCP context accessor into the tool instrumentation layer
  • Modified service registration to conditionally use MCP-specific output helpers when in MCP mode

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
McpLogging.cs Core MCP logging infrastructure including context accessor, logger provider, and raw output helper
McpLoggingHostedService.cs Hosted service to initialize and manage MCP server context lifecycle
McpLoggingExtensions.cs Extension method to configure MCP logging services
InstrumentedTool.cs Added MCP server context accessor injection and initialization in tool invocation
ServiceRegistrations.cs Conditional registration of MCP raw output helper and context accessor based on output mode
Program.cs Logging configuration changes for MCP mode with console provider filtering and MCP logging setup

@benbp benbp force-pushed the benbp/mcp-progress branch from af1ead6 to e952fe7 Compare January 8, 2026 21:14
@benbp benbp changed the title [azsdk-cli] Register mcp compatible logger [azsdk-cli] Log to MCP clients over json-rpc instead of stdout Jan 8, 2026
@benbp benbp force-pushed the benbp/mcp-progress branch 3 times, most recently from 6bcc186 to 3e91233 Compare January 8, 2026 21:37
@benbp benbp marked this pull request as ready for review January 8, 2026 21:38
@samvaity
Copy link
Member

samvaity commented Jan 9, 2026

@benbp I think this implementation can close #13422

@benbp
Copy link
Member Author

benbp commented Jan 9, 2026

Added a couple updates:

  • Removed the category name so the logger view is cleaner (users don't need to see the class FQN).
  • Added a filter so process output logs don't get uploaded to azure monitor
  • Refactored logger setup into its own extensions class so Program.cs is cleaner

@benbp benbp force-pushed the benbp/mcp-progress branch from 566a83e to 9274090 Compare January 9, 2026 20:33
@benbp benbp force-pushed the benbp/mcp-progress branch from 794e8ea to d5b93ef Compare January 13, 2026 18:50
@benbp benbp merged commit f4b7f08 into Azure:main Jan 13, 2026
12 checks passed
@benbp benbp deleted the benbp/mcp-progress branch January 13, 2026 19:37
@kurtzeborn kurtzeborn moved this from 🔬 Dev in PR to 🎊 Closed in Azure SDK EngSys 📆🎇 Jan 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

azsdk-cli Issues related to Azure/azure-sdk-tools::tools/azsdk-cli Central-EngSys This issue is owned by the Engineering System team.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

[Bug Bash] Too many warning messages which should ideally be info [azsdk-cli] Support MCP logging/notifications for ILogger

2 participants