PTP MCP Server 是一个模型上下文协议(MCP)服务器,用于在 OpenShift 集群中监控和分析精确时间协议(PTP)系统。它能帮助用户更好地管理和维护 PTP 系统,确保时间同步的准确性和稳定性。
oc)openshift-ptp)克隆仓库:
git clone https://github.com/aneeshkp/ptp-mcp-server.git
cd ptp-mcp-server
安装依赖项:
pip install -r requirements.txt
验证 OpenShift 访问权限:
oc whoami
oc get namespace openshift-ptp
运行综合测试套件:
python quick_test.py
预期输出:
🔍 PTP MCP Server API Quick Test
==================================================
Tests Passed: 8/8
Success Rate: 100.0%
🎉 ALL TESTS PASSED! Your API is ready for agent integration.
启动 MCP 服务器以与支持 MCP 的客户端集成:
python ptp_mcp_server.py
import asyncio
from ptp_tools import PTPTools
async def check_health():
tools = PTPTools()
health = await tools.check_ptp_health({})
if health["success"]:
print(f"Status: {health['overall_status']}")
for check_name, result in health["checks"].items():
print(f"{check_name}: {result}")
else:
print(f"Error: {health.get('error')}")
asyncio.run(check_health())
async def ask_question():
tools = PTPTools()
response = await tools.query_ptp({
"question": "What is the current grandmaster?"
})
if response["success"]:
print(f"Answer: {response['response']}")
else:
print(f"Error: {response.get('error')}")
asyncio.run(ask_question())
async def analyze_logs():
tools = PTPTools()
# Get recent logs
logs = await tools.get_ptp_logs({"lines": 500})
# Search for specific events
sync_loss = await tools.search_logs({"query": "sync loss"})
clock_changes = await tools.search_logs({"query": "clockClass change"})
print(f"Total logs: {logs['logs_count']}")
print(f"Sync loss events: {sync_loss['matching_logs']}")
print(f"Clock changes: {clock_changes['matching_logs']}")
asyncio.run(analyze_logs())
服务器提供以下 MCP 工具:
get_ptp_config - 获取 PTP 配置get_ptp_logs - 获取 linuxptp 守护进程日志search_logs - 搜索日志中的模式get_grandmaster_status - 获取主时钟信息analyze_sync_status - 分析同步状态get_clock_hierarchy - 获取时钟层次结构check_ptp_health - 全面的健康检查query_ptp - 自然语言接口from ptp_tools import PTPTools
tools = PTPTools()
result = await tools.get_ptp_config({"namespace": "openshift-ptp"})
result = await tools.get_ptp_logs({"lines": 1000})
result = await tools.search_logs({"query": "dpll", "time_range": "last_hour"})
result = await tools.check_ptp_health({"check_config": True, "check_sync": True})
result = await tools.query_ptp({"question": "What is the current grandmaster?"})
result = await tools.get_grandmaster_status({"detailed": True})
result = await tools.analyze_sync_status({"include_offsets": True})
result = await tools.get_clock_hierarchy({"include_ports": True})
ptp-mcp-server/
├── ptp_mcp_server.py # 主 MCP 服务器
├── ptp_config_parser.py # PTP 配置解析器
├── ptp_log_parser.py # Linuxptp 日志解析器
├── ptp_model.py # PTP 数据模型
├── ptp_query_engine.py # 自然语言查询引擎
├── ptp_tools.py # API 端点实现
├── quick_test.py # 快速测试套件
├── performance_test.py # 性能基准测试
└── requirements.txt # Python 依赖项
python quick_test.py
python performance_test.py
# 测试配置解析器
python -c "from ptp_config_parser import PTPConfigParser; import asyncio; asyncio.run(PTPConfigParser().get_ptp_configs())"
# 测试日志解析器
python -c "from ptp_log_parser import PTPLogParser; import asyncio; asyncio.run(PTPLogParser().get_ptp_logs())"
git checkout -b feature/amazing-feature)。git commit -m 'Add amazing feature')。git push origin feature/amazing-feature)。本项目采用 MIT 许可证 - 有关详细信息,请参阅 LICENSE 文件。
如有问题,请:
状态:✅ 可用于生产
最后更新时间:2025 年 1 月
版本:1.0.0