In-depth MCP Protocol Guide: The Standard Protocol for Connecting AI Agents with Local Tools - XBSTACK

MCP Protocol Boundaries: How to Layer Client, Server, Tools, and Resources

Release Date
2026-04-24
Reading Time
4分钟
Content Size
6,827 chars
MCP 协议
JSON-RPC
AI Agent
Developer Tools
Architecture Design
Laboratory Note

This article documents my real-world experiments in the lab. I believe that building your own digital assets with AI is the ultimate moat for developers.

Quick Answer

  • Break down the MCP protocol by the boundaries of Clients, Servers, Tools, Resources, Prompts, and transport layers. This helps developers build a foundational understanding of protocol layering before diving into SQLite implementation, file gateways, remote deployment, and OAuth security.

Who Should Read This

  • Developers evaluating MCP / JSON-RPC / AI Agent / Developer Tools for production use.
  • Indie builders who need a practical implementation path instead of another generic concept article.
  • Readers comparing architecture trade-offs, risks, tooling boundaries and next actions.

Article Positioning: MCP Protocol Layers and Boundaries

This article is solely responsible for answering the protocol boundaries of MCP: what responsibilities Client, Server, Tools, Resources, Prompts, stdio, and remote transports each bear. For specific code walkthroughs, see MCP Server SQLite Private Data Mounting; for secure file gateways, see MCP File and Data Gateway in Action; for public network deployment, see MCP Streamable HTTP in Action.

Protocol Boundary Review Checklist

After reading this article, you should at least be able to distinguish:

  • The Client is responsible for maintaining context and initiating protocol requests, and should not directly handle business permissions.
  • The Server is responsible for exposing resource and tool manifests, and must enforce permission controls, timeouts, and logging governance.
  • Resources lean toward read-only context, while Tools may produce side effects, meaning they carry different security levels.
  • stdio is suitable for local single-user scenarios; remote team sharing should utilize HTTP transport and authentication layers.
  • MCP is not a universal plugin marketplace; its true value lies in standardization, auditability, and governability.

The Key Point: MCP Defines the Protocol Boundary for AI Calling Local Tools

The value of MCP is not “allowing models to arbitrarily operate on the local machine,” but rather encapsulating local tools, files, databases, and remote services into a discoverable, permission-scoped, and auditable capability manifest. It is well-suited for private database mounting, internal enterprise toolchain integration, and automated code refactoring, but requires pre-designed permissions, logging, timeouts, and isolation boundaries.

  • Suitable Scenarios: Local private database mounting, enterprise-grade internal toolchain integration, automated code refactoring workflows.

What This Guide Covers: Query Intent Locking

  • What is MCP (Model Context Protocol) and why does it matter?
  • How to build a production-grade TypeScript MCP Server from scratch?
  • How to choose between Stdio mode and SSE mode in actual development?
  • How to handle high-concurrency deadlocks and buffer overflows in MCP Servers?
  • How to implement cross-region remote MCP connections via Cloudflare Tunnel?

Who This Guide Is For

  • AI Application Developers: Looking to add powerful local extension capabilities to their applications.
  • Full-Stack Engineers: Want to master the most mainstream AI plugin development standards of 2026.
  • System Architects: Designing the underlying connection protocols for enterprise-grade AI agent platforms.

1. Xiaobai’s Note

There is always a thin layer of mist over Guiyang in the early mornings. Sitting in my “Local Development Environment” studio, I watched Cursor on my screen frantically conversing with my local database via the MCP (Model Context Protocol). I couldn’t help but sigh: In 2026, if you still don’t understand MCP, your collaboration efficiency with AI might still be stuck in the Stone Age. If Agents are the “command center” I build, then MCP is the “USB-C port” of this system. It not only unifies the communication protocol between AI and the external world but also thoroughly breaks down “local data silos.” Today, I will take a practical perspective to deconstruct this underlying protocol that is reshaping the AI ecosystem.

