Loading...

Building a Tool-Integrated AI Assistant with Model Context Protocol (MCP) and Google Gemini 2.5 Pro

By John SwansonApril 4, 2025 — 10 min read

As Large Language Models (LLMs) like GPT-4, Claude, Gemini, and Llama 3 continue to advance, the need for a standardized way to connect them to real-time data sources, APIs, and tools becomes essential. These models, while powerful, are isolated—they don't naturally interface with the outside world.

In a previous post, I introduced Function Calling as a way to bridge this gap. Today, we'll take that further with the Model Context Protocol (MCP) — a robust, open protocol that transforms how LLMs interact with external systems.

What Is Model Context Protocol (MCP)?

Developed by Anthropic, MCP acts like a "USB-C for AI tools", offering a universal interface for connecting LLMs to external APIs, databases, files, and services.

MCP Architecture:

  • Clients: LLMs or AI applications
  • Servers: Host tools/APIs and expose them to clients

This client-server design enables structured, dynamic tool interactions across systems.

Key Benefits:

  • Standardization: Unified method for connecting LLMs to APIs
  • Modularity: Reuse and compose tools with ease
  • Security: Clean handling of API keys and sensitive data
  • Interoperability: Works across languages and frameworks
  • Discoverability: Tools self-describe via schema, so no more guesswork

When Should You Use MCP?

  • Building AI agents or assistant frameworks
  • Integrating with multiple tools (e.g., search, databases, file systems)
  • Scaling systems with reusable and discoverable tools
  • Replacing hardcoded integration logic with dynamic function execution

Real-World Example: Flight Search with Gemini + MCP

Let's walk through building a natural language flight search tool powered by Gemini 2.5 Pro and an MCP server.

Tools:

  • Gemini API – for language understanding + function calling
  • SerpAPI – to get real-time flight data
  • MCP Server (`mcp-flight-search`) – a FastMCP server wrapper

Step-by-Step Implementation

✅ Prerequisites:

  • Python 3.8+
  • Google Gemini API key
  • SerpAPI key

1. Set Up the Environment

python -m venv venv
source venv/bin/activate
pip install google-genai mcp mcp-flight-search

2. Understand the MCP + Gemini Stack

from google import genai
from google.genai import types
from mcp import ClientSession, StdioServerParameters
from mcp.client.stdio import stdio_client

3. Initialize the Gemini Client

client = genai.Client(api_key=os.getenv("GEMINI_API_KEY"))

Best Practices for Using MCP + Gemini

🛠 Tool Design

  • Use descriptive names (`search_flights`)
  • Keep input schema simple and well-typed
  • Make descriptions model-friendly

🔄 Model Usage

  • Don't overload with too many tools
  • Dynamically load tools based on context
  • Prompt Gemini with purpose (e.g., "You are a travel assistant...")

⚙️ Server & Security

  • Use `stdio` for ease of development
  • Pass API keys using env vars
  • Log clearly but securely

Limitations (as of March 2025)

  • Partial OpenAPI support
  • Function calling only available in Python SDK
  • Some parameter types not yet supported

GitHub Repository

All source code and the working demo can be found here:
👉 GitHub – arjunprabhulal/mcp-gemini-search

Conclusion

By combining Google Gemini with the Model Context Protocol, we created an intelligent AI agent that:

  • Understands natural language
  • Dynamically discovers tools
  • Fills in parameters via function calling
  • Executes real-world actions in real time

This pattern enables you to build extensible, secure, and modular AI systems that go beyond chat — into automation, reasoning, and real-world utility.