inspector icon indicating copy to clipboard operation
inspector copied to clipboard

CLI --log-level rejects valid MCP log levels and accepts invalid ones (spec mismatch)

Open ayaangazali opened this issue 4 months ago • 4 comments

Inspector Version

1.0.0 (repo HEAD, commit ac3c1a12)

Affected client

CLI (--cli mode). Web UI is not affected (it imports the SDK schema directly).

Describe the bug

The CLI --log-level flag validates against a hardcoded list that does not match the MCP spec logging levels, so it rejects valid levels and accepts invalid ones.

cli/src/client/connection.ts:5-11 defines:

export const validLogLevels = ["trace", "debug", "info", "warn", "error"] as const;

The MCP spec / SDK LoggingLevelSchema (RFC 5424 syslog levels) is:

["debug", "info", "notice", "warning", "error", "critical", "alert", "emergency"]

So the CLI:

  • rejects the spec-valid levels notice, warning, critical, alert, emergency
  • accepts trace and warn, which are not valid MCP levels, and forwards them to the server via logging/setLevel

The validator that enforces this is at cli/src/index.ts:307-318.

To Reproduce

# spec-valid level, gets wrongly rejected before any request is sent:
mcp-inspector --cli <server> --method logging/setLevel --log-level warning
# -> "Invalid log level: warning. Valid levels are: trace, debug, info, warn, error"  (exit 1)

# non-spec level, wrongly accepted (passes validation, proceeds to connect):
mcp-inspector --cli <server> --method logging/setLevel --log-level warn

Reproduced against HEAD (built CLI). Only debug, info, and error overlap between the CLI list and the spec, so those are the only levels that both pass validation and are actually valid.

Expected behavior

--log-level should accept exactly the MCP spec levels: debug, info, notice, warning, error, critical, alert, emergency, and reject anything else (including trace and warn).

Actual behavior

Valid levels notice/warning/critical/alert/emergency are rejected; invalid trace/warn are accepted and sent to the server.

Suggested fix

Derive the list from the SDK instead of hardcoding, so it can never drift from the spec:

import { LoggingLevelSchema } from "@modelcontextprotocol/sdk/types.js";
export const validLogLevels = LoggingLevelSchema.options;
export type LogLevel = (typeof validLogLevels)[number];

The validator at cli/src/index.ts:307-318 stays as-is; it just validates against the correct set. The web client already uses LoggingLevelSchema directly (client/src/components/Sidebar.tsx), so this also aligns CLI and Web on one source of truth.

Version Consideration

This is an MCP spec-compliance bug in V1 CLI, so it fits the current V1 scope. Suggesting the v1 label (targets main).


apologies if I got any detail wrong here. I reproduced this locally against HEAD and talked through the logic with Claude Code to double-check the spec levels, but I am a freshman still learning, so happy to be corrected. just trying to help out where I can :)

ayaangazali avatar Jul 21 '26 23:07 ayaangazali

Confirmed — here is the root cause and a one-file fix.

Root cause

cli/src/client/connection.ts defines:

export const validLogLevels = ["trace", "debug", "info", "warn", "error"] as const;

The MCP spec uses RFC 5424 syslog levels. The SDK's LoggingLevelSchema (in @modelcontextprotocol/sdk) is:

"debug" | "info" | "notice" | "warning" | "error" | "critical" | "alert" | "emergency"

So the hardcoded list:

  • Rejects 6 spec-valid levels: notice, warning, critical, alert, emergency
  • Accepts 2 non-spec levels: trace, warn

Fix

Replace the hardcoded array with the SDK's own schema so the CLI can never diverge from the spec again:

import { LoggingLevelSchema } from "@modelcontextprotocol/sdk/types.js";

export const validLogLevels = LoggingLevelSchema.options;
export type LogLevel = (typeof validLogLevels)[number];

If importing from the SDK feels too tight a coupling, a direct fix is:

export const validLogLevels = [
  "debug", "info", "notice", "warning", "error", "critical", "alert", "emergency"
] as const;

Happy to open a PR for either approach — whichever the maintainers prefer.

manjunathbhaskar avatar Jul 22 '26 10:07 manjunathbhaskar

Update: this looks resolved on main now by the v2 tree swap (ec5d8e13, released as 2.0.0).

The old hardcoded list at cli/src/client/connection.ts is gone with the v1 tree. The CLI now derives the levels from the schema instead of hardcoding them, in clients/cli/src/cli.ts:84:

export const validLogLevels: LoggingLevel[] = Object.values(
  LoggingLevelSchema.enum,
);

So warning, notice, critical, alert, and emergency are accepted, and trace / warn are correctly rejected, which is what this issue was asking for. It also can't drift from the spec again since there is only one source of truth now.

Feel free to close this out. Leaving the details up in case they are useful for anyone still on 1.x.

thanks for the work on the v2 migration, and sorry for the extra item in the triage queue. still a freshman learning my way around this stuff, so it is good to see how the fix ended up being done properly upstream :)

ayaangazali avatar Jul 28 '26 21:07 ayaangazali

Closing: v1 is deprecated.

Thank you for reporting this, and apologies for the long wait for a response.

v1 will receive security fixes only — this issue describes a functionality, compatibility, or usability problem rather than a vulnerability, so it is being closed against v1. This is not a judgment on whether the problem is real — it's a consequence of the v1 line being frozen. This is happening as part of #1872.

If this still happens in v2, we'd genuinely like to know. v2 is a complete rewrite — three clients over a shared core — so many v1 behaviours no longer exist in the same form. Please open a fresh issue against v2 with steps to reproduce, and we'll look at it. Note that we accept external contributions as issues rather than pull requests; maintainers handle design and implementation through a prompt-driven workflow. See CONTRIBUTING.md.

Thanks for taking the time to report it.

cliffhall avatar Aug 01 '26 12:08 cliffhall

Totally fair, thanks for coming back to it.

Just to close the loop so nobody has to re-check: this one does not need a fresh v2 issue. v2 already does the right thing, it derives the levels from the schema instead of hardcoding them, in clients/cli/src/cli.ts:84:

export const validLogLevels: LoggingLevel[] = Object.values(
  LoggingLevelSchema.enum,
);

So the full RFC 5424 set is accepted and trace / warn are correctly rejected, and it cannot drift from the spec again since there is one source of truth. The rewrite fixed it independently.

Understood on issues rather than PRs, I will keep to that. Thanks for the clear explanation of the v1 policy, that is helpful for knowing what is worth reporting where.

ayaangazali avatar Aug 04 '26 21:08 ayaangazali