MCP 服务器
RelayCore 包含一个 MCP(Model Context Protocol)服务器,为 AI 代理暴露工具以编程方式观察和控制流量拦截。
启用 MCP
# 通过 CLI
relay-core-cli run --mcp
# 通过 config.toml
[mcp]
enabled = true
port = 25519 连接到 MCP
使用任何 MCP 兼容的客户端(Claude Desktop、Cursor 等):
# 在你的 MCP 客户端配置中
{
"mcpServers": {
"relay-core": {
"command": "npx",
"args": ["@relay-core/mcp"]
}
}
} 工具
观察
search_flows
搜索和过滤捕获的流量。
{
"filter": "method:GET host:*.example.com",
"limit": 10
} get_flow
获取详细的流量信息。
{
"flow_id": "fld_01HX5K9P3Q8Y2Z7"
} get_metrics
获取当前代理指标。
控制
set_intercept
创建拦截断点。
{
"filter": {
"method": "POST",
"host": "api.example.com"
},
"pause_at": "request"
} resume_flow
恢复暂停的流量。
{
"flow_id": "fld_01HX5K9P3Q8Y2Z7",
"action": "resume" # 或 "drop"
} set_rule
创建或更新规则。
{
"name": "Log API requests",
"filter": { "path": "/api/*" },
"action": { "type": "log" }
} delete_rule
删除规则。
{
"rule_id": "rul_01HX5K9P3Q8Y2Z7"
} 分析
export_har
以 HAR 格式导出流量。
{
"filter": "host:example.com",
"format": "har"
} replay_flow
重放捕获的流量。
{
"flow_id": "fld_01HX5K9P3Q8Y2Z7",
"modifications": {
"headers": { "x-test": "value" }
}
} 策略
get_policy
获取当前拦截策略。
update_policy
更新拦截策略。
资源
MCP 还暴露只读访问的资源:
relay://flows— 列出最近的流量relay://rules— 当前规则relay://metrics— 运行时指标relay://config— 当前配置
使用场景
- AI 驱动的 API 测试和调试
- 自动化流量分析
- 基于流量模式的动态规则生成
- 与 CI/CD 管道集成