feat: Update server scripts to use root path for HTTP transport and add process management scripts
This commit is contained in:
@@ -129,5 +129,5 @@ def clear_folder(path: str) -> str:
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
mcp.run(transport="streamable-http", host="127.0.0.1", port=4201, path="/fs")
|
||||
mcp.run(transport="streamable-http", host="127.0.0.1", port=4201, path="/")
|
||||
|
||||
|
||||
@@ -87,6 +87,6 @@ def is_prime(n: int) -> bool:
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
mcp.run(transport="streamable-http", host="127.0.0.1", port=4200, path="/math")
|
||||
mcp.run(transport="streamable-http", host="127.0.0.1", port=4200, path="/")
|
||||
|
||||
# mcp.run(transport="stdio")
|
||||
@@ -65,5 +65,5 @@ def current_timestamp() -> float:
|
||||
return datetime.datetime.now().timestamp()
|
||||
|
||||
if __name__ == "__main__":
|
||||
mcp.run(transport="streamable-http", host="127.0.0.1", port=4300, path="/tools")
|
||||
mcp.run(transport="streamable-http", host="127.0.0.1", port=4300, path="/")
|
||||
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
import os
|
||||
import signal
|
||||
import time
|
||||
|
||||
PID_FILE = "mcps.pid"
|
||||
|
||||
def cerrar_procesos(pid_file):
|
||||
if not os.path.exists(pid_file):
|
||||
print(f"❌ No se encontró el archivo {pid_file}")
|
||||
return
|
||||
|
||||
with open(pid_file, "r") as f:
|
||||
pids = [line.strip() for line in f if line.strip().isdigit()]
|
||||
|
||||
for pid_str in pids:
|
||||
pid = int(pid_str)
|
||||
try:
|
||||
os.kill(pid, signal.SIGTERM)
|
||||
print(f"✔ Proceso {pid} terminado con SIGTERM.")
|
||||
except ProcessLookupError:
|
||||
print(f"⚠ El proceso {pid} no existe o ya fue terminado.")
|
||||
except PermissionError:
|
||||
print(f"❌ No tienes permiso para terminar el proceso {pid}.")
|
||||
except Exception as e:
|
||||
print(f"❌ Error al cerrar el proceso {pid}: {e}")
|
||||
|
||||
try:
|
||||
os.remove(pid_file)
|
||||
print(f"🧹 Archivo {pid_file} eliminado.")
|
||||
except Exception as e:
|
||||
print(f"⚠ No se pudo eliminar {pid_file}: {e}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
cerrar_procesos(PID_FILE)
|
||||
@@ -0,0 +1,69 @@
|
||||
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.")
|
||||
@@ -0,0 +1,3 @@
|
||||
20136
|
||||
21880
|
||||
12708
|
||||
Reference in New Issue
Block a user