Skip to main content
Glama

fofa-mcp

FOFA 网络空间搜索引擎的 MCP 服务,Node.js 实现(TypeScript),移植自 keyblues/fofa-skills。内置 SQLite 缓存、F 点预算守卫、1 req/s 限流与审计日志,支持 stdio 与 Streamable HTTP 两种传输。

使用预构建镜像

docker pull ghcr.io/fb0sh/fofa-mcp:latest

多架构(linux/amd64、linux/arm64),标签:latest(main 分支)、main、v*(打 tag 时同时生成 1.0.0 / 1.0)。

从源码构建:

docker build -t fofa-mcp:local .

Related MCP server: SecOps-MCP-Server

方式一:stdio(Claude Desktop / Cursor 等本地 MCP 客户端)

{
  "mcpServers": {
    "fofa": {
      "command": "docker",
      "args": [
        "run", "-i", "--rm",
        "-e", "FOFA_KEY=你的32位KEY",
        "-e", "FOFA_BASE_URL=https://fofa.info/api/v1",
        "-v", "fofa-data:/data",
        "ghcr.io/fb0sh/fofa-mcp:latest"
      ]
    }
  }
}
  • MCP_TRANSPORT 默认就是 stdio,无需额外参数。

  • -v fofa-data:/data 让 SQLite 缓存在容器重建后仍然保留;不挂载则每次 --rm 都会丢缓存。

  • 用目录 bind mount 时,容器以 uid 1000(node)运行,宿主机目录需对该 uid 可写;不想处理权限就用上面的命名卷。

方式二:Streamable HTTP

docker run -d --name fofa-mcp \
  -p 8080:8080 \
  -e MCP_TRANSPORT=http \
  -e FOFA_KEY=你的32位KEY \
  -e MCP_AUTH_TOKEN=换成一个随机token \
  -v fofa-data:/data \
  ghcr.io/fb0sh/fofa-mcp:latest
  • MCP 端点:http://127.0.0.1:8080/mcp,健康检查:http://127.0.0.1:8080/healthz

  • 客户端配置(支持 HTTP 的 MCP 客户端):

{
  "mcpServers": {
    "fofa": {
      "type": "http",
      "url": "http://127.0.0.1:8080/mcp",
      "headers": { "Authorization": "Bearer 换成一个随机token" }
    }
  }
}
  • 设置了 MCP_AUTH_TOKEN 后,未携带正确 Authorization: Bearer <token> 的请求返回 401。

  • MCP_TRANSPORT=both 可在同一进程里同时提供 stdio 和 HTTP。

  • HTTP 模式默认绑定 0.0.0.0(容器内需要),暴露到公网前请务必设置 MCP_AUTH_TOKEN 并在反向代理上启用 TLS。

  • 绑定非 localhost 时不自动做 Host 头校验;需要 DNS rebinding 防护就设置 MCP_ALLOWED_HOSTS(例如 MCP_ALLOWED_HOSTS=mcp.example.com,127.0.0.1),不在白名单的 Host 返回 403。

环境变量

变量

默认

说明

FOFA_KEY

空

FOFA API Key(32 位 hex);仅用缓存工具可不填

FOFA_BASE_URL

https://fofa.info/api/v1

API 基地址

MCP_TRANSPORT

stdio

stdio / http / both

MCP_HOST

0.0.0.0

HTTP 监听地址

MCP_PORT

8080

HTTP 监听端口(兼容 PORT)

MCP_PATH

/mcp

HTTP 上的 MCP 路径

MCP_AUTH_TOKEN

空

HTTP 静态 Bearer Token;为空则不校验

MCP_ALLOWED_HOSTS

空

HTTP Host 头白名单(逗号分隔);为空不限制

FOFA_DB_PATH

/data/fofa_cache.db(容器)

SQLite 缓存路径

FOFA_FPOINTS_STATE

/data/fpoints_state.json(容器)

F 点预算持久化状态

FOFA_FPOINTS_BUDGET

空

会话 F 点预算;设置后翻页按累计估算消耗放行

FOFA_ALLOW_FPOINTS

false

全局放开翻页限制(仍会消耗 F 点)

工具(14 个)

工具

免费

说明

fofa_info

✓

账号信息(邮箱、VIP、F 点余额),缓存 5 分钟

fofa_search

page=1 免费

