feat: Implement MCP server generation and process management scripts

This commit is contained in:
2025-06-22 12:34:24 +02:00
parent 58238a5918
commit daebea9e9c
4 changed files with 74 additions and 20 deletions
-3
View File
@@ -1,3 +0,0 @@
20136
21880
12708
@@ -5,17 +5,13 @@ import re
from pathlib import Path
ROOT = Path(__file__).resolve().parent
PYTHON_PATH = (ROOT.parent / ".venv" / "Scripts" / "python.exe").resolve()
PYTHON_PATH = (ROOT.parent / ROOT.parent / ".venv" / "Scripts" / "python.exe").resolve()
PID_FILE = ROOT / "mcps.pid"
# Rutas relativas de scripts (no es necesario configurar puertos)
scripts = [
"../domains/Llms/MCPs/McpServers/server_files.py",
"../domains/Llms/MCPs/McpServers/server_math.py",
"../domains/Llms/MCPs/McpServers/server_utils.py"
]
# Carpeta de MCPs
MCPS_DIR = (ROOT / "../domains/Llms/MCPs/McpServers").resolve()
print("🚀 Iniciando scripts MCP con entorno virtual...")
print("🚀 Iniciando todos los MCPs en el directorio:", MCPS_DIR)
# Verificar intérprete Python
if not PYTHON_PATH.exists():
@@ -29,13 +25,10 @@ if PID_FILE.exists():
# Expresión regular para capturar la URL de uvicorn
URL_REGEX = re.compile(r"Uvicorn running on (?P<url>http://[^\s]+)")
# Lanzar cada script y detectar su URL
for relative_path in scripts:
script_path = (ROOT / relative_path).resolve()
if not script_path.exists():
print(f"⚠ Script no encontrado: {script_path}")
continue
# Ejecutar todos los archivos .py en MCPS_DIR
for script_path in sorted(MCPS_DIR.glob("*.py")):
if script_path.name.startswith("__"):
continue # Evita archivos como __init__.py
try:
proc = subprocess.Popen(
@@ -57,13 +50,13 @@ for relative_path in scripts:
with open(PID_FILE, "a", encoding="utf-8") as f:
f.write(str(proc.pid) + "\n")
print(f"{relative_path} lanzado con PID {proc.pid}")
print(f"{script_path.relative_to(ROOT)} lanzado con PID {proc.pid}")
if url:
print(f" 🛰️ Servidor accesible en: {url}")
else:
print(" ⚠ No se detectó URL del servidor.")
except Exception as e:
print(f"❌ Error al lanzar {relative_path}:\n{e}")
print(f"❌ Error al lanzar {script_path.name}:\n{e}")
print("✅ Todos los scripts han sido procesados. PIDs guardados en mcps.pid.")