Skip to main content
Glama
mohdhaji87

JWT Auditor MCP Server

by mohdhaji87

jwt_analyze

Analyze JSON Web Tokens for security vulnerabilities and common issues to identify potential weaknesses in authentication systems.

Instructions

Analyze a JWT for common vulnerabilities and issues.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
tokenYes

Implementation Reference

  • server.py:31-91 (handler)
    The main handler function for the 'jwt_analyze' tool. It decodes the JWT, checks for vulnerabilities such as 'none' algorithm, weak symmetric algorithms, sensitive data exposure, missing claims, expiration issues, potential header injection, and algorithm confusion attacks. Returns findings list along with header and payload.
    @server.tool()
    def jwt_analyze(token: str) -> dict:
        """Analyze a JWT for common vulnerabilities and issues."""
        import re
        import time
        findings = []
        try:
            header_b64, payload_b64, signature_b64 = token.split(".")
            def b64decode(data):
                rem = len(data) % 4
                if rem:
                    data += '=' * (4 - rem)
                return base64.urlsafe_b64decode(data.encode())
            header = json.loads(b64decode(header_b64))
            payload = json.loads(b64decode(payload_b64))
            # 1. Algorithm vulnerabilities
            alg = header.get("alg", "")
            if alg.lower() == "none":
                findings.append({"type": "alg_none", "severity": "critical", "description": "JWT uses 'none' algorithm (no signature)."})
            if alg.lower() in ["hs256", "hs384", "hs512"]:
                findings.append({"type": "weak_alg", "severity": "warning", "description": f"JWT uses symmetric algorithm: {alg}. Check for secret reuse and brute-force risk."})
            if alg.lower() in ["rs256", "rs384", "rs512"]:
                findings.append({"type": "asymmetric_alg", "severity": "info", "description": f"JWT uses asymmetric algorithm: {alg}."})
            # 2. Sensitive data exposure
            sensitive_patterns = [
                (re.compile(r"(password|secret|api[_-]?key|access[_-]?token)", re.I), "Potential credential exposure"),
                (re.compile(r"\b(?:\d[ -]*?){13,16}\b"), "Possible credit card number"),
                (re.compile(r"[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}"), "Possible email address (PII)")
            ]
            for k, v in payload.items():
                for pat, desc in sensitive_patterns:
                    if isinstance(v, str) and pat.search(v):
                        findings.append({"type": "sensitive_data", "severity": "warning", "description": f"{desc} in claim '{k}'"})
            # 3. Missing security claims
            for claim in ["exp", "iss", "aud", "jti"]:
                if claim not in payload:
                    findings.append({"type": "missing_claim", "severity": "warning", "description": f"Missing recommended claim: {claim}"})
            # 4. Header injection vulnerabilities (kid)
            if "kid" in header:
                if isinstance(header["kid"], str) and (".." in header["kid"] or "/" in header["kid"]):
                    findings.append({"type": "header_injection", "severity": "critical", "description": "Potential header injection in 'kid' parameter."})
            # 5. Token lifetime and replay attack analysis
            now = int(time.time())
            if "exp" in payload:
                try:
                    exp = int(payload["exp"])
                    if exp < now:
                        findings.append({"type": "expired", "severity": "critical", "description": "Token is expired."})
                    elif exp - now > 60*60*24*7:
                        findings.append({"type": "long_lifetime", "severity": "warning", "description": "Token lifetime is unusually long (> 7 days)."})
                except Exception:
                    findings.append({"type": "invalid_exp", "severity": "warning", "description": "Invalid 'exp' claim format."})
            # 6. Replay attack analysis (jti)
            if "jti" not in payload:
                findings.append({"type": "replay_attack", "severity": "info", "description": "No 'jti' claim: token may be replayable."})
            # 7. Algorithm confusion (alg confusion attacks)
            if alg.lower().startswith("hs") and "kid" in header and header["kid"].endswith(".pem"):
                findings.append({"type": "alg_confusion", "severity": "critical", "description": "Potential algorithm confusion: HS* with 'kid' referencing a PEM file."})
            return {"findings": findings, "header": header, "payload": payload}
        except Exception as e:
            return {"error": str(e)}
  • server.py:31-31 (registration)
    Registration of the 'jwt_analyze' tool using the @server.tool() decorator from FastMCP.
    @server.tool()
  • Input schema defined by type hint 'token: str', output 'dict'. Docstring provides usage description.
    def jwt_analyze(token: str) -> dict:
        """Analyze a JWT for common vulnerabilities and issues."""
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions analyzing for 'common vulnerabilities and issues,' which implies a read-only, diagnostic operation, but doesn't specify details like what vulnerabilities are checked, whether it modifies the token, potential rate limits, or output format. For a security tool with zero annotation coverage, this leaves significant gaps in understanding its behavior.

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

Conciseness5/5

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

The description is a single, clear sentence: 'Analyze a JWT for common vulnerabilities and issues.' It's front-loaded with the core purpose, has zero wasted words, and is appropriately sized for a simple tool. Every part of the sentence contributes directly to understanding the tool's function.

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?

Given the complexity (security analysis tool), lack of annotations, and no output schema, the description is incomplete. It doesn't cover behavioral aspects like what specific vulnerabilities are analyzed, whether it's safe for production use, or what the output looks like. For a tool with potential security implications and no structured data to rely on, this leaves the agent under-informed about critical context.

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 input schema has 1 parameter (token) with 0% description coverage, so the schema provides no semantic information. The description doesn't add any parameter details beyond implying the token is a JWT. It doesn't explain format requirements (e.g., string encoding) or constraints. With low schema coverage, the description fails to compensate adequately, but the single parameter is straightforward, so it meets the baseline for minimal viability.

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 a JWT for common vulnerabilities and issues.' It specifies the verb ('analyze') and resource ('JWT'), making it easy to understand what the tool does. However, it doesn't explicitly differentiate from sibling tools like jwt_decode (which might decode without analysis) or jwt_bruteforce (which might attempt exploitation), leaving some ambiguity about its unique role.

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 sibling tools (jwt_bruteforce, jwt_decode, jwt_generate) or specify contexts like security testing versus debugging. Without any usage context, the agent must infer based on tool names alone, which is insufficient for clear decision-making.

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/mohdhaji87/JWTAuditorMCP'

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