Skip to main content
Glama

generate_password

Read-only

Create secure random passwords with customizable length and optional special characters for enhanced account protection.

Instructions

Generate a random password with specified length, optionally including special characters.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
lengthNoThe length of the password to generate (between 8 and 64 characters).
use_special_charsNoInclude special characters in the password.

Implementation Reference

  • Handler function for the 'generate_password' tool. Generates a secure random password ensuring complexity requirements are met (lowercase, uppercase, digits, optional special chars). Includes input schema via Annotated Fields with Pydantic validation.
    async def generate_password(
        self,
        ctx: Context,
        length: Annotated[
            int,
            Field(
                default=12,
                ge=8,
                le=64,
                description="The length of the password to generate (between 8 and 64 characters).",
            ),
        ] = 12,
        use_special_chars: Annotated[
            bool,
            Field(
                default=False,
                description="Include special characters in the password.",
            ),
        ] = False,
    ) -> ToolResult:
        """Generate a random password with specified length, optionally including special characters."""
        """The password will meet the complexity requirements of at least one lowercase letter, one uppercase letter, and two digits.
        If special characters are included, it will also contain at least one such character.
        Until the password meets these requirements, it will keep regenerating.
        This is a simple example of a tool that can be used to generate passwords. It is not intended for production use."""
        characters = string.ascii_letters + string.digits
        if use_special_chars:
            characters += string.punctuation
        password_generation_attempts = 0
        while True:
            password = "".join(secrets.choice(characters) for _ in range(length))
            password_generation_attempts += 1
            if (
                any(c.islower() for c in password)
                and any(c.isupper() for c in password)
                and sum(c.isdigit() for c in password) >= 2
                and (not use_special_chars or any(c in string.punctuation for c in password))
            ):
                await ctx.info("Generated password meets complexity requirements.")
                break
            else:
                # Exclude from coverage because this may not always happen in tests
                await ctx.warning(  # pragma: no cover
                    f"Re-generating since the generated password did not meet complexity requirements: {password}"
                )
        return self.get_tool_result(
            result=password,
            metadata={
                "generate_password": {
                    "length_satisfied": len(password) == length,
                    "character_set": characters,
                    "generation_attempts": password_generation_attempts,
                }
            },
        )
  • Registration of the 'generate_password' tool in the PyMCP class's tools list, specifying name, tags, and read-only annotation.
    {
        "fn": "generate_password",
        "tags": ["password-generation", "example"],
        "annotations": {"readOnlyHint": True},
    },
  • Input schema defined via Pydantic Annotated parameters with Field descriptions, defaults, and constraints for length and use_special_chars.
    async def generate_password(
        self,
        ctx: Context,
        length: Annotated[
            int,
            Field(
                default=12,
                ge=8,
                le=64,
                description="The length of the password to generate (between 8 and 64 characters).",
            ),
        ] = 12,
        use_special_chars: Annotated[
            bool,
            Field(
                default=False,
                description="Include special characters in the password.",
            ),
        ] = False,
    ) -> ToolResult:
Behavior4/5

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

The annotations declare readOnlyHint=true, indicating a safe read operation. The description adds useful behavioral context beyond annotations: it specifies that the tool generates a 'random' password (implying non-deterministic output) and mentions the optional inclusion of special characters. However, it doesn't detail aspects like character sets, entropy, or generation algorithms, which could be relevant for security contexts.

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, well-structured sentence that efficiently conveys the tool's purpose and key parameters. It is front-loaded with the main action and avoids redundancy. Every word earns its place, making it highly concise without sacrificing clarity.

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 the tool's low complexity (2 parameters, no output schema, read-only operation), the description is reasonably complete. It covers the core functionality and parameters. However, it lacks details on output format (e.g., string type) and doesn't mention security considerations or error handling, which could be relevant for a password generator. The annotations help by indicating safety, but more context could be added.

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 100% description coverage, with clear documentation for both parameters (length and use_special_chars). The description adds minimal semantic value beyond the schema, only reiterating that length is 'specified' and special characters are 'optional'. No additional syntax, constraints, or usage examples are provided, so the baseline score of 3 is appropriate.

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 the specific action ('generate a random password') and the resource ('password'), with explicit mention of key parameters (length and special characters). It distinguishes this tool from all sibling tools listed (greet, permutations, pirate_summary, text_web_search, vonmises_random), which are unrelated to password generation.

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

Usage Guidelines3/5

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

The description implies usage for password generation scenarios but provides no explicit guidance on when to use this tool versus alternatives. There are no mentioned prerequisites, exclusions, or comparisons to other password-related tools (though none are listed as siblings). The 'optionally including special characters' phrase hints at a choice but doesn't specify contexts for that choice.

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/anirbanbasu/pymcp'

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