-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathinstall_ubuntu.py
More file actions
150 lines (128 loc) · 4.75 KB
/
install_ubuntu.py
File metadata and controls
150 lines (128 loc) · 4.75 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
#!/usr/bin/env python3
# ====================================================
# Project: MCP2Serial
# Description: Installation script for Ubuntu/Raspberry Pi
# Repository: https://github.com/mcp2everything/mcp2serial.git
# License: MIT License
# Author: mcp2everything
# Copyright (c) 2024 mcp2everything
# ====================================================
import os
import sys
import json
import subprocess
from pathlib import Path
import shutil
def get_uv_path():
"""Get uv executable path."""
# 检查是否已安装uv
try:
result = subprocess.run(['which', 'uv'], capture_output=True, text=True)
if result.returncode == 0:
return result.stdout.strip()
except:
pass
return None
def install_uv():
"""Install uv package manager."""
print("Installing uv package manager...")
try:
# 使用curl安装uv
curl_command = 'curl -LsSf https://astral.sh/uv/install.sh | sh'
subprocess.run(curl_command, shell=True, check=True)
# 添加uv到PATH
home = str(Path.home())
bashrc_path = os.path.join(home, '.bashrc')
with open(bashrc_path, 'a') as f:
f.write('\n# uv package manager\nexport PATH="$HOME/.cargo/bin:$PATH"\n')
print("uv installed successfully!")
return True
except Exception as e:
print(f"Error installing uv: {e}")
return False
def install_mcp2serial():
"""Install mcp2serial package."""
try:
# 创建虚拟环境并安装包
subprocess.run(['uv', 'venv', '.venv'], check=True)
subprocess.run(['.venv/bin/uv', 'pip', 'install', 'mcp2serial'], check=True)
return True
except Exception as e:
print(f"Error installing mcp2serial: {e}")
return False
def configure_claude_desktop():
"""Configure Claude Desktop with mcp2serial."""
try:
home = str(Path.home())
config_dir = os.path.join(home, '.config', 'claude-desktop')
os.makedirs(config_dir, exist_ok=True)
config_file = os.path.join(config_dir, 'config.json')
config = {
"mcpServers": {
"mcp2serial": {
"command": "uvx",
"args": ["mcp2serial"]
}
}
}
# 如果配置文件已存在,则更新而不是覆盖
if os.path.exists(config_file):
with open(config_file, 'r') as f:
existing_config = json.load(f)
existing_config.setdefault('mcpServers', {})
existing_config['mcpServers']['mcp2serial'] = config['mcpServers']['mcp2serial']
config = existing_config
with open(config_file, 'w') as f:
json.dump(config, f, indent=4)
print("Claude Desktop configured successfully!")
return True
except Exception as e:
print(f"Error configuring Claude Desktop: {e}")
return False
def setup_config():
"""Setup configuration files."""
try:
home = str(Path.home())
config_dir = os.path.join(home, '.mcp2serial')
os.makedirs(config_dir, exist_ok=True)
# 复制默认配置文件
default_config = os.path.join(os.path.dirname(__file__), 'config.yaml')
user_config = os.path.join(config_dir, 'config.yaml')
if os.path.exists(default_config):
shutil.copy2(default_config, user_config)
print(f"Configuration file copied to: {user_config}")
return True
except Exception as e:
print(f"Error setting up configuration: {e}")
return False
def main():
"""Main installation process."""
print("Starting MCP2Serial installation for Ubuntu/Raspberry Pi...")
# 检查Python版本
if sys.version_info < (3, 11):
print("Error: Python 3.11 or higher is required")
sys.exit(1)
# 安装uv(如果需要)
if not get_uv_path():
if not install_uv():
print("Failed to install uv package manager")
sys.exit(1)
# 安装mcp2serial
if not install_mcp2serial():
print("Failed to install mcp2serial")
sys.exit(1)
# 配置Claude Desktop
if not configure_claude_desktop():
print("Warning: Failed to configure Claude Desktop")
# 设置配置文件
if not setup_config():
print("Warning: Failed to setup configuration files")
print("\nInstallation completed!")
print("\nTo use mcp2serial:")
print("1. Activate the virtual environment:")
print(" source .venv/bin/activate")
print("2. Run the server:")
print(" uv run mcp2serial")
print("\nFor more information, visit: https://github.com/mcp2everything/mcp2serial")
if __name__ == "__main__":
main()