#!/usr/bin/env python3
"""Connect to Vigil over MCP and print its public tool inventory."""

import json
import urllib.request

URL = "https://vigilnotary.com/mcp"


def rpc(message):
    request = urllib.request.Request(
        URL,
        data=json.dumps(message).encode(),
        method="POST",
        headers={"Content-Type": "application/json", "Accept": "application/json, text/event-stream"},
    )
    with urllib.request.urlopen(request, timeout=20) as response:
        return json.load(response)


initialized = rpc({
    "jsonrpc": "2.0",
    "id": 1,
    "method": "initialize",
    "params": {
        "protocolVersion": "2025-06-18",
        "capabilities": {},
        "clientInfo": {"name": "vigil-public-example", "version": "1.0.0"},
    },
})
listed = rpc({"jsonrpc": "2.0", "id": 2, "method": "tools/list", "params": {}})

print(initialized["result"]["serverInfo"])
for tool in listed["result"]["tools"]:
    print(f"{tool['name']}: {tool.get('description', '')}")
