portview

io.github.Mapika由 GitHub 帳號 Mapika 發布v2.1.0更新於 Oct 25, 2026

See what's on your ports, the processes behind them, and diagnose conflicts and leaks.

概覽

AI 產生的概覽

一個本機 MCP 伺服器,讓助理列出監聽埠、查看背後的行程、診斷衝突,並終止行程。

可以做什麼
列出監聽埠及行程詳情,例如 PID、使用者、指令、記憶體與執行時間,並依行程名稱或指令子字串尋找埠。檢查單一埠,包括工作目錄、子行程與開啟的連線。執行診斷,檢查埠衝突、萬用字元綁定暴露、連線堆積與高記憶體用量。將目前埠與基準比較,查看哪些埠新開、關閉或更換了擁有者。終止佔用某個埠的行程,並可用 dry-run 預覽目標。
適用情境
適合助理排查本機開發伺服器:查明某個埠被誰佔用、找出洩漏或衝突的監聽、釋放卡住的埠。較適合開發者在自己的電腦上使用,而非共用或正式環境主機。
執行需求
以 stdio 方式作為本機行程執行;MCP 伺服器內建於 portview 二進位檔中,可透過 Homebrew、安裝腳本、cargo 或發行版二進位檔安裝。未宣告帳號、API 金鑰或環境變數。Docker 相關檢查需要 docker CLI 與常駐程式;SSH 功能使用系統 ssh 用戶端。
安裝前請注意
kill_port 工具會終止行程,並被標示為破壞性操作;可用唯讀參數停用它。殺錯行程可能導致服務中斷或未儲存的工作遺失。Linux 上辨識其他使用者的行程需要 sudo,macOS 上不加 sudo 則不會列出其他使用者的埠。Docker 與 SSH 模式會作用於容器和遠端主機。

安裝

在 SourceWeft 中

  1. 開啟 儀表板中的 portview,將其新增到工作區。
  2. 為需要使用其工具的對話啟用該服務。

Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。

其他 MCP 客戶端

參照 儲存庫 中的啟動說明。

README

portview

[CI] [Crates.io] [License: MIT]

portview lists ports and the processes using them on Linux, macOS, and Windows. It shows process names, commands, memory usage, and uptime. You can inspect a port, stop its process, or monitor changes in an interactive terminal UI.

[portview demo]

It also supports Docker, remote hosts over SSH, and an MCP server for coding agents.

Install

Homebrew:

bash
brew install mapika/tap/portview

Linux / macOS:

bash
curl -fsSL https://raw.githubusercontent.com/mapika/portview/main/install.sh | sh

Windows (PowerShell):

powershell
irm https://raw.githubusercontent.com/mapika/portview/main/install.ps1 | iex

Or use cargo install portview, or download a binary from Releases.

What it does

bash
portview                          # list all listening portsportview 3000                     # inspect port 3000 in detailportview node                     # find ports by process nameportview watch                    # interactive TUI with live refreshportview watch --docker           # TUI with Docker containers as rowsportview kill 3000 --force        # terminate the process using port 3000portview doctor                   # diagnose port conflicts and issuesportview ssh user@server          # inspect ports on a remote hostportview ssh user@server watch    # remote TUI over SSHportview ssh user@server --agentless   # no portview needed on the remoteportview mcp                      # run as an MCP server for AI agents

Features

Scan

$ portview╭──────┬───────┬─────┬──────────────┬──────┬────────────┬────────┬────────┬────────────────────────────╮│ PORT │ PROTO │ PID │ ADDR         │ USER │ PROCESS    │ UPTIME │ MEM    │ COMMAND                    │├──────┼───────┼─────┼──────────────┼──────┼────────────┼────────┼────────┼────────────────────────────┤│ 3000 │ TCP   │ 8   │ 127.0.0.1    │ root │ node       │     7s │  44 MB │ node /opt/app/web.js       ││ 5000 │ TCP   │ 11  │ 127.0.0.1    │ root │ python3.12 │     7s │  18 MB │ python3 /opt/app/worker.py ││ 6380 │ TCP   │ 12  │ 127.0.0.1    │ root │ node       │     7s │ 1.2 GB │ node /opt/app/cache.js     ││ 7000 │ TCP   │ 10  │ 127.0.0.1    │ root │ node       │     7s │  45 MB │ node /opt/app/ingest.js    ││ 8080 │ TCP   │ 9   │ 127.0.0.1    │ root │ node       │     7s │  44 MB │ node /opt/app/api.js       │╰──────┴───────┴─────┴──────────────┴──────┴────────────┴────────┴────────┴────────────────────────────╯

--all includes non-listening connections, with one row per connection. --wide shows full commands. --json produces JSON output for scripts.

