from dotenv import load_dotenv
load_dotenv()
import os,asyncio
from pathlib import Path
from mcp_use import MCPAgent, MCPClient
from dotenv import load_dotenv
load_dotenv()
# Get the full path to uvx
uvx_path = '/Users/usmankhalid/.local/bin/uvx'

# Option 2: Use local wheel file (for testing before publishing)
# Adjust this path based on your notebook location
wheel_path = '/Users/usmankhalid/Desktop/usman_firecrawl/dist/usman_firecrawl-1.0.2-py3-none-any.whl'
mcp_config = {
  "mcpServers": {
    "usman-firecrawl": {
      "command": uvx_path,
      "args": [
        "--from", str(wheel_path),
        "usman_firecrawl",
          "--FIRECRAWL_API_KEY",
          os.getenv("FIRECRAWL_API_KEY")
      ]
    }
  }
}




# mcp_config = {
#     "mcpServers": {
#     "barie-aml-watcher-mcp": {
#         "command": uvx_path,
#         "args": [
#         "barie-aml-watcher-mcp",
#         "--api-key",
#         os.getenv("aml_api_key")
#         ]
#     }
#     }
# }



async def main():
    print(f"\n\n- - - MCP Config: {mcp_config}\n- - - -\n")
    # Create MCPClient from configuration dictionary
    client = MCPClient.from_dict(mcp_config)


    await client.create_all_sessions()
    print("🔄 Connected to Supabase MCP server!")

    mcp_session = client.get_session("usman-firecrawl")

    # Test list tools
    tools = await mcp_session.list_tools()
    print(f"✅ Available tools:\n{tools}")

    search_result = await mcp_session.call_tool("search_tools", {"query": "latest news about AI"})
    print(f"✅ Search result:\n{search_result}",'\n\n\n========')

    scrape_result = await mcp_session.call_tool("scrape", {"url": "https://www.google.com"})
    print(f"✅ Scrape result:\n{scrape_result}")


if __name__ == "__main__":
    asyncio.run(main())
