How to Use Gemini CLI with NPX: Advanced Setup and MCP Integration Guide

JeanJean
2 min read

Want to use Gemini CLI without installing anything globally? With npx, you can launch Gemini CLI on-demand, making it perfect for lightweight and modular AI development. When you run Gemini CLI with npx, it automatically creates a .gemini/settings.json file in your user directory to store your configuration.

In this guide, I’ll show you how to use npx to run Gemini CLI, verify or edit your .gemini/settings.json, add your API key securely, and plug in powerful MCP tools like taskmaster-ai or context7. Whether you're experimenting or automating real workflows, this approach keeps your system clean and your AI powerful.

Video Walkthrough

Follow along with this detailed video guide:

🎥 https://youtu.be/HpasFDFxsmk?si=78D76_6re8iszbAG

Step 1: Run Gemini CLI with NPX

Instead of installing Gemini CLI globally with npm, you can run it instantly using npx:

bash npx @google/gemini-cli

This command downloads the latest version of Gemini CLI and executes it without installing anything permanently. Running this once will create the .gemini/settings.json file in your user folder.

Tip: You must have Node.js and npm installed first. You can check with:

bash node -v
npm -v

Step 2: Locate and Verify the .gemini/settings.json File

Check your user directory for the .gemini folder:

bashCopyEdit# Windows
cd %USERPROFILE%\.gemini
# macOS/Linux
cd ~/.gemini

Open the settings.json file with a text editor (like VS Code or Notepad++). It should have a basic structure that you can update with your API keys and MCP configuration.

If the file is missing or empty, you can create or overwrite it with valid JSON as shown below.

Step 3: Configure settings.json Properly

Here is an example settings.json that works well with NPX and MCP tools:

jsonCopyEdit{
  "auth": {
    "apiKey": "YOUR_API_KEY_HERE"
  },
  "theme": "Default",
  "selectedAuthType": "oauth-personal",
  "mcpServers": {
    "context7": {
      "command": "npx",
      "args": ["-y", "@upstash/context7-mcp"]
    },
    "taskmaster-ai": {
      "command": "npx",
      "args": ["-y", "--package=task-master-ai", "task-master-ai"],
      "env": {
        "OPENAI_API_KEY": "your-openai-key",
        "GOOGLE_API_KEY": "your-google-api-key"
      }
    }
  }
}

Step 4: Run a Prompt with NPX

After your config is set, you can run prompts with NPX like this:

bashCopyEditnpx @google/gemini-cli --prompt "Write a powerful quote about perseverance."

You should receive a generated response immediately.

Conclusion

Using Gemini CLI via NPX is the easiest way to get started with advanced AI workflows without cluttering your system. The auto-generated .gemini/settings.json file can be edited to add your API keys and customize MCP tools.

Questions or issues? Drop a comment or reach out on YouTube. Happy coding!

0
Subscribe to my newsletter

Read articles from Jean directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Jean
Jean