π§ MCP Server: Model Context Prototyping with Gemini + MySQL + FastAPI
GitHub: https://github.com/nishantmunjal2003/mcp-server-gemini
π 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
bashCopyEditmcp-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
bashCopyEditunzip mcp_server.zip
cd mcp-server
β 2. Install Requirements
bashCopyEditpip install -r requirements.txt
β 3. Configure Environment Variables
Create or edit the .env
file:
iniCopyEditGEMINI_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:
sqlCopyEditCREATE 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
);
Option B: Manually create in MySQL Workbench or CLI
β 5. Run the FastAPI Server
bashCopyEdituvicorn 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
jsonCopyEdit{
"prompt": "What is quantum computing?"
}
π€ Response
jsonCopyEdit{
"status": "success",
"response": "Quantum computing is a field of computing that..."
}
β Example Error
jsonCopyEdit{
"status": "error",
"message": "Prompt is required"
}
π Security Notes
- API key stored securely in
.env
- Use HTTPS if deploying online
- Add authentication middleware if needed
βοΈ Cloud Deployment (Optional)
You can deploy this on:
π¦ Postman Collection
Import this cURL into Postman:
bashCopyEditcurl --location --request POST 'http://127.0.0.1:8000/get-context/' \
--header 'Content-Type: application/json' \
--data-raw '{
"prompt": "What is quantum computing?"
}'
Or use the included .postman_collection.json
(if provided).
π License
This project is open-source and free to use for educational, academic, and research purposes.