-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathsetup_nodejs.py
More file actions
162 lines (136 loc) Β· 5.65 KB
/
setup_nodejs.py
File metadata and controls
162 lines (136 loc) Β· 5.65 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
150
151
152
153
154
155
156
157
158
159
160
161
162
#!/usr/bin/env python3
"""
Setup script for Node.js installation and MCP server configuration
"""
import subprocess
import sys
import os
import webbrowser
from pathlib import Path
def check_current_nodejs():
"""Check current Node.js installation"""
print("π Checking current Node.js installation...")
try:
result = subprocess.run(["node", "--version"],
capture_output=True, text=True, timeout=10)
if result.returncode == 0:
version = result.stdout.strip()
major_version = int(version.lstrip('v').split('.')[0])
print(f"π¦ Current Node.js version: {version}")
if major_version >= 18:
print("β
Node.js version is compatible with MCP servers!")
return True
else:
print(f"β οΈ Node.js version {version} is too old for MCP servers")
print("π― Recommended: Node.js v18+ or v20+")
return False
else:
print("β Node.js check failed")
return False
except Exception as e:
print(f"β Node.js not found: {e}")
return False
def check_npm():
"""Check npm installation"""
try:
result = subprocess.run(["npm", "--version"],
capture_output=True, text=True, timeout=10)
if result.returncode == 0:
version = result.stdout.strip()
print(f"π¦ NPM version: {version}")
return True
else:
print("β NPM check failed")
return False
except Exception as e:
print(f"β NPM not found: {e}")
return False
def download_nodejs():
"""Open Node.js download page"""
print("\nπ Opening Node.js download page...")
webbrowser.open("https://nodejs.org/en/download/")
print("π₯ Please download and install Node.js v20.x LTS (recommended)")
print("π After installation, restart your terminal and run this script again")
def test_mcp_servers():
"""Test if MCP servers can be installed"""
print("\nπ§ͺ Testing MCP server installation...")
npx_cmd = "npx.cmd" if os.name == 'nt' else "npx"
# Test filesystem server
print("Testing @modelcontextprotocol/server-filesystem...")
try:
result = subprocess.run([
npx_cmd, "-y", "@modelcontextprotocol/server-filesystem", "--help"
], capture_output=True, text=True, timeout=30)
if result.returncode == 0:
print("β
Filesystem server can be installed!")
else:
print(f"β οΈ Filesystem server test failed: {result.stderr}")
except Exception as e:
print(f"β Filesystem server test error: {e}")
# Test brave search server
print("Testing @modelcontextprotocol/server-brave-search...")
try:
result = subprocess.run([
npx_cmd, "-y", "@modelcontextprotocol/server-brave-search", "--help"
], capture_output=True, text=True, timeout=30)
if result.returncode == 0:
print("β
Brave search server can be installed!")
else:
print(f"β οΈ Brave search server test failed: {result.stderr}")
except Exception as e:
print(f"β Brave search server test error: {e}")
def check_environment():
"""Check environment variables"""
print("\nπ§ Checking environment variables...")
env_vars = {
"GROQ_API_KEY": "Groq LLM API",
"OPENAI_API_KEY": "OpenAI GPT API",
"ANTHROPIC_API_KEY": "Anthropic Claude API",
"BRAVE_API_KEY": "Brave Search API",
"SEGMIND_API_KEY": "Segmind Image API"
}
env_file = Path(".env")
if env_file.exists():
print(f"β
Found .env file: {env_file.absolute()}")
else:
print("β οΈ No .env file found - you may want to create one")
for var, description in env_vars.items():
value = os.getenv(var)
if value:
masked_value = value[:4] + "***" + value[-4:] if len(value) > 8 else "***"
print(f"β
{var}: {masked_value} ({description})")
else:
print(f"β οΈ {var}: Not set ({description})")
def main():
"""Main setup function"""
print("π CrewAI MCP Setup Helper")
print("=" * 50)
# Check current Node.js
nodejs_ok = check_current_nodejs()
# Check npm
npm_ok = check_npm()
# Check environment
check_environment()
if not nodejs_ok:
print("\nπ Next Steps:")
print("1. Install Node.js v18+ or v20+ LTS")
print("2. Restart your terminal")
print("3. Run this script again to verify")
print("4. Run main.py to test MCP servers")
choice = input("\nβ Open Node.js download page? (y/N): ").strip().lower()
if choice in ['y', 'yes']:
download_nodejs()
else:
print("\nβ
Node.js setup looks good!")
# Test MCP servers if Node.js is OK
choice = input("\nβ Test MCP server installation? (y/N): ").strip().lower()
if choice in ['y', 'yes']:
test_mcp_servers()
print("\nπ You can now run main.py to use all MCP servers!")
print("\nπ‘ Tips:")
print(" - Add API keys to .env file for full functionality")
print(" - GROQ_API_KEY is recommended for fast LLM responses")
print(" - BRAVE_API_KEY enables web search capabilities")
print(" - SEGMIND_API_KEY enables image generation")
if __name__ == "__main__":
main()