This MCP server has been refactored with clean separation of concerns to support multiple deployment scenarios:
- Local development with IDE integration (STDIO transport)
- Production deployment on Kubernetes with authentication (Streamable HTTP transport)
- Stateful (session-based) and stateless (horizontally scalable) modes
Location: src/core/redshift-tools.ts
Pure business logic with no transport or MCP awareness:
- Database connection management
- Query execution (read-only transactions)
- Schema introspection
- PII redaction
- Table statistics
Key Class: RedshiftTools
const tools = new RedshiftTools(databaseUrl);
await tools.query("SELECT * FROM table");
await tools.describeTable("schema", "table");
await tools.findColumn("pattern");Location: src/mcp/server.ts
Transport-agnostic MCP protocol implementation:
- Tool registration (query, describe_table, find_column)
- Resource registration (schemas, tables, samples, statistics)
- Request schema validation using Zod
- Error handling
Key Function: createRedshiftMcpServer(databaseUrl: string): Server
Location: src/transports/stdio.ts
Simple wrapper for standard input/output communication:
await runStdioTransport(mcpServer);Used by: Claude Desktop, Cursor IDE, Windsurf
Location: src/transports/streamable-http.ts
Full HTTP server with:
- POST
/mcp- Client sends messages to server - GET
/mcp- Client opens SSE stream for server messages - DELETE
/mcp- Client terminates session - GET
/health- Health check - GET
/ready- Readiness probe (K8s)
Key Class: StreamableHttpTransportManager
Features:
- Session management (stateful mode)
- Stateless mode for horizontal scaling
- Event resumability (reconnection support)
- CORS configuration
- Security headers
- Request logging
- Graceful shutdown
Location: src/middleware/auth.ts
Authentication middleware for production deployments:
- Bearer token authentication
- Skips auth for health/ready endpoints
- Returns proper JSON-RPC error responses
Future: Can be extended for OAuth support using MCP SDK
Location: src/index.ts
Orchestrates everything:
- Loads configuration from environment
- Creates MCP server instance
- Selects transport based on
TRANSPORT_MODE - Applies middleware (if enabled)
- Starts the appropriate transport
IDE/CLI → STDIN → StdioTransport → MCP Server → RedshiftTools → Redshift
↓
IDE/CLI ← STDOUT ← StdioTransport ← MCP Server ← RedshiftTools ← Query Results
Client → POST /mcp (InitializeRequest) → Create Transport + Session → MCP Server
↓
Client ← Response with Mcp-Session-Id ← Transport ← MCP Server ← RedshiftTools
Client → POST /mcp (with session ID) → Reuse Transport → MCP Server → RedshiftTools
↓
Client ← JSON Response ← Transport ← MCP Server ← RedshiftTools ← Query Results
Client → GET /mcp (with session ID) → SSE Stream → Server-initiated messages
Client → POST /mcp (InitializeRequest) → Create Ephemeral Transport → MCP Server
↓
Client ← Response (no session ID) ← Transport (destroyed) ← MCP Server ← Results
(Next request creates new transport from scratch)
src/
├── index.ts # Application entry point
├── core/
│ └── redshift-tools.ts # Business logic layer
├── mcp/
│ └── server.ts # MCP protocol layer
├── transports/
│ ├── stdio.ts # STDIO transport
│ └── streamable-http.ts # HTTP transport manager
└── middleware/
└── auth.ts # Authentication middleware
All configuration via environment variables (see .env.example):
| Variable | Purpose | Default |
|---|---|---|
DATABASE_URL |
Redshift connection | Required |
TRANSPORT_MODE |
Transport type | stdio |
PORT |
HTTP server port | 3000 |
STATELESS_MODE |
Enable stateless | false |
ENABLE_RESUMABILITY |
Enable reconnection | false |
ENABLE_AUTH |
Enable auth | false |
API_TOKEN |
Bearer token | - |
ALLOWED_ORIGINS |
CORS origins | * |
export DATABASE_URL="redshift://..."
npm startUsed in .cursor/mcp.json or Windsurf config.
export TRANSPORT_MODE="http"
export DATABASE_URL="redshift://..."
npm run start:httpFor testing with MCP Inspector or browser clients.
env:
- name: TRANSPORT_MODE
value: "http"
- name: STATELESS_MODE
value: "true"
- name: ENABLE_AUTH
value: "true"
- name: API_TOKEN
valueFrom: { secretKeyRef: ... }
- name: DATABASE_URL
valueFrom: { secretKeyRef: ... }Horizontal scaling with load balancer.
env:
- name: TRANSPORT_MODE
value: "http"
- name: STATELESS_MODE
value: "false"
- name: ENABLE_RESUMABILITY
value: "true"
- name: ENABLE_AUTH
value: "true"Requires sticky sessions on load balancer.
- Separation of Concerns: Each layer has single responsibility
- Transport Agnostic: Core logic works with any transport
- Testable: Business logic can be unit tested independently
- Extensible: Easy to add new transports or middleware
- Production Ready: Security, health checks, graceful shutdown
- Spec Compliant: Follows MCP Streamable HTTP specification
- ✅ Same codebase for all deployment scenarios
- ✅ Easy to test (mock database, mock transport)
- ✅ Clear boundaries between layers
- ✅ Future-proof (OAuth, new transports, etc.)
- ✅ Horizontally scalable (stateless mode)
- ✅ Production-ready (auth, monitoring, K8s support)