All open source labs

Open Source

mcp-rds-jumphost

mcp-rds-jumphost — a free open source hands-on lab from AWS Fundamentals. Get your hands dirty with AWS services.

Shell1 stars

MCP RDS Jumphost

Secure Claude Code connection to RDS PostgreSQL via AWS Session Manager port forwarding.

This repository demonstrates how to set up a secure, private RDS PostgreSQL database that Claude Code can query through an MCP (Model Context Protocol) server, without exposing any public endpoints.

Architecture

┌─────────────────────────────────────────────────────────────────────────────┐
│                                   AWS VPC                                   │
│                          (Private Isolated Subnets)                         │
│                                                                             │
│  ┌─────────────────────────────────────────────────────────────────────┐   │
│  │                        VPC Endpoints                                 │   │
│  │              (ssm, ssmmessages, ec2messages)                        │   │
│  └─────────────────────────────────────────────────────────────────────┘   │
│                                    │                                        │
│                                    │ HTTPS (443)                            │
│                                    ▼                                        │
│  ┌──────────────────────┐    ┌──────────────────────┐                      │
│  │   EC2 Jumphost       │    │   RDS PostgreSQL     │                      │
│  │   (t4g.micro)        │───▶│   (db.t4g.micro)     │                      │
│  │                      │5432│                      │                      │
│  │   - Amazon Linux 2023│    │   - PostgreSQL 16    │                      │
│  │   - SSM Agent        │    │   - Encrypted        │                      │
│  │   - No SSH Key       │    │   - Private only     │                      │
│  └──────────────────────┘    └──────────────────────┘                      │
│            ▲                                                                │
│            │ SSM Session Manager                                            │
│            │ Port Forwarding                                                │
└────────────┼────────────────────────────────────────────────────────────────┘
             │
             │
┌────────────┼────────────────────────────────────────────────────────────────┐
│            │                    Local Machine                               │
│            ▼                                                                │
│  ┌──────────────────────┐    ┌──────────────────────┐                      │
│  │   SSM Tunnel         │    │   MCP Server         │                      │
│  │   localhost:5432 ────┼───▶│   (@mcp/postgres)    │                      │
│  └──────────────────────┘    └──────────────────────┘                      │
│                                       │                                     │
│                                       ▼                                     │
│                              ┌──────────────────────┐                      │
│                              │   Claude Code        │                      │
│                              │   (queries DB)       │                      │
│                              └──────────────────────┘                      │
└─────────────────────────────────────────────────────────────────────────────┘

Prerequisites

Tool Installation
AWS CLI v2.x Install Guide
Session Manager Plugin Install Guide
Node.js 18+ nodejs.org
pnpm 8+ pnpm.io
Claude Code claude.ai/code
jq jqlang.org

Quick Start

1. Clone and Install

git clone https://github.com/your-org/mcp-rds-jumphost.git
cd mcp-rds-jumphost
pnpm install

2. Deploy Infrastructure

# Bootstrap CDK (first time only)
pnpm cdk bootstrap

# Deploy the stack
pnpm cdk deploy

3. Seed the Database (Optional)

In a separate terminal, start the tunnel and seed the database:

# Terminal 1: Start the tunnel
./scripts/tunnel.sh

# Terminal 2: Run seed script
./scripts/seed.sh

4. Use with Claude Code

Open Claude Code in the project directory. The .mcp.json is already configured. The MCP server will connect automatically when you ask database-related questions.

Example Prompts

Try these prompts with Claude Code:

  • "List all authors in the database"
  • "Show me all posts with their author names"
  • "How many posts does each author have?"
  • "Find posts published in 2024 sorted by date"
  • "What's the schema of the posts table?"

Scripts

scripts/tunnel.sh

Starts an SSM tunnel to the RDS database (runs in foreground).

Usage:

./scripts/tunnel.sh [STACK_NAME] [LOCAL_PORT]
# Defaults: McpRdsJumphostStack, 5432

scripts/mcp-postgres.sh

Combined script that:

  1. Validates prerequisites (SSM plugin, AWS CLI, jq)
  2. Fetches CloudFormation outputs
  3. Retrieves database credentials from Secrets Manager
  4. Starts SSM tunnel in background
  5. Launches MCP PostgreSQL server

Usage:

./scripts/mcp-postgres.sh [STACK_NAME] [LOCAL_PORT]
# Defaults: McpRdsJumphostStack, 5432

scripts/seed.sh

Seeds the database with sample blog data (5 authors, 15 posts).

Usage:

./scripts/seed.sh [STACK_NAME] [LOCAL_PORT]

Requires: Active tunnel on the specified port and psql client installed.

Security

  • All resources in private isolated subnets, no public IPs
  • No SSH keys — access via Session Manager only
  • SSM connectivity through private VPC endpoints
  • RDS storage encrypted at rest
  • Database credentials stored in Secrets Manager
  • RDS only accepts connections from the jumphost security group

Cost Estimate

Running this infrastructure costs approximately ~$40/month:

Resource Estimated Cost
EC2 t4g.micro ~$6/month
RDS db.t4g.micro ~$12/month
VPC Endpoints (3x) ~$22/month
Total ~$40/month

Important: Remember to destroy the stack when not in use to avoid ongoing charges. VPC endpoints are particularly costly if left running.

Cleanup

To delete all resources and stop incurring costs:

pnpm cdk destroy

This will remove:

  • VPC and all subnets
  • VPC Endpoints
  • EC2 jumphost
  • RDS instance (data will be lost)
  • Security groups
  • IAM roles
  • Secrets Manager secret

Project Structure

mcp-rds-jumphost/
├── bin/
│   └── mcp-rds-jumphost.ts    # CDK app entry point
├── lib/
│   └── mcp-rds-jumphost-stack.ts  # Main CDK stack
├── scripts/
│   ├── tunnel.sh              # SSM tunnel to RDS
│   ├── mcp-postgres.sh        # MCP server launcher
│   └── seed.sh                # Database seeder
├── .mcp.json                     # MCP server configuration
├── package.json
├── tsconfig.json
├── cdk.json
└── README.md

License

MIT License - see LICENSE for details.

Looking for more hands-on labs?

Everything we build in the open — CLIs, libraries, and infrastructure snippets.

Browse all repositories →