-
-
Save edxeth/80998f07fd35c16a9afef28c29efc5aa to your computer and use it in GitHub Desktop.
gem - Interactive MCP server selector for Gemini CLI. Uses fzf for multi-select. Works on Linux/macOS.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env zsh | |
| # gem - Gemini CLI launcher with interactive MCP server selection | |
| # Works on Linux and macOS | |
| set -euo pipefail | |
| settings="${GEMINI_SETTINGS_PATH:-$HOME/.gemini/settings.json}" | |
| if [[ ! -f "$settings" ]]; then | |
| echo "Missing settings file: $settings" >&2 | |
| exit 1 | |
| fi | |
| # Extract MCP server names from settings.json | |
| names=$(jq -r '.mcpServers | keys[]' "$settings" 2>/dev/null | sort) || { | |
| echo "Failed to parse $settings (is it valid JSON?)" >&2 | |
| exit 1 | |
| } | |
| if [[ -z "$names" ]]; then | |
| echo "No mcpServers found in $settings" >&2 | |
| exit 1 | |
| fi | |
| # Multi-select via fzf if available; otherwise allow all | |
| if command -v fzf >/dev/null 2>&1; then | |
| selected=$(print -r -- "$names" | fzf -m \ | |
| --layout=reverse \ | |
| --prompt="Select MCP servers (TAB=toggle, ENTER=confirm): ") || { | |
| echo "No MCP servers selected; aborting." >&2 | |
| exit 1 | |
| } | |
| else | |
| echo "fzf not found; enabling all servers" >&2 | |
| selected="$names" | |
| fi | |
| # Build the allow-list flags | |
| allow_flags=() | |
| while IFS= read -r name; do | |
| [[ -n "$name" ]] && allow_flags+=( --allowed-mcp-server-names "$name" ) | |
| done <<< "$selected" | |
| # Report and launch | |
| echo "✓ Enabled: ${selected//$'\n'/, }" | |
| exec gemini -m gemini-3-pro-preview --yolo "${allow_flags[@]}" "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment