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

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

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
    ]
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It mentions computational intensity but doesn't address performance characteristics, error handling, input validation beyond the n>=0 constraint, or system impact. Significant behavioral gaps remain.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Well-structured with purpose statement, context note, and clear Args/Returns sections. The 'computationally intensive' sentence could be more integrated but doesn't significantly detract from overall efficiency.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a single-parameter mathematical function with output schema, the description covers basics adequately but lacks context about performance trade-offs, typical use cases, or how it differs from similar computational tools. The presence of an output schema reduces but doesn't eliminate the need for more operational context.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

With 0% schema description coverage and only 1 parameter, the description fully compensates by clearly explaining n as 'position in the Fibonacci sequence' with the constraint 'must be >= 0'. This adds essential meaning beyond the bare schema.

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 tool's purpose with specific verb ('calculate') and resource ('nth Fibonacci number'), distinguishing it from siblings like echo_tool or get_time. It precisely defines what mathematical operation it performs.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided about when to use this tool versus alternatives like simulate_heavy_computation or process_batch_data. The description mentions it's 'computationally intensive' but doesn't specify appropriate contexts or exclusions.

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

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