Skip to main content

MCP — Model Context Protocol

“A USB-C port for AI applications.”

What Is MCP

MCP (Model Context Protocol) is an open standard protocol for connecting AI applications to external systems. It was created by Anthropic, inspired by Microsoft’s Language Server Protocol (LSP), and is now managed by the Linux Foundation. MCP follows the same design philosophy as LSP: through a standardized protocol layer, it reduces the N x M integration problem to N + M. Official Specification: modelcontextprotocol.io Specification Repository: github.com/modelcontextprotocol/specification Current Protocol Version: 2025-11-25 In Plain Terms: USB-C lets your phone connect to chargers, displays, and flash drives. MCP lets AI applications connect to databases, APIs, file systems, and all kinds of tools. One standard interface to connect everything.

Broad Ecosystem Support

MCP is supported by the following AI applications and development tools:
PlatformRoleDescription
Claude (Anthropic)AI AssistantNative MCP connector support
ChatGPT (OpenAI)AI AssistantMCP server connection support
VS Code (Microsoft)Development ToolCopilot supports MCP servers
CursorDevelopment ToolNative MCP support
Claude CodeCLI ToolNative MCP support

MCP Architecture

Three Participants

MCP is a stateful protocol using a client-server architecture with three core participants:
ParticipantRoleExamples
MCP HostAI application that manages one or more MCP clientsClaude Desktop, VS Code, ChatGPT
MCP ClientInternal component of the Host, maintains a 1:1 connection with one ServerAutomatically created within the Host
MCP ServerProvides tools, data, and prompts to clientsServices you develop

Two-Layer Architecture

LayerResponsibilityProtocols and Technologies
Data LayerDefines message structure and semantics (lifecycle, tools, resources, prompts, sampling, elicitation, logging)JSON-RPC 2.0
Transport LayerDefines communication channels and authenticationstdio / Streamable HTTP / Custom transport

Transport Methods

TransportDescriptionUse Case
stdioServer runs as a child process, communicating via stdin/stdout with newline-delimited messagesLocal process, zero network overhead
Streamable HTTPSingle MCP endpoint; POST sends requests, GET subscribes to SSE streams. Mcp-Session-Id header manages sessionsRemote servers with OAuth authentication support

MCP Core Capabilities (Primitives)

Server-Side Primitives

1. Tools — Model-Controlled Executable functions that AI models autonomously decide when to invoke. Discovered via tools/list, executed via tools/call. Supports inputSchema for defining input parameters, and optional outputSchema for defining structured output.
{
  "name": "weather_current",
  "description": "Get current weather for any city",
  "inputSchema": {
    "type": "object",
    "properties": {
      "location": { "type": "string", "description": "City name" }
    },
    "required": ["location"]
  }
}
2. Resources — Application-Controlled Data sources that provide context to AI applications, identified by URIs (supporting RFC 6570 URI templates). Discovered via resources/list, read via resources/read, with subscription support via resources/subscribe. Resources carry Annotations (audience, priority, lastModified, and other metadata). 3. Prompts — User-Controlled Reusable interaction templates. Discovered via prompts/list, retrieved via prompts/get (with parameterized arguments).

Client-Side Primitives

PrimitivePurposeMethod
SamplingServer requests LLM inference from the Hostsampling/createMessage
RootsInforms the Server of filesystem boundariesroots/list (returns file:// URIs)
ElicitationServer requests information from the userelicitation/request

Content Types

MCP supports five content types, all of which can carry Annotations:
TypeDescription
textText content
imageImages (Base64 or URI)
audioAudio content
resource_linkResource link reference
embedded_resourceEmbedded resource

MCP in Commerce Applications

ScenarioTools Provided by MCP ServerEffect
Product Searchsearch_products(query, category)AI agents can search your product catalog
Inventory Querycheck_inventory(sku)AI agents can check real-time inventory
Order Statusget_order_status(order_id)Customers can check order progress via AI
Return Processingcreate_return(order_id, reason)AI agents can initiate returns for customers
Price Inquiryget_price(sku, quantity)AI agents get real-time quotes (including volume discounts)
Trust Queryotr_verify(domain)AI agents query merchant trust scores

MCP Server Development Workflow

1. Define Tools

Determine which tools your MCP Server will expose. Each tool needs:
  • A name and description (the description directly influences the AI model’s selection decisions)
  • Input parameter JSON Schema (inputSchema)
  • Optional output Schema (outputSchema, defining structured return format)
  • Execution logic

2. Choose an SDK

MCP provides multi-language SDKs:
  • TypeScript/JavaScript: @modelcontextprotocol/sdk
  • Python: mcp
  • Other languages: Implement via JSON-RPC 2.0 directly

3. Implement the Server

// TypeScript MCP Server example scaffold
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";

const server = new McpServer({
  name: "my-commerce-server",
  version: "1.0.0"
});

// Define a tool
server.tool(
  "search_products",
  "Search the product catalog",
  { query: { type: "string" }, category: { type: "string" } },
  async ({ query, category }) => {
    // Call your product database or API
    const results = await searchProducts(query, category);
    return { content: [{ type: "text", text: JSON.stringify(results) }] };
  }
);

// Start the server
server.start();

4. Deploy

  • Local Server: Use stdio transport, runs on the user’s machine
  • Remote Server: Use Streamable HTTP transport, deployed on your server

5. User Connection

Users add your Server connection information in MCP-enabled applications such as Claude, ChatGPT, or VS Code to start using it.

Protocol Lifecycle

An MCP connection has three phases:
1. Initialization
   -> Client sends initialize request, negotiating protocol version and capabilities
   -> Server responds with supported capabilities
   -> Client sends initialized notification to confirm

2. Operation
   -> Client requests tools/list to get available tools
   -> Client calls tools/call to execute specific tools
   -> Server pushes notifications such as tool list changes
   -> Server can request LLM inference via Sampling
   -> Server can request user input via Elicitation

3. Shutdown
   -> Connection terminates, resources are cleaned up

Table of Contents

  1. MCP Core Concepts — Architecture details, participant roles, protocol lifecycle
  2. Data Layer Protocol — JSON-RPC 2.0 message format, capability negotiation
  3. Transport Layer — stdio vs Streamable HTTP, OAuth 2.1 authentication
  4. Building an MCP Server — Complete TypeScript/Python development guide
  5. Commerce MCP Server — MCP Server design patterns for e-commerce
  6. Resources and Prompts — Working with Resources and Prompts
  7. Security and Authentication — OAuth 2.1 integration, PKCE, permission management
  8. Testing and Debugging — MCP Inspector usage guide
  9. Deployment Guide — Local deployment vs remote deployment
  10. Case Studies — MCP Server implementations for different scenarios

AI Prompt: Build a Commerce MCP Server

Help me build a commerce MCP Server.

Preparation:
1. Read the MCP official documentation: https://modelcontextprotocol.io
2. Pay special attention to: /docs/develop/build-server

My requirements:
- Purpose: [product search / inventory query / order management / customer service / other]
- Tech stack: [TypeScript / Python / other]
- Data source: [database / API / files]
- Deployment: [local / remote]

Please output:
1. MCP Server tool design (name, description, input/output for each tool)
2. Complete runnable code
3. Configuration file (connection config for Claude Desktop or other clients)
4. Testing methods
5. Deployment steps
MCP is an actively evolving protocol with ongoing specification updates. This book is based on the official documentation as of April 2026 (protocol version 2025-11-25). Always refer to the latest version at modelcontextprotocol.io.