Blogs

How to Harden Your MCP Server

Mustafa Mokashi

  • 25 Sep 2025
  • 9 min read
Diagram of MCP Server architecture with layered security: outer firewall, authentication and rate limiting, HTTPS encryption, nginx reverse proxy, and monitoring at the core

Model Context Protocol, or MCP, servers have seemingly become the new API server, with many products getting one these days. But these powerful new tools can also leave you exposed if you’re not careful.

Imagine your MCP Server as the front door to your valuable data, InsightFinder or otherwise. Just like you wouldn’t leave your house door unlocked in a busy neighborhood, you shouldn’t leave your server unprotected on the internet. 

This guide will help you understand why security for your MCP server is crucial and how to harden it properly, even if you’re not a security expert. This post is specific to InsightFinder’s MCP server, but the guidance should also apply to any MCP server.

What Could Go Wrong Without MCP Server Security?

Here are some real world scenarios:

Unauthorized users accessing sensitive monitoring data can lead to data theft, while attackers overwhelming your server can cause service disruption and make it unavailable. Compromised systems can result in a significant financial impact due to downtime and lost revenue. Furthermore, unprotected data can expose you to regulatory penalties, leading to compliance violations.

Approaching the security landscape means thinking about how to build the best defense for these kinds of threats. A solid defense  begins with using multiple security layers. Good security works like an onion: use multiple layers of protection, like so.

  1. Outer layer: Network-level protection (firewalls, IP filtering)
  2. Middle layer: Application-level security (authentication, rate limiting)
  3. Inner layer: Data protection (encryption, access controls)
  4. Core: Monitoring and incident response

If one layer fails, others are there to protect you.

Core Security Concepts  for MCP Hardening

Diagram of MCP Server architecture with layered security: outer firewall, authentication and rate limiting, HTTPS encryption, nginx reverse proxy, and monitoring at the core1. Authentication: Proving Who You Are

What it is: Authentication is like showing your ID at a club—proving you’re allowed to enter.

Why it matters: Without authentication, anyone can access your server and your data.

Real-world analogy: Your ATM card (something you have) plus your PIN (something you know) proves you’re authorized to access your bank account.

In MCP Server terms:
API Keys: Like a special password that applications use
Bearer Tokens: Like a temporary access badge
Basic Authentication: Traditional username/password combination

2. Rate Limiting: Controlling the Flow

What it is: Rate limiting is like having a bouncer at a club who only lets in a certain number of people per minute.

Why it matters: Prevents attackers from overwhelming your server with too many requests.

Real-world analogy: A popular restaurant limits how many reservations they take per hour to ensure good service for everyone.

How it works:
– Your server tracks how many requests each user makes
– If someone exceeds the limit (default: 60 requests per minute), they’re temporarily blocked
– Legitimate users are rarely affected; attackers are stopped

3. IP Whitelisting: Controlling Who Can Connect

What it is: Like having a guest list at an exclusive party—only people from approved locations can connect.

Why it matters: Even if someone has your authentication credentials, they can’t connect from unauthorized locations.

When to use:
Internal corporate networks: Only allow connections from office IPs
Partner integrations: Only allow specific business partners to connect
Home office setups: Only allow connections from your home network

4. HTTPS and Encryption: Protecting Data in Transit

What it is: HTTPS is like sending mail in a locked briefcase instead of a transparent envelope.

Why it’s critical: Without HTTPS, everything is sent in plain text that anyone can read.

What gets encrypted:
– Your API keys and passwords
– All data requests and responses
– User credentials and session information

Real-world impact: Without HTTPS, someone on the same Wi-Fi network could steal your credentials just by listening to network traffic.

5. Reverse Proxy (nginx): Your Security Gateway

What nginx is: Think of nginx as a highly trained security guard stationed in front of your building.

Why use nginx instead of direct connections:

The Bouncer Analogy

Imagine your MCP server is a shy, brilliant scientist working in a lab. They’re great at their job but not good at dealing with crowds or troublemakers. nginx is like hiring a professional bouncer to stand at the door:

