mcp_server_example
This project demonstrates the implementation of building a custom MCP client-server solution, the client is developed using the Pydantic AI Framework, and it interacts with Brave Search MCP Server and a custom Send_Email server, all powered by the Gemini-2.0-Flash LLM. This approach eliminates the need for pre-built solutions like Claude Desktop, offering full flexibility and control over the client-server integration.
Demo Video
Watch the demo video here: Demo Video
Prerequisites
To set up and run the custom MCP server, ensure you have the following:
-
Python 3.12: Download and install the latest version from the official Python website.
-
Node.js 22.14.0: Install this version from the Node.js official site.
-
Gemini API Key: Sign up for a free API key at the Google AI Studio.
-
Brave Search API Key: Obtain a free API key by visiting the Brave Search API page and registering for an account.
-
Gmail App Password: Generate a 16-character app password for your Gmail account by following these steps:
- Navigate to Google Account Security Settings.
- Under "Signing in to Google," select "App passwords."
- Choose the app and device for which you need the password, then click "Generate."
- Copy the generated 16-character password for use in your application.
Setup Instructions
1) Clone the project
Clone the repository to your local machine:```bash
git clone <repository_url>
cd mcp_server_example
### 2) Create a virtual environment
Create a Python virtual environment for the project:```bash
python -m venv venv
3) Activate the virtual environment
Activate the virtual environment:
-
On Windows:
bash .\venv\Scripts\ctivate -
On MacOS/Linux:
bash source venv/bin/activate
4) Install the requirements for the MCP server
Navigate to the mcp_server directory and install the necessary dependencies:```bash
cd mcp_server
pip install -r requirements.txt
### 5) Install the requirements for the MCP client
Next, navigate to the `mcp_client` directory and install the necessary dependencies:```bash
cd mcp_client
pip install -r requirements.txt
6) Populate .env files
You need to configure the environment variables for both the server and client. Create .env files in both mcp_server and mcp_client directories and populate them with the following keys:
GEMINI_API_KEY— Free API key from Google AI Studio.BRAVE_API_KEY— Free API key from Brave Search.GMAIL_APP_PASSWORD— Generated app password (not your Gmail password).SENDER_EMAIL- Email address of the sender(the account for which you created the gmail_app_password).
7) Install the Brave Search MCP server
Install the MCP server. This will be called by the mcp_client using STDIO```bash
npm install -g @modelcontextprotocol/server-brave-search
### 8) Run the server
Start the MCP server by running the following command in the `mcp_server` directory. This will be called by the mcp_client using SSE```bash
cd mcp_server
python main.py
9) Run the client
Once the server is running, start the MCP client:bash
cd mcp_client
python main.py
10) Sample Prompts which invokes both the tools
VERY IMPORTANT NOTE: Conversational Memory is not yet implemented and the context is not passed between messages, so if you want to invoke multiple tools, make sure to provide full context in the same message.
1) find the most bizarre food combinations that actually taste good and email them with the subject 'Food Fusion Fiasco!' Add a fun note: 'Time to spice up your taste buds!'" to
2) Find the funniest quotes from comedians and email with the subject 'Comedy Gold!' Add a personal note: 'Get ready to laugh out loud!' to .
3) Search for the weirdest facts about space and email with the subject 'Cosmic Curiosities!' Add a fun note: 'Prepare to have your mind blown!' to .
4) Find the top 5 unusual travel destinations and email them with the subject 'Offbeat Adventures!' Add a fun note: 'Time to start planning your next getaway!' to
