The MCP Standard: A Developer's Guide to Building Universal Al Tools with the Model Context Protocol

The MCP Standard: A Developer's Guide to Building Universal Al Tools with the Model Context Protocol

The MCP Standard: A Developer's Guide to Building Universal Al Tools with the Model Context Protocol
Автор: Sekar Srinivasan
Дата выхода: 2026
Издательство: Apress Media, LLC.
Количество страниц: 246
Размер файла: 1.5 MB
Тип файла: PDF
Добавил: codelibs
 Проверить на вирусы

The MCP Standard....2

Foreword....5

Introduction....7

What This Book Is About....8

Who This Book Is For....9

The Journey Ahead....9

A Word on Philosophy....10

How to Use This Book....10

The Bigger Picture....10

Acknowledgments....13

Table of Contents....14

About the Author....23

About the Technical Reviewers....24

Part I: The Foundation: Why MCP Matters....26

1. The Age of Tooling Chaos....27

The M×N Integration Nightmare....27

A Closer Look at the Pain: Anatomy of the Chaos....29

1. Interfaces....29

2. The Developer’s Cognitive Tax....30

3. The API Treadmill and Technical Debt by Fragmentation....31

4. The Siloed Garden of Innovation....31

Echoes of the Past: Lessons from the Cloud Native Revolution....32

Chapter Summary....33

Key Takeaways....33

2. The Solution: A Universal Language for AI....35

Introducing the Model Context Protocol (MCP)....35

The Monolithic Agent: An Architecture Before MCP....36

The MCP Architecture: The Decoupled Agent....37

The Core Promise: A Standardized Interface for Capabilities....39

1. Tools: Designed for Model Control....39

2. Resources: Designed for Application Control....40

3. Prompts: Designed for User Control....40

Key Benefits of a Unified Approach....41

Analogy: The Universal Translator for AI Agents....42

MCP in the Emerging Agentic Ecosystem: A Look Ahead....43

Chapter Summary....44

Key Takeaways....44

3. MCP and the AI-Native Transformation....45

Learning from History: From Cloud Native to AI Native....45

The Role of Standardization in Technological Waves....47

How MCP Paves the Way for AI-Native Architectures....47

Positioning Your Organization for the Future....48

Chapter Summary....51

Key Takeaways....51

Part II: The Architecture: A Technical Deep Dive....52

4. The MCP Architectural Roles....53

The Host: The Conductor of the AI Orchestra....55

Core Responsibilities of the Host....55

1. Managing the User Experience (the Stage)....55

2. Maintaining Session State (the Director’s Notes)....55

3. Initiating and Configuring Connections (Assembling the Orchestra)....56

4. Governing Capability (The Ultimate Gatekeeper)....56

The Client....56

Core Responsibilities of the Client....57

1. Managing the Connection Lifecycle (Opening Diplomatic Channels)....57

2. Serializing and Deserializing Messages (Translation and Interpretation)....57

3. Dynamic Capability Discovery (Requesting the Menu)....57

The Server: The Specialist in the Workshop....58

Core Responsibilities of the Server....58

1. Advertising Skills (Putting Up a Sign)....58

2. Listening for and Executing Requests (Fulfilling the Order)....58

3. The Range of Servers (from Local Scripts to Enterprise Services)....59

A Complete Interaction Trace....59

Chapter Summary....62

Key Takeaways....62

5. The Language of MCP: Tools, Resources, and Prompts....63

Breaking Down MCP’s Core Capabilities....63

Tools: The Verbs of Action....64

Anatomy of a Tool....64

Advanced Capabilities: ResourceLinks and Server-Side Sampling....66

Resources: The Nouns of Context....68

Prompts: The Grammar of Conversation....70

Summary Table: Tools vs. Resources vs. Prompts....71

Overview of Tools, Resources, and Prompts....71

Chapter Summary....73

Key Takeaways....73

6. Under the Hood: The Protocol Specification....75

The Transport Layer: How Messages Travel....75

1. Standard I/O (stdio)....76

2. Streamable HTTP....76

The Message Format: The Anatomy of a Request....77

The Interaction Flow: A Step-by-Step Sequence....79

Error Handling and Timeouts....80

Chapter Summary....82

Key Takeaways....82

Part III: The Practitioners: Building with MCP....83

7. For the Tool Provider: Creating an MCP Server....84

A Complete, End-to-End Guide to Building the Advanced MCP Server....84

Step 1: Environment Setup....84

Step 2: Create and Populate the Database....86

Step 3: The Server Foundation and Core Logic....87

Step 4: Building Rich, Discoverable Resources....89

Step 5: Implementing Prompts....92

Step 6: Advanced Tool Implementation....95

Tool 1: Listing Tables with Pagination....95

Tool 2: Creating a Table and Notifying the Client....98

