portmap
Enables AI agents to deterministically discover which localhost ports and env URLs are actually running, resolving declared configs, OS listeners, and service connections into a machine-readable .portmap.json with actionable findings.
README
<div align="center">
portmap
Your agent hardcoded localhost:3000. This maps what actually runs.
git clone https://github.com/paladini/portmap.git && cd portmap
npm ci && npm run build && node dist/cli.js scan /path/to/your-app
Deterministic · No LLM · No network · Read-only
</div>
What is this?
portmap is a command-line tool + MCP server that answers one question:
Before your agent runs
curl localhost:3000, does anything actually listen there?
It fuses three layers of local dev reality into a single map:
- Declared — ports in
vite.config,package.jsonscripts,.envURLs,docker-compose - Actual — what your OS says is listening right now (Windows, macOS, Linux)
- Connected — how env vars (
VITE_API_URL,API_URL, …) link services together
Output: .portmap.json + actionable findings (PRT-01 … PRT-07) that agents and CI can consume without guessing.
Who is it for?
- Developers tired of "kill port 3000" and "works on my machine" port drift
- Teams using AI coding agents (Cursor, Claude Code, Copilot) that hardcode wrong localhost URLs
- Monorepos where frontend and API live in sibling folders and env refs cross repos
- Anyone who wants a 5-second sanity check before debugging API connectivity
What it is not
| Expectation | Reality |
|---|---|
| Starts/stops your dev servers | No — use Switchboard or PortPilot for lifecycle |
| Manual port registry you maintain | No — portmap discovers from configs + OS |
| Production monitoring / uptime | No — local dev topology only |
| Uses an LLM to infer ports | No — 100% deterministic filesystem + socket table |
If you need to kill a process, use your OS tools. portmap tells you which port to hit before you waste twenty minutes.
The problem
Every AI-assisted dev session hits this eventually:
Agent: fetch('http://localhost:3000/api/users')
Reality: Vite on :5173, API on :8080, nothing on :3000
Why it happens:
- Next.js defaults to
:3000— agents memorize that - Vite defaults to
:5173— different stack, different port - Docker remaps
8080:3000— the app listens inside the container, not where you think .env.localpoints at a port nobody started today- You debug CORS, auth, and "network error" for twenty minutes when the real bug is PRT-04
portmap surfaces the mismatch in seconds — declared vs listening vs env — so you fix the URL, not the symptom.
How it works
Two scanners, one reconcile step, zero 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
Full rule list: docs/FINDINGS.md · Before/after fixes: docs/EXAMPLES.md · JSON spec: docs/SCHEMA.md
Try it in 30 seconds
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 → resolved
What demo:mismatch looks like
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 …
That's the entire debug session an agent skips when it reads .portmap.json first.
Install & run
Option A — Clone (works today)
git clone https://github.com/paladini/portmap.git
cd portmap
npm ci && npm run build
node dist/cli.js scan /path/to/your-app
Option B — npm (when published)
npx portmap scan .
Typical workflow
- Run
portmap scan .(ordeclare .if nothing is running yet) - Read
references[]for correct localhost URLs — never assume:3000 - Fix PRT-04 (broken env URL) before debugging API connectivity
- Write
.portmap.jsonfor future agent sessions:portmap scan . --write - Optional: gate CI with
--min-findings 1 --min-severity error
Commands
| Command | What it does |
|---|---|
portmap scan [path] |
Full scan: static configs + OS listeners |
portmap declare [path] |
Static only — no running processes needed |
portmap listen |
List OS listeners (debug) |
portmap workspace [dir] |
Multi-repo: resolve cross-folder env refs |
portmap mcp |
Start read-only MCP stdio server |
Flags: --json · --markdown · --write (save .portmap.json) · --out <file> · --min-findings N · --quiet
Findings at a glance
| ID | Rule | Severity |
|---|---|---|
| PRT-01 | Declared port not listening | error |
| PRT-02 | Listener without declared config | warning |
| PRT-03 | Two services declare same port | error |
| PRT-04 | Env URL points to port with no listener | error |
| PRT-05 | Listener on different port than declared | warning |
| PRT-06 | Docker host:container port mismatch | warning |
| PRT-07 | Cross-workspace env ref unresolved | error |
Full catalog with fixes: docs/FINDINGS.md
MCP for agents (read-only)
Add to .cursor/mcp.json or Claude Code config:
{
"mcpServers": {
"portmap": {
"command": "node",
"args": ["/path/to/portmap/dist/cli.js", "mcp"]
}
}
}
| Tool | Use when |
|---|---|
portmap_scan |
Full .portmap.json report |
portmap_graph |
Slim { services, edges, references } |
portmap_resolve_url |
"What URL should I use for VITE_API_URL?" |
portmap_findings |
List PRT-* issues filtered by severity |
Skill for Cursor/Claude: .cursor/skills/portmap/SKILL.md
.portmap.json — the artifact agents read
portmap scan . --write
git add .portmap.json # optional: commit for stable agent context
Spec: docs/SCHEMA.md
Agent-readiness pipeline
Part of the paladini agent toolkit — three deterministic checks, zero 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?
| Tool | Question |
|---|---|
| harness-score | AGENTS.md, rules, hooks, CI maturity |
| portmap | Declared ports, listeners, env graph |
| unhappypath | Loading, empty, error, retry UI states |
Limitations (honest)
- PID → repo attribution is heuristic; low-confidence matches are flagged, not hidden
- WSL / Docker networking — listeners inside containers may not appear as expected on the host
- Runtime-only ports (hardcoded in JS with no config) won't be declared — PRT-02 may warn
- YAML compose — v1 parses common
ports:patterns; exotic compose features are skipped - Prefer false negatives over noisy false positives — if unsure, portmap stays quiet
Contributing
Issues, false-positive reports, and parser contributions welcome.
| Channel | Link |
|---|---|
| Bug report | Open issue |
| False positive | Report PRT-* misfire |
| Feature request | Request parser / rule |
| Questions & ideas | Discussions |
See CONTRIBUTING.md · ROADMAP.md · CODE_OF_CONDUCT.md
Security issues: SECURITY.md — please do not file publicly.
Development
npm ci
npm run build
npm test
npm run demo:mismatch
npm run demo:workspace
Agent/contributor guide: AGENTS.md
License
MIT © 2026 Fernando Paladini
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。
mcp-server-qdrant
这个仓库展示了如何为向量搜索引擎 Qdrant 创建一个 MCP (Managed Control Plane) 服务器的示例。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。