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
| Name | Required | Description | Default |
|---|---|---|---|
| n | Yes |
Implementation Reference
- my_mcp/server.py:41-60 (handler)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()
- my_mcp/server.py:14-21 (helper)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