Tool 3 and 4: The Admin/Modification Flow (Dynamic Capabilities and Advanced Notifications)....99

Tool 5: Interactive User Creation with Complex Elicitation....103

Step 7: Running the Server....106

Option 1: Running with stdio....106

Option 2: Running with StreamableHTTP....107

Step 8: Testing and Verification....109

Chapter Summary....116

Key Takeaways....116

8. For the AI Application Developer: Building an MCP Client....118

Step 1: Project Scaffolding and Environment Setup....118

Step 2: Defining Schemas and Initializing the Core Components....120

Step 3: The Bidirectional Contract-Handling Server-Initiated Communication....124

Handling Notifications....124

Responding to Server Requests....125

Step 4: Orchestrating the Agent—The Manual Tool-Calling Loop....128

Step 5: Running the End-to-End System and a Guided Interaction....132

Interaction 1: Dynamic Capabilities....133

Interaction 2: Elicitation....133

Interaction 3: Resource Updates....134

Chapter Summary....135

Key Takeaways....135

Part IV: Security and Production Readiness....137

9. The Agentic Threat Landscape....138

A New Paradigm, a New Attack Surface....138

The Lethal Trifecta: A Recipe for Disaster....139

Case Studies in Agentic Failure: Two Real-World Breaches....139

Case Study 1: The GitHub MCP Exploit (the Hijacked Agent)....140

Case Study 2: The Asana Data Leak (the Broken Wall)....141

A New Framework: Securing Flows, Not Just Prompts....142

A Catalog of Agentic Threats....143

Chapter Summary....145

Key Takeaways....145

10. Foundational Security: Authentication with OpenID Connect (OIDC)....147

The Architectural Pattern: The Three Roles of OAuth....147

Understanding OAuth 2.1 vs OpenID Connect (OIDC)....148

Step 1: Configuring the Google Cloud OAuth 2.1 Client for OIDC....149

Step 2: Building the Server-Side OAuth 2.1/OIDC Authentication Flow....150

2.1. Server and Session Setup....150

2.2. The /authorize and /callback Endpoints....150

2.3. The /token Endpoint and PKCE Validation....152

2.4. Protecting and Proxying the MCP Endpoint....152

Step 3: Building the Advanced OAuth/OIDC Client....153

3.1. The HTTPCallbackOAuthMCPClient Class....153

Running the End-to-End System: A Look at the Logs....153

Production Readiness: Analysis and Recommendations....154

Chapter Summary....155

Key Takeaways....155

11. Server-Side Hardening: Mitigating Common Vulnerabilities....156

Vulnerability 1: Excessive Permission Scope....156

The Fundamental Problem....156

The Threat: The Valet with the Master Key....157

Exploit 1: The Unconstrained Log Viewer....157

Attack Vector 1—Implementation Bug (Path Traversal)....157

The Attack....158

Why This Happens....158

Mitigation 1: Fix the Implementation Bug (Application-Level Defense)....159

Why This Works....161

The Hidden Problem: Architectural Flaw....162

Mitigation 2: Fix the Architectural Flaw (Operating System-Level Defense)....163

Dockerfile (Minimal Hardening)....163

Docker Compose (Where the Security Happens)....163

What This Does....164

Proof It Works....164

Why Both Mitigations Are Required....164

Vulnerability 2: Malicious Code Execution....165

The Threat: The Unsandboxed Playground....165

The Exploit: The “Helpful” Report Generator....165

The Mitigation: Never eval( ), Use Safe Interpreters....166

Vulnerability 3: Command Injection....167

The Threat: The Unescaped String....167

The Exploit: The Insecure Diagnostic Tool....168

The Mitigation: Parameterized Execution....169

Chapter Summary....171

Key Takeaways....171

12. LLM-Centric Threats: Injection and Poisoning....172

Vulnerability 1: Prompt Injection (Direct and Indirect)....172

The Threat: The Deceitful Conversation....172

The Exploit: The Poisoned Document....173

The Mitigation: Data/Instruction Separation and Sanitization....174

Vulnerability 2: Tool Poisoning....176

The Threat: The Deceptive Toolmaker....176

The Exploit: The Deceitful Calculator....177

The Mitigation: Host-Side Validation and Sandboxing....179

Chapter Summary....181

Key Takeaways....181

13. Ecosystem and Dynamic Threats....182

Vulnerability 1: Tool Shadowing (Tool Hijacking)....182

The Threat: The Fake Person in the Workshop....182

The Exploit: The Hijacked Email....184

The Mitigation: Namespacing, Prioritization, and Host-Level Defenses....185

1. For Server Developers: Use Namespacing....185

2. For Host Developers: The Critical Defense Layer....186

Vulnerability 2: Rug Pull Attacks....187

