portviewer
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., "@portviewer check if port 8080 is in use"
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.
English | 简体中文
Port Viewer
Port Viewer is a local TCP / UDP port and process inspection tool. It provides both a desktop UI and an MCP interface:
Desktop app: built with pywebview + Vue 3, with visual pages for port queries, process queries, process details, process trees, and process termination.
MCP server: built with FastMCP, exposing port and process operations as MCP tools for clients such as Codex, Claude Code, and Cursor.
This project is mainly designed for local Windows usage. Because it can terminate processes and process trees, only deploy it in trusted environments.
Features
The desktop app provides:
Query IPv4 / IPv6 and TCP / UDP port usage.
Query a specific port, a port range, or ports occupied by one or more PIDs.
Filter occupied and free ports.
View the process list for an occupied port.
View all processes occupying TCP / UDP ports.
View process details, occupied ports, and process trees.
Terminate a process or a process tree.
Simplified Chinese, Traditional Chinese, and English UI.
The MCP server provides:
List TCP / UDP / IPv4 / IPv6 network connections.
Query a specific port, endpoint, listening port, or established connection.
Check whether a port is in use.
Query all ports occupied by a process.
Query all processes using a port.
Find any free port or all free ports in a specified range.
Terminate a process.
Return the process tree containing a specified process.
Terminate the process tree containing a specified process.
Related MCP server: port-doctor-mcp
Project Structure
portviewer/
netstatmanager.py # Core port and process management logic
mcpmain.py # MCP stdio entry point
webviewmain.py # pywebview desktop backend entry point
frontend/ # Vue 3 + Vite frontend project
frontpage/ # Built frontend files loaded by the desktop app
pyproject.toml # Python project configuration
uv.lock # Python dependency lock fileRequirements
Windows
Python 3.11 or later
uv, recommended for Python dependency installation
Node.js and npm, only needed when rebuilding the frontend
Python dependencies include:
fastmcp
psutil
pywebview
Install Dependencies
Run this in the project root:
cd H:\portviewer
uv syncIf you are not using uv, create a virtual environment manually:
cd H:\portviewer
python -m venv .venv
.venv\Scripts\python.exe -m pip install fastmcp psutil pywebviewRun the Desktop App
The desktop entry point is webviewmain.py.
cd H:\portviewer
.venv\Scripts\python.exe webviewmain.pyThe desktop app loads frontpage/index.html. If you modify the Vue code under frontend, rebuild the frontend first:
cd H:\portviewer\frontend
npm install
npm run build
cd ..
.venv\Scripts\python.exe webviewmain.pyRun the MCP Server
The MCP entry point is mcpmain.py. It uses stdio transport by default.
cd H:\portviewer
.venv\Scripts\python.exe mcpmain.pyWhen started normally, the stdio MCP server waits for an MCP client to communicate over standard input and standard output. It does not open a window and does not provide an interactive command-line UI. Press Ctrl+C to exit during manual testing.
Local stdio Deployment Recommendation
During development, you can use the project directory directly:
H:\portviewerFor a more stable local deployment, copy the project to a fixed directory such as:
C:\Tools\portviewer-mcpThen install dependencies there:
cd C:\Tools\portviewer-mcp
uv syncThe MCP configuration examples below use the development directory H:\portviewer. If you deploy to C:\Tools\portviewer-mcp, replace the paths accordingly.
Configure MCP in Codex
Codex stores MCP configuration in config.toml. The user-level configuration file is usually:
C:\Users\<your-user-name>\.codex\config.tomlYou can also use a project-level configuration:
H:\portviewer\.codex\config.tomlSteps
Make sure dependencies are installed:
cd H:\portviewer
uv syncOpen or create the Codex configuration file:
notepad $env:USERPROFILE\.codex\config.tomlIf the .codex directory does not exist, create it first:
New-Item -ItemType Directory -Force "$env:USERPROFILE\.codex"
notepad $env:USERPROFILE\.codex\config.tomlAdd the complete configuration:
[mcp_servers.portviewer]
command = "H:\\portviewer\\.venv\\Scripts\\python.exe"
args = ["H:\\portviewer\\mcpmain.py"]
cwd = "H:\\portviewer"
startup_timeout_sec = 15
tool_timeout_sec = 120Restart Codex.
In Codex, run:
/mcpConfirm that portviewer is connected.
Configure MCP in Claude Code
Claude Code can add a stdio MCP server from the command line or from a JSON configuration.
Method 1: Add with Command Line
Run this in PowerShell:
claude mcp add --transport stdio portviewer -- H:\portviewer\.venv\Scripts\python.exe H:\portviewer\mcpmain.pyThen inspect the server:
claude mcp get portviewerInside a Claude Code session, you can also run:
/mcpto check the MCP connection status.
Method 2: Use JSON Configuration
Create .mcp.json in the project root, or use Claude Code's user-level configuration. Example project-level .mcp.json:
{
"mcpServers": {
"portviewer": {
"type": "stdio",
"command": "H:\\portviewer\\.venv\\Scripts\\python.exe",
"args": [
"H:\\portviewer\\mcpmain.py"
],
"env": {}
}
}
}Restart Claude Code after saving, then use /mcp to verify the connection.
Configure MCP in Cursor
Cursor uses mcp.json to configure MCP servers. You can use a project-level or global configuration.
Project-level configuration:
H:\portviewer\.cursor\mcp.jsonGlobal configuration:
C:\Users\<your-user-name>\.cursor\mcp.jsonProject-level configuration is useful when you only want this MCP server in the current project. Global configuration makes it available in all Cursor workspaces.
Steps
Create the project-level configuration directory:
cd H:\portviewer
New-Item -ItemType Directory -Force .cursor
notepad .cursor\mcp.jsonWrite the complete configuration:
{
"mcpServers": {
"portviewer": {
"type": "stdio",
"command": "H:\\portviewer\\.venv\\Scripts\\python.exe",
"args": [
"H:\\portviewer\\mcpmain.py"
],
"env": {}
}
}
}Restart Cursor.
Confirm that
portvieweris enabled in Cursor's MCP settings or Agent MCP list.
Cursor also supports global configuration. Create or edit:
New-Item -ItemType Directory -Force "$env:USERPROFILE\.cursor"
notepad "$env:USERPROFILE\.cursor\mcp.json"Use the same JSON configuration.
MCP Usage Examples
After the server is connected, ask your MCP client things like:
List all currently listening TCP ports.Find free ports between 3000 and 9000.Show all ports used by PID 1234.Show the process tree containing PID 1234.Terminate the process with PID 1234.Security Notes
Port Viewer MCP can read local network connection and process information, and it can terminate processes and process trees. Keep these points in mind:
Enable it only in trusted local environments.
Do not expose this MCP server to the public internet.
If you convert it to a long-running HTTP service, bind to
127.0.0.1by default.For process termination tools, verify the target PID and executable path before calling them.
References
MCP Transport Specification: https://modelcontextprotocol.io/specification/draft/basic/transports
Codex MCP Configuration: https://codex-console.com/config
Claude Code MCP Documentation: https://code.claude.com/docs/en/mcp
Cursor MCP Documentation: https://prod.cursor.com/docs/mcp
Available Tools
30 toolscan_bind_tcpCan Bind TcpC
实际尝试 bind TCP 端口。
Inputs: port (required), host. Returns: result
can_bind_udpCan Bind UdpC
实际尝试 bind UDP 端口。
Inputs: port (required), host. Returns: result
find_endpointFind EndpointD
查询指定 IP + Port。
Inputs: ip (required), port (required), protocol. Returns: result
find_listening_portFind Listening PortC
查询指定 TCP LISTEN 端口。
Inputs: port (required). Returns: result
find_portFind PortC
查询使用指定本地端口的所有记录。
Inputs: port (required), protocol. Returns: result
find_tcp_portFind Tcp PortC
查询使用指定本地 TCP 端口的所有记录。
Inputs: port (required). Returns: result
find_udp_portFind Udp PortB
查询使用指定本地 UDP 端口的所有记录。
Inputs: port (required). Returns: result
get_established_connectionsGet Established ConnectionsB
获取所有 TCP ESTABLISHED 连接。
Inputs: no named parameters. Returns: result
get_free_portGet Free PortC
返回指定范围内任意一个空闲端口。
Inputs: family, end_port, protocol, start_port. Returns: result
get_free_portsGet Free PortsC
返回指定范围内所有空闲端口。
Inputs: family, end_port, protocol, start_port. Returns: result
get_listening_portsGet Listening PortsB
获取所有 TCP LISTEN 端口。
Inputs: no named parameters. Returns: result
get_port_processGet Port ProcessC
获取指定端口的第一个进程。
Inputs: port (required), protocol. Returns: result
get_port_processesGet Port ProcessesC
获取使用指定端口的所有进程。
Inputs: port (required), protocol. Returns: result
get_process_portsGet Process PortsB
获取某个进程正在使用的全部 TCP / UDP 端口。
Inputs: pid (required). Returns: result
get_process_tcp_portsGet Process Tcp PortsC
获取某个进程使用的 TCP 连接。
Inputs: pid (required). Returns: result
get_process_treeGet Process TreeC
返回指定进程所处的完整进程树。
Inputs: pid (required). Returns: result
get_process_udp_portsGet Process Udp PortsC
获取某个进程使用的 UDP 连接。
Inputs: pid (required). Returns: result
is_port_usedIs Port UsedB
判断本地端口是否出现在系统网络连接表中。
Inputs: port (required), protocol. Returns: result
is_tcp_port_listeningIs Tcp Port ListeningC
判断 TCP 端口是否存在 LISTEN 状态。
Inputs: port (required). Returns: result
is_tcp_port_usedIs Tcp Port UsedC
判断 TCP 端口是否被使用。
Inputs: port (required). Returns: result
is_udp_port_usedIs Udp Port UsedC
判断 UDP 端口是否被使用。
Inputs: port (required). Returns: result
kill_processKill ProcessC
结束指定 PID 的进程。
Inputs: pid (required), timeout. Returns: object
kill_process_treeKill Process TreeC
结束指定 PID 及其子孙进程。
Inputs: pid (required), timeout, include_parent. Returns: result
list_allList AllA
列出所有 IPv4 / IPv6 TCP + UDP 网络连接。
Inputs: no named parameters. Returns: result
list_tcpList TcpB
列出 TCP IPv4 + IPv6。
Inputs: no named parameters. Returns: result
list_tcp4List Tcp4C
列出 IPv4 TCP。
Inputs: no named parameters. Returns: result
list_tcp6List Tcp6C
列出 IPv6 TCP。
Inputs: no named parameters. Returns: result
list_udpList UdpB
列出 UDP IPv4 + IPv6。
Inputs: no named parameters. Returns: result
list_udp4List Udp4C
列出 IPv4 UDP。
Inputs: no named parameters. Returns: result
list_udp6List Udp6C
列出 IPv6 UDP。
Inputs: no named parameters. Returns: result
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 30 tools
Many tools overlap heavily: list_tcp/list_tcp4/list_tcp6 and list_udp/list_udp4/list_udp6, is_port_used/is_tcp_port_used/is_udp_port_used, and find_port/find_tcp_port/find_udp_port/find_listening_port. The descriptions clarify the granularity, but an agent must carefully distinguish near-duplicate variants.
All tool names use consistent snake_case and generally follow a verb_noun pattern (list_tcp, get_listening_ports, find_endpoint, kill_process, can_bind_udp). Minor singular/plural pairs like get_port_process/get_port_processes are predictable and intentional.
30 tools is excessive for a port/process viewer, largely because many operations are expanded into protocol- and IP-version-specific permutations. This creates redundancy rather than distinct capability, making the surface heavy for the domain.
The tool set comprehensively covers listing, filtering, checking, finding, binding, free-port discovery, process inspection, process tree retrieval, and process termination for TCP/UDP and IPv4/IPv6. No obvious lifecycle or inspection operation for the stated port/process domain is missing.
Maintenance
Related MCP Connectors
MCP server for mandates, delegation, policy-gated execution, credential grants, and audit.
Read-only MCP access to a documented IT fleet: state, changes, posture. 15 tools.
Use a person's computer after they approve it there: files, Terminal, browser, local MCP.
Use a person's computer after they approve it there: files, Terminal, browser, local MCP.
Related MCP Servers
- 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.7 npm1MIT
- AlicenseNot gradedqualityDmaintenanceEnables developers to inspect port occupancy with process details, scan common development ports, and terminate processes blocking a specified port via MCP tools.MIT
- AlicenseNot gradedqualityCmaintenanceEnables local Linux network diagnostics through MCP tools for status checks, device discovery, reachability tests, topology inspection, incident review, monitoring status, and label or declared-link management.MIT
- AlicenseNot gradedqualityBmaintenanceEnables inspecting local listening ports, process owners, Docker mappings, and local LLM signatures, plus looking up or terminating the process that owns a specific port when write access is allowed. Mutating actions require confirmation and are blocked in dry-run mode.20 npm1MIT