Ports whose owner can't be resolved are still listed, with - in the columns that can't be filled. That happens for another user's process without sudo, and for sockets like TIME_WAIT that outlive the process that opened them.

The scan, doctor, and MCP examples below are real output, captured by demo/record.sh inside an isolated namespace — which is why the user is root and the paths are /opt/app. The Docker example is illustrative, since it needs a running daemon.

MCP server (for AI agents)

portview mcp provides port queries, diagnostics, and process termination over the Model Context Protocol using stdio. To register it with Claude Code:

bash
claude mcp add portview -- portview mcp

Or configure it manually:

json
{  "mcpServers": {    "portview": {      "command": "portview",      "args": ["mcp"]    }  }}
ToolWhat it does
list_portsList listening ports with available process details
inspect_portInspect a port, including process working directories and descendants
find_processFind ports by process name or command substring
doctorCheck for conflicts, wildcard exposure, connection buildup, and high memory usage
diff_portsReport ports that opened, closed, or changed owner since a baseline
kill_portTerminate processes using a port; dry_run previews the targets. Marked destructive to the client

[portview MCP server demo]

The MCP server is included in the portview binary. Pass --read-only to disable the kill_port tool:

bash
portview mcp --read-only

Listed in the MCP Registry as mcp-name: io.github.Mapika/portview.

Watch mode (interactive TUI)

bash
portview watch                    # live-refresh every 1sportview watch --docker           # include Docker containersportview watch --sort mem         # sort by memory on launch
KeyAction
j/k, ↑/↓Navigate rows
EnterInspect port (full command, cwd, children, connections)
d/DKill process or manage Docker container
/Filter across all columns
←/→, rCycle sort column, reverse direction
tToggle process tree view
aToggle all/listening-only
qQuit

Tree view (t): Groups child processes under their parents.

Detail view (Enter): Shows the full unwrapped command, working directory, child process list with ports, and open connections (in --all mode).

Doctor

portview doctor checks for port conflicts, wildcard bindings, connection buildup, and high memory usage:

$ portview doctor  ✓ No port conflicts  ✓ No wildcard exposure issues  ! Port 7000 has 16 CLOSE_WAIT connections — possible connection leak  ! node (PID 12) is listening on port 6380 and using 1.2 GB of memory
  2 warnings found
CheckFlags
Port conflictsMultiple PIDs bound to the same port
Wildcard exposureDatabases (postgres, redis, mysql, mongod, …) listening on 0.0.0.0
Docker-host conflictsA container publishing a port the host already uses
Connection buildupHigh counts of TIME_WAIT or CLOSE_WAIT connections on one port; these do not by themselves establish a leak
High memory usageListening processes using more than 1 GB of resident memory

Docker is auto-detected. portview doctor --json for scripting (exit code 1 on errors).

In CI

The GitHub Action runs doctor and can fail a workflow on errors or warnings:

yaml
- uses: mapika/portview@v2  with:    fail-on: error        # error | warning | never

It annotates each finding inline on the run, writes a summary table, and exposes findings (JSON), count, errors, and warnings as step outputs:

yaml
- uses: mapika/portview@v2  id: doctor  with:    fail-on: never- run: echo '${{ steps.doctor.outputs.findings }}' | jq .

Set install: false if portview is already on PATH. Linux and macOS runners.

SSH remote mode

Inspect ports on a remote host over SSH:

bash
portview ssh user@server              # one-shot scanportview ssh user@server watch        # full interactive TUIportview ssh user@server doctor       # remote diagnosticsportview ssh user@server 3000         # inspect a remote portportview ssh user@server --ssh-opt "-p 2222"  # custom SSH port

Kill actions in the remote TUI are forwarded over SSH.

If portview is not installed on the remote host, SSH mode collects data using ss and ps, or lsof and ps where ss is unavailable. This requires a POSIX shell and the collection tools on the remote host.

$ portview ssh user@serverportview not found on user@server — falling back to agentless mode (ss + ps over SSH).╭──────┬───────┬─────┬──────────────┬──────┬─────────┬────────┬───────┬──────────────────────╮│ PORT │ PROTO │ PID │ ADDR         │ USER │ PROCESS │ UPTIME │ MEM   │ COMMAND              │├──────┼───────┼─────┼──────────────┼──────┼─────────┼────────┼───────┼──────────────────────┤│ 3000 │ TCP   │ 6   │ 127.0.0.1    │ root │ node    │     3s │ 45 MB │ node /opt/app/web.js ││ 8080 │ TCP   │ 7   │ 127.0.0.1    │ root │ node    │     3s │ 45 MB │ node /opt/app/api.js │╰──────┴───────┴─────┴──────────────┴──────┴─────────┴────────┴───────┴──────────────────────╯

Use --agentless to collect data this way even when portview is installed on the remote host. It supports scans, port inspection, process search, diagnostics, and watch mode.

