PTP MCP Server
Monitors and analyzes Precision Time Protocol (PTP) systems in OpenShift clusters, enabling configuration analysis, real-time log monitoring, and health checks.
README
PTP MCP Server
A Model Context Protocol (MCP) server for monitoring and analyzing Precision Time Protocol (PTP) systems in OpenShift clusters.
🚀 Features
- PTP Configuration Analysis: Parse and validate PTP configurations from OpenShift
- Real-time Log Monitoring: Access linuxptp daemon logs with intelligent parsing
- Natural Language Queries: Ask questions about PTP status in plain English
- Health Monitoring: Comprehensive PTP system health checks
- Synchronization Analysis: Monitor sync status, offsets, and BMCA state
- Clock Hierarchy: Track grandmaster and clock hierarchy information
- ITU-T Compliance: Validate configurations against ITU-T G.8275.1 standards
📋 Prerequisites
- Python 3.8 or higher
- OpenShift CLI (
oc) installed and configured - Access to OpenShift cluster with PTP operator installed
- PTP namespace (
openshift-ptp) exists
🛠️ Source Installation
- Clone the repository:
git clone https://github.com/redhat-cne/ptp-mcp-server.git cd ptp-mcp-server
To Deploy For Quick Tests
-
Install dependencies:
pip install -r requirements.txt -
Verify OpenShift access:
export KUBECONFIG=/path/to/kubeconfig oc whoami oc get namespace openshift-ptp -
Quick Testing
Run the comprehensive test suite:
export KUBECONFIG=/path/to/kubeconfig
python quick_test.py
Expected output:
🔍 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 Server
The MCP server supports two transport modes:
- stdio: For local MCP clients (Claude Code, Claude Desktop)
- HTTP/SSE: For OpenShift Lightspeed integration
Local Usage (stdio mode)
python ptp_mcp_server.py
Remote Usage (http mode)
# Default port 8080
python ptp_mcp_server.py --http
# Custom port
python ptp_mcp_server.py --http --port 9000
# Or use environment variable
PTP_MCP_PORT=9000 python ptp_mcp_server.py --http
Deploy to OpenShift
podman build -t quay.io/$USER/ptp-mcp-server:latest .
podman push quay.io/$USER/ptp-mcp-server:latest
cd k8s && kustomize edit set image quay.io/redhat-cne/ptp-mcp-server=quay.io/$USER/ptp-mcp-server:latest && cd ..
oc apply -k k8s/
Configure in OpenShift Lightspeed
Add the MCP server to your OLSConfig:
apiVersion: ols.openshift.io/v1alpha1
kind: OLSConfig
metadata:
name: cluster
spec:
featureGates:
- MCPServer
mcpServers:
- name: ptp-monitoring
url: 'http://ptp-mcp-server.openshift-ptp.svc.cluster.local:8080/mcp'
timeout: 30
Usage in OpenShift Lightspeed
By default, the MCP server assumes that it is running on the cluster that is to be monitored/queried. Any tool use will target the local cluster. However, if the MCP server is running on a hub cluster and the user intends for its prompt to target spoke cluster then OLS context should include a base64 copy of the kubeconfig for the spoke cluster.
note: It is important to use a minimal kubeconfig that is token based rather than a client certificate based kubeconfig as the OLS context size will not allow for a larger kubeconfig value.
The following example generates such a kubeconfig for lab testing purposes. In a production environment care should be taken to limit the service account permissions to only the strict minimum RBAC policies required.
oc create sa ols-ptp-user -n default 2>/dev/null
oc adm policy add-cluster-role-to-user cluster-admin -z ols-ptp-user -n default
TOKEN=$(oc create token ols-ptp-user -n default --duration=24h)
API_SERVER=$(oc whoami --show-server)
cat << EOF > minimal-kubeconfig.yaml
apiVersion: v1
kind: Config
clusters:
- cluster:
server: ${API_SERVER}
insecure-skip-tls-verify: true
name: cluster
contexts:
- context:
cluster: cluster
user: user
name: ctx
current-context: ctx
users:
- name: user
user:
token: ${TOKEN}
EOF
📚 API Endpoints
1. Configuration API
from ptp_tools import PTPTools
tools = PTPTools()
result = await tools.get_ptp_config({"namespace": "openshift-ptp"})
2. Logs API
result = await tools.get_ptp_logs({"lines": 1000})
3. Search API
result = await tools.search_logs({"query": "dpll", "time_range": "last_hour"})
4. Health API
result = await tools.check_ptp_health({"check_config": True, "check_sync": True})
5. Natural Language API
result = await tools.query_ptp({"question": "What is the current grandmaster?"})
6. Grandmaster Status API
result = await tools.get_grandmaster_status({"detailed": True})
7. Sync Status API
result = await tools.analyze_sync_status({"include_offsets": True})
8. Clock Hierarchy API
result = await tools.get_clock_hierarchy({"include_ports": True})
🚀 Usage Examples
Basic Health Check
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())
Natural Language Query
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())
Log Analysis
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 Tools Available
| Tool | Description |
|---|---|
get_ptp_config |
Get PTP configuration |
get_ptp_logs |
Get linuxptp daemon logs |
search_logs |
Search logs for patterns |
get_grandmaster_status |
Get grandmaster info |
analyze_sync_status |
Analyze sync status |
get_clock_hierarchy |
Get clock hierarchy |
check_ptp_health |
Comprehensive health check |
query_ptp |
Natural language interface |
run_pmc_query |
Execute PMC commands |
Deployment Files
| File | Purpose |
|---|---|
Dockerfile |
Container image with Python + oc CLI |
k8s/rbac.yaml |
ServiceAccount, ClusterRole, ClusterRoleBinding |
k8s/deployment.yaml |
Deployment with health checks |
k8s/service.yaml |
ClusterIP Service |
k8s/olsconfig-example.yaml |
Example OLS configuration |
k8s/kustomization.yaml |
Deploy all with oc apply -k k8s/ |
RBAC Permissions
The ServiceAccount is granted these permissions:
| Resource | Verbs | Purpose |
|---|---|---|
ptpconfigs, ptpoperatorconfigs |
get, list, watch | Read PTP configurations |
pods |
get, list, watch | Find linuxptp-daemon pods |
pods/log |
get, list | Read daemon logs |
pods/exec |
create | Execute PMC queries |
namespaces |
get, list | Namespace access |
nodes |
get, list | Node topology (optional) |
📊 Performance
- Average Response Time: 0.78s
- Fastest API: Configuration API (0.22s)
- Concurrent Operations: 4/4 successful in 2.45s
- Success Rate: 100% (8/8 endpoints)
🏗️ Architecture
ptp-mcp-server/
├── ptp_mcp_server.py # Main MCP server (stdio + HTTP modes)
├── ptp_config_parser.py # PTP configuration parser
├── ptp_log_parser.py # Linuxptp log parser
├── ptp_model.py # PTP data models
├── ptp_query_engine.py # Natural language query engine
├── ptp_tools.py # API endpoint implementations
├── quick_test.py # Quick test suite
├── performance_test.py # Performance benchmarking
├── requirements.txt # Python dependencies
├── Dockerfile # Container image definition
└── k8s/ # Kubernetes/OpenShift manifests
├── kustomization.yaml # Kustomize configuration
├── rbac.yaml # ServiceAccount & RBAC
├── deployment.yaml # Deployment specification
├── service.yaml # Service definition
└── olsconfig-example.yaml # OLS integration example
🔍 PTP Concepts Supported
- BMCA (Best Master Clock Algorithm): Clock selection and hierarchy
- Clock Types: OC (Ordinary Clock), BC (Boundary Clock), TC (Transparent Clock)
- ITU-T G.8275.1: Profile compliance and validation
- Synchronization: Offset tracking, frequency adjustment, sync status
- Grandmaster: Primary time source identification and status
- Clock Class: Quality and traceability indicators
- Domain Numbers: PTP domain configuration (24-43 for ITU-T)
🧪 Testing
Run All Tests
python quick_test.py
Performance Testing
python performance_test.py
Individual Component Testing
# Test configuration parser
python -c "from ptp_config_parser import PTPConfigParser; import asyncio; asyncio.run(PTPConfigParser().get_ptp_configs())"
# Test log parser
python -c "from ptp_log_parser import PTPLogParser; import asyncio; asyncio.run(PTPLogParser().get_ptp_logs())"
📖 Documentation
- Testing Guide - Comprehensive testing instructions
- Agent Integration Guide - Integration examples for agents
- Testing Steps - Step-by-step testing process
- Testing Results - Complete test results
🤝 Contributing
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
🙏 Acknowledgments
- OpenShift PTP Operator team
- Linuxptp project
- Model Context Protocol (MCP) community
📞 Support
For issues and questions:
- Create an issue on GitHub
- Check the testing documentation
- Review the agent integration guide
Status: ✅ Production Ready
Last Updated: January 2025
Version: 1.0.0
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。
mcp-server-qdrant
这个仓库展示了如何为向量搜索引擎 Qdrant 创建一个 MCP (Managed Control Plane) 服务器的示例。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。