MCP Server: The Complete Architecture and Setup Guide for Developers (2026)
Integrating Large Language Models (LLMs) into real-world software development workflows requires connecting AI models to external data sources, developer tools, and live runtime environments.
Historically, connecting an LLM to a tool required writing bespoke function calling schemas, managing custom authentication headers, and parsing custom JSON outputs for every single service.
The Model Context Protocol (MCP), open-sourced by Anthropic, has fundamentally transformed this landscape. Described as the "USB-C of AI integrations", MCP provides a standardized protocol for AI models to discover and interact with external resources, tools, and prompts.
In this architectural guide, you will learn the core primitives of MCP, how MCP servers work under the hood, and how to build and configure custom MCP servers for your development stack.
1. The Core Architecture of Model Context Protocol (MCP)
MCP follows a strict Client-Server-Host Architecture powered by JSON-RPC 2.0:
┌─────────────────────────────────────────────────────────┐
│ MCP Host (e.g. Claude Desktop, Cursor)│
│ ┌───────────────────────┐ ┌────────────────────────┐ │
│ │ LLM Reasoning Core │ │ MCP Client Manager │ │
│ └───────────┬───────────┘ └───────────┬────────────┘ │
└──────────────┼───────────────────────────┼──────────────┘
│ │ (JSON-RPC 2.0 / stdio / SSE)
▼ ▼
┌─────────────────────────────────────────────────────────┐
│ MCP Server │
│ ┌──────────────────┐ ┌────────────────┐ ┌──────────┐ │
│ │ Resources (Data) │ │ Tools (Action) │ │ Prompts │ │
│ └────────┬─────────┘ └───────┬────────┘ └────┬─────┘ │
└───────────┼────────────────────┼────────────────┼───────┘
│ │ │
▼ ▼ ▼
Local Filesystem Postgres DB GitHub API
The 3 Core Primitives of MCP:
- Resources (Passive Context): Read-only data streams that provide background context (e.g., local files, database schemas, log outputs).
- Tools (Active Execution): Executable functions with JSON schemas that allow the LLM to take real-world actions (e.g., executing
git commit, querying SQL databases, making HTTP requests). - Prompts (Interaction Templates): Pre-defined prompt workflows designed to guide the AI through multi-step engineering tasks.
2. Why MCP Is a Game-Changer for Developers
Before MCP, if you wanted your AI coding assistant to query your PostgreSQL database, search your Jira tickets, and audit your GitHub pull requests, you had to write three custom integrations.
With MCP:
- Zero Custom Glue Code: You install standard open-source MCP servers for PostgreSQL, GitHub, and Jira.
- Model Agnostic: Works across Claude, Cursor, ChatGPT, and local models.
- Strict Security Boundaries: MCP servers declare explicit tool capabilities and permissions, giving developers fine-grained control over what files or databases the AI can touch.
3. Step-by-Step: Building a Custom MCP Server in TypeScript
Here is how to create a lightweight MCP server that exposes codebase analysis tools using the official @modelcontextprotocol/sdk:
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import {
CallToolRequestSchema,
ListToolsRequestSchema,
} from "@modelcontextprotocol/sdk/types.js";
import fs from "fs";
const server = new Server(
{ name: "codebase-helper", version: "1.0.0" },
{ capabilities: { tools: {} } }
);
// 1. Declare Available Tools
server.setRequestHandler(ListToolsRequestSchema, async () => {
return {
tools: [
{
name: "read_package_manifest",
description: "Read and parse package.json from the project root",
inputSchema: {
type: "object",
properties: {
path: { type: "string", description: "Path to package.json" }
},
required: ["path"]
}
}
]
};
});
// 2. Execute Tool Calls
server.setRequestHandler(CallToolRequestSchema, async (request) => {
if (request.params.name === "read_package_manifest") {
const filePath = String(request.params.arguments?.path || "package.json");
const content = fs.readFileSync(filePath, "utf8");
return { content: [{ type: "text", text: content }] };
}
throw new Error("Tool not found");
});
// 3. Connect via Standard I/O Transport
const transport = new StdioServerTransport();
await server.connect(transport);
4. Configuring MCP in Claude Desktop and Cursor
To connect your custom MCP server to Claude Desktop, add the following configuration to claude_desktop_config.json:
{
"mcpServers": {
"codebase-helper": {
"command": "node",
"args": ["/absolute/path/to/build/index.js"]
},
"postgres": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-postgres", "postgresql://localhost/mydb"]
}
}
}
6. Remote MCP Servers via Server-Sent Events (SSE)
While local MCP servers communicate via standard input/output (stdio), enterprise environments often deploy remote MCP servers hosted on Kubernetes, AWS Lambda, or Cloudflare Workers.
Remote MCP servers utilize Server-Sent Events (SSE) for real-time bidirectional streaming:
// Remote MCP SSE Transport Example
import express from "express";
import { SSEServerTransport } from "@modelcontextprotocol/sdk/server/sse.js";
const app = express();
let transport: SSEServerTransport;
app.get("/sse", async (req, res) => {
transport = new SSEServerTransport("/messages", res);
await server.connect(transport);
});
app.post("/messages", async (req, res) => {
await transport.handlePostMessage(req, res);
});
app.listen(3001, () => console.log("Remote MCP Server running on port 3001"));
7. MCP Security Best Practices for Development Teams
Connecting AI assistants to real tools requires strict security controls:
- Read-Only by Default: Limit filesystem and database MCP servers to read-only permissions unless the task explicitly requires write access.
- Path Sanitization: Validate that file paths remain within the designated project root to prevent directory traversal attacks (
../../). - Secret Redaction: Ensure MCP database servers filter out password columns, JWT secrets, and payment tokens before streaming records back to the LLM.
8. Summary & Next Steps
- Use standard MCP servers to connect AI coding tools to databases and APIs.
- Combine RepoBox Repo2Txt for zero-latency codebase grounding with MCP servers for dynamic tool execution.
- Enforce read-only permissions on sensitive enterprise data stores.