diff --git a/src/cli/environmentCommands.ts b/src/cli/environmentCommands.ts index 229d4deb27..f84d4967a6 100644 --- a/src/cli/environmentCommands.ts +++ b/src/cli/environmentCommands.ts @@ -11,6 +11,7 @@ import { logCliCommand } from "../cliLogging.js"; import { parseEnvironmentName } from "../config/environmentName.js"; import { parseMcpHttpEndpoint, + mcpHttpListenerPortSchema, type McpHttpEndpoint, } from "../config/mcpHttpEndpoint.js"; import type { AnalysisError } from "../domain/analysisErrorBase.js"; @@ -364,11 +365,7 @@ export const registerEnvironmentCommands = ( .min(1) .optional() .describe("Listener address; default MCP_HOST, else 127.0.0.1"), - port: z - .number() - .int() - .min(0) - .max(65535) + port: mcpHttpListenerPortSchema .optional() .describe( "Listener port; default MCP_PORT, else 0 for an ephemeral port", diff --git a/src/config/mcpHttpEndpoint.ts b/src/config/mcpHttpEndpoint.ts index 4604497ffb..06980156ba 100644 --- a/src/config/mcpHttpEndpoint.ts +++ b/src/config/mcpHttpEndpoint.ts @@ -11,12 +11,15 @@ export const DEFAULT_MCP_HTTP_HOST = "127.0.0.1"; /** Port 0 asks the host for an ephemeral port, reported by the listening log line. */ export const DEFAULT_MCP_HTTP_PORT = 0; +/** A listener may request an ephemeral port with 0; connected endpoints may not. */ +export const mcpHttpListenerPortSchema = z.number().int().min(0).max(65535); + /** Decimal TCP port text, shared by the `--port` flag and `MCP_PORT`. */ export const mcpHttpPortSchema = z .string() .regex(/^(?:0|[1-9]\d*)$/u) .transform(Number) - .pipe(z.number().int().min(0).max(65535)); + .pipe(mcpHttpListenerPortSchema); const mcpHttpHostSchema = z.string().trim().min(1); diff --git a/src/main/mcpHttpArguments.ts b/src/main/mcpHttpArguments.ts index 634c58ff32..6072857c3d 100644 --- a/src/main/mcpHttpArguments.ts +++ b/src/main/mcpHttpArguments.ts @@ -2,6 +2,7 @@ import { Help, z } from "incur"; import { MCP_HTTP_PORT_CONSTRAINT, + mcpHttpListenerPortSchema, mcpHttpPortSchema, } from "../config/mcpHttpEndpoint.js"; @@ -18,11 +19,7 @@ const MCP_HTTP_OPTIONS = z.object({ .min(1) .optional() .describe("Listener address; default MCP_HOST, else 127.0.0.1"), - port: z - .number() - .int() - .min(0) - .max(65535) + port: mcpHttpListenerPortSchema .optional() .describe("Listener port; default MCP_PORT, else 0 for an ephemeral port"), help: z.boolean().optional().describe("Show help"),