Gemini
How to connect MCP Servers to Google Gemini
Quick Overview
Connect your MCPHero servers to Google's Gemini ecosystem, including Gemini in Google AI Studio, the Gemini API, and Gemini integrations in IDEs. Google has adopted MCP as part of their agentic AI strategy.
MCP support in Gemini is available through Google AI Studio and the Gemini API. Consumer Gemini (gemini.google.com) does not yet support custom MCP servers.
Prerequisites
- A Google Cloud account with Gemini API access
- Google AI Studio access: aistudio.google.com
- An MCPHero server. Create one now.
Option 1: Google AI Studio
Google AI Studio provides a web-based interface for testing Gemini with MCP tools.
Step 1: Get Your MCP Server Credentials
From your MCPHero dashboard:
- Copy your server URL:
https://api.mcphero.app/mcp/{server_id}/mcp - Generate an API key from the Keys tab
Step 2: Open Google AI Studio
Navigate to aistudio.google.com and sign in with your Google account.
Step 3: Configure MCP Server
- Create a new prompt or open an existing one
- Click Tools in the right sidebar
- Select Add MCP Server
- Enter your server details:
- URL:
https://api.mcphero.app/mcp/{server_id}/mcp - Authentication: Bearer Token
- Token: Your MCPHero API key
- URL:
- Click Connect
Step 4: Verify Tools
Once connected, your MCP tools appear in the Tools panel. You can:
- View available tools and their schemas
- Test individual tools
- Use tools in conversations with Gemini
Option 2: Gemini API (Programmatic)
The google-genai SDK has native MCP support — you can pass an MCP ClientSession directly as a tool,
and Gemini handles discovery and function calling automatically.
Step 1: Install Dependencies
pip install google-genai mcpStep 2: Create the MCP Session
Connect to your MCPHero server using the MCP Python SDK:
from mcp import ClientSession
from mcp.client.streamable_http import streamablehttp_client
MCPHERO_URL = "https://api.mcphero.app/mcp/{server_id}/mcp"
MCPHERO_KEY = "YOUR_API_KEY"Step 3: Call Gemini with MCP Tools
Pass the MCP session directly as a tool — Gemini discovers available tools and calls them automatically:
import asyncio
from google import genai
GEMINI_KEY = "YOUR_GEMINI_API_KEY"
client = genai.Client(api_key=GEMINI_KEY)
async def main():
async with streamablehttp_client(
url=MCPHERO_URL,
headers={"Authorization": f"Bearer {MCPHERO_KEY}"}
) as (read, write, _):
async with ClientSession(read, write) as session:
await session.initialize()
response = await client.aio.models.generate_content(
model="gemini-2.5-flash",
contents="What tools do you have available?",
config=genai.types.GenerateContentConfig(
tools=[session],
),
)
print(response.text)
asyncio.run(main())No manual tool conversion needed — the SDK handles MCP tool discovery and execution natively.
Option 3: Gemini in IDX
Google's Project IDX (cloud IDE) supports MCP servers for AI-assisted development.
Step 1: Open IDX Settings
In your IDX workspace:
- Click the gear icon to open Settings
- Navigate to AI → MCP Servers
Step 2: Add MCPHero Server
Add a new server configuration:
{
"servers": {
"mcphero": {
"url": "https://api.mcphero.app/mcp/{server_id}/mcp",
"headers": {
"Authorization": "Bearer YOUR_API_KEY"
}
}
}
}Step 3: Use in Gemini Chat
Open Gemini in IDX and your MCP tools will be available for code generation, file operations, and other tasks defined in your server.
Troubleshooting
Connection Refused
- Verify your API key is valid and not expired
- Check the server URL includes the full path ending in
/mcp - Ensure your MCPHero server is deployed and running
Tools Not Appearing in AI Studio
- Refresh the Tools panel
- Check the browser console for connection errors
- Verify the MCP server responds to the
tools/listmethod
Function Call Errors
- Ensure tool input schemas match expected parameters
- Check Gemini's function calling documentation for schema requirements
- Validate JSON schema compatibility between MCP and Gemini formats
Rate Limiting
Both Gemini API and MCPHero have rate limits:
- Use exponential backoff for retries
- Cache tool definitions to reduce MCP calls
- Consider batching operations