Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion cli/__tests__/cli.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { describe, it, beforeAll, afterAll, expect } from "vitest";
import { LoggingLevelSchema } from "@modelcontextprotocol/sdk/types.js";
import { runCli } from "./helpers/cli-runner.js";
import {
expectCliSuccess,
Expand All @@ -18,6 +19,7 @@ import {
createEchoTool,
createTestServerInfo,
} from "./helpers/test-fixtures.js";
import { validLogLevels } from "../src/client/connection.js";

describe("CLI Tests", () => {
describe("Basic CLI Mode", () => {
Expand Down Expand Up @@ -363,6 +365,10 @@ describe("CLI Tests", () => {
});

describe("Logging Options", () => {
it("should use MCP spec logging levels", () => {
expect(validLogLevels).toEqual(LoggingLevelSchema.options);
});

it("should set log level", async () => {
const server = createTestServerHttp({
serverInfo: createTestServerInfo(),
Expand Down Expand Up @@ -396,7 +402,24 @@ describe("CLI Tests", () => {
}
});

it("should reject invalid log level", async () => {
it.each(["trace", "warn"])(
"should reject non-spec log level %s before connecting",
async (logLevel) => {
const result = await runCli([
NO_SERVER_SENTINEL,
"--cli",
"--method",
"logging/setLevel",
"--log-level",
logLevel,
]);

expectCliFailure(result);
expect(result.output).toContain(`Invalid log level: ${logLevel}`);
},
);

it("should reject unknown log level", async () => {
const { command, args } = getTestMcpServerCommand();
const result = await runCli([
command,
Expand Down
11 changes: 3 additions & 8 deletions cli/src/client/connection.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import type { Transport } from "@modelcontextprotocol/sdk/shared/transport.js";
import { LoggingLevelSchema } from "@modelcontextprotocol/sdk/types.js";
import { McpResponse } from "./types.js";

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

export type LogLevel = (typeof validLogLevels)[number];

Expand Down Expand Up @@ -47,7 +42,7 @@ export async function setLoggingLevel(
level: LogLevel,
): Promise<McpResponse> {
try {
const response = await client.setLoggingLevel(level as any);
const response = await client.setLoggingLevel(level);
return response;
} catch (error) {
throw new Error(
Expand Down