injection_check
Scan text for injection attempts and block content based on configurable severity thresholds to enhance security in AI agent interactions.
Instructions
Scan text and block if injection is detected above threshold.
Args: text: The text to check for injection attempts. threshold: Block at this severity or above — "LOW", "MEDIUM", "HIGH", "CRITICAL".
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| text | Yes | ||
| threshold | No | MEDIUM |
Implementation Reference
- src/agent_safety_mcp/server.py:226-248 (handler)The handler function 'injection_check' that executes the scan using PromptScanner and returns the result or error info.
def injection_check(text: str, threshold: str = "MEDIUM") -> dict: """Scan text and block if injection is detected above threshold. Args: text: The text to check for injection attempts. threshold: Block at this severity or above — "LOW", "MEDIUM", "HIGH", "CRITICAL". """ scanner = PromptScanner(threshold=threshold) try: result = scanner.check(text) return { "allowed": True, "severity": result.severity, "risk_score": result.risk_score, } except InjectionRiskError as e: return { "allowed": False, "severity": e.severity, "risk_score": e.risk_score, "matches": e.matches, "text_preview": e.text[:200], } - src/agent_safety_mcp/server.py:225-225 (registration)The @mcp.tool() decorator used to register the injection_check function as an MCP tool.
@mcp.tool()