Run diagnostics on the collected data:

bash
portview ssh user@server doctor --agentless

This uses the same diagnostic checks as local mode. The Docker check is skipped because agentless mode does not query remote containers.

Watch remote ports, with process termination available in the TUI:

bash
portview ssh user@server watch --agentless

Watch mode collects updates through a single persistent SSH connection.

Docker integration

Use --docker to include ports published by Docker containers:

$ portview --docker╭──────┬───────┬───────┬──────────────┬────────┬──────────┬────────┬────────┬────────────────────────────╮│ PORT │ PROTO │ PID   │ ADDR         │ USER   │ PROCESS  │ UPTIME │ MEM    │ COMMAND                    │├──────┼───────┼───────┼──────────────┼────────┼──────────┼────────┼────────┼────────────────────────────┤│ 3000 │ TCP   │ 48291 │ 127.0.0.1    │ mark   │ node     │ 3h 12m │ 248 MB │ next dev [docker:web]      ││ 8080 │ TCP   │ -     │ 0.0.0.0      │ docker │ pv-nginx │      - │      - │ nginx:alpine :8080->80/tcp │╰──────┴───────┴───────┴──────────────┴────────┴──────────┴────────┴────────┴────────────────────────────╯

Container-only rows have no host process, so PID, UPTIME, and MEM render as -.

In watch mode, press d on a Docker row to stop or restart the container, or follow its logs.

JSON output

bash
portview --json                   # pipe to jq, scripts, dashboardsportview --docker --json          # includes Docker ownership dataportview watch --json             # streaming JSON, one array per tickportview doctor --json            # machine-readable diagnostics

Custom colors

bash
PORTVIEW_COLORS="port=red,pid=magenta,command=bright_cyan" portview

Columns: port, proto, pid, user, process, uptime, mem, command. Use --no-color to disable.

How it works

Local port and process data comes from OS interfaces:

FieldLinuxmacOSWindows
Ports/proc/net/tcp{,6}, udp{,6}proc_pidfdinfoGetExtendedTcp/UdpTable
PIDinode→pid via /proc/*/fd/proc_listpidsIncluded in socket table
Process/proc/<pid>/exeproc_pidpathQueryFullProcessImageNameW
Memory/proc/<pid>/status VmRSSproc_pidinfoK32GetProcessMemoryInfo
Uptime/proc/<pid>/statproc_pidinfoGetProcessTimes

On Linux, portview reads the executable name from /proc/<pid>/exe. The thread name in /proc/<pid>/comm can be changed by the runtime and is limited to 15 bytes.

Docker integration uses the docker CLI. SSH mode uses the system ssh client to run portview or the agentless collection tools on the remote host. MCP mode uses newline-delimited JSON-RPC 2.0 on stdin/stdout.

Building from source

bash
git clone https://github.com/mapika/portviewcd portviewcargo build --release

Requires Rust 1.85+ (edition 2024). Shell completions and man page are generated at build time.

The repository includes a Dockerfile. To inspect the host from a container, share the host's network and PID namespaces:

bash
docker run --rm -i --network host --pid host portview

Contributing

See CONTRIBUTING.md for development setup and guidelines, and demo/README.md for regenerating the recordings.

Changes should type-check on all three platforms, not just yours:

bash
cargo check --target aarch64-apple-darwincargo check --target x86_64-pc-windows-msvc

Limitations

  • Linux: Other users' ports are listed, but naming the process needs sudo (it reads /proc/<pid>/fd/). Rows you can't attribute show - for PID, user, process, and command rather than being hidden.
  • macOS: Other users' ports are not listed without sudo — sockets are enumerated per process via proc_pidfdinfo, so a process that can't be opened contributes nothing to enumerate. For the same reason doctor cannot detect TIME_WAIT pileups there; CLOSE_WAIT is detected normally.
  • Windows: Ports owned by inaccessible system processes are listed with the PID but - for name and user. Kill always force-terminates. Run as Administrator for full detail.
  • Docker: Requires docker CLI and daemon access
  • SSH: every command falls back to agentless collection when portview is missing on the remote, using ss + ps on Linux and lsof where ss does not exist. The remote needs one of those and a POSIX shell. Agentless collection cannot see Docker on the far end, so that check reports as skipped rather than passed.

License

MIT

來源:README.md,提交 63052cd

工具

0
SourceWeft 尚未在沙箱中啟動過該軟體包,因此其工具未知。

版本歷史

1
  1. v2.1.0最新Sep 16, 2026

評分

已滿足適用檢查項的 50%

該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。

  • 近 30 天內可連通25 分

    請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。

  • 已宣告認證方式10 分

    請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。

  • 已列出工具15 分

    請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。

  • 描述必需15 分
  • 圖示10 分
  • 文件15 分
  • 授權條款10 分