Leanpub Header

Skip to main content

Creating AI Agents with MCP - Model Context Protocol

Part of the series, "The Only Book You'll Need On..."

Get started quickly, creating applications for the Model Context Protocol (MCP) using the official MCP SDKs for Python, Java 21, and Node.js.

Quickly master, all of the concepts needed in order to build MCP servers, including transport protocols, tools, resources, prompts, roots, and sampling.

Learn how to get familiar with popular MCP client applications such as, Claude Desktop, Postman, and the MCP Inspector.

Minimum price

$29.00

$45.00

You pay

$45.00

Author earns

$36.00
$

...Or Buy With Credits!

You can get credits with a paid monthly or annual Reader Membership, or you can buy them here.
PDF
EPUB
WEB
About

About

About the Book

About the Series: “The Only Book You’ll Need On..”

This is the very first title in the new book series, “The only book you’ll need on…“. We are partnering with Leanpub in order to provide you with the best authors in the industry writing about the most cutting edge technologies. The core premise of this series is quite simple: we want to ensure that our authors write the only book that you’ll ever need on any subject!

Therefore, as a signature trait with every book in this series, we will provide the code examples in multiple programming languages, when applicable. Therefore, this book will not only to cover Python, but also Java 21 and Node.js. This makes this book, the code, and examples usable to over 30 million developers worldwide using the top programming languages available.

Therefore, no matter if you’re working for a major enterprise, a nimble startup, or if you’re trying to level-up for your next job, you’ll have full working examples available to allow you to get your projects off the ground quickly.

About the Book: “Creating AI Agents with MCP - Model Context Protocol”

For developers who are working to create AI applications and services, they quickly begin to realize the pain of creating a dedicated (bespoke) client for each AI application service. The MCP standard solves this problem by enabling a single client to be configured in order to access any agent that conforms to the MCP standard. Additionally, the MCP protocol provides a convenient architecture to enable external resources (such as databases and file systems) to be made accessible to AI agents. This new standard builds upon pre-existing AI agent architectures to enable MCP clients to control external systems (often referred to as tool and function calling).

One of the biggest benefits of MCP is the fact that the protocol enables clients to dynamically discover an use new capabilities. This means that MCP clients can operate and function beyond the means of their own original system design. This is very similar to how traditional web browsers work with browser plugins or extensions.

Therefore, the goal of the book is to take a developer with experience in Python, Java, or Node.js and show them how to build AI Agents that leverage the MCP protocol.

Author

About the Author

Contents

Table of Contents

About the Series: “The Only Book You’ll Need On..”

About the Authors

Chapter 1: Understanding MCP Agents: the Golden Opportunity in the AI Era

  1. How the MCP Standard Won the AI Agent Protocol Wars (Before They Could Start)
  2. The Wild Wild West of AI: A Developer’s Nightmare
  3. Well, for Some of Us, We’ve Seen This Movie Before
  4. MCP: The Protocol That Changes Everything
  5. So How Does MCP Work?
  6. Who is Supporting MCP Right Now? Almost Everyone, Really…
  7. MCP: The Technology Disruptor and the Business Model Killer
  8. Conclusion

Chapter 2: Getting Hands-on with MCP Client Applications

  1. ChatGPT Playground
  2. Claude Desktop
  3. Postman
  4. MCP Inspector
  5. Conclusion

Chapter 3: Learning the Basics of MCP Servers

  1. Getting Started with MCP Servers
  2. We Have a Few Terms We Need to Learn First
  3. The Message Protocol is All About What is Sent Between MCP Clients and MCP Servers
  4. MCP Clients and Servers Communicate Over a Common Transport
  5. MCP Tools and Resources: The Core Functionality of Your MCP Server
  6. Prompts Help MCP Clients Understand How to Use the Server’s Tools and Resources
  7. Roots are Great for When You Need to Work with File Systems
  8. Sampling is a Powerful (Yet Underutilized) Technique to Offload Work from Your MCP Server to the MCP Client
  9. Conclusion

