MCP Whisker Go
去实现Calico Whisker MCP服务器进行流日志分析。
概述
这是TypeScript MCP Whisker项目的Go端口,提供模型上下文协议(MCP)服务器功能,用于分析Kubernetes环境中的Calico Whisker流日志。
特性
- 端口转发管理:自动管理kubectl端口转发到Calico Whisker服务
- 流量日志分析:从Calico Whisker检索和分析网络流日志
- 汇总流量报告:全面的流量分析,包括分类、主要来源/目的地、命名空间活动和安全态势
- 命名空间筛选:为特定命名空间生成详细的流摘要
- 阻塞流分析:识别和分析被阻塞的网络流及其阻塞策略
- 政策整合:检索和分析影响流量的Calico网络策略
安装
# Clone the repository
git clone https://github.com/aadhilam/mcp-whisker-go
cd mcp-whisker-go
# Build the application
go build -o mcp-whisker-go ./cmd/server
# Or install directly
go install ./cmd/server用法
作为MCP服务器(默认)
默认情况下,该二进制文件作为MCP服务器运行,使用stdin/stdout进行JSON-RPC通信:
# Run as MCP server (default behavior)
./mcp-whisker-go --kubeconfig ~/.kube/config
# Or explicitly use the 'server' command
./mcp-whisker-go server --kubeconfig ~/.kube/config注: 作为MCP服务器运行时:
- 所有JSON-RPC消息都使用stdout
- 所有日志和诊断都会转到stderr
- 不显示帮助文本或横幅
CLI命令
# Setup port-forward to Whisker service
./mcp-whisker-go setup-port-forward --kubeconfig ~/.kube/config
# Get flow logs (raw JSON)
./mcp-whisker-go get-flows
# Get aggregated flow logs with traffic analysis (Markdown format)
./mcp-whisker-go get-aggregated-flows
# Get aggregated flow logs as JSON
./mcp-whisker-go get-aggregated-flows --markdown=false
# Get aggregated flow logs with time filtering
./mcp-whisker-go get-aggregated-flows --start-time "2025-10-17T14:00:00Z" --end-time "2025-10-17T15:00:00Z"
# Analyze flows for a specific namespace
./mcp-whisker-go analyze-namespace --namespace production
# Analyze blocked flows
./mcp-whisker-go analyze-blocked --namespace production依赖项
- 转到1.21+
- kubectl配置了对Kubernetes集群的访问权限
- 集群中部署了Calico Whisker(Calico系统命名空间)
配置
该服务预计:
- Calico Whisker服务正在运行
calico-system命名空间 - 可通过端口8081访问服务
- kubectl访问,具有端口转发和读取网络策略的权限
MCP客户端设置
有关使用各种MCP客户端(Claude Desktop、VS Code、Continue.dev等)配置MCP Whisker的详细说明,请参阅 MCP客户端设置指南.
发展
# Run tests
go test ./...
# Run with development flags
go run ./cmd/server --kubeconfig ~/.kube/config --debug聚合流量日志
这 get-aggregated-flows 命令通过以下视图提供全面的流量分析:
交通概况
- 按源、目的地、协议、端口和操作聚合的流
- 带通配符的标准化pod名称,以获得更清晰的输出
- 网络分类(专用网络、公共网络)
- 人类可读的数据包和字节计数
按类别划分的流量
自动将流量分类为:
- DNS查询(端口53)
- API/HTTPS(端口443)
- 度量收集(端口10250、4443)
- Calico服务(Calico系统命名空间)
- 监控(端口9153)
- HTTP、数据库和其他流量类型
附加分析
- 热门流量来源和目的地:按流量计数和主要活动标识进行排名
- 命名空间活动:每个命名空间的入口/出口流量和流量
- 安全态势:允许与拒绝的流量,包括百分比和活动策略
输出格式
- 标记语言 (默认):人类可读的表格非常适合报告和文档
- JSON:用于程序化处理的结构化数据
示例用法
# Basic usage (Markdown output)
./mcp-whisker-go get-aggregated-flows
# JSON output for scripting
./mcp-whisker-go get-aggregated-flows --markdown=false | jq '.trafficByCategory'
# Time-filtered analysis
./mcp-whisker-go get-aggregated-flows \
--start-time "2025-10-17T14:00:00Z" \
--end-time "2025-10-17T15:00:00Z"测试
全面的测试套件可在 tests/ 目录:
# Quick connectivity test
cd tests && python3 quick_test.py
# Full test suite
cd tests && python3 run_all_tests.py
# Interactive launcher with menu
cd tests && python3 launcher.py
# Individual tool testing
cd tests && python3 test_tool.py check_whisker_service
cd tests && python3 test_tool.py analyze_namespace_flows '{"namespace": "kube-system"}'看 tests/README.md 获取详细的测试文档。
项目结构
├── cmd/
│ └── server/ # Main application entry point
├── internal/
│ ├── whisker/ # Calico Whisker service client
│ ├── portforward/ # Port forwarding functionality
│ └── mcp/ # MCP server implementation
├── pkg/
│ └── types/ # Shared types and interfaces
├── tests/ # Comprehensive test suite
│ ├── launcher.py # Interactive test launcher
│ ├── quick_test.py # Fast connectivity test
│ ├── run_all_tests.py # Full test suite
│ ├── test_tool.py # Individual tool testing
│ └── README.md # Testing documentation
└── README.md许可证
MIT许可证
