Skip to main content
Glama

calculate_fibonacci

Compute the nth Fibonacci number from the sequence to analyze complex mathematical operations. Use this tool for precise Fibonacci calculations with detailed results.

Instructions

Calculate the nth Fibonacci number.

This is a more computationally intensive example that demonstrates how tools can handle more complex operations. Args: n: The position in the Fibonacci sequence (must be >= 0) Returns: Dictionary containing the Fibonacci number and calculation info

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nYes

Implementation Reference

  • The main handler function for the calculate_fibonacci tool. It computes the nth Fibonacci number iteratively, validates input (n >= 0), measures computation time, and returns a dictionary with position, value, and timing info.
    async def calculate_fibonacci(n: int) -> Dict[str, Any]: """Calculate the nth Fibonacci number. This is a more computationally intensive example that demonstrates how tools can handle more complex operations. Args: n: The position in the Fibonacci sequence (must be >= 0) Returns: Dictionary containing the Fibonacci number and calculation info """ if n < 0: raise ValueError("n must be non-negative") if n <= 1: return {"position": n, "value": n, "calculation_time": 0} start_time = time.time() # Calculate Fibonacci number a, b = 0, 1 for _ in range(2, n + 1): a, b = b, a + b calculation_time = time.time() - start_time return { "position": n, "value": b, "calculation_time": calculation_time }
  • Registration loop in register_tools() that applies decorators (exception_handler, tool_logger) to each tool in example_tools (including calculate_fibonacci) and registers them explicitly with mcp_server.tool(name=tool_name).
    for tool_func in example_tools: # Apply SAAGA decorator chain: exception_handler → tool_logger decorated_func = exception_handler(tool_logger(tool_func, config.__dict__)) # Extract metadata from the original function tool_name = tool_func.__name__ # Register the decorated function directly with MCP # This preserves the function signature for parameter introspection mcp_server.tool( name=tool_name )(decorated_func) unified_logger.info(f"Registered tool: {tool_name}")
  • The example_tools list that includes the calculate_fibonacci function, which is imported and looped over in server/app.py for registration.
    example_tools = [ echo_tool, get_time, random_number, calculate_fibonacci ]

Other Tools

Related 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/SAGAAIDEV/mcp-ahrefs'

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