Chapter 4: Creating an MCP Server in Python

  1. Getting Started Python and MCP
  2. What We’re Building: A Weather MCP Server
  3. Understanding the Python MCP Ecosystem
  4. Setting Up Your Development Environment
  5. Creating Your First MCP Server
  6. Understanding STDIO Transport (Don’t Skip This Part!)
  7. Adding Tools to Your MCP Server
  8. Creating Prompt Templates to Teach MCP Clients How to Use Your Server
  9. The Complete Server Code
  10. Testing Your Server with the MCP Inspector
  11. Understanding the Request-Response Flow
  12. Project Structure and Package Organization
  13. Extending Your Server: Where to Go from Here
  14. Common Pitfalls and How to Avoid Them
  15. Conclusion

Chapter 5: Creating an MCP Server in Java

  1. Understanding the MCP Java SDK (Version 0.10.0)
  2. Creating Your First Java MCP Server: The Dependencies
  3. The Imports: Getting Acquainted with the MCP Packages
  4. Setting Up the Transport: Your Server’s Communication Channel
  5. Building the MCP Server: The Builder Pattern to the Rescue
  6. Creating Your First Tool: The get_weather Tool
  7. Handling Tool Parameters: Extracting and Validating Input
  8. Implementing the Business Logic: Getting Weather Data
  9. Creating Prompts: Helping AI Models Use Your Tools Effectively
  10. Putting It All Together: The Complete Weather MCP Server
  11. Building and Running Your Server
  12. Testing Your Server with Postman
  13. Testing with Claude Desktop
  14. Common Gotchas and How to Avoid Them
  15. What About Resources? Do We Need Them?
  16. Extending Your Server: Next Steps
  17. Performance Considerations for Production
  18. The Verbosity Trade-off: Why Java’s Explicitness Matters
  19. Conclusion

Chapter 6: Creating an MCP Server in Node.js

  1. Why TypeScript for Node.js MCP Servers?
  2. Setting Up Your Node.js MCP Project
  3. Configuring TypeScript for MCP Development
  4. Understanding the Dependencies and Imports
  5. Creating the MCP Server Instance
  6. Defining Tools with Zod Schema Validation
  7. Why Hardcoded Weather Data?
  8. Adding Prompts to Guide AI Interactions
  9. Setting Up the STDIO Transport
  10. Handling Graceful Shutdown
  11. Building and Running Your MCP Server
  12. Configuring Claude Desktop to Use Your MCP Server
  13. Understanding the STDIO Communication Flow
  14. Testing Your MCP Server with Claude Desktop
  15. Common Pitfalls and How to Avoid Them
  16. Extending Your MCP Server
  17. Conclusion

Chapter 7: Talking to Your Database Without Writing a Single Line of Code

  1. Your CIO Just Walked Into Your Office
  2. Spoiler Alert: You Shouldn’t
  3. The PostgreSQL MCP Server Landscape: Pick Your Flavor
  4. Setting Up Your PostgreSQL MCP Server: Prerequisites
  5. Configuring Claude Desktop to Talk to Your Database
  6. Building a Realistic Database: The Shoe Store Scenario
  7. Your First Conversation with the Database
  8. Asking Better Questions: Moving Beyond Simple Counts
  9. The “Holy Grail” Moment: Visualizations on Demand
  10. A Realistic Workflow: Ten Questions, Ten Answers
  11. Understanding the Tools Behind the Magic
  12. The Ramifications: A New Generation of Applications
  13. Security Considerations: Don’t Skip This Part
  14. Troubleshooting Common Issues
  15. Beyond Basic Queries: Advanced Capabilities
  16. The Economics of Not Building Software
  17. Practical Deployment Considerations
  18. Looking Forward: The Future of Database Interaction
  19. Wrapping Up: From Months to Minutes

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

Now, this is technically risky for us, since you'll have the book or course files either way. But we're so confident in our products and services, and in our authors and readers, that we're happy to offer a full money back guarantee for everything we sell.

You can only find out how good something is by trying it, and because of our 100% money back guarantee there's literally no risk to do so!

So, there's no reason not to click the Add to Cart button, is there?

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earned over $14 million writing, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub