Skip to main content
MCPClient is an async Python client for talking to any MCP server. It handles the MCP handshake (initialize), transport setup, and session management—so you can focus on the operations you want to perform. Use MCPClient when you want explicit, predictable control, like:
  • Testing MCP servers during development
  • Building applications that need reliable MCP interactions
  • Building higher-level clients (including “agentic” flows) on top of a typed protocol layer

Quick start

Connect → do work → close.
Prefer async with if you want guaranteed cleanup:

Connection

Connect

Protocol info

After connecting, initialize_result is populated:

Close

Alternative: open_connection(...)

open_connection(...) is a convenience wrapper that yields a connected MCPClient and cleans up automatically:

Ping

Operations

Most client code falls into one of these buckets:

Tools

List and call server-side functions

Resources

List and read data sources

Prompts

List and get message templates

Client capabilities (server → client)

Some MCP features are initiated by the server. If you want to support them, you configure handlers when connecting.

Sampling

Handle LLM completion requests from servers

Elicitation

Gather user input during tool execution

Roots

Advertise filesystem boundaries to servers

Logging

Receive log messages from servers

Authentication

For protected MCP servers:

Bearer Auth

API keys and service tokens

OAuth

User consent and delegated access via browser flow

DPoP authentication

For servers using DPoP (RFC 9449) sender-constrained tokens:
Last modified on June 30, 2026