Shield MCP
A shield for logging, deep debug and sanitization for MCP servers at development stage
shieldmcp
README
Shield MCP
A security middleware for Model Context Protocol (MCP) servers that enhances security and monitoring capabilities without modifying the official SDK. This package provides tools for securing and monitoring MCP tool calls, following the best practices outlined in the MCP documentation. Abstract yourself while interact at MCP development.
Table of Contents
- Features
- Requirements
- Installation
- Quick Start
- Components
- Best Practices
- Development
- Roadmap
- Acknowledgments
Features
- Tool Access Control: Whitelist-based access control for MCP tools
- Result Sanitization: Configurable sanitization of tool outputs
- Structured Logging: Comprehensive audit logging using structlog
- Rate Limiting: Token bucket algorithm for rate limiting
- Error Handling: Standardized error handling and formatting
- MCP Inspector Compatible: Works seamlessly with the MCP Inspector tool
Requirements
System Requirements
- Python 3.8 or higher
- pip (Python package installer)
- virtualenv (recommended for development)
Quick Start
from shieldmcp import secure_tool
from shieldmcp.sanitizers import ToolSanitizer
from shieldmcp.rate_limit import RateLimitConfig
# Define allowed tools
ALLOWED_TOOLS = {"search", "read_file", "write_file"}
# Create a text sanitizer
text_sanitizer = ToolSanitizer.createTextSanitizer(
max_length=1000,
sensitive_patterns=[
r"\b\d{16}\b", # Credit card numbers
r"\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b" # Email addresses
]
)
# Configure rate limiting
rate_limit = RateLimitConfig(
requests_per_minute=60, # 1 request per second
burst_size=10 # Allow bursts of up to 10 requests
)
# Apply the decorator to your MCP tools
@secure_tool(
allowed_tools=ALLOWED_TOOLS,
sanitize_fn=text_sanitizer,
user_id="user123",
session_id="session456",
rate_limit=rate_limit
)
def search(query: str):
# Your tool implementation
return results
Components
Decorators (decorators.py
)
The main @secure_tool
decorator that orchestrates all security features:
@secure_tool(
allowed_tools={"tool1", "tool2"}, # Set of allowed tool names
sanitize_fn=your_sanitizer, # Optional result sanitization function
user_id="user123", # Optional user identifier
session_id="session456", # Optional session identifier
rate_limit=RateLimitConfig( # Optional rate limit configuration
requests_per_minute=60,
burst_size=10
)
)
def your_tool():
pass
Audit Logging (audit.py
)
Structured logging using structlog:
from shieldmcp import ToolAudit
audit = ToolAudit()
audit.logToolCallStart(
tool_name="search",
args={"query": "test"},
user_id="user123"
)
Access Control (access.py
)
Tool access validation:
from shieldmcp import ToolAccess
access = ToolAccess(allowed_tools={"tool1", "tool2"})
access.validateToolAccess("tool1") # Raises ValueError if not allowed
Sanitizers (sanitizers.py
)
Result sanitization utilities:
from shieldmcp import ToolSanitizer
# Create a custom sanitizer
sanitizer = ToolSanitizer.createTextSanitizer(
max_length=1000,
sensitive_patterns=[r"\b\d{16}\b"]
)
# Use it directly
clean_text = sanitizer("Your text with sensitive data")
Rate Limiting (rate_limit.py
)
Token bucket rate limiting:
from shieldmcp import RateLimitConfig
# Configure rate limits
config = RateLimitConfig(
requests_per_minute=60,
burst_size=10
)
Best Practices
Tool Access Control
- Always define a whitelist of allowed tools
- Use the most restrictive set of tools possible
- Regularly review and update the whitelist
Result Sanitization
- Sanitize all text output
- Define patterns for sensitive data
- Set reasonable length limits
Logging
- Include user and session IDs when available
- Log both successful and failed operations
- Use structured logging for better analysis
Rate Limiting
- Set appropriate limits based on tool complexity
- Consider burst sizes for better user experience
- Monitor rate limit hits in logs
Development
Setup Development Environment
# Clone the repository
git clone https://github.com/shieldmcp/shieldmcp.git
cd shieldmcp
# Create virtual environment
python -m venv venv
source venv/bin/activate # or `venv\Scripts\activate` on Windows
# Install development dependencies
pip install -r requirements.txt
Running Tests
pytest tests/
Roadmap
Planned Features
- Support for Clerk MCP and Github MCP
- Extended documentation
- TypeScript support
Acknowledgments
- Model Context Protocol for the protocol specification
- structlog for structured logging
Feel free to make any inquiries.
Recommended Servers
Crypto Price & Market Analysis MCP Server
A Model Context Protocol (MCP) server that provides comprehensive cryptocurrency analysis using the CoinCap API. This server offers real-time price data, market analysis, and historical trends through an easy-to-use interface.
MCP PubMed Search
Server to search PubMed (PubMed is a free, online database that allows users to search for biomedical and life sciences literature). I have created on a day MCP came out but was on vacation, I saw someone post similar server in your DB, but figured to post mine.
dbt Semantic Layer MCP Server
A server that enables querying the dbt Semantic Layer through natural language conversations with Claude Desktop and other AI assistants, allowing users to discover metrics, create queries, analyze data, and visualize results.
mixpanel
Connect to your Mixpanel data. Query events, retention, and funnel data from Mixpanel analytics.

Sequential Thinking MCP Server
This server facilitates structured problem-solving by breaking down complex issues into sequential steps, supporting revisions, and enabling multiple solution paths through full MCP integration.

Nefino MCP Server
Provides large language models with access to news and information about renewable energy projects in Germany, allowing filtering by location, topic (solar, wind, hydrogen), and date range.
Vectorize
Vectorize MCP server for advanced retrieval, Private Deep Research, Anything-to-Markdown file extraction and text chunking.
Mathematica Documentation MCP server
A server that provides access to Mathematica documentation through FastMCP, enabling users to retrieve function documentation and list package symbols from Wolfram Mathematica.
kb-mcp-server
An MCP server aimed to be portable, local, easy and convenient to support semantic/graph based retrieval of txtai "all in one" embeddings database. Any txtai embeddings db in tar.gz form can be loaded
Research MCP Server
The server functions as an MCP server to interact with Notion for retrieving and creating survey data, integrating with the Claude Desktop Client for conducting and reviewing surveys.