forked from davehague/mcp-talk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_setup.py
More file actions
165 lines (137 loc) · 5.34 KB
/
test_setup.py
File metadata and controls
165 lines (137 loc) · 5.34 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
163
164
165
#!/usr/bin/env python3
"""
MCP Talk Demo Setup Test
Run this script to verify your environment is ready for the MCP demos.
"""
import sys
import subprocess
import importlib
import os
def check_virtual_env():
"""Check if we're running in a virtual environment"""
in_venv = (
hasattr(sys, 'real_prefix') or
(hasattr(sys, 'base_prefix') and sys.base_prefix != sys.prefix) or
os.environ.get('VIRTUAL_ENV') is not None
)
if in_venv:
venv_path = os.environ.get('VIRTUAL_ENV', sys.prefix)
print(f"✅ Virtual environment active: {venv_path}")
return True
else:
print("⚠️ No virtual environment detected")
print(" Recommended: source venv/bin/activate")
return False
def check_python_version():
"""Check if Python version is 3.8+"""
version = sys.version_info
if version.major == 3 and version.minor >= 8:
print(f"✅ Python {version.major}.{version.minor}.{version.micro} - OK")
return True
else:
print(f"❌ Python {version.major}.{version.minor}.{version.micro} - Need Python 3.8+")
return False
def check_package(package_name, import_name=None):
"""Check if a Python package is installed"""
if import_name is None:
import_name = package_name
try:
mod = importlib.import_module(import_name)
version = getattr(mod, '__version__', 'unknown')
print(f"✅ {package_name} ({version}) - Installed")
return True
except ImportError:
print(f"❌ {package_name} - Missing")
return False
def check_node_package(package_name):
"""Check if a Node.js package is available"""
try:
result = subprocess.run(['npx', '--version'],
capture_output=True, text=True, timeout=5)
if result.returncode == 0:
print(f"✅ npx available - Can run {package_name}")
return True
else:
print(f"❌ npx not available - Cannot run {package_name}")
return False
except (subprocess.TimeoutExpired, FileNotFoundError):
print(f"❌ npx not found - Cannot run {package_name}")
return False
def check_setup_files():
"""Check if setup files exist"""
files = ['requirements.txt', 'setup.sh', 'setup.bat']
all_exist = True
for file in files:
if os.path.exists(file):
print(f"✅ {file} - Found")
else:
print(f"❌ {file} - Missing")
all_exist = False
return all_exist
def main():
print("🔍 MCP Talk Demo Environment Check")
print("=" * 50)
all_good = True
# Check virtual environment
in_venv = check_virtual_env()
if not in_venv:
print(" 💡 Virtual environments isolate dependencies and are recommended")
print()
# Python version
if not check_python_version():
all_good = False
print("\n📦 Required Python Packages:")
packages = [
("mcp", "mcp"),
("psutil", "psutil"),
("fastapi", "fastapi"),
("uvicorn", "uvicorn"),
("aiohttp", "aiohttp")
]
missing_packages = []
for package, import_name in packages:
if not check_package(package, import_name):
missing_packages.append(package)
all_good = False
print("\n🌐 Node.js Tools (optional for filesystem server demo):")
node_available = check_node_package("@modelcontextprotocol/server-filesystem")
print("\n📁 Setup Files:")
if not check_setup_files():
all_good = False
print("\n" + "=" * 50)
if all_good and in_venv:
print("🎉 Environment ready for MCP demos!")
print("\nDemo execution order:")
print("1. python 03_prompts_demo.py # Standalone demo")
print("2. python 02_system_monitor_server.py # MCP server")
print("3. python 04_sse_server_complete.py # SSE server")
if node_available:
print("4. For client demo:")
print(" # Terminal 1:")
print(" npx -y @modelcontextprotocol/server-filesystem /tmp")
print(" # Terminal 2:")
print(" python 01_python_client_demo.py")
elif all_good and not in_venv:
print("⚠️ Environment ready, but virtual environment recommended!")
print("\nTo set up virtual environment:")
print("1. ./setup.sh (or setup.bat on Windows)")
print("2. source venv/bin/activate")
print("3. python test_setup.py")
else:
print("⚠️ Environment needs setup!")
if not in_venv:
print("\n🚀 Quick setup (recommended):")
print(" ./setup.sh (or setup.bat on Windows)")
if missing_packages:
print(f"\n📦 Missing packages: {', '.join(missing_packages)}")
if in_venv:
print(" pip install -r requirements.txt")
else:
print(" Activate venv first, then: pip install -r requirements.txt")
if not node_available:
print("\n🌐 Optional - Install Node.js for filesystem server demo:")
print(" Download from: https://nodejs.org/")
print(f"\n📍 Current working directory: {os.getcwd()}")
print(f"🐍 Python executable: {sys.executable}")
if __name__ == "__main__":
main()