Skip to content

Commit 8dae861

Browse files
committed
blog
1 parent 59afc14 commit 8dae861

File tree

2 files changed

+316
-0
lines changed

2 files changed

+316
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,6 @@ dist
129129
.yarn/build-state.yml
130130
.yarn/install-state.gz
131131
.pnp.*
132+
133+
# Claude Code
134+
.claude/

blog-post.md

Lines changed: 313 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,313 @@
1+
---
2+
title: "Building Scalable AI Integration with the MCP Everything Server"
3+
date: 2025-08-12
4+
author: "MCP Team"
5+
tags: ["MCP", "Model Context Protocol", "AI", "Architecture", "Tutorial"]
6+
---
7+
8+
# Building Scalable AI Integration with the MCP Everything Server
9+
10+
The Model Context Protocol (MCP) is revolutionizing how AI applications interact with external systems. Today, we're diving deep into the **MCP Everything Server** – a production-ready reference implementation that showcases every feature of the MCP specification while demonstrating enterprise-grade scalability patterns.
11+
12+
Whether you're building your first MCP integration or architecting a distributed AI system, this comprehensive implementation serves as both a learning tool and a production blueprint.
13+
14+
## What is the MCP Everything Server?
15+
16+
The MCP Everything Server is an open-source, horizontally-scalable implementation that demonstrates the complete Model Context Protocol specification. Unlike minimal examples that show isolated features, this server integrates everything – tools, resources, prompts, sampling, authentication, and multiple transport methods – into a cohesive, production-ready system.
17+
18+
### Why "Everything"?
19+
20+
The name isn't hyperbole. This server implements:
21+
- **All 7 core MCP tool patterns** including long-running operations and LLM sampling
22+
- **100 example resources** with real-time subscriptions
23+
- **Complete OAuth 2.0 authentication** with PKCE support
24+
- **Both modern and legacy transports** (Streamable HTTP and SSE)
25+
- **Horizontal scaling** via Redis-backed session management
26+
- **Enterprise security features** including CSP headers and session isolation
27+
28+
## Real-World Use Cases
29+
30+
### 1. Learning and Understanding MCP
31+
32+
**Who it's for:** Developers new to MCP or those wanting to understand advanced patterns
33+
34+
The Everything Server is the ultimate learning resource. Unlike documentation that explains concepts in isolation, here you can see how all MCP features work together in a real system.
35+
36+
For example, you can trace how a tool invocation flows through the authentication layer, gets routed via Redis pub/sub, executes in the MCP server, and returns results through either Streamable HTTP or SSE transport. Every pattern recommended in the MCP specification is implemented here.
37+
38+
### 2. Reference Architecture for Production Systems
39+
40+
**Who it's for:** Teams building production MCP servers
41+
42+
Starting a production MCP implementation from scratch? The Everything Server provides battle-tested patterns for:
43+
- **Session management** that survives server restarts
44+
- **Horizontal scaling** across multiple instances
45+
- **Security implementation** with proper OAuth flows
46+
- **Error handling** and structured logging
47+
- **Message routing** through distributed systems
48+
49+
Teams can fork this repository and replace the example tools and resources with their domain-specific implementations while keeping the robust infrastructure intact.
50+
51+
### 3. Testing and Development Environment
52+
53+
**Who it's for:** Client application developers
54+
55+
Developing an MCP client? You need a full-featured server for testing. The Everything Server provides:
56+
- **Predictable test data** with 100 numbered resources
57+
- **Various tool behaviors** from simple echo to long-running operations
58+
- **Error scenarios** for testing client resilience
59+
- **Multiple transport options** to test compatibility
60+
- **Authentication flows** for security testing
61+
62+
The fake OAuth provider means you can test authentication flows without external dependencies.
63+
64+
### 4. Integration Testing Platform
65+
66+
**Who it's for:** QA teams and CI/CD pipelines
67+
68+
The server's comprehensive test suite (unit, integration, and multi-user tests) demonstrates how to properly test MCP implementations. The included test utilities can be adapted for your own testing needs, and the server itself can be containerized for use in CI/CD pipelines.
69+
70+
### 5. Distributed System Blueprint
71+
72+
**Who it's for:** Architects designing scalable AI systems
73+
74+
The Redis-backed architecture demonstrates how to build stateless MCP servers that can scale horizontally. This pattern is essential for:
75+
- **High-availability deployments** where any server can handle any request
76+
- **Load-balanced environments** with multiple server instances
77+
- **Microservices architectures** where MCP is one component
78+
- **Cloud-native deployments** with auto-scaling
79+
80+
## Step-by-Step Getting Started Guide
81+
82+
Let's get the MCP Everything Server running on your machine. We'll go from zero to a fully functional MCP server with authentication in about 10 minutes.
83+
84+
### Prerequisites
85+
86+
Before starting, ensure you have:
87+
- **Node.js 16 or higher** (check with `node --version`)
88+
- **npm or yarn** (comes with Node.js)
89+
- **Redis server** (we'll show you how to install this)
90+
- **Git** for cloning the repository
91+
92+
### Step 1: Install Redis
93+
94+
Redis is essential for the server's session management and message routing.
95+
96+
**On macOS:**
97+
```bash
98+
brew install redis
99+
brew services start redis
100+
```
101+
102+
**On Ubuntu/Debian:**
103+
```bash
104+
sudo apt update
105+
sudo apt install redis-server
106+
sudo systemctl start redis
107+
```
108+
109+
**On Windows:**
110+
Use WSL2 or Docker:
111+
```bash
112+
docker run -d -p 6379:6379 redis:latest
113+
```
114+
115+
Verify Redis is running:
116+
```bash
117+
redis-cli ping
118+
# Should return: PONG
119+
```
120+
121+
### Step 2: Clone and Setup the Repository
122+
123+
```bash
124+
# Clone the repository
125+
git clone https://github.com/modelcontextprotocol/example-remote-server.git
126+
cd example-remote-server
127+
128+
# Install dependencies
129+
npm install
130+
```
131+
132+
### Step 3: Configure Environment
133+
134+
Create your environment configuration:
135+
136+
```bash
137+
# Copy the example environment file
138+
cp .env.example .env
139+
```
140+
141+
Edit `.env` with your preferred editor:
142+
```bash
143+
PORT=3232 # Server port
144+
BASE_URI=http://localhost:3232 # Base URI for OAuth redirects
145+
REDIS_HOST=localhost # Redis server host
146+
REDIS_PORT=6379 # Redis server port
147+
REDIS_PASSWORD= # Leave empty for local Redis
148+
```
149+
150+
### Step 4: Start the Development Server
151+
152+
```bash
153+
# Start with hot-reload for development
154+
npm run dev
155+
```
156+
157+
You should see:
158+
```
159+
MCP Everything Server listening on port 3232
160+
Redis client connected
161+
```
162+
163+
### Step 5: Verify the Server is Running
164+
165+
Open a new terminal and test the server:
166+
167+
```bash
168+
# Check the server is responding
169+
curl http://localhost:3232/health
170+
171+
# You should see: {"status":"ok"}
172+
```
173+
174+
### Step 6: Explore the OAuth Flow
175+
176+
The server includes a fake OAuth provider for testing. Open your browser and navigate to:
177+
178+
```
179+
http://localhost:3232/fakeupstreamauth/authorize?client_id=test&redirect_uri=http://localhost:3232/oauth/callback
180+
```
181+
182+
This simulates the OAuth flow without external dependencies.
183+
184+
### Step 7: Run the Test Suite
185+
186+
Understand the server's capabilities by running tests:
187+
188+
```bash
189+
# Run all tests
190+
npm test
191+
192+
# Run specific test suites
193+
npm test -- --testNamePattern="session ownership"
194+
```
195+
196+
### Step 8: Monitor Real-Time Activity
197+
198+
Open a new terminal to watch Redis activity:
199+
200+
```bash
201+
# Monitor all Redis commands in real-time
202+
redis-cli MONITOR | grep "mcp:"
203+
```
204+
205+
Keep this running while you interact with the server to see message flow.
206+
207+
### Step 9: Explore with Development Tools
208+
209+
The `scratch/` directory contains helpful development scripts:
210+
211+
```bash
212+
# Test OAuth flows
213+
./scratch/oauth.sh
214+
215+
# Run a simple test client
216+
node scratch/simple-test-client.js
217+
218+
# Debug MCP message flows
219+
./scratch/debug-mcp-flow.sh
220+
```
221+
222+
### Step 10: Connect Your MCP Client
223+
224+
Now you're ready to connect your MCP client application. Use these connection details:
225+
226+
- **Endpoint:** `http://localhost:3232/mcp`
227+
- **Transport:** Streamable HTTP (recommended) or SSE at `/sse`
228+
- **Authentication:** Bearer token from OAuth flow
229+
230+
Example client connection (using MCP SDK):
231+
```javascript
232+
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
233+
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
234+
235+
const transport = new StreamableHTTPClientTransport({
236+
url: "http://localhost:3232/mcp",
237+
headers: {
238+
Authorization: `Bearer ${yourAccessToken}`
239+
}
240+
});
241+
242+
const client = new Client({
243+
name: "my-client",
244+
version: "1.0.0"
245+
});
246+
247+
await client.connect(transport);
248+
```
249+
250+
### Troubleshooting Common Issues
251+
252+
**Redis connection errors:**
253+
- Ensure Redis is running: `redis-cli ping`
254+
- Check Redis port isn't blocked by firewall
255+
- Verify REDIS_HOST and REDIS_PORT in `.env`
256+
257+
**Port already in use:**
258+
- Change PORT in `.env` to another value (e.g., 3233)
259+
- Or find and stop the process using port 3232
260+
261+
**Authentication failures:**
262+
- The fake auth provider uses localStorage in the browser
263+
- Clear browser cache if seeing unexpected user IDs
264+
- Check bearer token is properly formatted
265+
266+
## Architecture Deep Dive
267+
268+
The Everything Server's architecture is designed for production scalability:
269+
270+
### Stateless Server Design
271+
Every server instance is stateless – session state lives in Redis, not memory. This means:
272+
- Servers can be added or removed without losing sessions
273+
- Load balancers can route requests to any instance
274+
- Zero-downtime deployments are possible
275+
276+
### Redis as the Backbone
277+
Redis serves three critical functions:
278+
1. **Session state storage** with automatic TTL expiration
279+
2. **Pub/sub message routing** between client connections and MCP servers
280+
3. **Connection tracking** via subscription counts
281+
282+
### Security-First Approach
283+
- OAuth 2.0 with PKCE prevents token interception
284+
- Session ownership ensures user isolation
285+
- Security headers protect against common web vulnerabilities
286+
- Structured logging sanitizes sensitive data
287+
288+
## Next Steps
289+
290+
Now that you have the Everything Server running:
291+
292+
1. **Explore the codebase:** Start with `src/services/mcp.ts` to understand tool implementations
293+
2. **Modify tools:** Replace example tools with your domain-specific functionality
294+
3. **Test scaling:** Spin up multiple instances and verify session sharing
295+
4. **Build your client:** Use the server to develop and test your MCP client application
296+
5. **Deploy to production:** Containerize and deploy to your cloud platform
297+
298+
## Resources
299+
300+
- [MCP Specification](https://modelcontextprotocol.io/specification)
301+
- [MCP Documentation](https://modelcontextprotocol.io)
302+
- [TypeScript SDK](https://github.com/modelcontextprotocol/typescript-sdk)
303+
- [Everything Server Repository](https://github.com/modelcontextprotocol/example-remote-server)
304+
305+
## Conclusion
306+
307+
The MCP Everything Server is more than just example code – it's a production-ready foundation for building scalable AI integrations. Whether you're learning MCP, building a production server, or testing client applications, this comprehensive implementation provides the patterns and infrastructure you need.
308+
309+
Start with the Everything Server today and build the next generation of AI-powered applications with confidence.
310+
311+
---
312+
313+
*The MCP Everything Server is open source and welcomes contributions. Join us in building the future of AI integration at [github.com/modelcontextprotocol/example-remote-server](https://github.com/modelcontextprotocol/example-remote-server).*

0 commit comments

Comments
 (0)