24 lines
831 B
Bash
24 lines
831 B
Bash
#!/bin/sh
|
|
set -eu
|
|
|
|
# Persistent launcher for OpenCode's local stdio MCP, without a listening port.
|
|
MCP_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
|
|
MCP_VENV="${HOME}/.local/share/opencode/duckduckgo-venv"
|
|
|
|
# A Docker restart preserves Python; image recreation may remove OS packages.
|
|
if ! command -v python3 >/dev/null 2>&1; then
|
|
if command -v apk >/dev/null 2>&1 && [ "$(id -u)" = 0 ]; then
|
|
apk add --no-cache python3 py3-pip >&2
|
|
else
|
|
echo 'DuckDuckGo MCP requires Python >=3.10 and venv/pip. Install them first.' >&2
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
if ! "$MCP_VENV/bin/python" -c 'import duckduckgo_mcp_server, curl_cffi' >/dev/null 2>&1; then
|
|
python3 -m venv --clear "$MCP_VENV" >&2
|
|
"$MCP_VENV/bin/pip" install -r "$MCP_DIR/requirements.txt" >&2
|
|
fi
|
|
|
|
exec "$MCP_VENV/bin/duckduckgo-mcp-server" "$@"
|