| #!/bin/bash |
| # Copyright 2025 The Fuchsia Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| |
| # Registers or removes a set of MCP servers from the gemini extension settings. |
| |
| source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/lib/vars.sh || exit $? |
| fx-config-read |
| |
| show_help() { |
| cat <<EOF |
| Usage: $0 [options] |
| |
| Options: |
| --project-only Apply settings to the project only (~/fuchsia/.gemini/settings.json). |
| --extension Install as a self-contained extension (in ~/.gemini/extensions/). |
| --uninstall Uninstall the MCP servers. |
| --help Show this help message. |
| EOF |
| } |
| |
| install_extensions() { |
| if command -v gemini &> /dev/null; then |
| GEMINI_CMD="gemini" |
| elif [ -x "/google/bin/releases/gemini-cli/tools/gemini" ]; then |
| GEMINI_CMD="/google/bin/releases/gemini-cli/tools/gemini" |
| else |
| fx-error "Error: 'gemini' executable not found. You might need to run gcert." |
| exit 1 |
| fi |
| |
| # TODO(b/442696047) remove this extra flag when gemini unbreaks extensions in the internal binary |
| if [[ -x "/google/bin/releases/gemini-cli/tools/gemini" ]]; then |
| $GEMINI_CMD --noenable_sawmill_logging extensions link $FUCHSIA_DIR/.gemini/extensions/rust |
| else |
| $GEMINI_CMD extensions link .gemini/extensions/rust |
| fi |
| } |
| |
| uninstall_extensions() { |
| # `gemini extensions` doesn't have an `unlink` subcommand?! |
| echo -n "Removing rust extension from home directory... " |
| rm -r $HOME/.gemini/extensions/rust |
| echo "done." |
| } |
| |
| PROJECT_ONLY=false |
| UNINSTALL=false |
| EXTENSION_MODE=false |
| for arg in "$@"; do |
| case "$arg" in |
| --project-only) |
| PROJECT_ONLY=true |
| shift |
| ;; |
| --uninstall) |
| UNINSTALL=true |
| shift |
| ;; |
| --extension) |
| EXTENSION_MODE=true |
| shift |
| ;; |
| --help) |
| show_help |
| exit 0 |
| ;; |
| esac |
| done |
| |
| if [[ "${EXTENSION_MODE}" == "true" ]]; then |
| SETTINGS_PATH="${HOME}/.gemini/extensions/fuchsia/gemini-extension.json" |
| mkdir -p "$(dirname "${SETTINGS_PATH}")" |
| elif [[ "${PROJECT_ONLY}" == "true" ]]; then |
| SETTINGS_PATH="${FUCHSIA_DIR}/.gemini/settings.json" |
| mkdir -p "$(dirname "${SETTINGS_PATH}")" |
| else |
| SETTINGS_PATH="${HOME}/.gemini/settings.json" |
| mkdir -p "$(dirname "${SETTINGS_PATH}")" |
| fi |
| |
| PYTHON_SCRIPT="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)/python/setup_mcp_servers.py" |
| PYTHON_ARGS=("${SETTINGS_PATH}" "${FUCHSIA_DIR}") |
| |
| if [[ "${UNINSTALL}" == "true" ]]; then |
| PYTHON_ARGS+=("--uninstall") |
| uninstall_extensions |
| else |
| install_extensions |
| fi |
| |
| if [[ "${EXTENSION_MODE}" == "true" ]]; then |
| PYTHON_ARGS+=("--extension") |
| fi |
| |
| "${PYTHON_SCRIPT}" "${PYTHON_ARGS[@]}" |