Gemini Function Calling + Model Context Protocol(MCP) Flight Search
LocalAbout Gemini Function Calling + Model Context Protocol(MCP) Flight Search
This project shows how Gemini 2.5 Pro can use function calling to turn natural language flight queries into calls to the mcp-flight-search tool. It is aimed at Python developers who want to combine Gemini with MCP and connects to a local MCP server over stdio.
Key features
- 01Natural language flight search
- 02Automatic parameter extraction via function calling
- 03Stdio connection to mcp-flight-search
- 04Formatted JSON search results
- 05API keys configured through environment variables
Use cases
- 01Querying flights between cities in plain language
- 02Learning how Gemini function calling works with an MCP client
MCP support
This project is an MCP client example that starts a local mcp-flight-search process, retrieves its tool list and calls those tools over stdio.
Configuration
Local server config is the same for every client. Copy it into your client’s MCP config file.
We haven’t collected a package or remote endpoint for this server. Follow the instructions in the project README.
Tools
Local servers expose tools only once running on your machine, and the maintainer has not provided a tool list.
Details
From the project READMEGemini Function Calling + Model Context Protocol(MCP) Flight Search


This project demonstrates how to use Google's Gemini 2.5 Pro with function calling capabilities to interact with the mcp-flight-search tool via Model Context Protocol (MCP). This client implementation shows how to:
- Connect to a local MCP server process (
mcp-flight-search) using stdio communication - Use natural language prompts with Gemini 2.5 Pro to search for flights (e.g., "Find flights from Atlanta to Las Vegas on 2025-05-05")
- Let Gemini automatically determine the correct function parameters from the natural language input
- Execute the flight search using the MCP tool
- Display formatted results from the search
Features
- Natural language flight search using Gemini 2.5 Pro
- Automatic parameter extraction via function calling
- Integration with
mcp-flight-searchtool via stdio - Formatted JSON output of flight results
- Environment-based configuration for API keys
Prerequisites
Before running this client, you'll need:
- Python 3.7+
- A Google AI Studio API key for Gemini
- A SerpAPI key (used by the flight search tool)
- The
mcp-flight-searchpackage installed
Dependencies
This project relies on several Python packages:
-
google-generativeai: Google's official Python library for accessing Gemini 2.5 Pro and other Google AI models.
- Provides the client interface for Gemini 2.5 Pro
- Handles function calling capabilities
- Manages API authentication and requests
-
mcp-sdk-python: Model Context Protocol (MCP) SDK for Python.
- Provides
ClientSessionfor managing MCP communication - Includes
StdioServerParametersfor configuring server processes - Handles tool registration and invocation
- Provides
-
mcp-flight-search: A flight search service built with MCP.
- Implements flight search functionality using SerpAPI
- Provides MCP-compliant tools for flight searches
- Handles both stdio and HTTP communication modes
-
asyncio: Python's built-in library for writing asynchronous code.
- Manages asynchronous operations and coroutines
- Handles concurrent I/O operations
- Required for MCP client-server communication
-
json: Python's built-in JSON encoder and decoder.
- Parses flight search results
- Formats output for display
- Handles data serialization/deserialization
Setup
-
Clone the Repository:
git clone https://github.com/arjunprabhulal/mcp-gemini-search.git cd mcp-gemini-search -
Install Dependencies:
# Install required Python libraries pip install -r requirements.txt # Install the MCP flight search tool pip install mcp-flight-search -
Set Environment Variables:
export GEMINI_API_KEY="YOUR_GEMINI_API_KEY" export SERP_API_KEY="YOUR_SERPAPI_API_KEY"Replace the placeholder values with your actual API keys:
- Get your Gemini API key from Google AI Studio
- Get your SerpAPI key from SerpApi
Architecture
This project integrates multiple components to enable natural language flight search. Here's how the system works:
Component Interactions
-
User to Client
- User provides natural language query (e.g., "Find flights from Atlanta to Las Vegas tomorrow")
- Client script (
client.py) processes the input
-
Client to MCP Server
- Client starts the MCP server process (
mcp-flight-search) - Establishes stdio communication channel
- Retrieves available tools and their descriptions
- Client starts the MCP server process (
-
Client to Gemini 2.5 Pro
- Sends the user's query
- Provides tool descriptions for function calling
- Receives structured function call with extracted parameters
-
Client to MCP Tool
- Takes function call parameters from Gemini
- Calls appropriate MCP tool with parameters
- Handles response processing
-
MCP Server to SerpAPI
- MCP server makes requests to SerpAPI
- Queries Google Flights data
- Processes and formats flight information
Data Flow
-
Input Processing
User Query → Natural Language Text → Gemini 2.5 Pro → Structured Parameters -
Flight Search
Parameters → MCP Tool → SerpAPI → Flight Data → JSON Response -
Result Handling
JSON Response → Parse → Format → Display to User
Communication Protocols
-
Client ↔ MCP Server
- Uses stdio communication
- Follows MCP protocol for tool registration and calls
- Handles asynchronous operations
-
MCP Server ↔ SerpAPI
- HTTPS requests
- JSON data exchange
- API key authentication
-
Client ↔ Gemini 2.5 Pro
- HTTPS requests
- Function calling protocol
- API key authentication
Error Handling
The integration includes error handling at multiple levels:
- Input validation
- API communication errors
- Tool execution failures
- Response parsing issues
- Data formatting problems
Usage
Run the client:
python client.py
The script will:
- Start the MCP flight search server process
- Send your flight search query to 2.5 Pro
- Use Gemini's function calling to extract search parameters
- Execute the search via the MCP tool
- Display the formatted results
Related Projects
This client uses the mcp-flight-search tool, which is available at:
- GitHub: arjunprabhulal/mcp-flight-search
- PyPI: mcp-flight-search
Author
For more articles on AI/ML and Generative AI, follow me on Medium: @arjun-prabhulal
License
This project is licensed under the MIT License.
Comments
New to MCP?
From what the protocol is to installing your first server, these answers cover most first questions.
An open protocol that defines how AI applications connect to external tools and data in a uniform way. Clients talk to the model; MCP servers provide tools, resources and prompt templates. They exchange standard messages, so one server can be reused by many clients.