What the bouncer (nginx) does:
Checks IDs: Verifies visitors before they can enter
Handles crowds: Manages busy periods without overwhelming the scientist
Blocks troublemakers: Stops obvious attackers at the door
Provides directions: Routes visitors to the right place efficiently
Keeps records: Logs who visits and when

Technical benefits:
SSL termination: Handles all encryption/decryption work
Load balancing: Distributes traffic across multiple servers if needed
Request filtering: Blocks malicious requests before they reach your application
Static file serving: Handles documentation and assets efficiently
Compression: Makes responses smaller and faster

Why Not Connect Directly?

Without nginx (direct connection):

Internet → Your MCP Server (vulnerable, overwhelmed)

With nginx (recommended):

Internet → nginx (filters, secures) → Your MCP Server (protected)

Direct connections expose your application server to: – SSL/TLS complexity and vulnerabilities – Direct attacks on your application code – Performance issues under high load – Difficulty implementing security policies

6. CORS: Controlling Browser Access

What CORS is: Cross-Origin Resource Sharing controls which websites can access your server from a web browser.

The security problem: By default, any website could make requests to your server from a user’s browser, potentially stealing data or performing unauthorized actions.

How CORS helps: You explicitly list which websites are allowed to access your server.

Example configuration:

HTTP_CORS_ENABLED=true
HTTP_CORS_ORIGINS=https://your-dashboard.com,https://your-monitoring-app.com

Step-by-Step Implementation for MCP Hardening

Phase 1 – Basic Security (Essential)

Step 1: Enable Authentication – Choose your method based on your needs:

Option A: API Key (Recommended for most users)

# In your .env file
HTTP_AUTH_ENABLED=true
HTTP_AUTH_METHOD=api_key
HTTP_API_KEY=your-very-secure-api-key-here

How to create a secure API key:

# Generate a random 32-character key
openssl rand -base64 32

Option B: Bearer Token (For OAuth integrations)

HTTP_AUTH_ENABLED=true
HTTP_AUTH_METHOD=bearer
HTTP_BEARER_TOKEN=your-bearer-token-here

Option C: Basic Authentication (Simple but less secure)

HTTP_AUTH_ENABLED=true
HTTP_AUTH_METHOD=basic
HTTP_BASIC_USERNAME=admin
HTTP_BASIC_PASSWORD=your-strong-password-here

Step 2: Configure Rate Limiting

# Prevent abuse by limiting requests
HTTP_RATE_LIMIT_ENABLED=true
MAX_REQUESTS_PER_MINUTE=60  # Adjust based on your needs

Choosing the right limit:
– Conservative (30-60): Good for small teams or light usage
– Moderate (100-200): Suitable for medium-sized operations
– High (300+): For high-traffic scenarios or automated systems

Step 3: Set Request Size Limits

# Prevent large payload attacks
MAX_PAYLOAD_SIZE=1048576  # 1MB - adjust as needed

Phase 2: Network Security (Important)

Step 4: Configure IP Whitelisting (If Applicable)

When to use: – Internal corporate deployments – Limited partner access – High-security environments

# Single IP address
HTTP_IP_WHITELIST=192.168.1.100

# Multiple IPs and networks
HTTP_IP_WHITELIST=192.168.1.0/24,10.0.0.100,203.0.113.15

Understanding CIDR notation:
192.168.1.100 = Only this specific IP
192.168.1.0/24 = All IPs from 192.168.1.1 to 192.168.1.254
10.0.0.0/8 = Large corporate network range

Step 5: Setup HTTPS with nginx

Why HTTPS is mandatory:
– Encrypts all communication
– Prevents credential theft
– Required for compliance
– Builds user trust

Quick setup using provided scripts:

For production with a real domain:

sudo ./scripts/setup-https.sh your-domain.com 8000

For local testing:

sudo ./scripts/setup-local-https.sh

Phase 3: Advanced Security (Recommended)

Step 6: Configure Secure nginx Settings

The provided nginx configuration includes many security best practices:

SSL/TLS Security:

# Only use modern, secure protocols
ssl_protocols TLSv1.2 TLSv1.3;

# Use strong cipher suites
ssl_ciphers ECDHE-RSA-AES256-GCM-SHA512:DHE-RSA-AES256-GCM-SHA384;

