express-recon-mcp

express-recon-mcp

Enables scanning Express.js route surfaces for inventory and audit, classifying routes as public/authenticated.

Category
访问服务器

README

express-recon

An inventory & audit harness for Express 4/5 route surfaces — built to be driven by humans, CI, and AI agents off the same contract. It enumerates every route, method, middleware chain, and source location, then (in audit mode) classifies each route as proven (behind known auth), public (no recognised auth), or review (guarded by something opaque), and emits machine findings including per-verb auth gaps.

Two scanners, opposite failure modes:

  • static (default) — parses JS/TS source with an AST (resolves ESM imports, tsconfig path aliases, and barrel re-exports). No app boot, no setup in the target repo, source file/line for free. Misses dynamically-registered routes.
  • runtime — loads the live app and walks its router stack. Sees dynamic routes; the app must import cleanly. Mount-path prefixes are captured via instrumentation, so they survive on Express 5.
  • hybrid — static for breadth + locations, runtime to verify and recover what static missed. Lowest chance of missing an open endpoint.

CLI

express-recon <command> [options]
command what it does
inventory list routes, methods, middleware chains, source — no judgment
audit inventory + classify (proven/public/review) + findings
suggest-auth propose auth-middleware allowlist candidates (JSON)
schema print the JSON Schema of the report contract
# Zero-setup audit of a checked-out repo:
express-recon audit --src ./ --config ./recon.config.js --format pretty

# CI / agent gate — non-zero exit if any unauthenticated route exists:
express-recon audit --src ./ --config ./recon.config.js --format json --fail-on public

# Bootstrap the allowlist on an unfamiliar repo:
express-recon suggest-auth --src ./ > candidates.json

# Verify static findings against the live app and catch dynamic routes:
express-recon audit --mode hybrid --src ./ --app ./src/app.js \
  --config ./recon.config.js --format json,md --out ./recon-out
option meaning
--mode static|runtime|hybrid scanner (default static)
--src <dir> repo root to scan (static/hybrid; default cwd)
--app <path> JS file exporting the Express app (runtime/hybrid)
--config <path> JS file exporting { authMiddleware: { name: tag } }
--format json,md,pretty output formats (default pretty)
--out <dir> write routes.json/routes.md (else stdout)
--fail-on <statuses> audit only: exit 2 if any route matches (e.g. public,unknown)

For agents & CI: the report contract

--format json emits one versioned, self-describing artifact. Run express-recon schema for the full JSON Schema. Shape:

{
  "schemaVersion": "1.0",
  "tool": "express-recon",
  "command": "audit",            // or "inventory"
  "mode": "static",
  "routes": [
    {
      "method": "PATCH",
      "path": "/widgets/:id",
      "middlewares": [{ "name": "express.json", "kind": "call", "raw": "express.json()" }],
      "source": { "file": "src/routes/widgets.js", "line": 12 },
      "pathConfidence": "full",  // "partial" when a mount/path couldn't be resolved
      "authStatus": "public",    // audit only: proven | public | unknown
      "tags": ["public"],        // audit only
      "presence": "both"         // hybrid only: both | static-only | runtime-only
    }
  ],
  "globalMiddleware": [{ "name": "helmet", "kind": "call", "raw": "helmet()" }],
  "summary": { "routes": 1, "public": 1, "unknown": 0, "proven": 0 },  // audit only
  "findings": [                                                        // audit only
    { "id": "public-route", "severity": "high", "method": "PATCH",
      "path": "/widgets/:id", "source": { "file": "...", "line": 12 },
      "detail": "No recognised auth middleware guards this route." }
  ]
}

Finding ids: public-route, per-verb-gap (same path, different auth per method), opaque-middleware. inventory reports omit summary/findings and the per-route authStatus/tags.

An agent workflow: suggest-auth to draft the allowlist → write --configaudit --format json → act on findings--fail-on public to assert.

MCP server (for agents)

A Model Context Protocol server exposes the harness as typed tools over stdio:

express-recon-mcp

Tools: inventory_routes({ dir }), audit_routes({ dir, authMiddleware? }), suggest_auth({ dir }), report_schema(). Each returns the same JSON report contract as the CLI. Static mode only — the MCP tools parse source and never execute the target repo, so an agent can't be coerced into running untrusted code. Runtime/hybrid stays a human-opt-in CLI path.

Register it with an MCP client (e.g. Claude Code / Claude Desktop):

{
  "mcpServers": {
    "express-recon": { "command": "npx", "args": ["express-recon-mcp"] }
  }
}

The agent loop becomes: suggest_authaudit_routes with the chosen allowlist → act on findings.

Library

const { inventory, audit, suggestAuth, buildReport, instrument, formatters } =
  require("express-recon");

// primitives — opts is { mode, src?, app? }
const inv = inventory({ mode: "static", src: "./" });          // raw, no judgment
const reg = audit({ mode: "static", src: "./" }, config);      // classified
const report = buildReport(reg, { command: "audit", mode: "static" });

console.log(formatters.markdown.format(report));
console.log(suggestAuth(inv).candidates);

// runtime: instrument the SAME express the app uses, BEFORE it registers routes,
// so mount-path prefixes survive (Express 5 compiles them away otherwise).
instrument(require("express"));
const live = audit({ mode: "runtime", app: require("./src/app") }, config);

The CLI does the instrument() step automatically for runtime/hybrid.

The auth allowlist

authMiddleware maps a middleware name or dotted callee to a tag:

module.exports = {
  authMiddleware: {
    requireAuth: "authenticated",
    "passport.authenticate": "session",
    snsSignatureVerifier: "signed:aws-sns",
  },
};

Classification (public-unless-proven):

  • proven — the chain contains a middleware whose name/callee is allow-listed.
  • review (unknown) — no match, but the chain has an opaque middleware (an inline/anonymous closure, or an unnameable expression) that could be hiding auth. Surfaced, not assumed safe.
  • public — no match and every middleware is a nameable identifier or call you could have allow-listed (express.json, a logger). Treated as unauthenticated. If a named middleware here is auth, add it to the allowlist and re-run — or run suggest-auth to find candidates automatically.

Runtime / hybrid: host-side gate

--app is required for runtime/hybrid; the CLI sets EXPRESS_RECON_DRY=1 before requiring it, so gate boot side effects on it:

const DRY = process.env.EXPRESS_RECON_DRY === "1";
if (!DRY) { connectDB(); redis.ping(); }
const app = express();
// …route wiring…
if (!DRY) app.listen(PORT);
module.exports = app;

Static mode: what it resolves

Parses JavaScript and TypeScript (.js/.jsx/.cjs/.mjs/.ts/.tsx/.mts/.cts) with oxc — no type-checking, no build step. It proves from the AST:

  • app.METHOD(path, …) and .route(path).get().post() chains.
  • router.use([path], subRouter) mounts, including across files.
  • Cross-file links via require and ESM import (default, named, namespace).
  • Module resolution via relative paths, tsconfig paths aliases + baseUrl, and barrel re-exports (export { default } from …, export * from …).
  • express.Router() whether imported by require, default, or named Router.
  • x as T, x!, and parenthesized expressions are unwrapped.

It does not resolve, and marks pathConfidence: "partial" rather than silently dropping a route:

  • Dynamically-registered routes (loops, data-driven) — shown as /<dynamic>. Use --mode hybrid to recover them.
  • Non-literal mount paths/routers, and routers reached only through a bare/node_modules import or a tsconfig that isn't found — emitted with an unknown prefix. tsconfig extends chains aren't followed.
  • Path-scoped app.use("/x", mw) is over-approximated to the whole host (errs toward "has middleware", never toward "public").

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选