Skip to main content
Glama
security-use

Security-Use MCP Server

by security-use

analyze_request

Analyzes HTTP requests to detect security threats like SQL injection, XSS, path traversal, and command injection patterns.

Instructions

Analyze an HTTP request for potential attacks. Detects SQL injection, XSS, path traversal, command injection, and other attack patterns.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
methodYesHTTP method (GET, POST, etc.).
pathYesRequest path (e.g., '/api/users').
query_paramsNoQuery parameters as key-value pairs.
headersNoRequest headers as key-value pairs.
bodyNoRequest body content.
source_ipNoSource IP address of the request.

Implementation Reference

  • The main handler function `handle_analyze_request` that executes the tool logic. It analyzes HTTP requests for potential security attacks including SQL injection, XSS, path traversal, and command injection using the AttackDetector from security-use sensor module.
    async def handle_analyze_request(arguments: dict[str, Any]) -> list[TextContent]:
        """
        Analyze an HTTP request for potential attacks.
    
        Uses the AttackDetector to check for SQL injection, XSS, path traversal,
        command injection, and other attack patterns.
    
        Args:
            arguments: Tool arguments containing:
                - method (required): HTTP method (GET, POST, etc.)
                - path (required): Request path
                - query_params (optional): Query parameters dict
                - headers (optional): Request headers dict
                - body (optional): Request body string
                - source_ip (optional): Source IP address
    
        Returns:
            List of TextContent with attack analysis results
        """
        method = arguments.get("method")
        path = arguments.get("path")
        query_params = arguments.get("query_params", {})
        headers = arguments.get("headers", {})
        body = arguments.get("body")
        source_ip = arguments.get("source_ip", "unknown")
    
        if not method:
            return [TextContent(type="text", text="Error: `method` is required")]
        if not path:
            return [TextContent(type="text", text="Error: `path` is required")]
    
        try:
            from security_use.sensor import AttackDetector, RequestData
    
            detector = AttackDetector(
                enabled_detectors=[
                    "sqli",
                    "xss",
                    "path_traversal",
                    "command_injection",
                    "suspicious_headers",
                ]
            )
    
            request = RequestData(
                method=method.upper(),
                path=path,
                query_params=query_params,
                headers=headers,
                body=body,
                source_ip=source_ip,
            )
    
            events = await asyncio.to_thread(detector.analyze_request, request)
    
            output_lines = [
                "## Request Security Analysis",
                "",
                f"**Method**: {method.upper()}",
                f"**Path**: {path}",
                f"**Source IP**: {source_ip}",
                "",
            ]
    
            if not events:
                output_lines.extend(
                    [
                        "### Result: No Threats Detected",
                        "",
                        "The request does not contain any obvious attack patterns.",
                    ]
                )
            else:
                output_lines.extend(
                    [
                        f"### ⚠️ {len(events)} Potential Threat(s) Detected",
                        "",
                    ]
                )
    
                for event in events:
                    severity_icon = (
                        "🔴"
                        if event.severity == "CRITICAL"
                        else "🟠"
                        if event.severity == "HIGH"
                        else "🟡"
                        if event.severity == "MEDIUM"
                        else "🟢"
                    )
                    output_lines.extend(
                        [
                            f"#### {severity_icon} {event.event_type.value.upper()}",
                            f"- **Severity**: {event.severity}",
                            f"- **Confidence**: {event.confidence:.0%}",
                            f"- **Description**: {event.description}",
                            f"- **Location**: {event.matched_pattern.location}",
                        ]
                    )
                    if event.matched_pattern.field:
                        output_lines.append(f"- **Field**: {event.matched_pattern.field}")
                    if event.matched_pattern.matched_value:
                        output_lines.append(
                            f"- **Matched Value**: `{event.matched_pattern.matched_value[:100]}`"
                        )
                    output_lines.append("")
    
                output_lines.extend(
                    [
                        "### Recommendations",
                        "",
                        "1. Block this request if in production",
                        "2. Log the source IP for monitoring",
                        "3. Consider rate limiting the source",
                        "4. Review application input validation",
                    ]
                )
    
            return [TextContent(type="text", text="\n".join(output_lines))]
    
        except ImportError:
            return [
                TextContent(
                    type="text",
                    text=(
                        "Error: security-use sensor module not available.\n\n"
                        "Please ensure security-use is installed: pip install security-use"
                    ),
                )
            ]
        except Exception as e:
            return [TextContent(type="text", text=f"Error analyzing request: {str(e)}")]
  • Tool definition and input schema for 'analyze_request'. Defines the tool name, description, and JSON schema for input parameters including method (required), path (required), and optional query_params, headers, body, and source_ip.
    name="analyze_request",
    description=(
        "Analyze an HTTP request for potential attacks. "
        "Detects SQL injection, XSS, path traversal, command injection, "
        "and other attack patterns."
    ),
    inputSchema={
        "type": "object",
        "properties": {
            "method": {
                "type": "string",
                "description": "HTTP method (GET, POST, etc.).",
            },
            "path": {
                "type": "string",
                "description": "Request path (e.g., '/api/users').",
            },
            "query_params": {
                "type": "object",
                "description": "Query parameters as key-value pairs.",
            },
            "headers": {
                "type": "object",
                "description": "Request headers as key-value pairs.",
            },
            "body": {
                "type": "string",
                "description": "Request body content.",
            },
            "source_ip": {
                "type": "string",
                "description": "Source IP address of the request.",
            },
        },
        "required": ["method", "path"],
    },
  • Registration mapping that associates the tool name 'analyze_request' to its handler function `handle_analyze_request` in the handlers dictionary.
    "analyze_request": handle_analyze_request,
  • Export of `handle_analyze_request` from sensor_handler module, making it available for import by the server.
    from .sensor_handler import (
        handle_acknowledge_alert,
        handle_analyze_request,
        handle_block_ip,
        handle_configure_sensor,
        handle_detect_vulnerable_endpoints,
        handle_get_alert_details,
        handle_get_blocked_ips,
        handle_get_security_alerts,
        handle_get_sensor_config,
    )
  • Import of `handle_analyze_request` from the handlers module into the server module.
    handle_analyze_request,
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. While it states what the tool detects, it doesn't describe important behavioral aspects: what format the analysis results take, whether this is a read-only analysis or has side effects, performance characteristics, or error handling. For a security analysis tool with 6 parameters, this leaves significant gaps in understanding how the tool behaves.

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 efficiently structured in two sentences that directly state the purpose and scope. There's no wasted language or redundancy. However, it could be slightly more front-loaded by immediately stating it's for HTTP request analysis rather than starting with 'Analyze an HTTP request'.

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

Completeness2/5

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

For a security analysis tool with 6 parameters, no annotations, and no output schema, the description is incomplete. It doesn't explain what the analysis returns, how results are formatted, whether this is a blocking operation, or what happens with incomplete inputs. The agent would need to guess about the tool's behavior and outputs based solely on the parameter schema.

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 description adds no parameter-specific information beyond what's already in the schema (which has 100% coverage). It doesn't explain how parameters interact, provide examples of valid inputs, or clarify edge cases. With complete schema coverage, the baseline score of 3 is appropriate since the schema does the heavy lifting, but the description adds no additional parameter context.

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

Purpose4/5

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

The description clearly states the tool's purpose: 'Analyze an HTTP request for potential attacks' with specific examples of attack patterns detected (SQL injection, XSS, etc.). It uses a specific verb ('analyze') and identifies the resource ('HTTP request'), but doesn't explicitly differentiate from sibling tools like 'detect_vulnerable_endpoints' or 'check_compliance' that might have overlapping security functions.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites, timing considerations, or how it differs from sibling tools like 'detect_vulnerable_endpoints' or 'check_compliance' that also appear to handle security analysis. The agent receives no usage context beyond the basic purpose statement.

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/security-use/mcp'

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