MCP Architecture

Understanding the MCP Architecture

MCP has three main players: the Host (the AI application), the Client (the MCP connector inside the host), and the Server (your code). The host creates MCP clients, each client connects to one server.
typescript
// Architecture Overview
//
// ┌─────────────────────────────────┐
// │         HOST (Claude Desktop)    │
// │                                  │
// │  ┌──────────┐  ┌──────────┐    │
// │  │ MCP      │  │ MCP      │    │
// │  │ Client 1 │  │ Client 2 │    │
// │  └────┬─────┘  └────┬─────┘    │
// │       │              │          │
// └───────┼──────────────┼──────────┘
//         │              │
//    ┌────▼─────┐  ┌────▼─────┐
//    │ MCP      │  │ MCP      │
//    │ Server 1 │  │ Server 2 │
//    │ (GitHub) │  │ (DB)     │
//    └──────────┘  └──────────┘

The Three Capabilities

Every MCP server can expose three types of capabilities. You don't need all three — most servers focus on Tools.
typescript
// 1. TOOLS - Actions the AI can perform
server.tool("create_issue", schema, handler);
// AI calls this to DO something (create, update, delete)

// 2. RESOURCES - Data the AI can read
server.resource("config://app", handler);
// AI reads this to GET information (files, DB records)

// 3. PROMPTS - Reusable templates
server.prompt("code_review", schema, handler);
// Pre-built prompts the user can invoke

Transports

MCP servers communicate with clients over transports. The two main transports are stdio (for local servers) and HTTP with SSE (for remote servers).
typescript
// STDIO Transport - Local servers
// The host spawns your server as a child process
// Communication happens over stdin/stdout
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
const transport = new StdioServerTransport();

// HTTP + SSE Transport - Remote servers
// Server runs on a URL, client connects via HTTP
import { SSEServerTransport } from "@modelcontextprotocol/sdk/server/sse.js";
// Useful for shared servers, cloud deployments

Tip:Start with stdio transport for local development. It's simpler and works great with Claude Desktop. Move to HTTP when you need to deploy remotely.

PreviewTypeScriptRead Only
Copy this code and run it locally with npx tsx server.ts

💬 Got questions? Ask me anything!