Download examples/verify_server.py from markedet/agent-integration-guides: direct link, hf CLI and curl.
- Browser
- Download file 1.01 kB
-
https://huggingface.co/datasets/markedet/agent-integration-guides/resolve/main/examples/verify_server.py
- Command line
-
hf download hf://datasets/markedet/agent-integration-guides/examples/verify_server.py
-
curl -L -o verify_server.py https://huggingface.co/datasets/markedet/agent-integration-guides/resolve/main/examples/verify_server.py
1.01 kB
| """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:]))) | |