from mcp.server.fastmcp import FastMCP

mcp = FastMCP("reverse")


@mcp.tool()
def reverse_text(text: str, by_line: bool = False) -> str:
    """反转文本内容。

    Args:
        text: 要反转的文本
        by_line: 若为 True，按行反转（行的顺序倒过来）；否则逐字符反转
    """
    if by_line:
        lines = text.splitlines()
        lines.reverse()
        return "\n".join(lines)
    else:
        return text[::-1]


def main():
    mcp.run()


if __name__ == "__main__":
    main()
