MCP-Query-Validation
This project provides an MCP server for validating entered queries to prevent sensitive information leaks. It automatically detects and masks sensitive data, logging all activities for audit and monitoring purposes.
GitHub Stars
1
User Rating
Not Rated
Forks
0
Issues
0
Views
1
Favorites
0
MCP Validation Server
This project provides an MCP server for validation of entered queries to prevent sensitive information leaks. It automatically detects and masks sensitive data (such as emails, phone numbers, SSNs, credit cards, etc.) in every query processed by the server. All activities are logged for audit and monitoring purposes.
Features
- Sensitive Data Masking: Automatically detects and masks sensitive information in queries, including:
- Emails
- Phone numbers
- Social Security Numbers (SSNs)
- Credit card numbers
- IP addresses
- Dates of birth
- Addresses
- Zip codes
- Comprehensive Logging: All validation activities and system events are logged with timestamps.
- MCP Server Integration: Runs as an MCP server, validating every incoming query before further processing.
How It Works
- The server uses a custom FastMCP class that intercepts every query, applies sensitive data masking, and then processes the (masked) query.
- All validation and masking actions are logged to timestamped log files in the
logs/
directory.
Setup & Installation
Clone the repository
git clone <your-repo-url> cd mcp-validation
Install Python 3.11+ Ensure you have Python 3.11 or higher installed.
Install dependencies
pip install -r requirements.txt # OR, if using PEP 621/pyproject.toml: pip install .
(Dependencies are specified in
pyproject.toml
.)
Running the MCP Validation Server
Start the server with:
python main.py
You should see output indicating the MCP server is running for validation.
Usage Example
You can interact with the MCP server using your preferred MCP client, or by integrating it into your workflow. Every query sent to the server will be validated and masked as needed.
If you want to use the validation logic directly in Python:
from validation_tools import validate_data
result = validate_data("My email is john@example.com and phone is 555-123-4567")
print(result)
Logging
- Logs are stored in the
logs/
directory. - Each server session creates a new log file named
validation_tools_YYYYMMDD_HHMMSS.log
. - Logs include:
- Query validation events
- Masked sensitive data
- System events (startup, shutdown, errors)
Example Log Entry
{
"timestamp": "2024-01-15T10:30:45.123456",
"event": "Validating data: My email is john@example.com and phone is 555-123-4567"
}
File Structure
mcp-validation/
├── main.py # Main server entry point
├── validation_tools.py # Core validation and masking logic
├── logs/ # Log files directory
│ └── validation_tools_YYYYMMDD_HHMMSS.log
├── pyproject.toml # Project dependencies
├── uv.lock # Dependency lock file
└── README.md # This file
Security & Privacy
- All sensitive information in queries is masked before further processing.
- All actions are logged for audit and monitoring.
Troubleshooting
- Log Files Not Created: Ensure the
logs/
directory exists and has write permissions. - Python Version Issues: Make sure you are using Python 3.11 or higher.
License
MIT License (or specify your license here)
Generative AI developer with 2.5 years of experience crafting innovative Retrieval-Augmented Generation (RAG) applications, smart assistants, and agentic workfl
0
Followers
9
Repositories
0
Gists
1
Total Contributions