portmap
portmap
你的智能体硬编码了 localhost:3000。这里映射的是真正运行的内容。
git clone https://github.com/paladini/portmap.git && cd portmap
npm ci && npm run build && node dist/cli.js scan /path/to/your-app确定性 · 无 LLM · 无网络 · 只读
这是什么?
portmap 是一个命令行工具 + MCP 服务器,它回答一个问题:
在你的智能体执行
curl localhost:3000之前,真的有服务在监听那个端口吗?
它将本地开发现实整合成一张图谱:
声明层 ——
vite.config、package.json脚本、.envURL、docker-compose中声明的端口实际层 —— 操作系统当前显示的监听状态(Windows、macOS、Linux)
连接层 —— 环境变量(
VITE_API_URL、API_URL、……)如何将服务连接起来
输出:.portmap.json + 可执行的发现(PRT-01 … PRT-07),智能体和 CI 无需猜测即可直接使用。
适合谁?
厌倦了**“杀掉 3000 端口”和“在我机器上能跑”**这类端口漂移问题的人
使用 AI 编程智能体(Cursor、Claude Code、Copilot)却总是被硬编码错误 localhost URL 坑害的团队
Monorepo 中前端和 API 在同级目录、环境变量引用跨仓库的团队
想在调试 API 连通性之前先做 5 秒快速检查 的人
它不做什么?
预期 | 现实 |
启动/停止你的开发服务器 | 不会 —— 生命周期管理请使用 Switchboard 或 PortPilot |
你手动维护的端口注册表 | 不会 —— portmap 从配置文件和操作系统中自动发现 |
生产环境监控 / 可用性 | 不会 —— 只处理本地开发拓扑 |
用 LLM 推断端口 | 不会 —— 100% 确定性的文件系统 + 套接字表 |
如果你需要杀掉某个进程,请使用操作系统的工具。portmap 只告诉你要命哪个端口,让你不再白白浪费 20 分钟。
Related MCP server: devenv-doctor-mcp
问题所在
每种 AI 辅助开发场景最终都会遇到这个问题:
Agent: fetch('http://localhost:3000/api/users')
Reality: Vite on :5173, API on :8080, nothing on :3000为什么会发生:
Next.js 默认使用
:3000—— 智能体记住了这个默认值Vite 默认使用
:5173—— 技术栈不同,端口也不同Docker 会把
8080:3000重新映射 —— 应用实际监听在容器里,而不是你以为的宿主机.env.local指向一个今天根本没人启动过的端口你花了二十分钟调试 CORS、认证和“network error”,真正的元凶其实是 PRT-04
portmap 能在几秒内暴露这种错配 —— 声明端口 vs 实际监听 vs 环境变量 —— 让你修复的是 URL,而不是表面症状。
工作原理
两个扫描器 + 一次对账,零 LLM:
┌─────────────────────────────────────────────────────────────┐
│ Your repo on disk │
├─────────────────────────────────────────────────────────────┤
│ 1. Static discovery │
│ package.json scripts · vite.config · .env localhost URLs│
│ docker-compose port mappings │
├─────────────────────────────────────────────────────────────┤
│ 2. Runtime scan (optional) │
│ OS listeners → port, PID, process, command line │
├─────────────────────────────────────────────────────────────┤
│ 3. Reconcile │
│ declared ↔ actual ↔ env references → service graph │
│ → .portmap.json + findings (PRT-01 … PRT-07) │
└─────────────────────────────────────────────────────────────┘
↓ ↓ ↓
CLI pretty MCP tools CI --min-findings完整规则列表:docs/FINDINGS.md · 修复前后示例:docs/EXAMPLES.md · JSON 规范:docs/SCHEMA.md
30 秒上手
git clone https://github.com/paladini/portmap.git
cd portmap
npm ci && npm run build
npm run demo:mismatch # classic agent mistake → 3 errors
npm run demo:workspace # frontend + API in sibling folders → resolveddemo:mismatch 的输出效果
portmap — mismatch-app
root: …/fixtures/mismatch
Services:
[down] vite — Vite dev server
declared :5173 (vite.config.ts:server.port)
not listening
Env references:
NEXT_PUBLIC_API_URL=http://localhost:3000 → :3000 [unresolved]
VITE_API_URL=http://localhost:8080 → :8080 [unresolved]
Findings: 3 error(s), 0 warning(s)
✖ PRT-01 Declared port 5173 is not listening …
✖ PRT-04 NEXT_PUBLIC_API_URL points to localhost:3000 but nothing is listening …
✖ PRT-04 VITE_API_URL points to localhost:8080 but nothing is listening …只要智能体先读 .portmap.json,这整个调试过程都可以直接省掉。
安装与运行
选项 A —— 克隆(现在就能用)
git clone https://github.com/paladini/portmap.git
cd portmap
npm ci && npm run build
node dist/cli.js scan /path/to/your-app选项 B —— npm(发布后)
npx portmap scan .常见工作流
运行
portmap scan .(如果当前没有服务在运行,可改用portmap declare .)查看
references[]里的正确 localhost 地址 —— 不要默认是:3000先修复 PRT-04(坏掉的环境变量 URL),再调试 API 连接
保存
.portmap.json供以后的智能体会话使用:portmap scan . --write可选: 用
--min-findings 1 --min-severity error做 CI 门禁
命令
命令 | 说明 |
| 完整扫描:静态配置 + 系统监听器 |
| 仅静态分析(无需运行中的进程) |
| 列出系统监听器(调试用) |
| 多仓库:解析跨目录环境变量引用 |
| 启动只读 MCP stdio 服务器 |
命令行选项: --json · --markdown · --write(保存 .portmap.json) · --out <file> · --min-findings N · --quiet
发现项速览
ID | 规则 | 严重级别 |
PRT-01 | 声明的端口没有监听 | 错误 |
PRT-02 | 有监听但没有对应的声明配置 | 警告 |
PRT-03 | 两个服务声明了同一个端口 | 错误 |
PRT-04 | 环境变量 URL 指向没有监听的端口 | 错误 |
PRT-05 | 监听端口和声明端口不一致 | 警告 |
PRT-06 | Docker 主机端口与容器端口映射不匹配 | 警告 |
PRT-07 | 跨工作区环境变量引用无法解析 | 错误 |
完整目录(含修复方法):docs/FINDINGS.md
面向智能体的 MCP(只读)
添加到 .cursor/mcp.json 或 Claude Code 配置中:
{
"mcpServers": {
"portmap": {
"command": "node",
"args": ["/path/to/portmap/dist/cli.js", "mcp"]
}
}
}工具 | 使用时机 |
| 完整的 |
| 精简的 |
| “ |
| 按严重级别列出 PRT-* 问题 |
Cursor / Claude 的 Skill 文件:.cursor/skills/portmap/SKILL.md
.portmap.json —— 智能体读取的产物
portmap scan . --write
git add .portmap.json # optional: commit for stable agent context智能体就绪流水线
属于 paladini agent toolkit 的一部分 —— 三项确定性检查,零 LLM:
harness-score → Is the repo harness ready for agents?
portmap → Do ports and env URLs align locally?
unhappypath → Is the UI ready for real users?工具 | 回答的问题 |
AGENTS.md、rules、hooks、CI 成熟度 | |
portmap | 已声明端口、监听器、环境变量图谱 |
加载、空、错误、重试 UI 状态 |
局限(坦诚版)
PID → 仓库归属 是启发式判断;低置信度的匹配会被标记,而不是被隐藏
WSL / Docker 网络 —— 容器内的监听器可能不会按预期出现在宿主机上
纯运行时端口(在 JS 中硬编码且没有配置文件)不会被声明 —— 这可能会触发 PRT-02
YAML compose —— v1 只解析常见
ports:配置;更奇特的 compose 功能会被跳过宁可漏报,也不要制造大量误报 —— 不确定时,portmap 保持安静
贡献
欢迎提交 Issue、误报反馈和解析器贡献。
参见 CONTRIBUTING.md · ROADMAP.md · CODE_OF_CONDUCT.md
安全问题:SECURITY.md —— 请勿公开提交。
开发
npm ci
npm run build
npm test
npm run demo:mismatch
npm run demo:workspace智能体 / 贡献者指南:AGENTS.md
许可证
MIT © 2026 Fernando Paladini
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Servers
- AlicenseNot gradedqualityAmaintenanceEnables AI agents to discover, configure, and manage local development servers. Provides tools for app registration, port allocation, lifecycle control, and log access without manual config editing.338MIT
- AlicenseNot gradedqualityCmaintenanceEnables LLM clients to inspect local dev environments—Docker container health, pnpm workspace integrity, and stuck process detection—without manual terminal copy-pasting.MIT
- AlicenseNot gradedqualityBmaintenanceSee and control the local dev servers your coding agents leave running. Lists listeners with provenance — which agent, terminal and git worktree started each — kills strays, and allocates collision-free ports so parallel agents stop fighting over :3000.MIT
- AlicenseNot gradedqualityAmaintenanceMCP 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.291MIT
Related MCP Connectors
Give your AI agent a persistent map of your project's structure, dependencies, and bugs.
Lints + auto-fixes how AI coding agents discover any new product. 24 rules, 6 tools, score 0-100.
Scan any URL for AI agent readability — Vercel Spec, llmstxt.org, and agent-protocol manifests.
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/paladini/portmap'
If you have feedback or need assistance with the MCP directory API, please join our Discord server