GuardrlyGuardrly
mcpsecuritybest-practices

AI Agents are powerful. They can manage your Shopify store, optimize your Meta Ads campaigns, and handle hundreds of API calls autonomously. But every one of those API calls is a potential security risk.

An unsecured MCP server is like leaving your store's back door wide open. API keys exposed. No audit trail. No way to know what your Agent did — or didn't do — until something breaks.

This guide covers the security practices that matter most when running MCP servers in production.

What Is an MCP Server and Why Does Security Matter?

The Model Context Protocol (MCP) lets AI Agents interact with external tools and APIs. An MCP server is the bridge — it receives requests from your Agent (Claude Desktop, Cursor, etc.) and executes them against real services like Shopify, Stripe, or Meta Ads.

The security problem is straightforward: your MCP server has access to production API keys, customer data, and business-critical operations. If it's not locked down, a single bad prompt or hallucination can cascade into real damage.

Here are 8 specific practices to prevent that.

1. Never Store API Keys in Plain Text

This sounds obvious, but it's the most common mistake. API keys hardcoded in config files, committed to Git, or stored in unencrypted environment files are the #1 attack vector.

What to do instead:

For MCP servers specifically, the server should read API keys from environment variables that are set by the MCP client configuration — not from any file inside the server's codebase.

2. Scrub PII Before It Leaves the Machine

Your MCP server intercepts every request your Agent makes. Those requests contain Authorization headers, access tokens, email addresses, and sometimes credit card numbers.

If you're shipping logs to a cloud service for monitoring, that sensitive data should never leave the user's machine in its original form.

How to implement PII scrubbing:

The goal is simple: your cloud dashboard should show what happened (endpoint, method, status code, timing), not the sensitive data that was involved.

How Guardrly handles this: PII scrubbing runs locally using 5 precompiled regex patterns, processing each request in under 1ms. Authorization headers, tokens, emails, phone numbers, and card numbers are all scrubbed before any data is uploaded.

3. Authenticate Every Request with HMAC Signatures

Your MCP server sends data to a cloud API for storage and analysis. How does the cloud API know the request is legitimate and hasn't been tampered with?

Basic API key authentication is a start, but it doesn't protect against replay attacks or request tampering. HMAC-SHA256 signatures solve both problems.

How HMAC authentication works:

  1. The client creates a message string: METHOD + PATH + TIMESTAMP + SHA256(BODY)
  2. The client signs the message with a shared secret using HMAC-SHA256
  3. The server receives the request, recreates the same message, and computes its own signature
  4. If the signatures match, the request is authentic. If not, it's rejected.

The timestamp component prevents replay attacks — the server rejects any request where the timestamp is more than 5 minutes old.

4. Rate Limit Everything

Rate limiting isn't just about preventing abuse. It's about protecting the external platforms your Agent interacts with.

Shopify, Meta, and most APIs have their own rate limits. If your Agent exceeds them, you don't just get a 429 error — you risk account flags, reviews, and bans.

Three layers of rate limiting:

Use Redis sliding windows for accurate rate limiting. Token bucket algorithms work too, but sliding windows are simpler to implement and debug.

5. Build an Audit Trail for Every Operation

When something goes wrong — and it will — you need to answer three questions: What happened? When? And why?

A proper audit trail logs every API call your Agent makes, with enough context to reconstruct the sequence of events.

What to log for each operation:

What NOT to log:

Store logs locally first (SQLite is perfect for this), then ship them to a cloud service asynchronously. This way, even if the network is down, you don't lose data.

6. Detect and Alert on Dangerous Operations

Not all API calls are equal. A GET request to list products is routine. Three consecutive DELETE requests to remove products is a red flag.

Alert rules that matter for production MCP servers:

The key is acting on alerts before more damage is done. A 5-second email notification can save you a day of cleanup.

7. Use Platform-Specific Security Rules

Generic HTTP monitoring catches broad issues, but platform-specific rules catch the dangerous operations that generic rules miss.

Shopify-specific risks:

Meta Ads-specific risks:

A good MCP security tool should have pre-built rule sets for the platforms you use, not just generic HTTP monitoring.

8. Validate and Cap External API Call Volume

If your MCP server uses AI models (like Claude) for semantic analysis of operations, those API calls cost money. A malicious or misconfigured agent can drive up costs quickly.

Protections to implement:

These controls prevent a single bad actor from running up your infrastructure costs.

Putting It All Together

Here's what a properly secured MCP server architecture looks like:

AI Agent
  → MCP Server (local)
      → PII scrubbing (local, <1ms)
      → Platform detection (Shopify/Meta/generic)
      → Risk assessment (local rules)
      → Local SQLite queue
  → Original API (request forwarded unchanged)

Background (every 30s):
  → HMAC-signed upload to cloud API
  → Rate limit check
  → Alert evaluation
  → Email notification if critical

The request path is never blocked or slowed down. All the security processing happens asynchronously, after the request has already been forwarded.

Getting Started

If you're running AI Agents against production APIs, start with the basics: local logging, PII scrubbing, and at least one alert rule for consecutive DELETE operations. You can add cloud features later.

Guardrly implements all 8 practices described in this guide. One command to install:

curl -fsSL https://guardrly.com/install.sh | bash

Works with Claude Desktop, Cursor, and any MCP-compatible AI tool.

Monitor your AI Agent with Guardrly

Real-time alerts and complete audit logs for your AI Agent. Free plan available.

Start Free

Related articles