port_conflict
Diagnose port conflicts by identifying the blocking server and suggesting 5 free alternative ports nearby.
Instructions
Diagnose why a port is busy. Returns the blocking server and 5 free alternative ports nearby.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| port | Yes |
Implementation Reference
- src/dev-servers.ts:90-102 (handler)The portConflict function that executes the tool logic. It calls portInfo(port) to find the blocking server, then scans ports (port+1 .. port+49) to find up to 5 free alternative ports. Returns { blocking, free_alternatives }.
export async function portConflict(port: number): Promise<{ blocking: DevServer | null; free_alternatives: number[]; }> { const blocking = await portInfo(port); const all = await listDevServers(); const taken = new Set(all.map((s) => s.port)); const free_alternatives: number[] = []; for (let p = port + 1; p < port + 50 && free_alternatives.length < 5; p++) { if (!taken.has(p)) free_alternatives.push(p); } return { blocking, free_alternatives }; } - src/index.ts:61-70 (schema)Tool definition (inputSchema) for 'port_conflict'. Declares a required 'port' (number) input and describes the tool's purpose: diagnose why a port is busy, return the blocking server and 5 free alternatives.
{ name: "port_conflict", description: "Diagnose why a port is busy. Returns the blocking server and 5 free alternative ports nearby.", inputSchema: { type: "object", properties: { port: { type: "number" } }, required: ["port"], additionalProperties: false, }, }, - src/index.ts:105-109 (registration)Handler registration in the CallToolRequestSchema switch-case. Parses the port argument with Zod and calls the portConflict function from dev-servers.ts, returning the result.
case "port_conflict": { const port = z.number().int().parse((args as any)?.port); const data = await portConflict(port); return ok(data); } - src/dev-servers.ts:44-47 (helper)Helper function portInfo used by portConflict to look up which dev server (if any) is blocking the given port.
export async function portInfo(port: number): Promise<DevServer | null> { const all = await listDevServers(); return all.find((s) => s.port === port) ?? null; }