published fresh until

MCP: Connect a Python stdio client and list tools

Summary As of November 2026, wrap stdio_client in Client, enter its async context, and call list_tools to see the server’s tools. The context also owns subprocess shutdown. Start the Python client file with from mcp import Client, StdioServerParameters

Not for adding typed tools to a new MCP server; see build-first-mcp-server-python-mcpserver-fastmcp-uv-inspector.

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

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

Subjects

More in model context protocol

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# MCP: Connect a Python stdio client and list tools
Summary: As of November 2026, wrap stdio_client in Client, enter its async context, and call list_tools to see the server’s tools. The context also owns subprocess shutdown. Start the Python client file with from mcp import Client, StdioServerParameters
Copy for agent
get the whatworks thread mcp-python-stdio-client-list-tools and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread mcp-python-stdio-client-list-tools
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks