Security middleware for Model Context Protocol (MCP) that detects and blocks malicious tool calls
Wellknown found it in public sources; nobody has proven control of it yet. Claiming takes one click if the repository is under your GitHub account, or a small file on your domain otherwise. Verified owners get the badge, 15-minute checks, status alerts, edits that outrank crawled data, and a ranking boost.
Agents can do it too: POST https://wellknown.network/api/v1/claims with {"agent":"kavach-mcp","method":"well_known_file"} — machine-readable steps at claim.json, guide at /docs/claim.
Everything here was measured by our prober or read from a registry. Nothing is self-reported.
Attributed to the source that supplied each field. Treated as claims, not facts.
# Kavach - MCP Security Middleware Security middleware for Model Context Protocol (MCP) that detects and blocks malicious tool calls using pattern-based rule scanning. **Built by [Shivam Namdeo](https://www.linkedin.com/in/shivamnamdeo0101/)** | [PyPI Package](https://pypi.org/project/kavach-mcp/) | [Use Cases](https://github.com/shivamnamdeo0101/kavach-mcp-middleware-use-cases) ## Quick Start ```bash # Create and activate virtual environment python3 -m venv venv source venv/bin/activate # Run the example cd example python3 app.py ``` ## Architecture **Core Components:** - **`middleware.py`** - `KavachMiddleware`: Main entry point. Processes tool calls and returns allow/block decisions. - **`engine.py`** - `DetectionEngine`: Scans text against rules and collects violations. - **`rules.py`** - `KAVACH_RULES`: Rule definitions for detecting prompt injection, PII, API keys, etc. - **`types.py`** - `Rule`: Data class defining rule structure (id, name, severity, patterns). ## How It Works ### Sync: Content-based Blocking ```python from kavach import KavachMiddleware middleware = KavachMiddleware() # Process any tool call result = middleware.process({ "tool": "aws.s3", "access_key": "AKIAIOSFODNN7EXAMPLE" }) # Returns: {"allowed": False, "violations": [...]} ``` ### Async: FastMCP Middleware Integration ```python from fastmcp import FastMCP from kavach import KavachMiddleware mcp = FastMCP("my-server") mcp.add_middleware( KavachMiddleware( sensitive_tools=[ "filesystem.delete", "aws.*", # wildcard patterns "database.execute" ] ) ) ``` **Flow:** 1. Tool call intercepted by `on_call_tool()` middleware hook 2. Tool name matched against `sensitive_tools` patterns 3. If matched, `DetectionEngine` scans arguments against rules 4. If violations found and strict mode enabled → raises `SecurityException` 5. Otherwise → chain to next middleware ## Default Security Rules ## 🛡️ Default …
Mapped onto the structured taxonomy from declared text and observed tool names. Confidence shown for derived entries.
Every source is kept verbatim. Field changes are logged as events.