Skip to content

Dev/anushakolan/set default log level none#3420

Draft
anushakolan wants to merge 2 commits intomainfrom
dev/anushakolan/set-default-log-level-none
Draft

Dev/anushakolan/set default log level none#3420
anushakolan wants to merge 2 commits intomainfrom
dev/anushakolan/set-default-log-level-none

Conversation

@anushakolan
Copy link
Copy Markdown
Contributor

@anushakolan anushakolan commented Apr 8, 2026

PR Description

Why make this change?

Closes #3275 - When --mcp-stdio is used, control the output

When DAB runs as an MCP server with --mcp-stdio, stdout must be reserved exclusively for JSON-RPC protocol messages. Any log output (even informational) causes MCP clients like Claude Desktop to interpret them as protocol violations, displaying warnings like "Discovered 7 tools" mixed with actual tool discovery results.

Related: #3274 - MCP logging/setLevel method not found

What is this change?

This PR implements proper output control for MCP stdio mode:

  1. Default log level is None when --mcp-stdio is used (no CLI or config override)

    • Ensures zero characters are emitted to stdout/stderr by default
    • No log noise interfering with MCP protocol
  2. Output redirection based on log level:

    • LogLevel.None: Both stdout and stderr → TextWriter.Null (zero output)
    • Other levels: stdout → stderr (logs appear on stderr, JSON-RPC stays on stdout)
  3. Log level precedence: CLI --LogLevel > Config runtime.telemetry.log-level > MCP logging/setLevel

    • CLI passes --LogLevelFromConfig flag when config specifies a log level
    • Service correctly identifies the source and blocks MCP override if appropriate
  4. Early logging suppression in CLI before Service starts

    • Added IsMcpStdioMode flag to suppress CLI's own logging in MCP mode

How was this tested?

  • Manual Tests
    • Configured mcp.json to run DAB with --mcp-stdio
    • Verified zero output when no log-level specified (default LogLevel.None)
    • Verified config override by adding "log-level": { "default": "Error" } to runtime.telemetry - logs appeared on stderr
    • Verified CLI override (--LogLevel) takes precedence over config
  • Unit Tests
    • DynamicLogLevelProviderTests (5 tests) - CLI > Config > MCP precedence
    • StartCommandTests (39 tests) - CLI start command functionality

Sample Request(s)

CLI Usage - Default (Zero Output)

dab start --mcp-stdio --config dab-config.json

With no log-level in config, MCP mode produces zero log output.

CLI Usage - Config Override

Config file (dab-config.json):

{
  "runtime": {
    "telemetry": {
      "log-level": {
        "default": "Warning"
      }
    }
  }
}
dab start --mcp-stdio --config dab-config.json

Logs at Warning level appear on stderr; MCP logging/setLevel requests are accepted but ignored.

CLI Usage - CLI Override (Highest Priority)

dab start --mcp-stdio --LogLevel Error --config dab-config.json

Logs at Error level appear on stderr; both config and MCP logging/setLevel are ignored.

MCP logging/setLevel Request

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "logging/setLevel",
  "params": {
    "level": "info"
  }
}

Only changes log level if neither CLI nor config specified a level.

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.

[Bug]: When -mcp-stdio is used, control the output

1 participant