FortiGate MCP Server
概述
这是一个 MCP(Model Context Protocol)服务器,让 AI 助手能够管理 FortiGate 防火墙 —— 从单台实验室设备到包含数十个客户、站点和集群的多租户环境。
它围绕三个理念构建,而大多数 FortiGate 自动化工具无法同时具备这三者:
没有预览就没有变更。 每个创建/更新/删除调用都会返回一个 diff 和一个
change_id,而不是立即执行。真正执行它的是单独的change_apply调用,并且在执行前会重新检查实时状态是否存在漂移。即使对于受信任的自动化,也不存在一步到位的"直接执行"模式。Claude 永远不会看到真实凭据。 设备密码/API 令牌通过本地、非 MCP 的 CLI(
fortinet-mcp-cred)直接配置到操作系统的凭据存储中(Windows 凭据管理器 / macOS 钥匙串 / Linux Secret Service)。MCP 工具面只处理不透明的credential_id。它覆盖整个生命周期,而不仅仅是策略 CRUD。 设备引导(DNS/NTP/syslog/SNMP/admin/HA)、VDOM 多租户、接口/区域/DHCP、路由、防火墙策略、VPN(IPsec + SSL)、安全/合规分析和文档生成都是头等工具命名空间 —— 参见完整的工具参考(115 个工具)。
Related MCP server: FortiGate MCP Server
功能特性
领域 | 功能说明 |
清单与多租户 | 本地 SQLite 存储中的 客户 -> 站点 -> 设备 -> VDOM 层级结构。按名称、站点、客户或 IP 解析设备 —— 永远不需要在提示词中输入 IP。 |
设备引导 | DNS、NTP、syslog、SNMP(sysinfo + v1/v2c community)、全局设置(主机名/时区/管理端口)、本地管理员账户、HA —— 将设备从出厂默认状态带到生产就绪所需的一切。 |
VDOM 生命周期 | 创建/删除 VDOM,创建/删除 VDOM 间链路。 |
网络拓扑 | 接口(VLAN 子接口、loopback、vdom-link 成员)、区域、DHCP 服务器、静态路由。 |
防火墙与 NAT | 策略、地址/服务对象、虚拟 IP —— 完整的 CRUD。 |
VPN | IPsec 站点到站点隧道(phase1/phase2)及实时状态;SSL VPN 可见性。 |
变更安全 | READ_ONLY / SAFE / FULL 操作模式,每次变更都执行 预览 -> 应用 -> 回滚,应用时进行漂移检测。 |
分析与合规 | 重复/遮蔽/any-any 策略检测、未使用对象检测、子网重叠、最佳实践检查(策略和系统配置)、启发式 0-100 安全评分、综合合规报告。 |
文档生成 | 拓扑图(Mermaid/drawio/PlantUML)、策略/路由/VPN/系统配置 Markdown 文档、组合导出。 |
集群运维 | 设备对比、在整个环境中搜索对象、同步对象、复制配置、全集群报告。 |
自然语言意图 | 复合工具( |
完整的 115 个工具自动生成列表请参见 docs/TOOLS.md。
快速开始
git clone https://github.com/Serrinho02/fortigate-mcp-server.git
cd fortigate-mcp-server
uv sync创建一个最小的 config/config.json(一旦你使用下面的清单系统,传统的单文件设备列表就是可选的 —— 参见安装):
{ "fortigate": { "devices": {} } }将你的 MCP 客户端(例如 Claude Desktop)指向该服务器:
{
"mcpServers": {
"fortigate": {
"command": "/absolute/path/to/fortigate-mcp-server/.venv/bin/python",
"args": ["-m", "src.fortigate_mcp.server"],
"env": {
"FORTIGATE_MCP_CONFIG": "/absolute/path/to/fortigate-mcp-server/config/config.json",
"FORTINET_MCP_MODE": "full"
}
}
}
}然后,从 Claude 中:注册设备(inventory_register_device_pending),使用 fortinet-mcp-cred set <credential_id> 在本地配置其凭据,然后调用 get_device_status。完整演练、Windows 路径和 Docker 说明:docs/INSTALLATION.md。概念指南和实际示例:docs/USAGE.md。
架构
七层架构,依赖关系仅单向流动:
flowchart TB
Transport["MCP Tool Layer -- inventory.*, connection.*, policy/network/routing/vip.*, vpn.*, system.*, vdom.*, analysis.*, doc.*, fleet.*, intent.*, change.*"]
Services["Service Layer -- one Service per capability, mode enforcement, error translation"]
Domain["Domain / Analysis Engines -- pure functions: DiffEngine, policy analyzers, scoring"]
Repo["Repository Layer -- inventory/change/snapshot persistence"]
Adapters["Vendor Adapter Layer -- FortinetProductAdapter Protocol (the plugin boundary)"]
Clients["Vendor API Client -- FortiOSRestClient (httpx, persistent per-device connection)"]
Infra["Infra -- ConnectionManager, CredentialManager (keyring), SQLite/SQLAlchemy"]
Transport --> Services
Services --> Domain
Services --> Repo
Domain --> Repo
Repo --> Adapters
Adapters --> Clients
Services -.uses.-> InfraFortinetProductAdapter 是唯一的可扩展边界:目前 FortiOSAdapter 是唯一的实现,但添加另一个 Fortinet 产品意味着针对同一个 Protocol 编写一个新的 adapter —— 该层之上的任何内容都不需要更改。
操作模式
通过 FORTINET_MCP_MODE 设置(默认 full):
模式 | 行为 |
| 任何变更甚至不允许预览。 |
| 拒绝删除操作;创建/更新仍需要 预览 -> 应用。 |
| 允许所有操作,但仍然需要 预览 -> 应用 —— 任何模式下都没有一步到位的快速路径。 |
安全模型
设备凭据永远不会作为工具参数出现,也永远不会出现在对话中。
inventory_register_device_pending只收集元数据(主机、名称、客户、站点)并生成不透明的credential_id;实际密钥通过fortinet-mcp-cred set <credential_id>在本地输入一次,直接存入操作系统凭据存储。在完成该 CLI 步骤之前,
connection_connect/ 任何需要实时会话的工具都会以明确的"凭据未配置"错误失败 —— 不存在让密钥通过 MCP 流动的备用路径。两个文档化的例外,均直接在其工具描述中标注:IPsec 隧道的 PSK(
vpn_create_ipsec_tunnel)和本地管理员账户的密码(system_create_admin)是普通的工具参数,因为 FortiOS 本身在 GET 时从不返回它们 —— 如果值不通过调用传递一次,就无法预览/diff 它们。
已知限制
没有声明式的"应用此期望状态"工具。 这是设计使然 —— Claude 自己组合细粒度工具(参见
intent.*模式),而不是由该服务器拥有 Terraform/Ansible 风格的应用引擎。Docker + 无头 Linux: 凭据管理器封装了操作系统的
keyring库。在没有 Secret Service 守护进程的容器/无头 Linux 主机上,你需要keyrings.cryptfile回退方案(默认未启用)—— 参见 docs/INSTALLATION.md。在 Windows/macOS/桌面 Linux 上原生安装开箱即用。SNMP: 仅支持 v1/v2c community;尚不支持 SNMPv3 用户。
尚无 FortiManager/FortiWeb/其他 Fortinet 产品适配器 —— adapter Protocol 支持此功能,但除 FortiOS 外尚未实现任何内容。
已通过针对模拟 FortiOS REST API 捕获的真实 HTTP 流量进行端到端验证;如果你遇到真实设备的怪癖,请提交包含 FortiOS 版本和端点的 issue。
测试
uv run pytest548 个测试,无需外部依赖(完整测试套件在 HTTP 传输层模拟设备交互)。
贡献
欢迎提交 issue 和 PR。如果你要添加新的资源类型,请参考 VPN 或系统配置域的实现方式(services/vpn_service.py、services/system_service.py、services/change_dispatch.py)—— 每个新的变更资源都遵循相同的 adapter -> change_dispatch -> service -> MCP 工具模式。
作者
由 Nicola Serra 构建和维护。
许可证
MIT —— 参见 LICENSE。
This server cannot be deployed
Maintenance
Related MCP Connectors
AI pentesting: run scans, triage vulnerabilities, review PRs, manage schedules and assets.
Manage ConfigDirector feature flags, remote configs, and targeting rules from AI assistants.
- FullmaktOAuthai.fullmakt
Credential broker for AI agents: scoped, revocable API access with policy enforcement and audit.
- emisarOAuthdev.emisar
Let AI operate servers without SSH. Choose actions, approve risky changes, and audit every step.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceEnables programmatic management of FortiGate firewall devices through MCP, supporting firewall policies, network objects, virtual IPs, routing, and interface management with Cursor IDE integration.MIT
- AlicenseNot gradedqualityCmaintenanceA production-ready MCP server for managing FortiGate firewalls, enabling AI assistants to manage firewall policies, network objects, routing, and device configurations.37MIT
- AlicenseBqualityAmaintenanceEnables AI assistants to interact with FortiManager for centralized firewall policy management, device provisioning, and network configuration through the FortiManager JSON-RPC API.1007MIT
- AlicenseNot gradedqualityBmaintenanceProvides programmatic access to FortiGate devices for managing firewall policies, routing, virtual IPs, and device operations, enabling integration with MCP-compatible clients like Claude Desktop.MIT