Skip to main content
Glama
mohdhaji87

JWT Auditor MCP Server

by mohdhaji87

jwt_generate

Create JSON Web Tokens by specifying header, payload, algorithm, and cryptographic key for testing and security validation.

Instructions

Generate a JWT with the given header, payload, algorithm, and key (HS* or RS*).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
headerYes
payloadYes
algYes
keyYes

Implementation Reference

  • The jwt_generate tool handler, decorated with @server.tool() for registration. Generates JWT tokens supporting HS256/HS384/HS512 and RS256/RS384/RS512 algorithms using provided header, payload, alg, and key. Handles base64 encoding, signing with HMAC or RSA private key.
    @server.tool()
    def jwt_generate(header: dict, payload: dict, alg: str, key: str) -> dict:
        """Generate a JWT with the given header, payload, algorithm, and key (HS* or RS*)."""
        import base64
        import json
        import hmac
        import hashlib
        try:
            def b64encode(data):
                return base64.urlsafe_b64encode(data).rstrip(b'=').decode()
            header_b64 = b64encode(json.dumps(header, separators=(",", ":")).encode())
            payload_b64 = b64encode(json.dumps(payload, separators=(",", ":")).encode())
            signing_input = f"{header_b64}.{payload_b64}".encode()
            alg_upper = alg.upper()
            if alg_upper in ["HS256", "HS384", "HS512"]:
                hash_alg = {"HS256": hashlib.sha256, "HS384": hashlib.sha384, "HS512": hashlib.sha512}[alg_upper]
                sig = hmac.new(key.encode(), signing_input, hash_alg).digest()
                signature_b64 = b64encode(sig)
            elif alg_upper in ["RS256", "RS384", "RS512"]:
                from cryptography.hazmat.primitives import serialization, hashes
                from cryptography.hazmat.primitives.asymmetric import padding
                private_key = serialization.load_pem_private_key(key.encode(), password=None)
                hash_alg = {"RS256": hashes.SHA256(), "RS384": hashes.SHA384(), "RS512": hashes.SHA512()}[alg_upper]
                sig = private_key.sign(
                    signing_input,
                    padding.PKCS1v15(),
                    hash_alg
                )
                signature_b64 = b64encode(sig)
            else:
                return {"error": f"Unsupported algorithm: {alg}"}
            jwt = f"{header_b64}.{payload_b64}.{signature_b64}"
            return {"jwt": jwt}
        except Exception as e:
            return {"error": str(e)}
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. It states the tool generates a JWT but doesn't disclose behavioral traits such as whether it requires specific permissions, what the output format is (e.g., string), error handling, or security implications (e.g., key storage). The mention of algorithm types (HS* or RS*) adds minimal context but lacks depth.

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, efficient sentence that front-loads the core action and parameters without unnecessary words. Every part earns its place by specifying the tool's function and inputs clearly.

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 of JWT generation with 4 parameters, no annotations, and no output schema, the description is incomplete. It lacks details on output (e.g., JWT string format), error cases, algorithm specifics, and security considerations. For a cryptographic tool with nested objects in the schema, more context is needed for safe and effective use.

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

Parameters2/5

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

Schema description coverage is 0%, so the description must compensate. It lists the four parameters (header, payload, algorithm, key) and specifies algorithm types (HS* or RS*), adding some meaning beyond the bare schema. However, it doesn't explain what each parameter represents (e.g., header fields like 'typ', payload claims), expected formats, or examples, leaving significant gaps.

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 verb 'Generate' and the resource 'JWT', specifying the four input parameters (header, payload, algorithm, key). It distinguishes from siblings like jwt_analyze, jwt_bruteforce, and jwt_decode by focusing on creation rather than analysis or decryption. However, it doesn't explicitly contrast with siblings beyond the different action.

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 like jwt_analyze or jwt_decode. It mentions algorithm types (HS* or RS*) but doesn't explain when to choose this over other JWT tools or what scenarios warrant JWT generation. There's no mention of prerequisites or exclusions.

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