from mcp.server.fastmcp import FastMCP
from markitdown import MarkItDown
import os

mcp = FastMCP("MarkItDown")

@mcp.tool()
def convert_to_markdown(file_path: str) -> str:
    """Convert any supported file (PDF, DOCX, PPTX, XLSX, HTML, EPUB, XML) to Markdown."""
    file_path = os.path.expanduser(os.path.abspath(file_path))
    if not os.path.exists(file_path):
        return f"Error: File not found: {file_path}"
    md = MarkItDown()
    result = md.convert(file_path)
    return result.text_content

if __name__ == "__main__":
    mcp.run(transport="stdio")
