Skip to main content
Glama
eLyiN
by eLyiN

consult_gemini

Send queries to Google's Gemini AI via CLI to get AI-generated responses with configurable model, directory, and timeout settings.

Instructions

Send a query directly to the Gemini CLI.

Args:
    query: Prompt text forwarded verbatim to the CLI.
    directory: Working directory used for command execution.
    model: Optional model alias (``flash``, ``pro``) or full Gemini model id.
    timeout_seconds: Optional per-call timeout override in seconds.

Returns:
    Gemini's response text or an explanatory error string.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYes
directoryYes
modelNo
timeout_secondsNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The main handler function for the 'consult_gemini' tool. Registered with @mcp.tool(), defines input schema via type annotations and docstring, and implements logic by delegating to the execute_gemini_simple helper.
    @mcp.tool()
    def consult_gemini(
        query: str,
        directory: str,
        model: str | None = None,
        timeout_seconds: int | None = None,
    ) -> str:
        """Send a query directly to the Gemini CLI.
    
        Args:
            query: Prompt text forwarded verbatim to the CLI.
            directory: Working directory used for command execution.
            model: Optional model alias (``flash``, ``pro``) or full Gemini model id.
            timeout_seconds: Optional per-call timeout override in seconds.
    
        Returns:
            Gemini's response text or an explanatory error string.
        """
        return execute_gemini_simple(query, directory, model, timeout_seconds)
  • Supporting helper function that performs the actual execution of the Gemini CLI subprocess for simple queries, including validation, model normalization, timeout handling, and error management.
    def execute_gemini_simple(
        query: str,
        directory: str = ".",
        model: Optional[str] = None,
        timeout_seconds: Optional[int] = None,
    ) -> str:
        """
        Execute gemini CLI command for simple queries without file attachments.
        
        Args:
            query: The prompt to send to Gemini
            directory: Working directory for the command
            model: Optional model name (flash, pro, etc.)
            
        Returns:
            CLI output or error message
        """
        # Check if gemini CLI is available
        if not shutil.which("gemini"):
            return "Error: Gemini CLI not found. Install with: npm install -g @google/gemini-cli"
        
        # Validate directory
        if not os.path.isdir(directory):
            return f"Error: Directory does not exist: {directory}"
        
        # Build command - use stdin for input to avoid hanging
        selected_model = _normalize_model_name(model)
        cmd = ["gemini", "-m", selected_model]
        
        # Execute CLI command - simple timeout, no retries
        timeout = _coerce_timeout(timeout_seconds)
        try:
            result = subprocess.run(
                cmd,
                cwd=directory,
                capture_output=True,
                text=True,
                timeout=timeout,
                input=query
            )
            
            if result.returncode == 0:
                return result.stdout.strip() if result.stdout.strip() else "No output from Gemini CLI"
            else:
                return f"Gemini CLI Error: {result.stderr.strip()}"
                
        except subprocess.TimeoutExpired:
            return f"Error: Gemini CLI command timed out after {timeout} seconds"
        except Exception as e:
            return f"Error executing Gemini CLI: {str(e)}"
  • Utility helper for coercing and validating timeout values, used by execute_gemini_simple.
    def _coerce_timeout(timeout_seconds: Optional[int]) -> int:
        """Return a positive timeout, preferring explicit overrides."""
        if timeout_seconds is None:
            return _get_timeout()
    
        try:
            timeout = int(timeout_seconds)
        except (TypeError, ValueError):
            logging.warning(
                "Invalid timeout override '%s' (must be integer). Using default.",
                timeout_seconds,
            )
            return _get_timeout()
    
        if timeout <= 0:
            logging.warning(
                "Invalid timeout override '%s' (must be positive). Using default.",
                timeout_seconds,
            )
            return _get_timeout()
    
        return timeout
  • Utility helper for normalizing model names to standard Gemini CLI formats, called within execute_gemini_simple.
    def _normalize_model_name(model: Optional[str]) -> str:
        """
        Normalize user-provided model identifiers to canonical Gemini CLI model names.
        Defaults to gemini-2.5-flash when not provided or unrecognized.
    
        Accepted forms:
        - "flash", "2.5-flash", "gemini-2.5-flash" -> gemini-2.5-flash
        - "pro", "2.5-pro", "gemini-2.5-pro" -> gemini-2.5-pro
        - "3-pro", "gemini-3-pro", "gemini-3-pro-preview" -> gemini-3-pro-preview
        - "3-flash", "gemini-3-flash", "gemini-3-flash-preview" -> gemini-3-flash-preview
        - "auto" -> auto (model router, lets CLI choose optimal model)
        """
        if not model:
            return "gemini-2.5-flash"
        value = model.strip().lower()
    
        # Gemini 2.5 aliases
        if value in {"flash", "2.5-flash", "gemini-2.5-flash"}:
            return "gemini-2.5-flash"
        if value in {"pro", "2.5-pro", "gemini-2.5-pro"}:
            return "gemini-2.5-pro"
    
        # Gemini 3 aliases (preview models)
        if value in {"3-pro", "gemini-3-pro", "gemini-3-pro-preview"}:
            return "gemini-3-pro-preview"
        if value in {"3-flash", "gemini-3-flash", "gemini-3-flash-preview"}:
            return "gemini-3-flash-preview"
    
        # Model router (let CLI choose best model)
        if value == "auto":
            return "auto"
    
        # Pass through any other gemini-* model name
        if value.startswith("gemini-"):
            return value
    
        # Fallback to flash for anything else
        return "gemini-2.5-flash"
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It describes the core behavior (forwarding queries verbatim, using a working directory, optional model/timeout parameters) and mentions the return format. However, it lacks details about authentication requirements, rate limits, error handling specifics, or whether this is a read-only vs. mutating operation. The description adds basic context but doesn't provide comprehensive behavioral traits.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is perfectly structured and concise. It begins with a clear purpose statement, then provides organized parameter documentation in an Args section, followed by return information. Every sentence earns its place with no wasted words, and the information is front-loaded appropriately.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (4 parameters, CLI interaction) and the presence of an output schema (which handles return value documentation), the description is mostly complete. It covers purpose, parameters, and basic behavior. The main gap is lack of information about authentication, rate limits, or whether this tool performs mutations vs. read-only operations, which would be helpful for an AI agent.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

With 0% schema description coverage, the description compensates well by explaining all 4 parameters in the Args section. It provides meaningful context for each parameter: 'query' is prompt text forwarded verbatim, 'directory' is the working directory for execution, 'model' can be an alias or full ID, and 'timeout_seconds' is a per-call override. This adds substantial value beyond the bare schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('Send a query directly to the Gemini CLI') and identifies the resource (Gemini CLI). It distinguishes from the sibling tool 'consult_gemini_with_files' by specifying this is for direct queries without file handling. The verb+resource combination is precise and unambiguous.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides clear context for when to use this tool ('Send a query directly to the Gemini CLI'), which implies it's for text-only queries. However, it doesn't explicitly state when NOT to use it or name the alternative sibling tool 'consult_gemini_with_files' as a specific alternative for file-based queries, though the distinction is strongly implied.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/eLyiN/gemini-bridge'

If you have feedback or need assistance with the MCP directory API, please join our Discord server