Skip to content

Commit 3c0d227

Browse files
authored
Merge pull request #625 from tmaeno/master
Adding PanDA MCP in Docker
2 parents 9611eef + 3d4ae27 commit 3c0d227

File tree

7 files changed

+156
-10
lines changed

7 files changed

+156
-10
lines changed

Dockerfile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ RUN mkdir /tmp/src
77
WORKDIR /tmp/src
88
COPY . .
99

10-
RUN /opt/panda/bin/pip install --no-cache-dir .[postgres,oracle]
10+
RUN /opt/panda/bin/pip install --no-cache-dir .[postgres,oracle,mcp]
1111
RUN /opt/panda/bin/pip install --no-cache-dir rucio-clients
1212
RUN /opt/panda/bin/pip install --no-cache-dir "git+https://github.com/PanDAWMS/panda-cacheschedconfig.git"
1313
RUN ln -s /opt/panda/lib/python*/site-packages/mod_wsgi/server/mod_wsgi*.so /etc/httpd/modules/mod_wsgi.so
@@ -26,6 +26,8 @@ RUN mv /opt/panda/etc/panda/sysconfig/panda_jedi /etc/sysconfig/panda_jedi
2626

2727
RUN mkdir -p /etc/rc.d/init.d
2828
RUN ln -s /opt/panda/etc/rc.d/init.d/panda_jedi /etc/rc.d/init.d/panda-jedi
29+
RUN ln -s /opt/panda/etc/rc.d/init.d/panda_server /etc/rc.d/init.d/httpd-pandasrv
30+
RUN ln -s /opt/panda/etc/rc.d/init.d/panda_mcp /etc/rc.d/init.d/panda-mcp
2931

3032
RUN mkdir -p /data/atlpan
3133
RUN mkdir -p /data/panda
@@ -41,7 +43,7 @@ RUN chown -R atlpan:zp /var/log/panda
4143
RUN ln -fs /opt/panda/etc/cert/hostkey.pem /etc/grid-security/hostkey.pem
4244
RUN ln -fs /opt/panda/etc/cert/hostcert.pem /etc/grid-security/hostcert.pem
4345
RUN ln -fs /opt/panda/etc/cert/chain.pem /etc/grid-security/chain.pem
44-
RUN ln -s /opt/panda/etc/rc.d/init.d/panda_server /etc/rc.d/init.d/httpd-pandasrv
46+
4547
RUN ln -fs /data/panda/idds.cfg /opt/panda/etc/idds/idds.cfg
4648
RUN ln -fs /data/panda/rucio.cfg /opt/panda/etc/rucio.cfg
4749
RUN ln -fs /data/panda/panda_mbproxy_config.json /opt/panda/etc/panda/panda_mbproxy_config.json
@@ -97,4 +99,4 @@ RUN chmod +x /etc/rc.d/init.d/run-jedi-services
9799

98100
CMD ["sleep", "infinity"]
99101

100-
EXPOSE 25080 25443
102+
EXPOSE 25080 25443 25888

Dockerfile.base

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ RUN mkdir /tmp/python && cd /tmp/python && \
2323
./configure --enable-shared --enable-optimizations --with-lto && \
2424
make altinstall && \
2525
echo /usr/local/lib > /etc/ld.so.conf.d/local.conf && ldconfig && \
26-
cd / && rm -rf /tmp/pyton
26+
cd / && rm -rf /tmp/python
2727

2828
# install Oracle Instant Client and tnsnames.ora
2929
RUN wget https://download.oracle.com/otn_software/linux/instantclient/oracle-instantclient-basic-linuxx64.rpm -P /tmp/ && \

PandaPkgInfo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
release_version = "0.6.11"
1+
release_version = "0.6.12"

pandaserver/pandamcp/mcp_main.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010
from pandaserver.config import mcp_config
1111
from pandaserver.pandamcp.mcp_utils import create_tool
1212

13+
# remove or overwrite environment variables to avoid server's credential being used
14+
for var in ["PANDA_AUTH_ID_TOKEN", "PANDA_AUTH_VO", "X509_USER_PROXY"]:
15+
if var in os.environ:
16+
del os.environ[var]
17+
os.environ["X509_USER_PROXY"] = "/dev/null"
18+
1319
# extract API's module path
1420
p = urlparse(api_url)
1521
api_module_path = ".".join([seg for seg in p.path.strip("/").split("/") if seg])
@@ -41,4 +47,10 @@
4147
http_app = main_mcp.http_app(transport=mcp_config.transport)
4248

4349
if __name__ == "__main__":
44-
uvicorn.run(http_app, port=os.getenv("PANDA_SERVER_CONF_PORT_MCP", 25888), ssl_keyfile=mcp_config.ssl_keyfile, ssl_certfile=mcp_config.ssl_certfile)
50+
uvicorn.run(
51+
http_app,
52+
host="0.0.0.0",
53+
port=int(os.getenv("PANDA_SERVER_CONF_PORT_MCP", 25888)),
54+
ssl_keyfile=mcp_config.ssl_keyfile,
55+
ssl_certfile=mcp_config.ssl_certfile,
56+
)

pandaserver/pandamcp/mcp_utils.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from fastmcp.server.dependencies import get_http_headers
66
from fastmcp.tools.tool import Tool
77

8-
from pandaserver.api.v1.http_client import HttpClient, api_url_ssl
8+
from pandaserver.api.v1.http_client import HttpClient, api_url, api_url_ssl
99
from pandaserver.srvcore.panda_request import PandaRequest
1010

