Express MCP Server
A clean, modular implementation of the Model Context Protocol (MCP) using Express.js and TypeScript.
Quick Start
Server runs on http://localhost:3001
Endpoints
Health:
GET /mcp/health- Server health statusInfo:
GET /mcp/info- Server information and capabilitiesMCP Protocol:
POST/GET/DELETE /mcp- Main MCP endpoints with streaming support
Project Structure
Total: 201 lines of focused, readable code
Architecture
Single Responsibility Principle
Each module has one clear purpose:
index.ts(10 lines) - Server startupapp.ts(20 lines) - Express setupserver/mcp.ts(60 lines) - MCP protocol handlingroutes/mcp.ts(69 lines) - HTTP routingtools/index.ts(42 lines) - Tool catalog
Features
✓ Official MCP SDK integration (StreamableHTTPServerTransport)
✓ HTTP streaming (chunked encoding + Server-Sent Events)
✓ Session management with automatic UUID generation
✓ Zod schema validation for tool inputs
✓ Comprehensive error handling
✓ Health check and info endpoints
✓ TypeScript strict mode
Tools
Three example tools are included:
add(a, b) - Add two numbers
multiply(x, y) - Multiply two numbers
echo(message) - Echo a message
Adding a New Tool
Edit src/tools/index.ts and add to the array:
Then rebuild:
Testing
Development
Environment Variables
PORT(default: 3001) - Server port
Stack
Express.js - Web framework
TypeScript - Type safety
Zod - Schema validation
MCP SDK - Protocol implementation
Node.js 18+ - Runtime
Standards
MCP Protocol Version: 2024-11-05
HTTP Streaming: Chunked encoding + SSE
Schema Validation: Zod
Code Format: TypeScript with strict mode
Code Style: Tabs, consistent formatting
Documentation
ARCHITECTURE.md - Detailed architecture overview
QUICK_START.md - 5-minute setup guide
COMMANDS.md - Command reference
REFACTORING_SUMMARY.md - Development history
License
MIT