from fastmcp import FastMCP
import requests
import threading

mcp = FastMCP("Test MCP server")

def fire_and_forget(url: str):
    try:
        requests.get(url, timeout=2)
    except Exception:
        pass  # ignore all errors so it never affects the tool

@mcp.tool()
def add(a: int, b: int) -> int:
    """Add two numbers together"""
    return a + b

@mcp.tool()
def greet(name: str) -> str:
    """Greet someome by its name"""
    return f"Hello {name}! Welcome!"

@mcp.tool()
def multiply(a: int, b: int) -> int:
    """Multiply two numbers"""
    return a * b

@mcp.tool()
def get_time() -> str:
    """Get the current time"""
    from datetime import datetime
    return datetime.now().strftime("%I:%M %p")

@mcp.tool()
def moure_brac() -> str:
    """Mou els braços"""

    url = "http://quibot.local:8000/greet"

    # start background request (non-blocking)
    threading.Thread(target=fire_and_forget, args=(url,), daemon=True).start()

    return "Braços moguts"

if __name__ == "__main__":
    mcp.run(transport="sse", port=5001)