Security Headers:

# Prevents clickjacking attacks
add_header X-Frame-Options DENY;

# Prevents MIME type sniffing
add_header X-Content-Type-Options nosniff;

# Enables XSS protection
add_header X-XSS-Protection "1; mode=block";

# Forces HTTPS for future visits
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;

Step 7: Environment-Specific Configuration

Development environment:

TRANSPORT_TYPE=http
SERVER_HOST=127.0.0.1  # Only local access
HTTP_AUTH_ENABLED=true
HTTP_RATE_LIMIT_ENABLED=true
MAX_REQUESTS_PER_MINUTE=100  # More lenient for testing
ENABLE_DEBUG_MESSAGES=true   # Helpful for troubleshooting

Production environment:

TRANSPORT_TYPE=http
SERVER_HOST=127.0.0.1        # Behind nginx
BEHIND_PROXY=true
TRUST_PROXY_HEADERS=true
HTTP_AUTH_ENABLED=true
HTTP_RATE_LIMIT_ENABLED=true
MAX_REQUESTS_PER_MINUTE=60   # Conservative limit
ENABLE_DEBUG_MESSAGES=false  # Disable verbose logging

Step 8: Configure CORS Properly

Secure CORS configuration:

HTTP_CORS_ENABLED=true
# Never use * in production - specify exact domains
HTTP_CORS_ORIGINS=https://your-dashboard.com,https://your-app.com

Avoid wildcards (*) because they:
– Allow any website to access your API
– Create potential security vulnerabilities
– Defeat the purpose of CORS protection

Monitoring and Maintenance

Security Events to Track:
1. Authentication failures – Potential brute force attacks
2. Rate limit violations – Possible abuse or misconfigured clients
3. IP whitelist blocks – Unauthorized access attempts
4. Unusual traffic patterns – Potential attacks or system issues

Log Analysis:

# Check nginx access logs for suspicious activity
sudo tail -f /var/log/nginx/mcp-server-access.log

# Look for authentication errors in application logs
grep "AuthenticationError" /path/to/your/logs

# Monitor rate limiting events
grep "Rate limit exceeded" /path/to/your/logs

Security has a performance impact and you should understand the trade-offs:

Security Feature Performance Impact Recommendation
Authentication Very Low (~1-2ms) Always enable
Rate Limiting Low (~0.5ms) Always enable
IP Whitelisting Very Low (~0.1ms) Enable when applicable
HTTPS/SSL Low (~5-10ms) Always enable
Request Size Limits Very Low (~0.1ms) Always enable

The cost of not having security is always higher than the minimal performance impact.

Best Practices for MCP Server Hardening

The Golden Rules

  1. Never disable authentication – Even in development, use test credentials
  2. Always use HTTPS – Never send credentials over HTTP
  3. Keep software updated – Regularly update nginx, Python, and dependencies
  4. Monitor continuously – Set up alerts for security events
  5. Test your security – Regularly verify your configuration works correctly
  6. Document everything – Keep records of your security configuration
  7. Plan for incidents – Have response procedures ready

Conclusion

Security isn’t a one-time setup—it’s an ongoing process of protection, monitoring, and improvement. By following this guide, you’ve implemented multiple layers of security that will protect your MCP Server from common attacks and provide early warning of potential issues.

Remember: The goal isn’t perfect security (which doesn’t exist), but reasonable protection that makes attacking your server more difficult and expensive than the potential gain for attackers.

Your MCP Server is now protected by:
Authentication – Only authorized users can access
Rate limiting – Prevents abuse and overload
Network controls – Filters traffic at the network level
Encryption – Protects data in transit
nginx security – Professional-grade web server protection
Monitoring – Early warning system for issues

You can use these tips for hardening any MCP server. You can also check out InsightFinder’s MCP server to learn how you can get comprehensive incident management, anomaly detection, and system monitoring capabilities within your AI agents. To test out InsightFinder’s MCP Server, sign up for a free trial

Contents

Explore InsightFinder AI

Take InsightFinder AI for a no-obligation test drive. We’ll provide you with a detailed report on your outages to uncover what could have been prevented.