Skip to main content
Glama
binaykushwaha1244

MCP Web Search Assistant

MCP Web Search Assistant with Gemini

A simple MCP-based web search assistant that uses Google Gemini as the Large Language Model (LLM) and a local MCP server to perform web searches through DuckDuckGo.

This project demonstrates how an LLM can interact with external tools using a client-server architecture.


Features

  • Uses Google Gemini for natural-language understanding and responses.

  • Uses an MCP-style client/server architecture for tool integration.

  • Performs web searches using DuckDuckGo.

  • Uses a local Flask server to handle tool requests.

  • Runs the MCP server and client separately.

  • Uses an environment variable to securely provide the Gemini API key.


Related MCP server: web-mcp-server

Architecture

                         User
                           |
                           v
                  +----------------+
                  |  ask_claude.py |
                  |  Client App    |
                  +----------------+
                           |
                           v
                  +-------------------+
                  | ClaudeClient       |
                  | Gemini Integration |
                  +-------------------+
                           |
                           v
                     Gemini API
                           |
                           | Tool Call
                           v
                  +----------------+
                  |   MCP Server   |
                  | mcp_server.py  |
                  +----------------+
                           |
                           v
                  +----------------+
                  |   DuckDuckGo   |
                  |   Web Search   |
                  +----------------+
                           |
                           v
                    Search Results
                           |
                           v
                        Gemini
                           |
                           v
                    Final Response

Request Flow

  1. The user enters a question through the client application.

  2. The client sends the question to Google Gemini.

  3. Gemini determines whether external web information is required.

  4. If a web search is required, Gemini requests the fetch_web_content tool.

  5. The client sends the tool request to the local MCP server.

  6. The MCP server performs the search using DuckDuckGo.

  7. Search results are returned to the client.

  8. Gemini uses the retrieved information to generate the final response.


Project Structure

MCP/
│
├── mcp_integration.py
├── mcp_server.py
├── claude_mcp_client.py
├── ask_claude.py
├── requirements.txt
├── .gitignore
└── README.md

File Description

File

Description

mcp_integration.py

Handles Gemini integration, MCP tool definitions, and web-search functionality.

mcp_server.py

Runs the local Flask-based MCP server and exposes the tool endpoint.

claude_mcp_client.py

Client responsible for communicating with Gemini and the MCP server.

ask_claude.py

Command-line interface used to interact with the assistant.

requirements.txt

Contains the required Python dependencies.

.gitignore

Prevents sensitive and unnecessary files from being committed.

README.md

Project documentation and setup instructions.

Note: Some filenames and class names retain the original Claude-based naming from the tutorial, although the project now uses Google Gemini.


Requirements

Before running the project, make sure you have:

  • Python 3.10 or higher

  • pip

  • A Google Gemini API key

  • An active internet connection


Installation

1. Clone the Repository

git clone <YOUR_GITHUB_REPOSITORY_URL>
cd MCP

2. Install Dependencies

pip install -r requirements.txt

If the Google GenAI SDK is not installed:

pip install google-genai

Gemini API Key Setup

This project requires a Google Gemini API key.

Set the API key as an environment variable in PowerShell:

$env:GEMINI_API_KEY="YOUR_GEMINI_API_KEY"

Verify that the key is available without displaying the actual key:

python -c "import os; print('Gemini key found:', bool(os.environ.get('GEMINI_API_KEY')))"

Expected output:

Gemini key found: True

Security: Never add your actual Gemini API key to the source code, README, or GitHub repository.


Running the Project

The application uses two PowerShell terminals.

Terminal 1 — Start the MCP Server

Open the first PowerShell terminal and navigate to the project directory:

cd D:\Projects\MCP

Set the Gemini API key:

$env:GEMINI_API_KEY="YOUR_GEMINI_API_KEY"

Verify the key:

python -c "import os; print('Gemini key found:', bool(os.environ.get('GEMINI_API_KEY')))"

Start the MCP server:

python mcp_server.py

The server will run on:

http://localhost:5001

Keep Terminal 1 running.


Terminal 2 — Start the Client

Open a second PowerShell terminal.

Navigate to the project:

cd D:\Projects\MCP

Set the Gemini API key:

$env:GEMINI_API_KEY="YOUR_GEMINI_API_KEY"

Verify the key:

python -c "import os; print('Gemini key found:', bool(os.environ.get('GEMINI_API_KEY')))"

Start the client:

python ask_claude.py

You can now enter questions for the assistant.

Example

What is the latest information about Python?

Example Workflow

User Question
      |
      v
ask_claude.py
      |
      v
ClaudeClient
      |
      v
Gemini API
      |
      | Tool required
      v
MCP Server
      |
      v
DuckDuckGo
      |
      v
Search Results
      |
      v
Gemini
      |
      v
Final Answer

MCP Server Endpoints

The MCP server runs locally on port 5001.

Health Check

GET /health

Used to verify that the MCP server is running.

Tool Call

POST /tool_call

Used by the client to request the web-search tool.

Example request:

{
  "name": "fetch_web_content",
  "parameters": {
    "query": "Python programming language"
  }
}

Technologies Used

  • Python — Core programming language

  • Google Gemini — Large Language Model

  • Google GenAI SDK — Gemini API integration

  • Flask — Local MCP server

  • DuckDuckGo — Web search

  • Requests — HTTP communication

  • MCP-style Client/Server Architecture — Tool integration


Security

The Gemini API key is provided through an environment variable rather than being stored directly in the source code.

Recommended .gitignore:

__pycache__/
*.pyc
.env
.venv/
venv/

Never commit API keys, passwords, tokens, or other credentials to GitHub.


Troubleshooting

Gemini API Key Not Found

Run:

python -c "import os; print(bool(os.environ.get('GEMINI_API_KEY')))"

Expected:

True

If it returns False, set the key again:

$env:GEMINI_API_KEY="YOUR_GEMINI_API_KEY"

PowerShell environment variables set using $env: apply only to the current terminal session. If you open a second terminal, set the variable there as well.

MCP Server Not Responding

Make sure the MCP server is running in Terminal 1:

python mcp_server.py

The server should be available at:

http://localhost:5001

Port Already in Use

If port 5001 is already being used, stop the existing server process or configure the application to use another available port.


Future Improvements

  • Rename the remaining Claude-based filenames and classes to Gemini-based names.

  • Add additional MCP tools.

  • Improve conversation history management.

  • Add more robust error handling and retry mechanisms.

  • Support additional search providers.

  • Add a web-based user interface.


Output

alt text alt text

License

This project is licensed under the MIT License.

You are free to use, modify, distribute, and reuse this project, subject to the terms of the license.

MIT License

Copyright (c) 2026

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Maintenance

ActivityMaintained
ResponsivenessNo issues

Related MCP Connectors

Related MCP Servers

  • F
    license
    Not graded
    quality
    D
    maintenance
    A lightweight MCP server that enables LLMs to search the web via DuckDuckGo, search GitHub code repositories, and extract clean content from web pages in LLM-friendly formats.
    8
    -
  • F
    license
    Not graded
    quality
    D
    maintenance
    MCP server that exposes web_search and web_fetch tools, allowing LLM applications to search the web via DuckDuckGo and fetch page content as cleaned markdown.
    -