Skip to main content
Glama
CSOAI-ORG

OWASP Agentic MCP

check_prompt_injection

Analyze text to detect prompt injection attack patterns and provide structured classification results without modifying external systems.

Instructions

Check text for prompt injection attack patterns.

Behavior: This tool is read-only and stateless — it produces analysis output without modifying any external systems, databases, or files. Safe to call repeatedly with identical inputs (idempotent). Free tier: 10/day rate limit. Pro tier: unlimited. No authentication required for basic usage.

When to use: Use this tool when you need structured analysis or classification of inputs against established frameworks or standards.

When NOT to use: Not suitable for real-time production decision-making without human review of results.

Args: input_text (str): The input text to analyze or process. api_key (str): The api key to analyze or process.

Behavioral Transparency: - Side Effects: This tool is read-only and produces no side effects. It does not modify any external state, databases, or files. All output is computed in-memory and returned directly to the caller. - Authentication: No authentication required for basic usage. Pro/Enterprise tiers require a valid MEOK API key passed via the MEOK_API_KEY environment variable. - Rate Limits: Free tier: 10 calls/day. Pro tier: unlimited. Rate limit headers are included in responses (X-RateLimit-Remaining, X-RateLimit-Reset). - Error Handling: Returns structured error objects with 'error' key on failure. Never raises unhandled exceptions. Invalid inputs return descriptive validation errors. - Idempotency: Fully idempotent — calling with the same inputs always produces the same output. Safe to retry on timeout or transient failure. - Data Privacy: No input data is stored, logged, or transmitted to external services. All processing happens locally within the MCP server process.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
input_textYes
callerNo
api_keyNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The main handler function for the 'check_prompt_injection' tool. It takes input_text, caller, and api_key, checks auth and rate limits, scans the input against INJECTION_PATTERNS regex list, checks for special/unicode character encoding attacks, checks for unusually long input, calculates a risk level (SAFE/MEDIUM/HIGH/CRITICAL), and returns a JSON response.
    def check_prompt_injection(
        input_text: str,
        caller: str = "",
        api_key: str = "",
    ) -> str:
        """Check text for prompt injection attack patterns.
    
        Behavior:
            This tool is read-only and stateless — it produces analysis output
            without modifying any external systems, databases, or files.
            Safe to call repeatedly with identical inputs (idempotent).
            Free tier: 10/day rate limit. Pro tier: unlimited.
            No authentication required for basic usage.
    
        When to use:
            Use this tool when you need structured analysis or classification
            of inputs against established frameworks or standards.
    
        When NOT to use:
            Not suitable for real-time production decision-making without
            human review of results.
    
        Args:
            input_text (str): The input text to analyze or process.
            api_key (str): The api key to analyze or process.
    
        Behavioral Transparency:
            - Side Effects: This tool is read-only and produces no side effects. It does not modify
              any external state, databases, or files. All output is computed in-memory and returned
              directly to the caller.
            - Authentication: No authentication required for basic usage. Pro/Enterprise tiers
              require a valid MEOK API key passed via the MEOK_API_KEY environment variable.
            - Rate Limits: Free tier: 10 calls/day. Pro tier: unlimited. Rate limit headers are
              included in responses (X-RateLimit-Remaining, X-RateLimit-Reset).
            - Error Handling: Returns structured error objects with 'error' key on failure.
              Never raises unhandled exceptions. Invalid inputs return descriptive validation errors.
            - Idempotency: Fully idempotent — calling with the same inputs always produces the
              same output. Safe to retry on timeout or transient failure.
            - Data Privacy: No input data is stored, logged, or transmitted to external services.
              All processing happens locally within the MCP server process.
        """
        if err := _check_auth(api_key):
            return err
        if err := _rl(caller):
            return err
    
        detections = []
        text_lower = input_text.lower()
    
        for i, pattern in enumerate(INJECTION_PATTERNS):
            matches = re.findall(pattern, text_lower, re.IGNORECASE)
            if matches:
                detections.append({
                    "pattern_id": f"INJ-{i+1:03d}",
                    "pattern": pattern,
                    "matches": [str(m) if isinstance(m, str) else str(m) for m in matches[:3]],
                    "severity": "CRITICAL" if i < 3 else "HIGH",
                })
    
        special_chars = sum(1 for c in input_text if ord(c) > 127 or c in '\x00\x01\x02\x03')
        if special_chars > len(input_text) * 0.1 and len(input_text) > 20:
            detections.append({
                "pattern_id": "INJ-SPECIAL",
                "description": "High ratio of special/unicode characters (possible encoding attack)",
                "severity": "MEDIUM",
            })
    
        if len(input_text) > 5000:
            detections.append({
                "pattern_id": "INJ-LENGTH",
                "description": f"Unusually long input ({len(input_text)} chars). May contain hidden instructions.",
                "severity": "LOW",
            })
    
        risk = "SAFE"
        if any(d.get("severity") == "CRITICAL" for d in detections):
            risk = "CRITICAL"
        elif any(d.get("severity") == "HIGH" for d in detections):
            risk = "HIGH"
        elif detections:
            risk = "MEDIUM"
    
        return json.dumps({
            "input_length": len(input_text),
            "risk_level": risk,
            "detections": detections,
            "detection_count": len(detections),
            "recommendation": "Block or sanitize this input before passing to agent."
                if risk in ("CRITICAL", "HIGH") else "Input appears safe.",
            "owasp_ref": "A01 - Prompt Injection",
        }, indent=2)
  • server.py:251-252 (registration)
    The @mcp.tool() decorator registers 'check_prompt_injection' as an MCP tool on the FastMCP server instance.
    @mcp.tool()
    def check_prompt_injection(
  • Input schema for the tool: input_text (required str), caller (optional str with default ''), api_key (optional str with default ''). The return type is str (JSON).
    def check_prompt_injection(
        input_text: str,
        caller: str = "",
        api_key: str = "",
    ) -> str:
  • INJECTION_PATTERNS — a list of 10 regex patterns used to detect prompt injection attacks (e.g., instruction override, system role impersonation, special tokens, jailbreak phrases, code execution attempts).
    INJECTION_PATTERNS = [
        r"ignore\s+(previous|all|above)\s+(instructions?|prompts?)",
        r"(you\s+are|act\s+as|pretend|roleplay|imagine)\s+.{0,30}(admin|root|system)",
        r"system\s*:\s*",
        r"<\|?(system|im_start|endoftext)\|?>",
        r"\\n\\nHuman:|\\n\\nAssistant:",
        r"IMPORTANT:\s*override",
        r"jailbreak|DAN\s*mode|developer\s*mode",
        r"base64_decode|eval\(|exec\(|__import__",
        r"\{\{.*\}\}",
        r"\\x[0-9a-fA-F]{2}",
    ]
  • _check_auth helper: validates the API key against the MEOK_API_KEY environment variable.
    def _check_auth(api_key: str = "") -> str | None:
        if _MEOK_API_KEY and api_key != _MEOK_API_KEY:
            return "Invalid API key. Get one at https://meok.ai/api-keys"
        return None
  • _rl helper: enforces free-tier rate limiting (10 calls/day) for the tool.
    def _rl(caller: str = "anonymous", tier: str = "free") -> Optional[str]:
        if tier == "pro":
            return None
        now = datetime.now()
        cutoff = now - timedelta(days=1)
        _usage[caller] = [t for t in _usage[caller] if t > cutoff]
        if len(_usage[caller]) >= FREE_DAILY_LIMIT:
            return (
                f"Free tier limit ({FREE_DAILY_LIMIT}/day). "
                "Upgrade: https://meok.ai/mcp/owasp-agentic/pro"
            )
        _usage[caller].append(now)
        return None
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden and does an excellent job. It covers side effects (read-only, stateless), authentication, rate limits, error handling, idempotency, and data privacy in a dedicated section.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured with clear sections and front-loaded purpose. It is somewhat long but every sentence adds value; minor redundancy exists (e.g., repeating behavioral details in both inline and a dedicated section).

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given no annotations and an output schema present, the description covers behavioral aspects thoroughly. However, it misses describing the 'caller' parameter and has slight inconsistency about api_key/authentication, leaving minor gaps.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema has 0% description coverage, so the description must compensate. It describes 'input_text' and 'api_key' in an Args block but omits the 'caller' parameter entirely. The descriptions given are minimal (e.g., 'The input text to analyze'). Partial coverage prevents a higher score.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states it checks text for prompt injection attack patterns. It uses a specific verb-resource combination and distinguishes from sibling tools like check_tool_poisoning or check_data_leakage.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description includes dedicated 'When to use' and 'When NOT to use' sections, providing clear context for when to invoke the tool. It could explicitly mention alternatives among siblings, but the guidance is sufficient.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/CSOAI-ORG/owasp-agentic-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server