Agent Zero AI framework
Edit: Changed mcp.py to mcp_handler.py to prevent potential import confusion between 'mcp' package and 'mcp.py'. Edited dockerfile to 'latest' so it doesnt spin up old builds after image creation. Also edited preinstall to ensure the mcp related dependencies can load non-interactive.
deci5c691dd5328d
diff --git a/agent.py b/agent.pyindex 56dd5af59..c5a8246b8 100644--- a/agent.py+++ b/agent.py@@ -703,7 +703,7 @@ class Agent:# Try getting tool from MCP firsttry:- import python.helpers.mcp as mcp_helper+ import python.helpers.mcp_handler as mcp_helpermcp_tool_candidate = mcp_helper.MCPConfig.get_instance().get_tool(self, tool_name)if mcp_tool_candidate:tool = mcp_tool_candidatediff --git a/docker/run/docker-compose.yml b/docker/run/docker-compose.ymlindex 725be771a..d2a828b31 100644--- a/docker/run/docker-compose.yml+++ b/docker/run/docker-compose.yml@@ -1,7 +1,7 @@services:agent-zero:container_name: agent-zero- image: frdel/agent-zero-run:testing+ image: frdel/agent-zero:latestvolumes:- ./agent-zero:/a0ports:diff --git a/docker/run/fs/ins/install_A0.sh b/docker/run/fs/ins/install_A0.shindex 586a3779b..db63265fc 100644--- a/docker/run/fs/ins/install_A0.sh+++ b/docker/run/fs/ins/install_A0.sh@@ -1,5 +1,8 @@#!/bin/bash+# Exit immediately if a command exits with a non-zero status.+# set -e+# branch from parameterif [ -z "$1" ]; thenecho "Error: Branch parameter is empty. Please provide a valid branch name."@@ -7,20 +10,43 @@ if [ -z "$1" ]; thenfiBRANCH="$1"-# clone project repo branch-git clone -b "$BRANCH" "https://github.com/frdel/agent-zero" "/git/agent-zero"+git clone -b "$BRANCH" "https://github.com/frdel/agent-zero" "/git/agent-zero" || {+ echo "CRITICAL ERROR: Failed to clone repository. Branch: $BRANCH"+ exit 1+}-# setup python environment. "/ins/setup_venv.sh" "$@"-# Ensure the virtual environment and pip setup-pip install --upgrade pip ipython requests+pip install --upgrade pip ipython requests || {+ echo "CRITICAL ERROR: Failed to upgrade pip or install ipython/requests."+ exit 1+}++pip install -v torch --index-url https://download.pytorch.org/whl/cpu || {+ echo "CRITICAL ERROR: Failed to install PyTorch."+ exit 1+}++pip install -v mcp==1.3.0 || {+ echo "ERROR: Failed during separate attempt to install mcp==1.3.0. Will proceed to full requirements.txt install anyway."+}+python -c "import mcp; from mcp import ClientSession; print(f'DEBUG: mcp and mcp.ClientSession imported successfully after separate install. mcp path: {mcp.__file__}')" || {+ echo "ERROR: mcp package or mcp.ClientSession NOT importable after separate mcp==1.3.0 installation attempt. Full requirements.txt will run next."+}-# Install some packages in specific variants-pip install torch --index-url https://download.pytorch.org/whl/cpu+pip install -v -r /git/agent-zero/requirements.txt || {+ echo "CRITICAL ERROR: Failed to install A0 requirements from requirements.txt."+ exit 1+}-# Install remaining A0 python packages-pip install -r /git/agent-zero/requirements.txt+python -c "import mcp; from mcp import ClientSession; print(f'DEBUG: mcp and mcp.ClientSession imported successfully after requirements.txt. mcp path: {mcp.__file__}')" || {+ echo "CRITICAL ERROR: mcp package or mcp.ClientSession not found or failed to import after requirements.txt processing."+ exit 1+}++python /git/agent-zero/preload.py --dockerized=true || {+ echo "CRITICAL ERROR: Failed during A0 preload."+ exit 1+}-# Preload A0-python /git/agent-zero/preload.py --dockerized=true+echo "install_A0.sh completed successfully."diff --git a/docker/run/fs/ins/pre_install.sh b/docker/run/fs/ins/pre_install.shindex 35cb14b9d..d901d1200 100644--- a/docker/run/fs/ins/pre_install.sh+++ b/docker/run/fs/ins/pre_install.sh@@ -5,20 +5,24 @@ chmod 0644 /etc/cron.d/*echo "=====BEFORE UPDATE====="+# Set DEBIAN_FRONTEND to noninteractive to prevent prompts+export DEBIAN_FRONTEND=noninteractive+# Update and install necessary packagesapt clean-apt-get update && apt-get upgrade -y && apt-get install -y \+apt-get update && apt-get upgrade -y && apt-get -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" install -y \python3 \python3-venv \python3-pip \nodejs \+ npm \openssh-server \sudo \curl \wget \git \ffmpeg \- nginx\+ nginx \supervisor \cron \libmagic-dev \@@ -40,6 +44,7 @@ echo "=====MID UPDATE====="# for some reason npm crashes builds on amd64 in this version and has to be installed separately# A0 can install it when needed+# The line below is now redundant as npm is included in the main install list above# apt-get install -y \# npm@@ -59,7 +64,13 @@ echo "=====AFTER UPDATE====="# fi# Install npx for use by local MCP Servers-npm i -g npx shx+echo "DEBUG: Installing npx and shx globally using npm..."+npm i -g npx shx || {+ echo "CRITICAL ERROR: Failed to install npx and shx using npm."+ # exit 1 # Optionally exit if this is critical enough+}+echo "DEBUG: npx and shx installation attempt finished."+# Prepare SSH daemonbash /ins/setup_ssh.sh "$@"diff --git a/initialize.py b/initialize.pyindex 92961689c..9e92a2270 100644--- a/initialize.py+++ b/initialize.py@@ -76,16 +76,17 @@ def initialize():# update config with runtime argsargs_override(config)- import python.helpers.mcp as mcp_helper+ import python.helpers.mcp_handler as mcp_helperimport agent as agent_helperimport python.helpers.print_style as print_style_helperif not mcp_helper.MCPConfig.get_instance().is_initialized():try:mcp_helper.MCPConfig.update(config.mcp_servers)except Exception as e:- if agent_helper.AgentContext.first():+ first_context = agent_helper.AgentContext.first()+ if first_context:(- agent_helper.AgentContext.first().log+ first_context.log.log(type="warning", content=f"Failed to update MCP settings: {e}", temp=False))(diff --git a/python/extensions/system_prompt/_10_system_prompt.py b/python/extensions/system_prompt/_10_system_prompt.pyindex 1ff461551..dda842fd3 100644--- a/python/extensions/system_prompt/_10_system_prompt.py+++ b/python/extensions/system_prompt/_10_system_prompt.py@@ -1,7 +1,7 @@from datetime import datetimefrom typing import Any, Optionalfrom python.helpers.extension import Extension-from python.helpers.mcp import MCPConfig+from python.helpers.mcp_handler import MCPConfigfrom agent import Agent, LoopDatafrom python.helpers.localization import Localizationdiff --git a/python/helpers/mcp.py b/python/helpers/mcp_handler.pysimilarity index 99%rename from python/helpers/mcp.pyrename to python/helpers/mcp_handler.pyindex cc2fb6f3f..fdd935ab8 100644--- a/python/helpers/mcp.py+++ b/python/helpers/mcp_handler.py@@ -5,6 +5,10 @@ import asynciofrom contextlib import AsyncExitStackfrom shutil import whichfrom datetime import timedelta++import os+print(f"DEBUG: Listing /opt/venv/lib/python3.11/site-packages/ before mcp import: {os.listdir('/opt/venv/lib/python3.11/site-packages/')}")+from mcp import ClientSession, StdioServerParametersfrom mcp.client.stdio import stdio_clientfrom mcp.client.sse import sse_clientdiff --git a/python/helpers/settings.py b/python/helpers/settings.pyindex d4b5b4a61..c84f81de7 100644--- a/python/helpers/settings.py+++ b/python/helpers/settings.py@@ -883,7 +883,7 @@ def _apply_settings(previous: Settings | None):memory_reload()# update mcp settings if necessary- from python.helpers.mcp import MCPConfig+ from python.helpers.mcp_handler import MCPConfigasync def update_mcp_settings(mcp_servers: str):PrintStyle(background_color="black", font_color="white", padding=True).print("Updating MCP config...")