AF_MCP
Enables automated device blocking and unblocking operations with authentication, whitelist, and confirmation modes for AF security devices.
README
设备联动封禁智能体
这是一个基于 FastMCP 最新版本构建的 AiPy 扩展脚手架,用于后续接入 AF 设备联动封禁能力。
项目结构
device_block_agent/:核心 Python 源码与 MCP 工具实现。docs/:API 整理文档、方案文档与原始 PDF。assets/:图标等静态资源。examples/:白名单样例和参考素材。- 根目录:保留
main.py、manifest.json、requirements.txt、README.md等项目入口文件。
当前状态
- 已接入 FastMCP 3.2.4。
- 已提供 Streamable HTTP MCP 服务入口,默认暴露路径为
/mcp。 - 已提供 AiPy 要求的
addition-system-instructionprompt。 - 已提供
auth_login、auth_keepalive、auth_logout、get_confirm_mode、set_confirm_mode五个认证与风控配置工具。 - 已提供例外封锁查询与维护工具,以及封锁攻击者、临时封锁、业务封锁、封锁总量、自动封锁时间等查询工具。
- 已提供白名单规则加载与人工确认判定模块,可供后续写操作工具直接复用。
- 已提供封锁攻击者、业务封锁、临时封锁、例外封锁和自动封锁时间相关写操作工具。
- 已提供本地 JSONL 审计日志与按操作类型细化的回检结果。
- 已支持通过本地 JSON 文件持久化登录会话,用于跨进程复用登录态。
- 已支持本地会话超时判断与临近过期自动 keepalive。
- 已支持默认 AF 账号与连接配置,认证和封禁工具可直接复用。
- 已提供最小工具
agent_info,用于验证 AiPy 到 MCP 服务的发现链路。 - 已接入首版业务级回检策略,
block_clear_attackers已升级为前后基线对比判定。
本地运行
- 安装依赖:
pip install -r requirements.txt - 启动服务:
python main.py - 服务启动后会在标准输出打印随机端口号。
API 测试平台
仓库额外提供了一个基于 docs/ip-ban-api.md 自动生成的本地 API 测试平台。
- 启动测试平台:
python run_api_test_platform.py - 浏览器打开:
http://127.0.0.1:8010 - 在页面中填写命名空间、请求头、Cookie 和请求参数。
- 从左侧选择接口后,可直接修改 Query 参数和 JSON 请求体并生成模拟响应。
测试平台特性:
- 自动读取文档中的接口总览和详细说明。
- 自动展示方法、路径、参数表、请求示例和响应示例。
- 只在本地模拟响应,不访问真实 AF 设备。
- 会按文档中的响应示例和字段规则生成 mock 结果。
- 已覆盖例外封锁、封锁攻击者、临时封锁、业务封锁、登录/注销/保活等接口的文档驱动 mock 结构。
风控配置
examples/whitelist.sample.json提供本地白名单示例。confirm_mode支持手动和自动两种模式,也兼容旧值manual和auto。WHITELIST_FILE和CONFIRM_MODE可通过manifest.json的user_config注入运行环境。- 通过
set_confirm_mode工具切换后,会写入本地CONFIRM_MODE_FILE,默认路径为data/confirm-mode.json。 - 通过
set_whitelist_file工具切换后,会写入本地白名单配置文件,默认路径为data/whitelist-config.json。 - 确认模式解析优先级为:工具显式参数 > 本地持久化配置 > 环境变量
CONFIRM_MODE> 默认值手动。 - 白名单文件解析优先级为:工具显式参数 > 本地持久化配置 > 环境变量
WHITELIST_FILE> 默认样例文件。 手动模式下所有写操作都要求显式确认;自动模式下仅高风险写操作要求显式确认。LOG_FILE可用于指定本地 JSONL 审计日志路径。SESSION_FILE可用于指定本地 JSON 会话持久化路径。SESSION_TIMEOUT_SECONDS和SESSION_REFRESH_WINDOW_SECONDS可用于控制本地会话超时与自动保活窗口。
账号配置
af_host用于配置默认 AF 主机地址。af_namespace用于配置默认命名空间,默认public。af_username和af_password用于配置默认登录账号。af_verify_tls用于配置默认 HTTPS 证书校验开关。- 配置完成后,
auth_login、auth_keepalive、auth_logout以及封禁相关工具都可直接复用这些默认值。
当前已实现工具
agent_infoauth_loginauth_keepaliveauth_logoutaccount_config_statusget_confirm_modeset_confirm_modeget_whitelist_configget_whitelist_rulesset_whitelist_filecheck_whitelist_targetsblock_list_exceptionsblock_add_exceptionsblock_delete_exceptionsblock_update_exceptionsblock_update_exceptionblock_list_attackersblock_list_tempblock_list_businessblock_get_total_countblock_get_block_timeblock_add_attackersblock_delete_attackersblock_add_businessblock_delete_tempblock_delete_businessblock_clear_attackersblock_clear_tempblock_clear_businessblock_set_block_time
下一步实现
- 如需生产落地,再补日志轮转和敏感字段分级脱敏。
- 如需更强回检能力,再补基于业务记录 ID 或操作结果对象的精确比对。
- 如需长期运行,再补 token 失效后的自动重新认证策略。
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.