| | import gradio as gr |
| | import os |
| | import sys |
| | import importlib |
| |
|
| | |
| | TOOLS_DIR = "tools" |
| |
|
| | |
| | if not os.path.exists(TOOLS_DIR): |
| | os.makedirs(TOOLS_DIR, exist_ok=True) |
| | with open(os.path.join(TOOLS_DIR, "__init__.py"), "w") as f: |
| | pass |
| |
|
| | |
| | sys.path.append(os.path.dirname(os.path.abspath(__file__))) |
| |
|
| | interfaces = [] |
| | names = [] |
| |
|
| | print(f"π Starting Meta-MCP Toolbox...") |
| | print(f"π Scanning '{TOOLS_DIR}' directory...") |
| |
|
| | |
| | try: |
| | for filename in sorted(os.listdir(TOOLS_DIR)): |
| | if filename.endswith(".py") and not filename.startswith("_"): |
| | module_name = filename[:-3] |
| | full_module_name = f"{TOOLS_DIR}.{module_name}" |
| |
|
| | try: |
| | print(f" π Importing {full_module_name}...") |
| | |
| | |
| | module = importlib.import_module(full_module_name) |
| | importlib.reload(module) |
| |
|
| | if hasattr(module, "create_interface"): |
| | |
| | tool_interface = module.create_interface() |
| | interfaces.append(tool_interface) |
| | names.append(module_name) |
| | print(f" β
Loaded {module_name}") |
| | else: |
| | print(f" β οΈ Module {module_name} has no create_interface()") |
| | except Exception as e: |
| | print(f" β Error loading {module_name}: {e}") |
| | import traceback |
| | traceback.print_exc() |
| |
|
| | except Exception as e: |
| | print(f"Error scanning tools directory: {e}") |
| |
|
| | |
| | if not interfaces: |
| | demo = gr.Interface( |
| | fn=lambda x: "No tools loaded yet. Add a tool via Meta-MCP!", |
| | inputs="text", |
| | outputs="text", |
| | title="Empty Toolbox", |
| | description="This Space is ready to receive tools." |
| | ) |
| | else: |
| | demo = gr.TabbedInterface(interfaces, names) |
| |
|
| | if __name__ == "__main__": |
| | demo.launch(mcp_server=True, show_error=True) |