Refactor and enhance MCP client and server functionality

- Removed prueba_cliente_mcp.py as it was no longer needed.
- Updated prueba_loop_agente.py to integrate MCPServerRunner for managing server instances.
- Modified prueba_mcp.py to implement a new structure for starting and stopping MCP servers.
- Enhanced AgenteAI class to support multiple MCP blocks execution.
- Improved MCPClient with timeout handling for tool calls.
- Added new sandbox files for children's stories.
- Created a simple ERP system with a main entry point.
- Added unit tests for the ERP system.
- Implemented MCPServerRunner to manage server processes.
- Developed server_files.py to handle file operations securely within a sandbox environment.
- Introduced ElementoWeb and Navegador classes for web scraping functionalities.
- Enhanced Scrapper and Tab classes for better interaction with web pages.
This commit is contained in:
2025-05-25 13:49:08 +02:00
parent a62778a030
commit cf6a768f6b
18 changed files with 880 additions and 107 deletions
+62 -30
View File
@@ -14,6 +14,7 @@ from src.Llms.MCPs.McpClient_Registry import ClientRegistry # o ajusta según t
from src.Credenciales.ollama_credencial import OllamaCredencial
from src.ConexionApis.Ollama_cliente import OllamaCliente
from src.Llms.Modelos.Ollama_model import ModeloOllama
from src.Llms.MCPs.McpServer import MCPServerRunner
import asyncio
@@ -22,32 +23,60 @@ async def main():
# # Usar Credencial openai
# conexion_admin = PostgresConexion(db_credencial)
# repo = OpenAICredencialRepo(conexion_admin)
# credencial_openai = repo.get_by_id("OPAK20250513-61b29978b7604031014")
# if credencial_openai is None:
# raise ValueError("No se encontró la credencial OpenAI con el ID proporcionado.")
# cliente = OpenAICliente(credencial_openai)
conexion_admin = PostgresConexion(db_credencial)
repo = OpenAICredencialRepo(conexion_admin)
credencial_openai = repo.get_by_id("OPAK20250513-61b29978b7604031014")
if credencial_openai is None:
raise ValueError("No se encontró la credencial OpenAI con el ID proporcionado.")
cliente = OpenAICliente(credencial_openai)
# # Llamamos a los servidores para iniciarlos
# venv_python = r"E:\Fitz_Studio\.venv\Scripts\python.exe"
# # runner_math = MCPServerRunner(
# # r"E:\Fitz_Studio\src\Llms\MCPs\McpServers\server_math.py",
# # python_path=venv_python
# # )
# # runner_tools = MCPServerRunner(
# # r"E:\Fitz_Studio\src\Llms\MCPs\McpServers\server_utils.py",
# # python_path=venv_python
# # )
# runner_files = MCPServerRunner(
# r"E:\Fitz_Studio\src\Llms\MCPs\McpServers\server_files.py",
# python_path=venv_python
# )
# # await runner_math.start()
# # await runner_tools.start()
# await runner_files.start()
# # Esperamos un poco para asegurarnos de que los servidores estén listos
# await asyncio.sleep(2)
# Usar Credencial ollama
credencial_ollama = OllamaCredencial(titulo="Ollama")
# credencial_ollama = OllamaCredencial(titulo="Ollama")
cliente = OllamaCliente(credencial_ollama)
# cliente = OllamaCliente(credencial_ollama)
modelo = ModeloOllama(
cliente=cliente,
model="llama3.1:8b")
# modelo = ModeloOllama(
# cliente=cliente,
# model="llama3.1:8b")
# # crea el modelo (openai)
# modelo = ModeloOpenAI(
# cliente=cliente,
# model="gpt-4o",
# temperature=1
# )
modelo = ModeloOpenAI(
cliente=cliente,
model="gpt-4o",
temperature=1
)
# Le otorga memoria
@@ -60,24 +89,30 @@ async def main():
# Cargamos las herramientas
herramientas = MCPClient.from_http(
name="tools",
url="http://127.0.0.1:4300/tools/"
# herramientas = MCPClient.from_http(
# name="tools",
# url="http://127.0.0.1:4300/tools/"
# )
# math = MCPClient.from_http(
# name="math",
# url="http://127.0.0.1:4200/math/"
# )
archivos = MCPClient.from_http(
name="files",
url="http://127.0.0.1:4201/fs"
)
math = MCPClient.from_http(
name="math",
url="http://127.0.0.1:4200/math/"
)
# Las añadimos al registro de herramientas
registry = ClientRegistry()
registry.add("tools", herramientas)
registry.add("math", math)
# registry.add("tools", herramientas)
# registry.add("math", math)
registry.add("files", archivos)
# --- INICIALIZACIÓN DEL AGENTE ---
@@ -98,7 +133,7 @@ async def main():
],
max_iterations=0,
# memoria=memoria,
memoria=memoria,
mcp=registry # ← ✅ Integración del cliente MCP
)
@@ -133,6 +168,3 @@ async def main():
if __name__ == "__main__":
asyncio.run(main())