Skip to Content
AI Agents with MCP
book

AI Agents with MCP

by Kyle Stratis
May 2026
Intermediate to advanced
275 pages
3h 52m
English
O'Reilly Media, Inc.
Content preview from AI Agents with MCP

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 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

AI Agents in Action

AI Agents in Action

Micheal Lanham
AI Agents in Action

AI Agents in Action

Micheal Lanham

Publisher Resources

ISBN: 9798341639546Errata Page