Allow MCP agent to override CLI and Config log levels (Agent > CLI > Config)#3544
Open
anushakolan wants to merge 7 commits into
Open
Allow MCP agent to override CLI and Config log levels (Agent > CLI > Config)#3544anushakolan wants to merge 7 commits into
anushakolan wants to merge 7 commits into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates Data API Builder’s dynamic logging control so that MCP agents can reliably override log levels at runtime, establishing the intended precedence order Agent (MCP) > CLI > Config > defaults, and ensuring agent-driven changes are visible through standard logging/notification pathways.
Changes:
- Adjusts
DynamicLogLevelProviderso MCPlogging/setLevelcan override CLI/config-set levels, and prevents hot-reload config updates from clobbering agent/CLI-selected levels. - Extends
ILogLevelControllerwith anIsAgentOverriddenflag and updates interface documentation to reflect the new precedence rules. - Updates MCP stdio handling and unit tests to validate the new precedence and hot-reload behavior.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Service/Telemetry/DynamicLogLevelProvider.cs | Implements agent-overrides and guards runtime-config hot reload from overwriting agent/CLI selections; emits an audit log on agent changes. |
| src/Service/Startup.cs | Wires an ILogger into the provider after ILoggerFactory is available so agent override audit logs flow through the normal pipeline. |
| src/Service.Tests/UnitTests/DynamicLogLevelProviderTests.cs | Updates and adds tests to lock in Agent > CLI > Config behavior, including a hot-reload-after-agent scenario. |
| src/Core/Telemetry/ILogLevelController.cs | Adds IsAgentOverridden and updates XML docs to match the new precedence contract. |
| src/Azure.DataApiBuilder.Mcp/Core/McpStdioServer.cs | Reorders notification enabling to ensure the agent override audit log is forwarded to the MCP client. |
4d15abd to
eb76771
Compare
…ore side effects, hoist logger wiring
souvikghosh04
approved these changes
May 15, 2026
Contributor
souvikghosh04
left a comment
There was a problem hiding this comment.
Posted the comments which needs some changes. Approving this assuming those gets addressed.
… and add successive-MCP-call test
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?
Closes #3533— Log-level precedence should be Agent > CLI > Config; MCP
logging/setLevelis silently ignored when CLI/Config set a level.The runtime today implements CLI > Config > Agent: once
--LogLevelis passed orruntime.telemetry.log-levelis set, the agent's request silently no-ops. There is no way for an agent to dial verbosity up or down at runtime, which defeats the purpose of MCPlogging/setLevel.The team locked the corrected precedence on 5/1 : Agent > CLI > Config > defaults. The agent must always be able to override; CLI still beats Config when the agent doesn't speak up; defaults (Production = Error, Development = Debug,
--mcp-stdio= None) are unchanged.What is this change?
DynamicLogLevelProvideris the single chokepoint for all log-level updates. The fix:UpdateFromMcpno longer rejects when CLI or Config has set a level. It updates the level, flips a newIsAgentOverridingflag, and emits anInformationaudit log ("Log level updated to {Level} via MCP logging/setLevel (agent override).").UpdateFromRuntimeConfigis guarded so a config hot-reload won't overwrite an Agent- or CLI-set level.ILogLevelControllergainsIsAgentOverridingand updated XML docs.Startup.cswires a logger on the provider onceILoggerFactoryexists, so the audit log reaches the standard pipeline.McpStdioServer.HandleSetLevelenables the MCP notification writer before callingUpdateFromMcpso the audit log surfaces to the agent.CLI > Config, default levels, and the
--mcp-stdiodefault ofNoneare unchanged.How was this tested?
Unit tests
Added 1 new test and updated existing ones in
DynamicLogLevelProviderTeststo lock Agent > CLI > Config under both single-call and concurrent paths. All 9 tests pass.Manual end-to-end test
Started the engine with
--mcp-stdio --LogLevel Errorand drove it from the MCP Inspector against a live SQL Server.logging/setLevel { level: "debug" }--LogLevel Errortools/list)Also spot-checked HTTP mode: Config-only, CLI-over-Config, and Config-alone all behave as before.
Sample Request(s)
MCP
logging/setLevelfrom the agentRequest:
{ "jsonrpc": "2.0", "id": 2, "method": "logging/setLevel", "params": { "level": "debug" } }Response:
{ "jsonrpc": "2.0", "id": 2, "result": {} }Followed by the new visibility notification:
{ "jsonrpc": "2.0", "method": "notifications/message", "params": { "level": "info", "logger": "Azure.DataApiBuilder.Service.Telemetry.DynamicLogLevelProvider", "data": "Log level updated to Debug via MCP logging/setLevel (agent override)." } }CLI usage (precedence still works as expected)