Skip to main content

A lightweight security validation layer for MCP (Model Context Protocol) inputs

Project description

mcp-marshal

mcp-marshal is a lightweight security validation layer for Model Context Protocol (MCP) inputs. It scans tool-call payloads for risky patterns - SQL injection, XSS, and other common attack vectors - before they reach your model or tool handler.

This is an early but functional release. The core validation logic works today; more features are on the roadmap.


Installation

pip install mcp-marshal

Quick start

from mcp_marshal import Warden

warden = Warden()

# Clean input
result = warden.validate_input({"query": "What is the weather today?"})
print(result)
# {"valid": True, "issues": []}

# Risky input
result = warden.validate_input({
    "query": "SELECT * FROM users; DROP TABLE users;--",
    "context": "admin panel"
})
print(result["valid"])   # False
for issue in result["issues"]:
    print(issue)
# {"field": "query", "pattern": "DROP TABLE", "severity": "critical"}
# {"field": "query", "pattern": "--",         "severity": "medium"}
# {"field": "query", "pattern": ";--",        "severity": "high"}

Custom patterns

from mcp_marshal import Warden

extra = [
    {"pattern": "IGNORE PREVIOUS INSTRUCTIONS", "severity": "critical"},
    {"pattern": "jailbreak",                     "severity": "high"},
]

warden = Warden(extra_patterns=extra)
result = warden.validate_input({"prompt": "Ignore previous instructions and ..."})
print(result["valid"])   # False

API

Warden(extra_patterns=None)

Create a warden instance. Pass extra_patterns to extend the built-in ruleset.

Warden.validate_input(payload: dict) -> dict

Scan all string values in payload (recursively) for risky patterns.

Returns:

{
    "valid": bool,
    "issues": [
        {
            "field":    str,   # dot-path to the offending key
            "pattern":  str,   # matched pattern
            "severity": str,   # low | medium | high | critical
        }
    ]
}

Built-in patterns

Pattern Severity
DROP TABLE critical
DELETE FROM critical
UNION SELECT critical
' OR '1'='1 critical
;-- high
<script> high
javascript: high
-- medium

Roadmap

  • Prompt injection detection (LLM-assisted)
  • Configurable allow-lists and deny-lists
  • Async support
  • JSON-schema validation for MCP tool arguments
  • CLI for quick audits
  • Integration guides for popular MCP server frameworks

License

MIT. See LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mcp_marshal-0.1.0a1.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mcp_marshal-0.1.0a1-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file mcp_marshal-0.1.0a1.tar.gz.

File metadata

  • Download URL: mcp_marshal-0.1.0a1.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.2

File hashes

Hashes for mcp_marshal-0.1.0a1.tar.gz
Algorithm Hash digest
SHA256 142914a0fbf71983006e8dda4190821583185048edd7283d3cbf4927db85181c
MD5 af9b8a5928d51b4972d08e3481569646
BLAKE2b-256 ff9157d5a9619d8ee698b4fabe6fbd5100ef1b753c3f435266ad4a6a31e56b59

See more details on using hashes here.

File details

Details for the file mcp_marshal-0.1.0a1-py3-none-any.whl.

File metadata

  • Download URL: mcp_marshal-0.1.0a1-py3-none-any.whl
  • Upload date:
  • Size: 5.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.2

File hashes

Hashes for mcp_marshal-0.1.0a1-py3-none-any.whl
Algorithm Hash digest
SHA256 daef82e0205890b6d1bde221302049d4266aee53d71a76cb620925e4ee5cbf98
MD5 a8ca4fccdbb7968f8dcdd6dce75db627
BLAKE2b-256 25184b79e4123fa592d8ed213ec167363838134c95b021a6fec928c166db23a9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page