Skip to main content
Glama

get_fibonacci_sequence

Generate the Fibonacci sequence up to a specified number. Use this tool to calculate mathematical sequences for analysis, programming, or educational purposes.

Instructions

Gets the Fibonacci sequence up to the nth number.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nYes

Implementation Reference

  • The main handler function for the 'get_fibonacci_sequence' tool, including its schema (Annotated parameter and docstring), registration via @mcp.tool(), and recursive implementation to generate the Fibonacci sequence up to n terms.
    @mcp.tool() @handle_errors def get_fibonacci_sequence( n: Annotated[int, "The length of the Fibonacci sequence to get"] ) -> str: """Gets the Fibonacci sequence up to the nth number.""" def build_sequence(count): if count <= 0: return [] elif count == 1: return [0] elif count == 2: return [0, 1] else: prev_sequence = build_sequence(count - 1) next_value = prev_sequence[-1] + prev_sequence[-2] return prev_sequence + [next_value] return str(build_sequence(n))
  • my_mcp/server.py:41-41 (registration)
    Registration of the tool using the FastMCP @mcp.tool() decorator.
    @mcp.tool()
  • Helper decorator applied to the tool handler for error handling.
    def handle_errors(func: Callable) -> Callable: @functools.wraps(func) def wrapper(*args, **kwargs): try: return func(*args, **kwargs) except Exception as e: raise ToolError(f"Error in {func.__name__}: {e}") return wrapper

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/vaheandonians/my-mcp'

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