Skip to main content
Glama

run_gemini

Execute prompts using Gemini AI to analyze files, directories, or URLs while conserving Claude Code tokens through efficient context management.

Instructions

Gemini를 사용하여 프롬프트를 실행합니다.

Args:
    prompt: Gemini에 전달할 프롬프트
    file_dir_url_path: 분석할 파일, 디렉토리 또는 URL 경로
    working_directory: 작업 디렉토리 (필수)

Returns:
    dict: 실행 결과 또는 에러 메시지

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
promptYes
file_dir_url_pathYes
working_directoryYes

Implementation Reference

  • The handler function for the MCP tool 'run_gemini'. It runs the Gemini CLI tool with the given prompt augmented with file_dir_url_path, in the specified working_directory, handling errors and timeouts. Registered via @mcp.tool() decorator, which also defines the input schema via type hints and docstring.
    @mcp.tool()
    def run_gemini(prompt: str, file_dir_url_path: str, working_directory: str) -> dict:
        """
        Gemini를 사용하여 프롬프트를 실행합니다.
    
        Args:
            prompt: Gemini에 전달할 프롬프트
            file_dir_url_path: 분석할 파일, 디렉토리 또는 URL 경로
            working_directory: 작업 디렉토리 (필수)
    
        Returns:
            dict: 실행 결과 또는 에러 메시지
        """
    
        prompt = prompt + f" (분석할 파일, 디렉토리 또는 URL 경로: {file_dir_url_path})"
        
        # 현재 디렉토리 저장
        original_cwd = os.getcwd()
        
        try:
            # 작업 디렉토리로 변경
            os.chdir(working_directory)
            
            # Gemini 명령 실행
            cmd = [
                "gemini",
                "-m", "gemini-2.5-flash",
                "-p", prompt
            ]
    
            # shell=True로 실행 (MCP 서버 환경에서 필수)
            shell_cmd = ' '.join(
                [f'"{arg}"' if ' ' in arg else arg for arg in cmd])
    
            result = subprocess.run(
                shell_cmd,
                shell=True,  # 필수
                capture_output=True,
                text=True,
                timeout=360,
                stdin=subprocess.DEVNULL
            )
    
            # 에러 체크
            if result.returncode != 0:
                return {"error": f"Gemini 실행 오류: {result.stderr}"}
    
            # 결과 반환
            return {"result": result.stdout.strip()}
    
        except subprocess.TimeoutExpired:
            return {"error": "Gemini 실행 시간 초과 (360초)"}
        except FileNotFoundError:
            return {"error": "Gemini CLI가 설치되어 있지 않습니다. 'gemini' 명령을 사용할 수 있는지 확인하세요."}
        except Exception as e:
            return {"error": f"실행 중 오류 발생: {str(e)}"}
        finally:
            # 원래 디렉토리로 복원
            os.chdir(original_cwd)
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/InfolabAI/gemini-cli-mcp'

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