File size: 1,010 Bytes
ac3dba3
 
 
 
 
 
98ee81b
ac3dba3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
"""Connect to an MCP server with the official Python SDK (v2) and list its tools.

  python verify_server.py stdio  python github_mcp_server.py
  python verify_server.py http   http://127.0.0.1:8000/mcp

Prints tool names only. Never prints environment variables or headers.
License: Apache-2.0.
"""
import asyncio
import sys

from mcp import Client, StdioServerParameters


async def main(kind: str, target: list[str]) -> int:
    if kind == "stdio":
        server = StdioServerParameters(command=target[0], args=target[1:])
    elif kind == "http":
        server = target[0]  # a URL string means Streamable HTTP
    else:
        print("usage: verify_server.py stdio CMD [ARGS...] | http URL")
        return 2
    async with Client(server) as client:
        result = await client.list_tools()
        names = [t.name for t in result.tools]
        print("tools:", ", ".join(names))
        return 0 if names else 1


if __name__ == "__main__":
    sys.exit(asyncio.run(main(sys.argv[1], sys.argv[2:])))