diff --git a/src/common/config/userConfig.ts b/src/common/config/userConfig.ts index 661e0046..bb52e1ea 100644 --- a/src/common/config/userConfig.ts +++ b/src/common/config/userConfig.ts @@ -113,10 +113,10 @@ export const UserConfigSchema = z4.object({ httpPort: z4.coerce .number() .int() - .min(1, "Invalid httpPort: must be at least 1") + .min(0, "Invalid httpPort: must be at least 0") .max(65535, "Invalid httpPort: must be at most 65535") .default(3000) - .describe("Port number for the HTTP server (only used when transport is 'http').") + .describe("Port number for the HTTP server (only used when transport is 'http'). Use 0 for a random port.") .register(configRegistry, { overrideBehavior: "not-allowed" }), httpHost: z4 .string() @@ -125,7 +125,7 @@ export const UserConfigSchema = z4.object({ .register(configRegistry, { overrideBehavior: "not-allowed" }), httpHeaders: z4 .object({}) - .passthrough() + .loose() .default({}) .describe( "Header that the HTTP server will validate when making requests (only used when transport is 'http')." diff --git a/src/lib.ts b/src/lib.ts index babdbde7..a1d8532d 100644 --- a/src/lib.ts +++ b/src/lib.ts @@ -1,6 +1,6 @@ export { Server, type ServerOptions } from "./server.js"; export { Session, type SessionOptions } from "./common/session.js"; -export { type UserConfig } from "./common/config/userConfig.js"; +export { type UserConfig, UserConfigSchema } from "./common/config/userConfig.js"; export { LoggerBase, type LogPayload, type LoggerType, type LogLevel } from "./common/logger.js"; export { StreamableHttpRunner } from "./transports/streamableHttp.js"; export { StdioRunner } from "./transports/stdio.js"; diff --git a/tests/unit/common/config.test.ts b/tests/unit/common/config.test.ts index c5f537d2..a8cd5f18 100644 --- a/tests/unit/common/config.test.ts +++ b/tests/unit/common/config.test.ts @@ -690,17 +690,17 @@ describe("config", () => { }); describe("httpPort", () => { - it("must be above 1", () => { + it("must be above 0", () => { const onErrorFn = vi.fn(); const onExitFn = vi.fn(); createUserConfig({ onError: onErrorFn, closeProcess: onExitFn, - cliArguments: ["--httpPort", "0"], + cliArguments: ["--httpPort", "-1"], }); expect(onErrorFn).toBeCalledWith( expect.stringContaining( - "Invalid configuration for the following fields:\nhttpPort - Invalid httpPort: must be at least 1" + "Invalid configuration for the following fields:\nhttpPort - Invalid httpPort: must be at least 0" ) ); expect(onExitFn).toBeCalledWith(1);