Skip to main content
Glama

calculate_fibonacci

Compute Fibonacci sequence values for SEO analysis and data processing tasks. Enter position n to generate the corresponding Fibonacci number with calculation details.

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 that computes the nth Fibonacci number using an iterative approach, handles input validation, measures computation time, and returns structured results.
    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
        }
  • Registers calculate_fibonacci (as part of example_tools) with the MCP server by applying SAAGA decorators and using FastMCP's tool decorator.
    # Register regular tools with SAAGA decorators
    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}")
  • Includes calculate_fibonacci in the list of regular example tools that get automatically registered.
    example_tools = [
        echo_tool,
        get_time,
        random_number,
        calculate_fibonacci
    ]

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