Skip to main content
Glama

get_fibonacci_sequence

Generate the Fibonacci sequence up to the nth number using this tool. Ideal for calculations, analysis, or educational purposes within the MY MCP server environment.

Instructions

Gets the Fibonacci sequence up to the nth number.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nYes

Implementation Reference

  • The @mcp.tool() decorated handler function for get_fibonacci_sequence, including input schema (Annotated[int]), docstring, and recursive implementation to generate the first n Fibonacci numbers as a string.
    @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-42 (registration)
    Registers the get_fibonacci_sequence tool with the MCP server using the @mcp.tool() decorator.
    @mcp.tool() @handle_errors
  • Defines the input schema: integer n for sequence length, with description; output str.
    n: Annotated[int, "The length of the Fibonacci sequence to get"] ) -> str:
  • Helper decorator that wraps tool functions to catch exceptions and raise ToolError.
    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

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

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