Skip to main content
Glama

MCP Energy Server

by ebarros23
RENDER_DEPLOYMENT.mdโ€ข8.9 kB
# ๐Ÿš€ Deploying MCP Energy Server to Render.com Complete guide to deploy your MCP Energy Server as a web API on Render.com using GitHub. ## ๐Ÿ“‹ Prerequisites - โœ… GitHub account - โœ… Render.com account (free tier available) - โœ… MCP Energy Server code (you have it!) ## ๐ŸŽฏ What You'll Get After deployment, you'll have: - ๐ŸŒ Live web API accessible via HTTPS - ๐Ÿ“Š Interactive API documentation at `/docs` - ๐Ÿ”„ Automatic deployments from GitHub - ๐Ÿ’š Health monitoring endpoint - ๐Ÿ†“ Free hosting on Render.com ## ๐Ÿ“ Step-by-Step Deployment ### Step 1: Push to GitHub First, push your code to GitHub if you haven't already: ```bash cd /mnt/user-data/outputs/mcp-energy # Initialize git (if not done) git init git add . git commit -m "Initial commit: MCP Energy Server with web API" # Add remote (replace YOUR_USERNAME) git remote add origin https://github.com/YOUR_USERNAME/mcp-energy.git # Push to GitHub git branch -M main git push -u origin main ``` ### Step 2: Create Render.com Account 1. Go to https://render.com 2. Click **"Get Started"** or **"Sign Up"** 3. Choose **"Sign up with GitHub"** (recommended) 4. Authorize Render to access your GitHub account ### Step 3: Create New Web Service 1. From your Render dashboard, click **"New +"** 2. Select **"Web Service"** 3. Click **"Connect GitHub"** if not already connected 4. Find and select your **`mcp-energy`** repository 5. Click **"Connect"** ### Step 4: Configure Web Service Fill in the following settings: **Basic Settings:** ``` Name: mcp-energy Region: Oregon (US West) [or your preferred region] Branch: main Root Directory: (leave blank) Runtime: Python 3 ``` **Build & Deploy:** ``` Build Command: pip install -r requirements.txt Start Command: python server_web.py ``` **Instance Type:** ``` Plan: Free ($0/month) ``` ### Step 5: Add Environment Variables Scroll down to **"Environment Variables"** section and add: ``` Key: EIA_API_KEY Value: BPlYS1rJRCA0cyGaS6c2JP0rl3wDgUv0QPZQf1o0 ``` ``` Key: PORT Value: 10000 ``` ### Step 6: Deploy! 1. Click **"Create Web Service"** at the bottom 2. Render will start building and deploying your service 3. Wait 2-5 minutes for the initial deployment 4. Watch the logs for any errors ### Step 7: Verify Deployment Once deployed, you'll see: - โœ… Green "Live" status - ๐ŸŒ Your service URL (e.g., `https://mcp-energy.onrender.com`) **Test your deployment:** 1. Open your service URL in a browser 2. You should see the API information page 3. Go to `https://your-service.onrender.com/docs` for interactive API documentation 4. Try the health check: `https://your-service.onrender.com/health` ## ๐Ÿงช Testing Your API ### Using the Browser Visit your service URL + `/docs` to see the interactive Swagger UI: ``` https://your-service.onrender.com/docs ``` ### Using curl ```bash # Health check curl https://your-service.onrender.com/health # Root endpoint curl https://your-service.onrender.com/ # Get electricity data curl -X POST https://your-service.onrender.com/electricity \ -H "Content-Type: application/json" \ -d '{"frequency": "monthly", "data_type": "generation"}' # Get natural gas data curl -X POST https://your-service.onrender.com/natural-gas \ -H "Content-Type: application/json" \ -d '{"frequency": "monthly", "data_type": "consumption"}' ``` ### Using Python ```python import requests base_url = "https://your-service.onrender.com" # Get electricity data response = requests.post( f"{base_url}/electricity", json={ "frequency": "monthly", "data_type": "generation", "facets": {"stateid": ["CA"]} } ) print(response.json()) ``` ### Using JavaScript/Node.js ```javascript const baseUrl = "https://your-service.onrender.com"; fetch(`${baseUrl}/electricity`, { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ frequency: 'monthly', data_type: 'generation', facets: { stateid: ['CA'] } }) }) .then(response => response.json()) .then(data => console.log(data)); ``` ## ๐Ÿ“ก Available API Endpoints Your deployed API has these endpoints: | Endpoint | Method | Description | |----------|--------|-------------| | `/` | GET | API information | | `/health` | GET | Health check | | `/docs` | GET | Interactive API documentation | | `/electricity` | POST | Electricity data | | `/natural-gas` | POST | Natural gas data | | `/petroleum` | POST | Petroleum data | | `/coal` | POST | Coal data | | `/renewable` | POST | Renewable energy data | | `/co2-emissions` | POST | CO2 emissions data | | `/steo` | POST | Energy forecasts | | `/international` | POST | International data | ## ๐Ÿ”„ Automatic Deployments Render automatically deploys when you push to GitHub: 1. Make changes to your code locally 2. Commit and push to GitHub: ```bash git add . git commit -m "Your changes" git push ``` 3. Render automatically detects the push and redeploys 4. Wait 2-3 minutes for the new version to go live ## ๐Ÿ“Š Monitoring Your Service ### View Logs 1. Go to your service in Render dashboard 2. Click on **"Logs"** tab 3. See real-time logs of your application ### Monitor Health Render automatically monitors your `/health` endpoint: - Green = Healthy - Red = Issues detected ### Check Metrics On the Render dashboard you can see: - Request rate - Response times - Memory usage - CPU usage ## โš™๏ธ Configuration Options ### Using render.yaml (Recommended) Your project already includes `render.yaml`. Render will automatically use this config! Benefits: - โœ… Configuration in code - โœ… Version controlled - โœ… Easy to replicate - โœ… No manual setup needed ### Custom Domain (Optional) To use your own domain: 1. Go to your service settings 2. Click **"Custom Domain"** 3. Add your domain 4. Follow DNS configuration instructions ### Environment Variables To update environment variables: 1. Go to **"Environment"** tab in your service 2. Click **"Add Environment Variable"** 3. Add key and value 4. Service will auto-redeploy ## ๐Ÿ› Troubleshooting ### Deployment Failed **Check build logs:** 1. Go to your service 2. Click on **"Logs"** or **"Events"** 3. Look for error messages **Common issues:** - Missing dependencies: Check `requirements.txt` - Python version: Ensure Python 3.11+ - Port configuration: Must use `PORT` env variable ### Service Not Responding **Check health endpoint:** ```bash curl https://your-service.onrender.com/health ``` **Check logs:** - Look for startup errors - Verify API key is set - Check for timeout issues ### API Returns Errors **Test locally first:** ```bash cd /mnt/user-data/outputs/mcp-energy python server_web.py ``` **Check EIA API:** - Verify API key is valid - Check if EIA service is up - Look at error messages in logs ## ๐Ÿ”’ Security Best Practices ### API Key Management **Current setup:** API key is in environment variables โœ… **For production:** 1. Rotate API keys regularly 2. Never commit API keys to GitHub 3. Use Render's environment variables ### Rate Limiting The free tier has limits: - 400 build hours/month - Automatic sleep after 15 min inactivity - 750 hours/month of runtime **Consider:** - Implementing caching - Adding rate limiting to endpoints - Upgrading to paid tier for production ## ๐Ÿ’ก Pro Tips ### Keep Service Awake Free tier services sleep after 15 minutes of inactivity. **Options:** 1. Use a monitoring service (UptimeRobot, etc.) 2. Upgrade to paid tier ($7/month) 3. Accept the cold start delay ### Optimize Cold Starts ```python # In server_web.py, add: import logging logging.basicConfig(level=logging.INFO) ``` ### Add Caching For better performance, add caching: ```python from functools import lru_cache @lru_cache(maxsize=100) async def cached_fetch(route, params_str): # Implementation pass ``` ## ๐Ÿ“ˆ Scaling ### When to Upgrade Consider upgrading when: - Consistent traffic (avoid sleep) - Need faster response times - Require more memory/CPU - Want custom domains ### Render Plans - **Free**: $0/month - Perfect for testing - **Starter**: $7/month - No sleep, better performance - **Standard**: $25/month - Autoscaling, more resources ## ๐ŸŽ‰ You're Live! Your MCP Energy Server is now: - โœ… Deployed on Render.com - โœ… Accessible via HTTPS - โœ… Automatically deploying from GitHub - โœ… Ready to serve energy data ## ๐Ÿ“ž Need Help? - **Render Docs**: https://render.com/docs - **Your Logs**: Check Render dashboard - **This Project**: See TROUBLESHOOTING.md - **GitHub Issues**: Create an issue in your repo ## ๐Ÿ”— Quick Links - [Your Render Dashboard](https://dashboard.render.com) - [Render Documentation](https://render.com/docs) - [EIA API Docs](https://www.eia.gov/opendata/) --- **Congratulations!** ๐ŸŽŠ Your MCP Energy Server is now live on the web! Share your API URL and start serving energy data to the world! ๐ŸŒ

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/ebarros23/mcp-energy'

If you have feedback or need assistance with the MCP directory API, please join our Discord server