Skip to main content
Glama
apetta

Vibe Math MCP

by apetta

percentage

Calculate percentages: find percentage of a value, increase or decrease by percentage, or determine percentage change between values.

Instructions

Perform percentage calculations: of, increase, decrease, or change.

Examples:

PERCENTAGE OF: 15% of 200 operation="of", value=200, percentage=15 Result: 30

INCREASE: 100 increased by 20% operation="increase", value=100, percentage=20 Result: 120

DECREASE: 100 decreased by 20% operation="decrease", value=100, percentage=20 Result: 80

PERCENTAGE CHANGE: from 80 to 100 operation="change", value=80, percentage=100 Result: 25 (25% increase)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
contextNoOptional annotation to label this calculation (e.g., 'Bond A PV', 'Q2 revenue'). Appears in results for easy identification.
output_modeNoOutput format: full (default), compact, minimal, value, or final. See batch_execute tool for details.full
operationYesType of calculation
valueYesBase value
percentageYesPercentage amount (or new value for 'change')

Implementation Reference

  • The main handler function that executes the percentage tool logic for different operations: 'of', 'increase', 'decrease', 'change'.
    async def percentage(
        operation: Annotated[
            Literal["of", "increase", "decrease", "change"], Field(description="Type of calculation")
        ],
        value: Annotated[float, Field(description="Base value")],
        percentage: Annotated[
            float, Field(description="Percentage amount (or new value for 'change')")
        ],
    ) -> str:
        """Perform percentage calculations."""
        try:
            if operation == "of":
                result = (percentage / 100) * value
                explanation = f"{percentage}% of {value}"
            elif operation == "increase":
                result = value * (1 + percentage / 100)
                explanation = f"{value} increased by {percentage}%"
            elif operation == "decrease":
                result = value * (1 - percentage / 100)
                explanation = f"{value} decreased by {percentage}%"
            elif operation == "change":
                # percentage is actually the new value in this case
                if value == 0:
                    raise ValueError("Cannot calculate percentage change from zero")
                result = ((percentage - value) / value) * 100
                explanation = f"Percentage change from {value} to {percentage}"
            else:
                raise ValueError(f"Unknown operation: {operation}")
    
            return format_result(
                result,
                {
                    "operation": operation,
                    "value": value,
                    "percentage": percentage,
                    "explanation": explanation,
                },
            )
        except Exception as e:
            raise ValueError(f"Percentage calculation failed: {str(e)}")
  • Registers the percentage tool with the MCP framework, specifying name, description, and annotations.
    @mcp.tool(
        name="percentage",
        description="""Perform percentage calculations: of, increase, decrease, or change.
    
    Examples:
    
    PERCENTAGE OF: 15% of 200
        operation="of", value=200, percentage=15
        Result: 30
    
    INCREASE: 100 increased by 20%
        operation="increase", value=100, percentage=20
        Result: 120
    
    DECREASE: 100 decreased by 20%
        operation="decrease", value=100, percentage=20
        Result: 80
    
    PERCENTAGE CHANGE: from 80 to 100
        operation="change", value=80, percentage=100
        Result: 25 (25% increase)""",
        annotations=ToolAnnotations(
            title="Percentage Calculator",
            readOnlyHint=True,
            idempotentHint=True,
        ),
    )
  • Pydantic schema definitions for the tool inputs using Annotated types and Field descriptions.
        operation: Annotated[
            Literal["of", "increase", "decrease", "change"], Field(description="Type of calculation")
        ],
        value: Annotated[float, Field(description="Base value")],
        percentage: Annotated[
            float, Field(description="Percentage amount (or new value for 'change')")
        ],
    ) -> str:

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/apetta/vibe-math-mcp'

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