Skip to main content
Glama
by apetta

percentage

Calculate percentages: find percentages of values, increase or decrease amounts by percentages, and determine percentage changes 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

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')

Input Schema (JSON Schema)

{ "properties": { "context": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "description": "Optional annotation to label this calculation (e.g., 'Bond A PV', 'Q2 revenue'). Appears in results for easy identification." }, "operation": { "description": "Type of calculation", "enum": [ "of", "increase", "decrease", "change" ], "type": "string" }, "output_mode": { "default": "full", "description": "Output format: full (default), compact, minimal, value, or final. See batch_execute tool for details.", "enum": [ "full", "compact", "minimal", "value", "final" ], "type": "string" }, "percentage": { "description": "Percentage amount (or new value for 'change')", "type": "number" }, "value": { "description": "Base value", "type": "number" } }, "required": [ "value", "percentage", "operation" ], "type": "object" }

Implementation Reference

  • The handler function implementing percentage calculations for 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' MCP tool with 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's input parameters: operation, value, 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:

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