refactor(config): share HTTP listener port contract

This commit is contained in:
morluto committed 2026-10-22 10:18:57 +08:00
1 parent ce5bc8cb01
commit dd46a13dec
3 files changed
+8 -11

No files matched your search

+2 -5
View File
@@ -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",
+4 -1
View File
@@ -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);
+2 -5
View File
@@ -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"),