Chapter 4. MCP Clients: Advanced Use and Best Practices
At the base of MCP, as well as the various SDK implementations of the
protocol, is a system that sends and receives messages between clients
and servers. In the Python SDK, all of the session methods we wrapped
themselves wrap a send_request() method. This method can be found in
mcp.shared.session.BaseSession, which both the client- and
server-specific Session classes inherit from. Because of this, you
could theoretically also send your own custom requests to a server that
supports them, but will have to create your own Request, RequestParams,
and Result classes to do so.
There are a few other methods you can make use of in the
client session object. send_ping() sends a ping request to the
connected server. The server will then return an EmptyResult within a
ServerResult, which carries no data but signifies the presence of a
working connection to the server. set_logging_level(), given a
LoggingLevel object from MCP’s types library, can ...