Skip to content

Instantly share code, notes, and snippets.

@edxeth
Created December 20, 2025 18:22
Show Gist options
  • Select an option

  • Save edxeth/80998f07fd35c16a9afef28c29efc5aa to your computer and use it in GitHub Desktop.

Select an option

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.
#!/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