Source code for mindroot.coreplugins.mcp_.server_installer
import subprocess
import asyncio
from typing import Dict, Optional
[docs]
class MCPServerInstaller:
"""Handles installation of MCP servers via different methods"""
[docs]
@staticmethod
async def install_with_uvx(package: str, args: list=None) -> bool:
"""Install package with uvx"""
if args is None:
args = []
try:
cmd = ['uvx', '--help']
result = subprocess.run(cmd, capture_output=True, text=True, timeout=10)
return result.returncode == 0
except Exception as e:
return False
[docs]
@staticmethod
async def install_with_npx(package: str, args: list=None) -> bool:
"""Install package with npx (similar to uvx, runs without global install)"""
if args is None:
args = []
try:
cmd = ['npx', '--help']
result = subprocess.run(cmd, capture_output=True, text=True, timeout=10)
return result.returncode == 0
except Exception as e:
return False
[docs]
@staticmethod
async def install_with_pip(package: str, args: list=None) -> bool:
"""Install package with pip"""
if args is None:
args = []
try:
cmd = ['pip', 'install'] + args + [package]
result = subprocess.run(cmd, capture_output=True, text=True, timeout=60)
return result.returncode == 0
except Exception as e:
return False
[docs]
@staticmethod
async def install_with_npm(package: str, args: list=None) -> bool:
"""Install package with npm"""
if args is None:
args = []
try:
cmd = ['npm', 'install', '-g'] + args + [package]
result = subprocess.run(cmd, capture_output=True, text=True, timeout=120)
return result.returncode == 0
except Exception as e:
return False