"""
Ping an MCP server (spawned via stdio) and list its tools.

Usage:
  python tools/ping_server.py mcp.servers.analyzer_server
  python tools/ping_server.py mcp.servers.redactor_server
  python tools/ping_server.py mcp.servers.auditor_server
"""

from __future__ import annotations

import asyncio
import sys
from typing import Tuple

from mcp import ClientSession
from mcp.client.stdio import stdio_client
from mcp.types import ListToolsResult
from mcp import StdioServerParameters


async def main() -> None:
    if len(sys.argv) < 2:
        print("Usage: python tools/ping_server.py <server_module>")
        sys.exit(2)
    server_module = sys.argv[1]

    params = StdioServerParameters(
        command=sys.executable,
        args=["-m", server_module],
    )

    async with stdio_client(params) as (read, write):
        async with ClientSession(read, write) as session:
            await session.initialize()
            tools: ListToolsResult = await session.list_tools()
            print("Tools:", [t.name for t in tools.tools])


if __name__ == "__main__":
    asyncio.run(main())
