This repository has been archived on 2025-11-27. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
Fitz_Studio/scripts/ejecutar_mcps.py
T

70 lines
2.0 KiB
Python

import os
import subprocess
import sys
import re
from pathlib import Path
ROOT = Path(__file__).resolve().parent
PYTHON_PATH = (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"
]
print("🚀 Iniciando scripts MCP con entorno virtual...")
# Verificar intérprete Python
if not PYTHON_PATH.exists():
print(f"❌ No se encontró Python en: {PYTHON_PATH}")
sys.exit(1)
# Limpiar archivo de PIDs previo
if PID_FILE.exists():
PID_FILE.unlink()
# 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
try:
proc = subprocess.Popen(
[str(PYTHON_PATH), str(script_path)],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
text=True
)
# Leer la salida para encontrar la URL
url = None
for line in proc.stdout:
match = URL_REGEX.search(line)
if match:
url = match.group("url")
break
# Guardar el PID
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}")
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("✅ Todos los scripts han sido procesados. PIDs guardados en mcps.pid.")