The Threat: The Bait-and-Switch....187

The Exploit: The Weather Tool That Spies....187

The Mitigation: Immutable Definitions and Host-Level Auditing....189

Chapter Summary....191

Key Takeaways....191

Part V: The Playbook: A Real-World Case Study....192

14. Deep Dive Case Study: Building an Agentic RAG System....193

Understanding RAG: Grounding LLMs in Reality....193

Agent vs. LLM vs. RAG....193

The Limitation of Basic RAG....194

The Next Evolution: Agentic RAG....194

The Architecture: A Secure, Multi-tool, Agentic System....195

Agentic Design Patterns in Our System....196

Building Blocks of Our AI Agent....196

Tech Stack Analysis....197

Implementation Phase 1: Infrastructure and Data Ingestion....197

Scrape the Documentation....198

Embedding and Upserting the Data....198

Implementation Phase 2: Building the Multi-tool MCP Server....199

Registering the Tools....199

Handling Tool Calls....200

Implementation Phase 3: Building the Agentic Client....202

The System Prompt....202

Processing User Input....202

Bringing It All Together: A Live Execution....203

Step 1: Setup and Data Ingestion....203

Step 2: Server and Client Initialization....204

Step 3: Interactive Session—The Agent in Action....205

Scenario A: Internal Knowledge Success....205

Scenario B: Web Search Fallback....205

Chapter Summary....207

Key Takeaways....207

Part VI: The Horizon: The Future of MCP....208

15. Navigating the Ecosystem: Servers, Clients, and Registries....209

The Server Landscape and the Rise of Registries....209

The Official MCP Registry: An App Store for AI Tools....210

A Tour of the Server Ecosystem....211

The Host and Client Landscape: Where the Magic Happens....213

1. The AI-Powered IDEs: The Developer’s Cockpit....213

2. The Conversational Powerhouses: Desktop Agents....214

3. The Headless and Terminal Clients: For the Power User....215

Chapter Summary....216

Key Takeaways....216

16. The Evolving Ecosystem and What’s Next....217

Introduction: From a Standard to an Ecosystem....217

The Path to a Formal Standard....217

The Growing Adoption: The Network Effect in Action....218

Emerging Patterns and Best Practices....218

Final Thoughts: Your Role in Building a Unified AI Future....219

Appendix A: MCP Resource Compendium....221

Official Protocol Resources....221

Official SDKs and Tools....221

Server Registries and Discovery Platforms....222

Popular MCP Host Applications....222

Security Tools and Resources....223

Appendix B: Glossary of Terms....224

Index....227

Master the art of building feature-rich Model Context Protocol (MCP) servers in TypeScript, by designing decoupled, scalable, and future-proof AI systems that are not locked into a single model vendor. In the world of AI development mired in a chaotic mess of proprietary, incompatible APIs, the Model Context Protocol is the open standard that will become the universal language for AI tools. This book will be your invaluable companion for understanding this solution.

The book takes you on a full, hands-on journey through MCP, looking at it not just as a technical specification but also as a way to help AI-native transformation. It first finds the "why”, the tool's issue — and shows how MCP is the only logical solution. After that, the book goes into deep detail about the protocol's architecture, breaking down the roles of the Host, Client, and Server, and giving you a guide to its main language of Tools, Resources, and Prompts.

Using the official TypeScript SDK, you will learn how to build a full-featured MCP server from scratch. You will learn best practices for everything from schema design with Zod to adding advanced features like elicitation and server-side sampling. The book is unique in its holistic approach. It doesn't just tell you how to do something; it also has a whole section on production readiness and security that talks about the MCP security model, threat landscapes, and client-side hardening.

This book will give developers, architects, and technical leaders not only the tactical skills they need to succeed in the next wave of software development but also the strategic vision they need to do so. By the end of this book, you will not only have learnt how to use the MCP, but you will have gained a deep understanding of MCP in the context of the larger shift from cloud-native to AI-native.

You Will Learn To:

  • Master the art of building feature-rich MCP servers in TypeScript, from basic tools to advanced capabilities like elicitation, resource linking, and server-side sampling.
  • Understand the complete MCP architecture and protocol specification, enabling you to debug complex interactions and build custom clients or servers.
  • Implement a robust, multi-layered security strategy for your MCP deployments, including authentication, authorization, and client-side hardening against common threats.
  • Solve the "M x N" integration problem by designing decoupled, scalable, and future-proof AI systems that are not locked into a single model vendor.
  • Gain a strategic understanding of MCP's role in the broader AI-native transformation, which empowers you to make informed architectural decisions for your organization.

This Book is For:

Software developers, AI engineers, and solutions architects who are creating apps that interface with large language models should read this book.


Похожее:

Список отзывов:

Нет отзывов к книге.