alihmaou commited on
Commit
08c36ed
Β·
verified Β·
1 Parent(s): 9979c8f

Deploy app.py via Meta-MCP

Browse files
Files changed (1) hide show
  1. app.py +67 -0
app.py ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import os
3
+ import sys
4
+ import importlib
5
+
6
+ # Configuration
7
+ TOOLS_DIR = "tools"
8
+
9
+ # Ensure tools directory exists and is a package
10
+ if not os.path.exists(TOOLS_DIR):
11
+ os.makedirs(TOOLS_DIR, exist_ok=True)
12
+ with open(os.path.join(TOOLS_DIR, "__init__.py"), "w") as f:
13
+ pass
14
+
15
+ # Add current directory to path so 'import tools.xxx' works
16
+ sys.path.append(os.path.dirname(os.path.abspath(__file__)))
17
+
18
+ interfaces = []
19
+ names = []
20
+
21
+ print(f"πŸš€ Starting Meta-MCP Toolbox...")
22
+ print(f"πŸ“‚ Scanning '{TOOLS_DIR}' directory...")
23
+
24
+ # Scan and import tools
25
+ try:
26
+ for filename in sorted(os.listdir(TOOLS_DIR)):
27
+ if filename.endswith(".py") and not filename.startswith("_"):
28
+ module_name = filename[:-3]
29
+ full_module_name = f"{TOOLS_DIR}.{module_name}"
30
+
31
+ try:
32
+ print(f" πŸ‘‰ Importing {full_module_name}...")
33
+ # Standard dynamic import
34
+ # Use reload to ensure latest version is taken if restarted
35
+ module = importlib.import_module(full_module_name)
36
+ importlib.reload(module)
37
+
38
+ if hasattr(module, "create_interface"):
39
+ # Create Gradio interface for this tool
40
+ tool_interface = module.create_interface()
41
+ interfaces.append(tool_interface)
42
+ names.append(module_name)
43
+ print(f" βœ… Loaded {module_name}")
44
+ else:
45
+ print(f" ⚠️ Module {module_name} has no create_interface()")
46
+ except Exception as e:
47
+ print(f" ❌ Error loading {module_name}: {e}")
48
+ import traceback
49
+ traceback.print_exc()
50
+
51
+ except Exception as e:
52
+ print(f"Error scanning tools directory: {e}")
53
+
54
+ # Final interface construction
55
+ if not interfaces:
56
+ demo = gr.Interface(
57
+ fn=lambda x: "No tools loaded yet. Add a tool via Meta-MCP!",
58
+ inputs="text",
59
+ outputs="text",
60
+ title="Empty Toolbox",
61
+ description="This Space is ready to receive tools."
62
+ )
63
+ else:
64
+ demo = gr.TabbedInterface(interfaces, names)
65
+
66
+ if __name__ == "__main__":
67
+ demo.launch(mcp_server=True, show_error=True)