Skip to content

feat: add support for Gemini CLI integration#1709

Merged
jlowin merged 9 commits into
PrefectHQ:mainfrom
jackwotherspoon:main
Sep 6, 2025
Merged

feat: add support for Gemini CLI integration#1709
jlowin merged 9 commits into
PrefectHQ:mainfrom
jackwotherspoon:main

Conversation

@jackwotherspoon
Copy link
Copy Markdown
Contributor

Gemini CLI 🤝 FastMCP

Description

This adds support for Gemini CLI as an AI assistant integration to FastMCP via fastmcp install gemini-cli.

Gemini CLI now has support for gemini mcp add commands which has enabled this integration.

fastmcp_gemini_cli.mp4

Contributors Checklist

  • My change is related to issue Add support for Gemini CLI integration #1708
  • I have followed the repository's development workflow
  • I have tested my changes manually and by adding relevant tests
  • I have performed all required documentation updates

Review Checklist

  • I have self-reviewed my changes
  • My Pull Request is ready for review

@marvin-context-protocol marvin-context-protocol Bot added enhancement Improvement to existing functionality. For issues and smaller PR improvements. cli Related to FastMCP CLI commands (run, dev, install) or CLI functionality. labels Sep 2, 2025
@strawgate
Copy link
Copy Markdown
Collaborator

This looks great, I'm a big Gemini user -- I'll give this a shot tomorrow and report back!

@jackwotherspoon
Copy link
Copy Markdown
Contributor Author

This looks great, I'm a big Gemini user -- I'll give this a shot tomorrow and report back!

@strawgate let me know if you run into any issues 😄

@strawgate
Copy link
Copy Markdown
Collaborator

Sorry, will try to find time today or by Monday at the latest

@strawgate
Copy link
Copy Markdown
Collaborator

Looks great; the only problem I ran into is not a problem with the Gemini CLI install command in particular but with the uv environment command building.

In UVEnvironment:

    def build_command(self, command: list[str]) -> list[str]:
        """Build complete uv run command with environment args and command to execute.

        Args:
            command: Command to execute (e.g., ["fastmcp", "run", "server.py"])

        Returns:
            Complete command ready for subprocess.run, including "uv" prefix if needed.
            If no environment configuration is set, returns the command unchanged.
        """
        # If no environment setup is needed, return command as-is
        if not self._needs_setup():
            return command

If it's determined it doesnt need setup, then the command becomes:

    "test-server": {
      "command": "fastmcp",
      "args": [
        "run",
        "/Users/bill.easton/repos/fastmcp/server.py"
      ]
    }

I don't have fastmcp in my path and so direct invocation doesn't work for me and requires uv run for it to work on my system. @jlowin perhaps we should add a check related to this?

Copy link
Copy Markdown
Collaborator

@strawgate strawgate left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small cleanup on the doc, otherwise looks good

Comment thread docs/integrations/gemini-cli.mdx Outdated
@strawgate strawgate requested a review from Copilot September 6, 2025 14:45
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for Gemini CLI as an AI assistant integration to FastMCP, enabling users to install FastMCP servers directly into Gemini CLI using fastmcp install gemini-cli. The integration leverages Gemini CLI's recently added MCP support via the gemini mcp add command.

Key changes:

  • New Gemini CLI integration module with command discovery and installation logic
  • Comprehensive test coverage for the new integration command
  • Complete documentation for the Gemini CLI integration

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
src/fastmcp/cli/install/gemini_cli.py Core implementation of Gemini CLI integration with command discovery, validation, and MCP server installation
src/fastmcp/cli/install/init.py Registration of the new gemini-cli command in the install app
tests/cli/test_install.py Test cases covering command parsing, options handling, and integration with existing test patterns
docs/integrations/gemini-cli.mdx User documentation explaining installation methods, configuration options, and usage examples

Comment on lines +20 to +61
def find_gemini_command() -> str | None:
"""Find the Gemini CLI command."""
# First try shutil.which() in case it's a real executable in PATH
gemini_in_path = shutil.which("gemini")
if gemini_in_path:
try:
# If 'gemini --version' fails, it's not the correct path
subprocess.run(
[gemini_in_path, "--version"],
check=True,
capture_output=True,
)
return gemini_in_path
except (subprocess.CalledProcessError, FileNotFoundError):
pass

# Check common installation locations (aliases don't work with subprocess)
potential_paths = [
# Default Gemini CLI installation location (after migration)
Path.home() / ".gemini" / "local" / "gemini",
# npm global installation on macOS/Linux (default)
Path("/usr/local/bin/gemini"),
# npm global installation with custom prefix
Path.home() / ".npm-global" / "bin" / "gemini",
# Homebrew installation on macOS
Path("/opt/homebrew/bin/gemini"),
]

for path in potential_paths:
if path.exists():
# If 'gemini --version' fails, it's not the correct path
try:
subprocess.run(
[str(path), "--version"],
check=True,
capture_output=True,
)
return str(path)
except (subprocess.CalledProcessError, FileNotFoundError):
continue

return None
Copy link

Copilot AI Sep 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function executes subprocess.run([path, '--version']) for each potential path and when checking shutil.which() result. This creates multiple subprocess calls during discovery. Consider adding a timeout parameter to prevent hanging on unresponsive executables, or implement early termination if the first successful validation is sufficient.

Copilot uses AI. Check for mistakes.
Comment on lines +147 to +148
subprocess.run(cmd_parts, check=True, capture_output=True, text=True)
return True
Copy link

Copilot AI Sep 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The subprocess call lacks a timeout parameter, which could cause the installation to hang indefinitely if the Gemini CLI command becomes unresponsive. Consider adding a reasonable timeout (e.g., 30-60 seconds) to prevent blocking.

Suggested change
subprocess.run(cmd_parts, check=True, capture_output=True, text=True)
return True
subprocess.run(cmd_parts, check=True, capture_output=True, text=True, timeout=60)
return True
except subprocess.TimeoutExpired as e:
print(
f"[red]Gemini CLI command timed out after 60 seconds while installing '[bold]{name}[/bold]'.[/red]"
)
return False

Copilot uses AI. Check for mistakes.
@jlowin
Copy link
Copy Markdown
Member

jlowin commented Sep 6, 2025

Oh good call @strawgate. You're right, this should be a uv run command. I'll open a separate issue to fix. Let's merge this, thanks @jackwotherspoon!!

@jlowin jlowin merged commit e5e4262 into PrefectHQ:main Sep 6, 2025
4 checks passed
@jackwotherspoon
Copy link
Copy Markdown
Contributor Author

Thank a ton @strawgate @jlowin 👏

Couple quick follow-up questions:

  1. Any time estimate on when the next release will go out with this change?
  2. Would either or both of you be interested in collaborating on an announcement blog with me for our Google for Developers blog? I would draft it up and just get you to review and then I would put you down as a co-author(s). Similar to our VS Code Extension announcement blog.

Super excited about this integration! 😄

@jlowin
Copy link
Copy Markdown
Member

jlowin commented Sep 7, 2025

  1. Definitely this week, I think we just have a few open threads to make sure we're happy with (like content ordering) before pulling the trigger, but there's no outstanding blockers to my knowledge.
  2. More than happy to. I'll ping you outside here to coordinate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli Related to FastMCP CLI commands (run, dev, install) or CLI functionality. enhancement Improvement to existing functionality. For issues and smaller PR improvements.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants