ports-mcp
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@ports-mcp what is using port 3000?"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
ports-mcp
Ask your AI agent "what is using port 3000?" and have it free the port safely, on Windows, macOS and Linux.
ports-mcp is an MCP server built on psutil, so the same six tools work on every OS. It lists listeners, explains what a process is (Vite, Next.js, uvicorn, Flask, docker-proxy, a database...), shows process trees, finds free ports, tests TCP reachability, and frees a port through a two-step confirmed kill that refuses to touch anything that would hurt.
Install
Claude Code:
claude mcp add ports -- uvx ports-mcpClaude Desktop (claude_desktop_config.json):
{
"mcpServers": {
"ports": { "command": "uvx", "args": ["ports-mcp"] }
}
}Needs uv and Python 3.10+. Without uv: pip install ports-mcp and use the ports-mcp command.
Related MCP server: wharfy
Try asking
"What is using port 3000?"
"Show me everything listening on this machine that is exposed to the network."
"List my node and uvicorn dev servers with their working directories."
"Free port 5173." (you get a plan first and confirm it)
"Find me 3 free ports between 8000 and 8100."
"Show the process tree of PID 4312. Who started it?"
"Is localhost:8080 reachable?"
Tools
Tool | What it does |
| Everything listening, grouped by process: PID, name, user, command line, cwd, inferred framework, bound address. Sockets on |
| Full detail for one port, plus parent/children and whether |
| Lowest unused port(s) in a range that the OS will really let you bind. |
| Two-step, confirmed kill (below). |
| Ancestors and all descendants of a PID, marking which ones listen on a port. |
| TCP connect with a timeout; tells refused vs timed out vs DNS failure. |
The kill is two steps
> kill_port(port=5173)
KILL PLAN for tcp port 5173 (nothing has been killed yet)
Token: 2c19fba46833 (single use, valid 60 s)
Will stop PID 13664 node.exe [Vite dev server] user me
holds 127.0.0.1:5173 (loopback only)
command: node C:\proj\node_modules\vite\bin\vite.js
plus child PID 13702 esbuild.exe
parent: PID 13650 npm.exe (NOT killed; if it restarts the child, stop the parent instead)
To go ahead call: kill_port(port=5173, confirm_token="2c19fba46833")
> kill_port(port=5173, confirm_token="2c19fba46833")
Stopped 2 of 2 process(es) on tcp port 5173.
Verified: tcp port 5173 is now free.The first call never kills. It returns the plan and a random token.
The token is single use, expires after 60 s, and only works for the port it was issued for. A wrong-port attempt also invalidates it.
On the second call the world is re-checked: if a different process now holds the port, or a PID was reused, nothing is killed.
Processes get a graceful terminate, then a force-kill after
grace_seconds(default 5). The tool then checks that the port is really free and says so, or reports what survived (for example a parent that respawned it).
Always refused, even with force: PID 0, 1 and 4, the ports-mcp process itself, and its ancestors (your MCP client and terminal).
Refused unless force=True on the planning call: operating-system services (svchost, systemd, launchd, SYSTEM-account processes, Docker Desktop's backend, processes whose identity the OS hides). Even then you still get a plan and must confirm it.
Permissions and what you will not see
ports-mcp runs as you. Some processes are invisible without elevation, and it says so rather than hiding them:
Windows: system services show up, but their command line and working directory may read "access denied, elevation needed".
Linux: sockets owned by other users are listed as "unidentified process"; run with
sudoto see owners.macOS: listing every socket needs root. Without it ports-mcp inspects each process it may read and warns how many it could not, so a port can be held by something it cannot see (
whats_on_portalso probes with a connect and a bind to catch that).
Security
kill_portterminates processes the current user can terminate. The plan/token flow exists so a model cannot do it in one careless call; show the plan to a human.The token is
secrets.token_hex, kept only in server memory, never written to disk.check_port_reachablemakes an outbound TCP connection to whatever host you give it (no data is sent). Do not expose this server to untrusted callers: it can probe your network.Command lines can contain secrets (tokens in arguments).
list_listeningandwhats_on_portprint them, truncated to 300 characters, to the connected model.On Windows
terminateis an immediate hard kill; there is no graceful stop for non-console programs.
Development
uv sync --extra test
uv run pytest # starts real listener processes on random ports
uv run ruff check src tests
uv run mypy --strict srcCompanion tutorial that builds a minimal version from scratch: ports-mcp-the-hard-way.
MIT licensed.
Available Tools
6 toolscheck_port_reachableA
Try a TCP connect to host:port and report REACHABLE or UNREACHABLE with the reason.
Distinguishes "connection refused" (host is up, nothing listening), "timed out" (firewall drop or host down) and DNS failures. Works for localhost and remote hosts alike. It only connects and disconnects; no data is sent. Timeout is in seconds (0.1 to 30).
Inputs: host (required), port (required), timeout. Returns: result
find_free_portA
Find unused TCP port(s) in start..end (inclusive), lowest first.
A port counts as free only if nothing is listening on it AND the OS lets us bind it on
host, so ports reserved by the OS (Windows excluded ranges) are skipped. count
returns that many ports. Use host "0.0.0.0" to require that the port is free on every
interface.
Inputs: end, host, count, start. Returns: result
kill_portA
Free a port by stopping the process on it. TWO STEPS, never kills on the first call.
Step 1: call kill_port(port). Nothing is killed. You get a plan naming every process (and its child processes) that would be stopped, what each one is (dev server such as vite/next/uvicorn, docker-proxy, database...), and a single-use confirm_token valid for 60 seconds. Show the plan to the user. Step 2: after the user agrees, call kill_port(port, confirm_token=). Processes get a graceful terminate, then a force-kill after grace_seconds; the tool then verifies the port is actually free and reports anything that survived.
Always refused, even with force: PID 0, 1 and 4, this server, and its ancestors (your MCP client). Refused unless force=True on step 1: operating-system services (svchost, systemd, SYSTEM-account processes, ...). The token only works for the port it was issued for.
Inputs: port (required), force, protocol, confirm_token, +1 more. Returns: result
list_listeningA
List what is listening on this machine, grouped by process.
Each process shows its PID, name, user, command line, working directory, an inferred framework (Vite, Next.js, uvicorn, Flask, docker-proxy, ...) and every port it holds with the address it is bound to. Sockets bound to 0.0.0.0 or :: are flagged EXPOSED (reachable from the network); 127.0.0.1 / ::1 are loopback only.
Filters: port_min/port_max (inclusive), process_name (case-insensitive substring of the process name or its command line, e.g. "node" or "uvicorn"), protocol "tcp" (default), "udp" or "all". Listeners whose owner the OS hides without elevation are listed under "unidentified process" rather than dropped.
Inputs: port_max, port_min, protocol, process_name. Returns: result
process_treeA
Show a process's ancestors (who started it) and all its descendants, as a tree.
Each node lists name, PID and a shortened command line, and marks processes that are listening on a port. Use it before killing: killing a child can be undone by its parent restarting it (npm, nodemon, a reloader, a service manager).
Inputs: pid (required). Returns: result
whats_on_portA
Answer "what is using port N?" in detail.
Returns every listener on the port: PID, process name, user, full command line, working directory, the inferred framework, the address it is bound to (and whether that exposes it to the network), the process's parent and children, and whether kill_port would refuse it (system process, your own MCP client). If nothing is listening it says so, and also checks whether the port can be bound, which catches OS-reserved ports (Windows excluded ranges) and listeners hidden by missing privileges.
Inputs: port (required), protocol. Returns: result
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 6 tools
Each tool has a reasonably distinct role: list_listening is a broad process-grouped scan, whats_on_port is a single-port deep dive, find_free_port, kill_port, process_tree and check_port_reachable are clearly separate operations. The main overlap is between list_listening and whats_on_port (the latter returns a superset of detail for one port), and process_tree partially re-surfaces process info, but the list-vs-detail and diagnostic-vs-action boundaries are clear enough to avoid misselection.
All names use snake_case, which is good, but the grammatical patterns are mixed: verb_noun (kill_port, find_free_port), gerund (list_listening), question phrase (whats_on_port), and bare noun (process_tree). It stays readable and mostly self-explanatory, but there is no single predictable verb_noun convention across the set.
Six tools is tightly scoped to the port-diagnostics-and-cleanup domain, and each one covers a distinct step (discover, inspect, find free, trace, kill, verify reachability). Nothing feels redundant or padded.
The surface covers the full practical lifecycle: discover listeners, drill into a port, find free ports, understand process lineage, safely kill, and test reachability, with a thoughtful two-step kill flow. Minor gaps remain—find_free_port only checks TCP (no UDP equivalent despite UDP being supported in list_listening), and there's no ability to bind/reserve or wait-for-port readiness—but these are workable around.
Maintenance
Related MCP Connectors
Operate Linux, macOS and Windows from your LLM. Every action runs through an auditable allowlist.
Use your own Windows, Mac or Linux computer from ChatGPT, Claude, Cursor or Gemini CLI: run commands, read, write and search files, run long processes. Your computer only makes an outgoing connection (no open ports or VPN). Read-only mode, allowed folders, blocked commands and an action log keep you in control. Free plan available.
Gives AI agents a public IPv6 identity, hostname, port forwarding, web fetch, team mesh. Free tier.
IP intelligence, network diagnostics, and AI service availability tools for AI agents.
Related MCP Servers
- AlicenseNot gradedqualityNot gradedmaintenanceEnables comprehensive Windows process and service management with secure UAC elevation. Supports discovery, inspection, and control of processes by name, PID, or port number, with both AI-assisted and direct command-line interfaces.-
- AlicenseNot gradedqualityCmaintenanceMCP server for managing local dev ports on macOS. It enables AI agents to inspect listening ports, identify owning processes and parent chains, kill processes safely, wait for ports, and report LAN exposure.6 npm1MIT
- AlicenseNot gradedqualityBmaintenanceEnables AI agents to coordinate ports and dev servers on a shared Linux machine, reserve ports, start and stop worktree servers, inspect listening services, Tailscale devices and dev worktrees, and clean up safely without collisions.15 npmMIT
- AlicenseNot gradedqualityBmaintenanceEnables AI agents and assistants to inspect live system telemetry, check TCP port connectivity, audit environment variables for leaked secrets, analyze and summarize log files, and list Docker containers — all with token-efficient, compressed output.1MIT