mcp-server-gemini

nishantmunjal2003/mcp-server-gemini

3.2

If you are the rightful owner of mcp-server-gemini and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.

MCP Server is a lightweight, extendable API server designed for natural language processing and database logging.

๐Ÿง  MCP Server: Model Context Prototyping with Gemini + MySQL + FastAPI

๐Ÿ“Œ Project Overview

MCP Server is a lightweight, extendable API server that:

  • Accepts a natural language prompt
  • Sends the prompt to Gemini (Google's LLM) via API
  • Stores both the prompt and the AI-generated response into a MySQL database
  • Built using FastAPI, Google Generative AI SDK, and MySQL

โš™๏ธ Features

  • ๐ŸŒ REST API Endpoint: /get-context/
  • ๐Ÿง  LLM Integration: Gemini via google-generativeai
  • ๐Ÿ—ƒ๏ธ Database Logging: Stores prompt & response
  • ๐Ÿ” API key secured via .env
  • ๐Ÿš€ Easy to deploy on local or cloud (Render, Railway, etc.)

๐Ÿ“ Folder Structure

mcp-server/
โ”‚
โ”œโ”€โ”€ app.py                  # Main FastAPI server
โ”œโ”€โ”€ gemini_integration.py   # Gemini API integration
โ”œโ”€โ”€ schema.sql              # SQL for DB setup
โ”œโ”€โ”€ requirements.txt        # Python dependencies
โ”œโ”€โ”€ .env                    # Environment variables
โ””โ”€โ”€ README.md               # Project documentation

๐Ÿ Getting Started

โœ… 1. Clone or Unzip the Project

unzip mcp_server.zip
cd mcp-server

โœ… 2. Install Requirements

pip install -r requirements.txt

โœ… 3. Configure Environment Variables

Create or edit the .env file:

GEMINI_API_KEY=your_google_gemini_api_key_here

You can get your key from Google AI Studio.

โœ… 4. Setup MySQL Database

Option A: Use schema.sql

Run this SQL file in MySQL:

CREATE DATABASE IF NOT EXISTS mcp_db;
USE mcp_db;

CREATE TABLE IF NOT EXISTS responses (
    id INT AUTO_INCREMENT PRIMARY KEY,
    prompt TEXT,
    response TEXT,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

โœ… 5. Run the FastAPI Server

uvicorn app:app --reload

Access it at:
๐Ÿ“ http://127.0.0.1:8000

๐Ÿงช How to Use

๐Ÿš€ API Endpoint

POST /get-context/
Content-Type: application/json

๐Ÿ“ฅ Request Body
{
  "prompt": "What is quantum computing?"
}
๐Ÿ“ค Response
{
  "status": "success",
  "response": "Quantum computing is a field of computing that..."
}

๐Ÿ” Security Notes

  • API key stored securely in .env
  • Use HTTPS if deploying online

โ˜๏ธ Cloud Deployment

Deploy on:

๐Ÿ“ฆ Postman Test

curl --location --request POST 'http://127.0.0.1:8000/get-context/' \
--header 'Content-Type: application/json' \
--data-raw '{
    "prompt": "What is quantum computing?"
}'

๐Ÿ“œ License

Open-source for research, learning, and educational purposes.