---
title: "How to connect Gemini to your MCP server | FluxOS MCP Blog"
description: "In Gemini CLI, one command connects your FluxOS MCP server. Also see how to use it from the Gemini SDK and why the Gemini app does not connect yet."
url: "https://www.fluxosmcp.com/en/blog/how-to-connect-gemini-to-your-mcp-server"
lang: "en-US"
---

[Blog](https://www.fluxosmcp.com/en/blog) · Nov 25, 2026 · FluxOS MCP Team

# How to connect Gemini to your MCP server

[Leia este artigo em português](https://www.fluxosmcp.com/blog/como-ligar-o-gemini-ao-seu-servidor-mcp)

“Gemini” is the name of several products, and the answer to “can I connect my MCP server?” changes from one to the next. In the terminal, yes, with one command. In code, yes, with a feature that is still experimental. In the app, not for now.

This article goes through all three, in order of what works best today.

## Before you start: address and key

You need two things, and both are in FluxOS MCP. The dashboard is still in Portuguese, so on-screen labels appear here as they are, with the meaning in parentheses.

- **The server address.** On the **Conexão** (Connection) tab of the published server (or, for the client, on the **Ferramentas e conexão** (Tools and connection) page of the client portal). It looks like `https://SEU-DOMINIO/mcp/dados-publicos`, where `SEU-DOMINIO` stands for your domain.
- **An access key.** Created on the client’s **Chaves** (Keys) tab. It starts with `amk_` and is shown only once.

In the examples, the server is `dados-publicos` from the [OpenAPI tutorial](https://www.fluxosmcp.com/en/blog/tutorial-postal-codes-holidays-and-rates-in-your-ai-assistant-with-openapi). Swap in your own.

FluxOS MCP speaks **Streamable HTTP** and authenticates **by key only**, sent in the `Authorization: Bearer` header. There is no OAuth. That detail is what decides where Gemini connects and where it does not.

## Gemini CLI: the path that works today

Gemini CLI is Google’s assistant for the terminal, and it supports remote MCP servers with a custom header.

### Step 1: add the server

```bash
gemini mcp add --transport http \
  --header "Authorization: Bearer amk_SUA_CHAVE" \
  dados-publicos https://SEU-DOMINIO/mcp/dados-publicos

```

Three details:

- `--transport http` is Streamable HTTP. The command’s default is `stdio`, which is meant for local servers, so do not forget the option.
- By default, the configuration applies only to the current project. With `--scope user`, it applies to all of them.
- **Do not use underscores in the server name.** Gemini CLI builds each tool’s name as `mcp_SERVIDOR_FERRAMENTA` (server, then tool) and gets confused when the server name contains `_`. Hyphens are fine: `dados-publicos` is correct.

### Step 2: verify

```bash
gemini mcp list

```

The server should show up as **Connected**. Inside a session, the `/mcp` command lists the servers and the tools on each one.

### Step 3: use it

Just ask:

- “What is the address for CEP 01001-000?” (a CEP is a Brazilian postal code)
- “What is the Selic rate right now?” (Selic is Brazil’s benchmark interest rate)

Before running a tool, Gemini CLI asks for your confirmation.

### The file behind the command

The command writes the configuration to `settings.json`: either `.gemini/settings.json` in the project, or `~/.gemini/settings.json` in your home folder. You can also edit it by hand:

```json
{
  "mcpServers": {
    "dados-publicos": {
      "httpUrl": "https://SEU-DOMINIO/mcp/dados-publicos",
      "headers": {
        "Authorization": "Bearer ${FLUXOS_MCP_KEY}"
      },
      "timeout": 30000
    }
  }
}

```

The field is **`httpUrl`**, not `url`. In Gemini CLI, `url` means the old transport (SSE), which FluxOS MCP does not use. This is the most common mistake people make when copying a configuration from another assistant.

Other useful fields:

- `timeout`: the maximum duration of a call, in milliseconds. The default is ten minutes. A lower value makes errors surface sooner.
- `includeTools` and `excludeTools`: lists of tools to enable or hide. If the same tool is in both, the exclusion wins.
- `trust`: when `true`, Gemini CLI stops asking for confirmation for that server’s tools. Leave it at `false` for any server with tools that change data.

### Keeping the key out of the file

The Gemini CLI documentation says string values in `settings.json` can read environment variables, in the `${NOME}` form. The example above relies on that: each person sets `FLUXOS_MCP_KEY` on their own machine, and the file can go into the repository without the key.

A caveat: the MCP page only shows this feature in the `env` field, not in `headers`. Test it before you count on it. If the server responds with a 401, the variable was not substituted. In that case, keep the configuration with the key in `~/.gemini/settings.json`, outside the repository.

### Who can use it

Gemini CLI changed its audience in 2026: according to the project’s own repository, free individual access and Google’s personal plans moved to a different command-line product. Before you write a rollout guide for your team, check the Gemini CLI repository to see whether your account type is still supported.

## In code: the Gemini SDK

If you are writing a program that calls Gemini, the official SDK (Google Gen AI SDK) has built-in MCP support. The documentation describes it as an **experimental feature**.

The idea: you open an MCP session with the server and hand it to the model as a tool. The SDK lists the tools, calls whichever one the model picks, and returns the result.

```python
import asyncio
import os

from google import genai
from mcp import ClientSession
from mcp.client.streamable_http import streamablehttp_client

client = genai.Client()

URL = "https://SEU-DOMINIO/mcp/dados-publicos"
HEADERS = {"Authorization": f"Bearer {os.environ['FLUXOS_MCP_KEY']}"}

async def main():
    async with streamablehttp_client(URL, headers=HEADERS) as (read, write, _):
        async with ClientSession(read, write) as session:
            await session.initialize()
            response = await client.aio.models.generate_content(
                model="MODELO_GEMINI",
                contents="What is the address for CEP 01001-000?",
                config=genai.types.GenerateContentConfig(tools=[session]),
            )
            print(response.text)

asyncio.run(main())

```

Two honest notes about this example:

- The official SDK example uses a **local** server. Here we swapped the local connection for the HTTP connection from Python’s `mcp` library, which accepts headers. The Gemini part (`tools=[session]`) is the same.
- Replace `MODELO_GEMINI` with the name of a current model. Model names age fast.

In JavaScript the path is equivalent, using the SDK’s `mcpToTool` function.

In this setup, **your program is what calls your server**, not Google. The FluxOS MCP key never leaves your machine.

The Gemini API also has a mode in which Google itself connects to the remote MCP server, with the address and headers passed in the request. It is in beta and has model restrictions. Check the Gemini API documentation before using it.

## The Gemini app: not yet

The Gemini app (gemini.google.com) gained a **custom apps** area, where you enter the address of an MCP server. Two limits prevent using it with FluxOS MCP today:

- **Authentication is OAuth.** The screen asks for the server address and, when needed, OAuth credentials. There is no field for a fixed key in the header, which is how FluxOS MCP authenticates.
- **Availability is restricted.** According to Google’s help pages, the feature requires a personal account (it does not work with work or school accounts), being over 18, being in the United States, and using the app in English.

It is the same situation as the [ChatGPT web app](https://www.fluxosmcp.com/en/blog/how-to-connect-chatgpt-and-codex-to-your-mcp-server): the assistant supports MCP servers, but only with a type of authentication that FluxOS MCP does not offer.

For Gemini Enterprise, the business version, we did not find a header key option in the documentation. If your company uses that product, it is worth confirming with your administrator before you plan around it.

## When it does not connect

The server responds with a code that tells you why:

- **401:** the key is missing, wrong, revoked or expired.
- **402:** the client’s subscription is awaiting payment.
- **403:** the client’s subscription is suspended or canceled.
- **429:** the key went over its per-minute or per-day limit.

In Gemini CLI, a 401 looks misleading: when it gets that response, it assumes the server requires OAuth and tries to start that flow. If you see a message about OAuth or authenticating in the browser, **the problem is the key**. Check the header and add the server again.

If the tool does not appear, check that the server is **published** and that the tool is among the ones enabled for that key.

## Summary

- **Gemini CLI:** connects, with `--transport http` and the `Authorization` header.
- **Gemini SDK:** connects, through your program, using an experimental feature.
- **Gemini app:** does not connect for now, because it only accepts OAuth.

The same server also works [in Claude Code](https://www.fluxosmcp.com/en/blog/how-to-connect-claude-code-to-your-mcp-server), [in Grok](https://www.fluxosmcp.com/en/blog/how-to-connect-grok-to-your-mcp-server), [in Codex](https://www.fluxosmcp.com/en/blog/how-to-connect-chatgpt-and-codex-to-your-mcp-server) and [in Cursor and VS Code](https://www.fluxosmcp.com/en/blog/how-to-connect-cursor-and-vs-code-to-your-mcp-server).
