forked from hluaguo/metabase-mcp
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup.py
More file actions
executable file
·149 lines (120 loc) · 4.46 KB
/
setup.py
File metadata and controls
executable file
·149 lines (120 loc) · 4.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/usr/bin/env python3
"""
Setup script for Metabase FastMCP Server
"""
import subprocess
import sys
from pathlib import Path
def install_dependencies():
"""Install required dependencies"""
print("Installing dependencies...")
# Try uv first, fall back to pip
if subprocess.run(["which", "uv"], capture_output=True).returncode == 0:
print("Using uv for dependency management...")
try:
subprocess.check_call(["uv", "sync"])
print("✓ Dependencies installed successfully with uv")
return True
except subprocess.CalledProcessError as e:
print(f"✗ Failed to install dependencies with uv: {e}")
print("Falling back to pip...")
# Fallback to pip
try:
subprocess.check_call([sys.executable, "-m", "pip", "install", "-r", "requirements.txt"])
print("✓ Dependencies installed successfully with pip")
except subprocess.CalledProcessError as e:
print(f"✗ Failed to install dependencies: {e}")
return False
return True
def setup_environment():
"""Set up environment configuration"""
env_file = Path(".env")
env_example = Path(".env.example")
if env_file.exists():
print("✓ .env file already exists")
return True
if env_example.exists():
print("Creating .env file from template...")
try:
env_example.rename(env_file)
print("✓ .env file created")
print("📝 Please edit .env file with your Metabase configuration")
return True
except Exception as e:
print(f"✗ Failed to create .env file: {e}")
return False
# Create basic .env file
env_content = """# Metabase Configuration
METABASE_URL=http://localhost:3000
METABASE_PASSWORD=your-password
METABASE_API_KEY=your-api-key
# Either use API_KEY or EMAIL+PASSWORD for authentication
# API_KEY takes precedence if both are provided
"""
try:
with open(".env", "w") as f:
f.write(env_content)
print("✓ .env file created")
print("📝 Please edit .env file with your Metabase configuration")
return True
except Exception as e:
print(f"✗ Failed to create .env file: {e}")
return False
def test_installation():
"""Test the installation"""
print("Testing installation...")
try:
# Test import
print("✓ All dependencies imported successfully")
# Test server creation (without running)
print("✓ Server module loaded successfully")
return True
except Exception as e:
print(f"✗ Installation test failed: {e}")
return False
def install_claude_desktop():
"""Install as Claude Desktop MCP server using FastMCP CLI"""
print("Installing as Claude Desktop MCP server...")
try:
server_path = Path("server.py").absolute()
subprocess.check_call(["fastmcp", "install", str(server_path), "-n", "Metabase MCP"])
print("✓ Successfully installed as Claude Desktop MCP server")
return True
except subprocess.CalledProcessError as e:
print(f"✗ Failed to install as Claude Desktop MCP server: {e}")
print("Make sure FastMCP CLI is installed: pip install fastmcp")
return False
except FileNotFoundError:
print("✗ FastMCP CLI not found. Install with: pip install fastmcp")
return False
def main():
"""Main setup function"""
print("🚀 Setting up Metabase FastMCP Server")
print("=" * 40)
success = True
# Install dependencies
if not install_dependencies():
success = False
# Setup environment
if not setup_environment():
success = False
# Test installation
if success and not test_installation():
success = False
print("\n" + "=" * 40)
if success:
print("✅ Setup completed successfully!")
print("\nNext steps:")
print("1. Edit .env file with your Metabase configuration")
print("2. Run the server: python server.py")
print("3. Or test with: python test_server.py")
# Ask about Claude Desktop installation
response = input("\nWould you like to install as Claude Desktop MCP server? (y/N): ")
if response.lower() in ["y", "yes"]:
install_claude_desktop()
else:
print("❌ Setup encountered errors. Please check the output above.")
sys.exit(1)
if __name__ == "__main__":
main()