TLS MCP服务器
A. 模型上下文协议(MCP) 服务器,为TLS证书分析提供统一、用户友好的工具。不再在函数之间复制PEM数据——一切都发生在一个干净的界面中! 这个工具完全是通过Claude Code编写的,是一个有趣的学习项目。
🚀 特性
- 多功能界面:单一工具,具有灵活的选项,可满足任何证书分析需求
- 智能分析:在可用时自动使用OpenSSL,回退到Python加密
- 证书过期监控:具有人性化警告的自动过期检查
- 密码套件分析:全面的TLS密码套件和版本支持测试
- 安全等级:自动安全评估,等级从A+到F
- 灵活的选项:选择快速/详细分析,包括/排除PEM,启用/禁用linting
- 零PEM复制:分析自动进行,无需手动处理证书
- 综合测试:单元、集成和真实世界测试的全面测试覆盖
🛠️ 提供的工具
fetch_certificate -一体化证书分析
通过灵活的选项获取和分析TLS证书-无需在工具之间复制PEM数据!
参数:
hostname(必填):网站主机名(例如“google.com”)port(可选):端口号(默认值:443)include_pem(可选):在输出中包含原始PEM证书(默认值:false)analyze(可选):分析级别-“无”、“快速”或“详细”(默认:“快速”)lint(可选):运行zlint合规性检查(默认值:false)use_openssl(可选):在可用时使用OpenSSL进行分析(默认值:true)analyze_ciphers(可选):分析支持的密码套件和TLS版本(默认值:false)cipher_scan_type(可选):密码扫描类型-“快速”或“完整”(默认:“快速”)
分析选项:
- 快速分析:基本证书信息(主题、颁发者、有效期、SAN)
- 详细分析:完整的证书详细信息,包括扩展名和密钥信息
- 过期监测:带有智能警告的自动过期检查:
- ✅ 有效证书显示到期前的时间 - 🟡 30天内到期的证书将收到黄色警告 - ⚠️ 7天内到期的证书将收到紧急警告 - 🔴 过期证书显示过期后的时间 - ⏳ 未来的有效证书显示有效期
- OpenSSL与密码学:自动使用OpenSSL(如果可用),回退到Python加密
示例:
{"hostname": "google.com"}-仅限快速分析{"hostname": "github.com", "analyze": "detailed", "lint": true}-详细分析+zlint{"hostname": "badssl.com", "analyze": "none", "include_pem": true}-只需取回PEM
📋 先决条件
- Python 3.13+
- zlint (用于证书装订)
- 心脏出血 (用于证书操作)
安装zlint
# macOS
brew install zlint
# Linux
go install github.com/zmap/zlint/v3/cmd/zlint@latest
# Or download from releases: https://github.com/zmap/zlint/releases🔧 安装
- 克隆并设置项目:
git clone
cd tls-mcp
python3.13 -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -e .- 安装开发依赖项(可选):
pip install -e ".[dev]"- 运行测试以验证安装:
pytest tests/ -v⚙️ 配置
将以下内容添加到您的Claude Desktop配置文件中:
地点: ~/Library/Application Support/Claude/claude_desktop_config.json
{
"mcpServers": {
"tls-mcp-server": {
"command": "/path/to/your/tls-mcp/venv/bin/python",
"args": [
"/path/to/your/tls-mcp/tls_mcp_server/main.py"
],
"env": {
"PYTHONPATH": "/path/to/your/tls-mcp"
}
}
}
}替换 /path/to/your/tls-mcp 根据您的实际项目路径。
🚦 使用示例
配置后,重新启动Claude Desktop并尝试以下命令:
快速证书分析(默认)
"Analyze the certificate for github.com"合规性检查的详细分析
"Do a detailed analysis of google.com's certificate and run zlint on it"只获取证书(无分析)
"Get me the raw PEM certificate for badssl.com"比较多个证书
"Use the TLS certificate tool to analyze both google.com and github.com, then compare their key differences"安全评估
"Use the TLS certificate tool to check if example.com uses secure certificate practices with full analysis and linting"密码套件分析
"Use the TLS certificate tool to analyze the cipher suites supported by github.com and give me a security assessment"综合安全分析
"Use the TLS certificate tool to do a full security analysis of google.com including cipher suites, TLS versions, and certificate compliance"主要优势:
- ✅ 无PEM复制 -分析自动进行
- ✅ 灵活的选择 -选择您需要的信息
- ✅ 智能默认值 -开箱即用,效果极佳
- ✅ OpenSSL集成 -使用最佳可用工具
🧪 测试
运行综合测试套件:
# Run all tests (including slow integration tests)
pytest tests/ -v
# Run only fast tests (excludes slow integration tests that require internet)
pytest tests/ -m "not slow" -v
# Run with coverage
pytest tests/ --cov=tls_mcp_server --cov-report=term-missing
# Run only unit tests
pytest tests/test_mcp_server.py -v
# Run only basic integration tests
pytest tests/test_integration.py -v
# Run real-world integration tests (requires internet and zlint)
pytest tests/test_google_integration.py -v测试覆盖率
- 单元测试:使用模拟依赖关系测试新的统一接口
- 密码分析测试:测试密码分类、TLS版本检测和安全分级
- 过期检查测试:测试证书有效性检查、持续时间格式化和时区处理
- 基本集成测试:测试服务器注册和工具选项
- 真实世界集成测试:使用实时Google证书测试完整工作流程
- 错误处理:测试各种故障场景
- 当前覆盖范围:34项通过全面覆盖的测试
📁 项目结构
tls-mcp/
├── tls_mcp_server/
│ ├── __init__.py # Package initialization
│ └── main.py # MCP server implementation
├── tests/
│ ├── __init__.py # Test package
│ ├── test_mcp_server.py # Unit tests
│ ├── test_cipher_analysis.py # Cipher analysis tests
│ ├── test_expiration_check.py # Expiration checking tests
│ └── test_integration.py # Integration tests
├── pyproject.toml # Project configuration
├── pytest.ini # Test configuration
└── README.md # This file🔍 建筑
服务器是使用 MCP Python SDK 采用现代、用户友好的设计:
- 单工具界面:一个
fetch_certificate具有灵活选项的工具 - 智能分析:自动选择OpenSSL或Python加密
- 异步操作:所有操作都是异步的,以获得更好的性能
- 错误处理:具有优雅回退功能的全面错误处理
- 模块化助手:用于不同分析方法的内部辅助函数
- 无PEM切换:分析自动进行,无需手动复制PEM
🚨 安全考虑
- 证书在本地处理,不向外部服务发送数据
- 网络连接使用标准SSL/TLS库
- zlint操作后会清理临时文件
- 错误消息不会暴露敏感的系统信息
🤝 贡献
- 分叉存储库
- 创建要素分支
- 添加新功能的测试
- 确保所有测试通过:
pytest tests/ -v - 提交拉取请求
📝 许可证
MIT许可证-有关详细信息,请参阅许可证文件。
🆘 故障排除
常见问题
“找不到zlint命令”
- 按照上面的说明安装zlint
- 验证它是否在您的PATH中:
which zlint
“获取证书失败”
- 检查您的互联网连接
- 验证主机名是否正确
- 某些服务器可能会阻止自动请求
“MCP服务器未出现在Claude中”
- 验证配置文件路径是否正确
- 检查配置中的Python路径是否指向您的虚拟环境
- 配置更改后重新启动Claude Desktop
调试模式
通过设置环境变量启用调试日志记录:
export PYTHONPATH="/path/to/tls-mcp"
python tls_mcp_server/main.py🏷️ 版本历史记录
- v0.2.1:添加了证书过期监控,具有人性化的警告和时区处理功能
- v0.2.0版本:主要界面重新设计,统一
fetch_certificate工具、OpenSSL集成、密码套件分析、安全分级 - v0.1.0:带有基本证书获取、分析和linting的初始版本