1. MCP: The Underlying Physical Standard for Breaking Data Silos in the AI Era

In the past, AI was like a genius locked in a glass room. If you wanted it to glance at your local financial spreadsheets, you had to manually copy and paste or write an extremely fragile, specific plugin. Now, with MCP, you simply install a standardized “drawer” on the glass room. When AI needs something, it directly requests it through the drawer (protocol request), and you place the data inside (protocol response).

MCP provides a JSON-RPC communication specification between AI models (such as Claude, GPT-4o) and external data sources, ensuring dynamic discovery of capabilities and persistent connections.

2. MCP Client, Server, Tools

  1. MCP Client (Brain Container): The protocol initiator, such as Cursor or Claude Desktop. It is responsible for maintaining context and deciding when to trigger calls.
  2. MCP Server (Protocol Relay): A lightweight process written by developers that encapsulates the actual logic and exposes a capability manifest.
  3. Tools & Resources (Underlying Limbs): Concrete code logic, including executable Tools (e.g., querying a database) and readable Resources (e.g., reading file streams).

3. Comparison: Stdio Transport Mode vs. SSE Transport Mode

DimensionStdio Mode (Standard I/O)SSE Mode (Server-Sent Events)
Connection CostVery low (launches local process directly)Moderate (requires running an HTTP server)
Communication LatencyMinimal (inter-process communication within the system)Depends on network quality
Concurrency CapabilitySuitable for single-user/single-sessionSupports multiple clients connected simultaneously
SecurityNetwork isolation (local only)Requires handling CORS and Token authentication
Use CasesPersonal configurations for Cursor, Claude DesktopEnterprise internal tool libraries, remote NAS mapping

Practical Pitfalls and Error Logs Guide

  1. Error: Stdio Stream Pollution
    • Cause: Your code contains print() or console.log(). These impurities disrupt JSON-RPC communication over Stdio.
    • Solution: All debug logs must be output via stderr (Python’s sys.stderr or TypeScript’s console.error).
  2. Error: Zombie Process Detected
    • Cause: After the client exits abnormally, the MCP Server process is not properly terminated.
    • Solution: Listen for the SIGTERM signal and implement “watchdog” logic. If there is no heartbeat for 5 minutes, execute process.exit(0).
  3. Error: JSON-RPC Buffer Overflow
    • Cause: Attempting to return multi-megabyte files via Resources, which overwhelms the Stdio buffer.
    • Solution: Never return large files through MCP. Instead, extract summaries or use chunked retrieval (RAG).

7. Frequently Asked Questions

Q: Why can’t my Cursor recognize the newly added Tool?

A: Click the Refresh button in the Cursor MCP configuration interface. If it still fails, check whether your function has proper Docstrings. AI models rely heavily on comments to understand tool intent.

Q: How do I secure MCP connections to remote servers?

A: We recommend using Cloudflare Tunnel. Map your local MCP port to an HTTPS domain and configure authentication headers on the client side to achieve secure, controlled remote context injection.

I’ve been diving deep into:

  • The performance of the MCP protocol within large-scale distributed Agent clusters
  • A unified workflow standard for cross-IDE environments (Cursor, Zed, VSCode) based on MCP
  • A custom security gateway solution for MCP using Server-Sent Events (SSE)

If you encounter bizarre protocol errors while building an MCP Server, feel free to leave a comment so we can discuss.

Topic path / MCP

Continue from protocol details to production MCP governance

The MCP hub connects protocol fundamentals, transports, authentication, security, JSON-RPC debugging and production deployment without splitting the search intent across isolated guides.

Next Reading

View Hub →
Xiaobai

Xiaobai

Full-Stack AI Engineer

Xiaobai, a full-stack AI engineer building production Agent systems, product tools and independent software assets.

About Xiaobai & XBSTACK →

Liked this article?
Join the newsletter

Every issue condenses production AI engineering changes, real failures, reproducible experiments, useful tools and new XBSTACK assets. No generic news digest and no filler.

Comments