搜索资产,返回总数 + 前 20 条预览,整页落库

fofa_stats

✓

按字段聚合统计,用于评估查询规模

fofa_host

✓

单个 IP/域名的资产详情(detail=true 含端口指纹)

fofa_cache_read

✓

按 query_hash 读取缓存,支持过滤与分页

fofa_cache_list

✓

列出缓存查询(找回 hash,避免重复付费搜索)

fofa_cache_tag

✓

给已缓存查询补打/清除 tag

fofa_cache_delete

✓

删除单个缓存查询

fofa_cache_clean

✓

清理 N 天前的缓存

fofa_cache_stats

✓

缓存行数统计

fofa_correlate

✓

多查询按字段去重/交集,输出重叠矩阵

fofa_report

✓

汇总暴露面报告(端口/国家/协议分布、高危端口、后台面板)

fofa_audit_log

✓

查看审计日志

fofa_audit_clean

✓

清理 N 天前的审计日志

F 点预算守卫

  • 默认只允许 page=1(零 F 点消耗)。

  • page>1 默认硬阻断(错误码 2001);只有以下任一条件才放行:

    1. 调用方显式传 allow_fpoints=true(应在用户明确授权预计消耗后);

    2. 进程环境设置 FOFA_ALLOW_FPOINTS=true;

    3. 设置了 FOFA_FPOINTS_BUDGET=N,按累计估算消耗校验。

  • 预算模式会把已消耗量持久化到 FOFA_FPOINTS_STATE,请求失败自动退回预留额度。

缓存与一致性

  • 缓存键:SHA-256(query|fields|full|page|size),只做精确匹配(与 Python 版一致)。

  • TTL:full=false 24 小时,full=true 7 天;cache_read 对过期数据仍返回并置 cache_expired=true。

  • 数据库表结构与 Python 版相同(query_cache / query_result / info_cache / host_cache / audit_log),可直接复用旧库文件。

发布

  • 推送 main 或打 v* tag 会触发 .github/workflows/docker.yml:先跑 npm run build + stdio/HTTP 离线 smoke,再构建 linux/amd64 + linux/arm64 并推送到 GHCR。

  • 仓库为 Public,因此 GHCR 包可直接匿名拉取;若改为 Private,需在 GitHub 包设置里调整可见性并 docker login ghcr.io。

本地开发与验证

npm ci
npm run build
npm run smoke       # stdio 全流程(离线 mock FOFA,无需真实 KEY)
npm run smoke:http  # Streamable HTTP 全流程

要求 Node.js 24+(使用内置 node:sqlite)。

本地运行:

FOFA_KEY=xxx npm start                      # stdio
MCP_TRANSPORT=http MCP_PORT=8080 FOFA_KEY=xxx npm start

与 Python 版的差异

  • 以 MCP 工具替代 CLI 子命令,参数语义保持一致(fields/page/size/full/allow_fpoints/tag)。

  • 输出为 JSON(content.text,同时提供 structuredContent);不再输出 __fofa__ 标记。

  • 不自动读取 .env 文件,请通过进程环境或 docker run --env-file 注入。

  • 数据库使用 Node 内置 node:sqlite,无需原生编译依赖。

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      A
      quality
      D
      maintenance
      A production-ready foundation for building secure, observable MCP servers with built-in authentication, rate limiting, and reference tools like database-query and semantic-search.
      15
      MIT
    • F
      license
      Not graded
      quality
      D
      maintenance
      Enterprise MCP server for Google SecOps (Chronicle) SIEM/SOAR, enabling alert triage, UDM telemetry search, YARA-L detection rule management, log ingestion, and parser administration via Streamable HTTP.
      -
    • A
      license
      Not graded
      quality
      A
      maintenance
      Enables authorized penetration testers to run reconnaissance, scanning, brute-force, exploitation, traffic capture, wordlist generation, and client-report workflows through MCP clients, with stdio/HTTP/SSE transport and OIDC bearer authentication.
      157 npm
      GPL 3.0
    • A
      license
      Not graded
      quality
      A
      maintenance
      Enables professional penetration testers to run reconnaissance, exploitation, brute-force, traffic-capture, and reporting workflows through MCP tools over STDIO/HTTP/SSE transports with bearer/OIDC authentication and Dockerized host tooling.
      157 npm
      GPL 3.0