This project is a FastAPI-based MCP (Model Control Protocol) Server that uses Google Gemini LLM to generate five interview questions from a given job description. It can run locally for testing or be deployed to Google Cloud Run using Terraform.
- REST API built with FastAPI
- Uses Gemini 2.5 Flash model via
google-generativeai - /generate_questions endpoint to generate interview questions
- Deployable to Google Cloud Run
- Secure Gemini API key stored in Secret Manager
- Infrastructure as code with Terraform
.
├── mcp_server.py # FastAPI app source code
├── requirements.txt # Python dependencies
├── docker-compose.yml # Container build file
├── terraform/
│ ├── provider.tf
│ ├── variables.tf
│ ├── enable_apis.tf
│ ├── service_account.tf
│ ├── secret_manager.tf
│ ├── secret_iam.tf
│ ├── cloud_run.tf
│ ├── outputs.tf
│ └── terraform.tfvars.example
└── README.md
Make sure you have the following installed locally:
- Python 3.11+
- Docker
- Terraform ≥ 1.2.0
- Google Cloud SDK (
gcloud) - A GCP project with billing enabled
- A Gemini API key from Google AI Studio
git clone https://github.com/your-username/fast-mcp-server.git
cd fast-mcp-serverpython -m venv .venv
source .venv/bin/activate # Linux / Mac
# or
.venv\Scripts\activate # Windowspip install --upgrade pip
pip install -r requirements.txtexport GEMINI_API_KEY="your_api_key_here" # Linux / Mac
# or
setx GEMINI_API_KEY "your_api_key_here" # Windows (PowerShell)uvicorn mcp_server:app --reloadcurl -X POST http://127.0.0.1:8000/generate_questions \
-H "Content-Type: application/json" \
-d '{"description": "We are looking for a data engineer with experience in Python, SQL, ETL pipelines, and cloud tools like GCP or AWS."}'Expected output:
{
"questions": [
"1. How would you design an ETL pipeline using Python and SQL?",
"2. What are the key differences between GCP and AWS for data workflows?",
"3. How would you handle failures in a production data pipeline?",
"4. What strategies do you use to optimize SQL queries for large datasets?",
"5. Describe a scenario where you automated a data process using Python."
]
}docker build -t mcp-server:latest .docker run -p 8000:8000 -e GEMINI_API_KEY=$GEMINI_API_KEY mcp-server:latestcurl http://127.0.0.1:8000/healthAll Terraform configuration files are in the terraform/ directory.
gcloud auth login
gcloud config set project YOUR_PROJECT_ID
gcloud auth application-default loginIMAGE="gcr.io/YOUR_PROJECT_ID/mcp-server:latest"
docker build -t $IMAGE .
docker push $IMAGECreate a file named terraform.tfvars inside the terraform/ folder:
project = "your-gcp-project-id"
region = "us-central1"
image = "gcr.io/your-gcp-project-id/mcp-server:latest"
gemini_api_key = "YOUR_GEMINI_API_KEY"(Do not commit this file with the real API key to version control.)
cd terraform
terraform initterraform applyType yes to confirm.
Terraform will:
- Enable required GCP APIs
- Create a Cloud Run service
- Store your Gemini API key in Secret Manager
- Assign necessary IAM roles
- Expose a public endpoint
After deployment, Terraform will output the service URL:
Outputs:
cloud_run_url = "https://mcp-server-xxxxxx-uc.a.run.app"
curl -X POST https://mcp-server-xxxxxx-uc.a.run.app/generate_questions \
-H "Content-Type: application/json" \
-d '{"description": "We are looking for a backend engineer with FastAPI and Google Cloud experience."}'- 403 Permission Denied:
Check IAM roles for the Cloud Run service account (should have
Secret Manager Secret Accessor). - 500 Internal Server Error:
Make sure
GEMINI_API_KEYis correctly stored and accessible by the service. - Invalid JSON Error: Ensure you are sending proper JSON with double quotes, not single quotes.
To remove all deployed resources:
terraform destroyRun command PROD:
docker-compose up --buildRun command DEV:
docker-compose -f docker-compose.dev.yml up --buildStop command:
docker-compose downUvicorn is an ASGI web server implementation for Python.
Run MCP Server
uvicorn mcp_server:app --reload