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