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.

deci committed May 13, 2025 at 18:54 UTC 5c691dd5328d1d49fc538d2129da9656984c7fec
8 files changed +63 -21
agent.py
+1 -1
@@ -703,7 +703,7 @@ class Agent:
703
704 # Try getting tool from MCP first
705 try:
706 - import python.helpers.mcp as mcp_helper
706 + import python.helpers.mcp_handler as mcp_helper
707 mcp_tool_candidate = mcp_helper.MCPConfig.get_instance().get_tool(self, tool_name)
708 if mcp_tool_candidate:
709 tool = mcp_tool_candidate
docker/run/docker-compose.yml
+1 -1
@@ -1,7 +1,7 @@
1 services:
2 agent-zero:
3 container_name: agent-zero
4 - image: frdel/agent-zero-run:testing
4 + image: frdel/agent-zero:latest
5 volumes:
6 - ./agent-zero:/a0
7 ports:
docker/run/fs/ins/install_A0.sh
+37 -11
@@ -1,5 +1,8 @@
1 #!/bin/bash
2
3 +# Exit immediately if a command exits with a non-zero status.
4 +# set -e
5 +
6 # branch from parameter
7 if [ -z "$1" ]; then
8 echo "Error: Branch parameter is empty. Please provide a valid branch name."
@@ -7,20 +10,43 @@ if [ -z "$1" ]; then
10 fi
11 BRANCH="$1"
12
10 -# clone project repo branch
11 -git clone -b "$BRANCH" "https://github.com/frdel/agent-zero" "/git/agent-zero"
13 +git clone -b "$BRANCH" "https://github.com/frdel/agent-zero" "/git/agent-zero" || {
14 + echo "CRITICAL ERROR: Failed to clone repository. Branch: $BRANCH"
15 + exit 1
16 +}
17
13 -# setup python environment
18 . "/ins/setup_venv.sh" "$@"
19
16 -# Ensure the virtual environment and pip setup
17 -pip install --upgrade pip ipython requests
20 +pip install --upgrade pip ipython requests || {
21 + echo "CRITICAL ERROR: Failed to upgrade pip or install ipython/requests."
22 + exit 1
23 +}
24 +
25 +pip install -v torch --index-url https://download.pytorch.org/whl/cpu || {
26 + echo "CRITICAL ERROR: Failed to install PyTorch."
27 + exit 1
28 +}
29 +
30 +pip install -v mcp==1.3.0 || {
31 + echo "ERROR: Failed during separate attempt to install mcp==1.3.0. Will proceed to full requirements.txt install anyway."
32 +}
33 +python -c "import mcp; from mcp import ClientSession; print(f'DEBUG: mcp and mcp.ClientSession imported successfully after separate install. mcp path: {mcp.__file__}')" || {
34 + echo "ERROR: mcp package or mcp.ClientSession NOT importable after separate mcp==1.3.0 installation attempt. Full requirements.txt will run next."
35 +}
36
19 -# Install some packages in specific variants
20 -pip install torch --index-url https://download.pytorch.org/whl/cpu
37 +pip install -v -r /git/agent-zero/requirements.txt || {
38 + echo "CRITICAL ERROR: Failed to install A0 requirements from requirements.txt."
39 + exit 1
40 +}
41
22 -# Install remaining A0 python packages
23 -pip install -r /git/agent-zero/requirements.txt
42 +python -c "import mcp; from mcp import ClientSession; print(f'DEBUG: mcp and mcp.ClientSession imported successfully after requirements.txt. mcp path: {mcp.__file__}')" || {
43 + echo "CRITICAL ERROR: mcp package or mcp.ClientSession not found or failed to import after requirements.txt processing."
44 + exit 1
45 +}
46 +
47 +python /git/agent-zero/preload.py --dockerized=true || {
48 + echo "CRITICAL ERROR: Failed during A0 preload."
49 + exit 1
50 +}
51
25 -# Preload A0
26 -python /git/agent-zero/preload.py --dockerized=true
52 +echo "install_A0.sh completed successfully."
docker/run/fs/ins/pre_install.sh
+14 -3
@@ -5,20 +5,24 @@ chmod 0644 /etc/cron.d/*
5
6 echo "=====BEFORE UPDATE====="
7
8 +# Set DEBIAN_FRONTEND to noninteractive to prevent prompts
9 +export DEBIAN_FRONTEND=noninteractive
10 +
11 # Update and install necessary packages
12 apt clean
10 -apt-get update && apt-get upgrade -y && apt-get install -y \
13 +apt-get update && apt-get upgrade -y && apt-get -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" install -y \
14 python3 \
15 python3-venv \
16 python3-pip \
17 nodejs \
18 + npm \
19 openssh-server \
20 sudo \
21 curl \
22 wget \
23 git \
24 ffmpeg \
21 - nginx\
25 + nginx \
26 supervisor \
27 cron \
28 libmagic-dev \
@@ -40,6 +44,7 @@ echo "=====MID UPDATE====="
44
45 # for some reason npm crashes builds on amd64 in this version and has to be installed separately
46 # A0 can install it when needed
47 +# The line below is now redundant as npm is included in the main install list above
48 # apt-get install -y \
49 # npm
50
@@ -59,7 +64,13 @@ echo "=====AFTER UPDATE====="
64 # fi
65
66 # Install npx for use by local MCP Servers
62 -npm i -g npx shx
67 +echo "DEBUG: Installing npx and shx globally using npm..."
68 +npm i -g npx shx || {
69 + echo "CRITICAL ERROR: Failed to install npx and shx using npm."
70 + # exit 1 # Optionally exit if this is critical enough
71 +}
72 +echo "DEBUG: npx and shx installation attempt finished."
73 +
74
75 # Prepare SSH daemon
76 bash /ins/setup_ssh.sh "$@"
initialize.py
+4 -3
@@ -76,16 +76,17 @@ def initialize():
76 # update config with runtime args
77 args_override(config)
78
79 - import python.helpers.mcp as mcp_helper
79 + import python.helpers.mcp_handler as mcp_helper
80 import agent as agent_helper
81 import python.helpers.print_style as print_style_helper
82 if not mcp_helper.MCPConfig.get_instance().is_initialized():
83 try:
84 mcp_helper.MCPConfig.update(config.mcp_servers)
85 except Exception as e:
86 - if agent_helper.AgentContext.first():
86 + first_context = agent_helper.AgentContext.first()
87 + if first_context:
88 (
88 - agent_helper.AgentContext.first().log
89 + first_context.log
90 .log(type="warning", content=f"Failed to update MCP settings: {e}", temp=False)
91 )
92 (
python/extensions/system_prompt/_10_system_prompt.py
+1 -1
@@ -1,7 +1,7 @@
1 from datetime import datetime
2 from typing import Any, Optional
3 from python.helpers.extension import Extension
4 -from python.helpers.mcp import MCPConfig
4 +from python.helpers.mcp_handler import MCPConfig
5 from agent import Agent, LoopData
6 from python.helpers.localization import Localization
7
python/helpers/mcp_handler.py renamed
+4
@@ -5,6 +5,10 @@ import asyncio
5 from contextlib import AsyncExitStack
6 from shutil import which
7 from datetime import timedelta
8 +
9 +import os
10 +print(f"DEBUG: Listing /opt/venv/lib/python3.11/site-packages/ before mcp import: {os.listdir('/opt/venv/lib/python3.11/site-packages/')}")
11 +
12 from mcp import ClientSession, StdioServerParameters
13 from mcp.client.stdio import stdio_client
14 from mcp.client.sse import sse_client
python/helpers/settings.py
+1 -1
@@ -883,7 +883,7 @@ def _apply_settings(previous: Settings | None):
883 memory_reload()
884
885 # update mcp settings if necessary
886 - from python.helpers.mcp import MCPConfig
886 + from python.helpers.mcp_handler import MCPConfig
887
888 async def update_mcp_settings(mcp_servers: str):
889 PrintStyle(background_color="black", font_color="white", padding=True).print("Updating MCP config...")