Integrating PingZen as an MCP Server: 126 Tools for AI Agents
The MCP server runs alongside the main application in a single process but with isolated endpoints. STDIO is ideal for desktop agents launching Python scripts via stdin/stdout. The HTTP transport is built into FastAPI for cloud-based services.
Registration of the 126 tools is handled through SDK decorators. Tools are grouped as follows:
- Monitors:
create_monitor,update_monitor,delete_monitor,get_monitor_status,list_monitors,pause_monitor,resume_monitor. - Alerts:
create_alert,update_alert,test_alert,list_alerts. - Incidents:
list_incidents,get_incident_details,resolve_incident,add_incident_update. - Heartbeats:
create_heartbeat,send_heartbeat_ping,get_heartbeat_status. - Status Pages:
create_status_page,add_monitor_to_status_page,update_status_page. - Webhooks:
create_webhook,list_webhooks. - Reports:
create_scheduled_report,get_report_history. - API Keys:
create_api_key,revoke_api_key.
Example registration:
from mcp.server import Server
import mcp.types as types
server = Server("pingzen-mcp")
@server.list_tools()
async def handle_list_tools() -> list[types.Tool]:
return [
types.Tool(
name="create_monitor",
description="Create a new monitor",
inputSchema={
"type": "object",
"properties": {
"name": {"type": "string"},
"type": {"type": "string", "enum": ["http", "tcp", "udp", "icmp", "dns", "smtp", "transaction", ...]},
"target": {"type": "string"},
"interval": {"type": "integer", "minimum": 60},
},
"required": ["name", "type", "target"]
}
),
]
@server.call_tool()
async def handle_call_tool(name: str, arguments: dict) -> list[types.TextContent]:
if name == "create_monitor":
monitor = await monitor_service.create(arguments)
return [types.TextContent(type="text", text=json.dumps(monitor.to_dict()))]
Arguments are passed as JSON schema, simplifying the definition of complex protocols like Transaction using Playwright.
OAuth 2.0 Authentication
OAuth 2.0 is implemented per RFC 9728 with zero configuration. Agents open a browser to authenticate via Telegram, Google, or Yandex. Upon consent, a token is issued. For CI/CD pipelines, API keys are available via environment variables. Simply set the URL https://pingzen.dev/mcp in agent settings.
Practical Tool Usage
Creating an HTTP monitor:
{
"name": "create_monitor",
"arguments": {
"name": "Habr",
"type": "http",
"target": "https://habr.com",
"interval": 60,
"alert_channels": ["telegram"]
}
}
Result: Monitor ID and confirmation. Same applies to list_monitors, resolve_incident, or heartbeat with a 24-hour interval and 1-hour grace period.
Implementation Nuances
- Validation: JSON Schema enforces strict typing. Explicit type casting is applied in handlers (e.g., interval as integer), even when AI returns strings.
- Synchronization: All tools are synchronous with timeouts. No background tasks for simplicity.
- Errors: Centralized error messages defined in
errors.py:
_ERROR_MESSAGES = {
"INVALID_PROTOCOL": "Invalid monitor type '{type}'. Available: http, tcp, udp, icmp, dns, smtp, transaction, ...",
"TIMEOUT": "Request timed out after {timeout} seconds",
}
- Logging: Output sent via stderr for STDIO, including call arguments.
Key Takeaways
- The 126 tools cover the full lifecycle—from monitor creation to incident management and reporting.
- Dual transport options ensure flexibility for both local and cloud agents.
- Zero-config OAuth reduces setup friction; API keys enable automation.
- Synchronous design with timeouts and strict validation ensures predictable behavior.
- Seamless integration with CI/CD and IDEs without context switching.
— Editorial Team
No comments yet.