What this thread does
Do first: use from mcp import Client, StdioServerParameters in the Python client file.
When you need it
You have an MCP server script and need a Python client to start it over stdio and list available tools. The tutorial uses a single Client context for connection setup and subprocess shutdown.
Steps
1. In the tutorial’s Python project, install its dependencies:
uv add mcp anthropic python-dotenv
2. In client.py, add the imports needed for the connection and entry point:
import asyncio
import sys
from mcp import Client, StdioServerParameters
from mcp.client.stdio import stdio_client
3. Use the page’s script-extension selection to describe the subprocess:
def server_params(server_script_path: str) -> StdioServerParameters:
if server_script_path.endswith(".py"):
command = "python"
elif server_script_path.endswith(".js"):
command = "node"
else:
raise ValueError("Server script must be a .py or .js file")
return StdioServerParameters(command=command, args=[server_script_path])
4. Use the connection-and-listing portion of the tutorial’s main() and its entry point. Pass the server script as the first argument:
async def main() -> None:
if len(sys.argv) < 2:
print("Usage: python client.py <path_to_server_script>")
sys.exit(1)
async with Client(stdio_client(server_params(sys.argv[1]))) as client:
tool_list = await client.list_tools()
tool_names = [tool.name for tool in tool_list.tools]
print("\nConnected to server with tools:", tool_names)
if __name__ == "__main__":
asyncio.run(main())
5. Launch the client using the page’s Python-server example, substituting your server script path:
uv run client.py path/to/server.py
For its Node.js example, use uv run client.py path/to/build/index.js.
Check it worked
Look for Connected to server with tools: followed by the tool names. This is the output printed after list_tools() in the tutorial.
Limits
The page requires Python MCP SDK 2.0.0 or higher; it does not describe that requirement as an introduction version. Its system requirements name Mac or Windows and the latest Python and uv versions without numeric versions for those two dependencies. The script-selection code accepts only .py and .js files and raises ValueError otherwise. This excerpt stops at tool discovery; it omits the tutorial’s Claude chat loop.
Not for: exposing new typed tools on a server; see build-first-mcp-server-python-mcpserver-fastmcp-uv-inspector.
Sources
- Build an MCP client, MCP documentation, read 2026-11-24: "You must use the Python MCP SDK 2.0.0 or higher"
Checked
2026-11-24; read <https://modelcontextprotocol.io/docs/develop/build-client.md>; no command was run.
Started from a post by @Model Context Protocol, packaged by the editor. Original post