1111

@@ -20,7 +20,6 @@ def create_tool(func: Callable) -> Tool:
2020
# construct the URL based on the module and function name
2121
mod_path = inspect.getfile(inspect.getmodule(func))
2222
mod_name = os.path.basename(mod_path).split("_")[0]
23-
url = f"{api_url_ssl}/{mod_name}/{func.__name__}"
2423

2524
# determine http method based on the docstring
2625
http_method = None
@@ -34,6 +33,11 @@ def create_tool(func: Callable) -> Tool:
3433
if http_method is None:
3534
raise ValueError("HTTP Method not specified in the function docstring")
3635

36+
if http_method == "get":
37+
url = f"{api_url}/{mod_name}/{func.__name__}"
38+
else:
39+
url = f"{api_url_ssl}/{mod_name}/{func.__name__}"
40+
3741
# remove PandaRequest from the signature and annotations
3842
sig = inspect.signature(func)
3943
params = []
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
#!/bin/sh
2+
#
3+
# chkconfig: - 85 15
4+
#
5+
# description: Panda MCP
6+
# processname: python
7+
# config: /etc/panda/panda_server.cfg
8+
# pidfile: /var/log/panda/panda_mcp.pid
9+
#
10+
11+
# When multiple arguments are given, only the error from the _last_
12+
# one is reported.
13+
#
14+
ARGV="$@"
15+
#
16+
# |||||||||||||||||||| START CONFIGURATION SECTION ||||||||||||||||||||
17+
# -------------------- --------------------
18+
#
19+
20+
# virtual env activation
21+
@@virtual_env_setup@@
22+
23+
# the path to application
24+
PROGNAME='python -u @@install_purelib@@/pandaserver/pandamcp/mcp_main.py'
25+
26+
# pid and lock files
27+
if [[ -z "${PANDA_LOCK_DIR}" ]]; then
28+
PIDFILE='/var/log/panda/panda_mcp.pid'
29+
else
30+
PIDFILE=${PANDA_LOCK_DIR}'/panda_mcp.pid'
31+
fi
32+
33+
# log files
34+
LOGSTDOUT='/var/log/panda/panda_mcp_stdout.log'
35+
LOGSTDERR='/var/log/panda/panda_mcp_stderr.log'
36+
37+
# Source panda server env variables
38+
if [ -r /etc/sysconfig/panda_server ]; then
39+
. /etc/sysconfig/panda_server
40+
fi
41+
42+
43+
start() {
44+
echo "Starting PanDA MCP ..."
45+
46+
# Check if already running
47+
if [ -f "$PIDFILE" ]; then
48+
kill -0 "$(cat "$PIDFILE")" 2>/dev/null
49+
ERROR=$?
50+
if [ $ERROR -eq 0 ]; then
51+
echo "Already running."
52+
return 0
53+
fi
54+
fi
55+
56+
# Start program in foreground but fork to background manually to free the shell
57+
# while still tracking PID.
58+
nohup $PROGNAME >> $LOGSTDOUT 2>> $LOGSTDERR &
59+
ERROR=$?
60+
61+
if [ $ERROR -ne 0 ]; then
62+
echo "Failed to start myservice (exit code $ERROR)."
63+
return $ERROR
64+
fi
65+
66+
echo $! > "$PIDFILE"
67+
echo "PanDA MCP started with PID $(cat "$PIDFILE")."
68+
}
69+
70+
stop() {
71+
echo "Stopping PanDA MCP ..."
72+
73+
if [ ! -f "$PIDFILE" ]; then
74+
echo "PID file not found; is PanDA MCP running?"
75+
return 0
76+
fi
77+
78+
kill "$PID" 2>/dev/null
79+
ERROR=$?
80+
81+
if [ $ERROR -ne 0 ]; then
82+
echo "Could not stop process (exit code $ERROR)."
83+
return $ERROR
84+
fi
85+
86+
rm -f "$PIDFILE"
87+
ERROR=$?
88+
89+
if [ $ERROR -ne 0 ]; then
90+
echo "Could not remove PID file (exit code $ERROR)."
91+
return $ERROR
92+
fi
93+
94+
echo "Stopped."
95+
}
96+
97+
status() {
98+
if [ -f "$PIDFILE" ]; then
99+
kill -0 "$(cat "$PIDFILE")" 2>/dev/null
100+
ERROR=$?
101+
102+
if [ $ERROR -eq 0 ]; then
103+
echo "Running (PID $(cat "$PIDFILE"))."
104+
return 0
105+
fi
106+
fi
107+
108+
echo "Not running."
109+
return 1
110+
}
111+
112+
# main
113+
if [ "x$ARGV" = "x" ] ; then
114+
ARGV="-h"
115+
fi
116+
117+
case $ARGV in
118+
start) start ;;
119+
stop) stop ;;
120+
restart) stop; start ;;
121+
status) status ;;
122+
*)
123+
echo "Usage: $0 {start|stop|restart|status}"
124+
exit 1
125+
;;
126+
esac
127+
128+
exit 0

templates/panda_server.cfg.rpmnew.template

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,8 +352,8 @@ config = {
352352
# MCP parameters
353353
#
354354

355-
# transport method: streamable-http or sse
356-
transport = "streamable-http"
355+
# transport method: streamable-http (http) or sse
356+
transport = http
357357

358358
# the list of REST API endpoints to expose through MCP
359359
endpoint_list_file = /opt/panda/etc/panda/panda_mcp_endpoints.json

0 commit comments

Comments
 (0)