Skip to main content
Glama

permutations

Read-only

Calculate permutations to determine the number of ordered arrangements when selecting items from a set without repetition.

Instructions

Calculate the number of ways to choose k items from n items without repetition and with order.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nYesThe number of items to choose from.
kNoThe optional number of items to choose.

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The main handler function for the 'permutations' tool, which calculates the permutation P(n, k) = n! / (n-k)! using math.perm, with validation for parameters n and k.
    async def permutations(
        self,
        ctx: Context,
        n: Annotated[
            int,
            Field(
                ge=1,
                description="The number of items to choose from.",
            ),
        ],
        k: Annotated[
            int | None,
            Field(
                default=None,
                ge=1,
                description="The optional number of items to choose.",
            ),
        ],
    ) -> int:
        """Calculate the number of ways to choose k items from n items without repetition and with order."""
        """If k is not provided, it defaults to n."""
        assert isinstance(n, int) and n >= 1, "n must be a positive integer."
    
        if k is None:
            k = n
        if k > n:
            raise McpError(
                error=ErrorData(
                    code=INVALID_PARAMS,
                    message=f"k ({k}) cannot be greater than n ({n}).",
                )
            )
    
        return math.perm(n, k)
  • Registration entry for the 'permutations' tool in the PyMCP class tools list, including tags and annotations.
    {
        "fn": "permutations",
        "tags": ["math", "permutation", "example"],
        "annotations": {"readOnlyHint": True},
    },
  • Inclusion of 'permutations' tool in the response caching middleware settings.
    included_tools=["greet", "permutations"],
  • Pydantic schema definitions for input parameters n and k of the permutations tool, including constraints and descriptions.
        n: Annotated[
            int,
            Field(
                ge=1,
                description="The number of items to choose from.",
            ),
        ],
        k: Annotated[
            int | None,
            Field(
                default=None,
                ge=1,
                description="The optional number of items to choose.",
            ),
        ],
    ) -> int:
        """Calculate the number of ways to choose k items from n items without repetition and with order."""
        """If k is not provided, it defaults to n."""
        assert isinstance(n, int) and n >= 1, "n must be a positive integer."
    
        if k is None:
            k = n
        if k > n:
            raise McpError(
                error=ErrorData(
                    code=INVALID_PARAMS,
                    message=f"k ({k}) cannot be greater than n ({n}).",
                )
            )
    
        return math.perm(n, k)
Behavior3/5

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

Annotations already declare readOnlyHint=true, indicating a safe read operation. The description adds value by specifying the mathematical behavior (permutations without repetition and with order), which isn't covered by annotations. However, it doesn't mention performance characteristics, error handling, or output format details beyond what the output schema provides.

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 directly states the tool's purpose without unnecessary words. It's front-loaded with the core functionality, making it easy to understand quickly.

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 (mathematical calculation), high schema coverage (100%), presence of annotations (readOnlyHint), and an output schema, the description is mostly complete. It clearly defines the operation but could benefit from slight elaboration on usage scenarios or mathematical 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?

Schema description coverage is 100%, with clear descriptions for both parameters. The description reinforces the meaning of n and k in the context of permutations but doesn't add significant semantic details beyond what the schema already provides, such as edge cases or mathematical constraints.

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 mathematical operation ('calculate the number of ways') with precise conditions ('choose k items from n items without repetition and with order'). It distinguishes itself from sibling tools like 'generate_password' or 'text_web_search' by focusing exclusively on combinatorial permutations.

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 through its mathematical definition but doesn't explicitly state when to use this tool versus alternatives (e.g., combinations vs. permutations, or other mathematical tools). No guidance is provided on prerequisites or exclusions, leaving usage context to inference.

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