Skip to main content
Glama

MCP Server on Cloudflare Workers & Azure Functions

by TedTschopp
AZURE_DEPLOYMENT.md8.03 kB
# Azure Deployment Guide ## Overview This MCP server can be deployed to **Azure Functions** in addition to Cloudflare Workers. Azure Functions provides a serverless compute service that allows you to run your MCP server on Microsoft's cloud infrastructure. ## Prerequisites ### Required Tools 1. **Node.js 18+** (already installed) 2. **Azure CLI** - Install from https://docs.microsoft.com/en-us/cli/azure/install-azure-cli ```bash # macOS brew install azure-cli # Verify installation az --version ``` 3. **Azure Functions Core Tools** (installed via package.json) ```bash npm install ``` 4. **Azure Account** - Create a free account at https://azure.microsoft.com/free/ ## Azure Setup ### 1. Login to Azure ```bash az login ``` This will open a browser window for authentication. ### 2. Create Resource Group ```bash az group create \ --name mcp-server-rg \ --location eastus ``` ### 3. Create Storage Account Azure Functions requires a storage account: ```bash az storage account create \ --name mcpserverstorage \ --location eastus \ --resource-group mcp-server-rg \ --sku Standard_LRS ``` ### 4. Create Function App ```bash az functionapp create \ --resource-group mcp-server-rg \ --consumption-plan-location eastus \ --runtime node \ --runtime-version 18 \ --functions-version 4 \ --name mcp-server \ --storage-account mcpserverstorage ``` **Note**: The function app name must be globally unique. Choose a different name if `mcp-server` is taken. ## Deployment ### Option 1: Deploy via Azure Functions Core Tools ```bash # Build the TypeScript code npm run build:azure # Deploy to Azure func azure functionapp publish mcp-server ``` Replace `mcp-server` with your actual function app name. ### Option 2: Deploy via npm script ```bash npm run deploy:azure ``` **Note**: You must update the function app name in `package.json` under the `deploy:azure` script. ### Option 3: Deploy via VS Code 1. Install the **Azure Functions** extension for VS Code 2. Sign in to Azure 3. Right-click on your function app 4. Select "Deploy to Function App..." 5. Choose your function app ## Local Testing Test the Azure Functions handler locally: ```bash npm run start:azure ``` The function will be available at: - http://localhost:7071/ Test the endpoints: ```bash # Health check curl http://localhost:7071/health # Server info curl http://localhost:7071/ # MCP endpoint curl -X POST http://localhost:7071/mcp \ -H "Content-Type: application/json" \ -d '{"jsonrpc":"2.0","id":1,"method":"tools/list","params":{}}' ``` ## Configuration ### Environment Variables Set environment variables in Azure: ```bash az functionapp config appsettings set \ --name mcp-server \ --resource-group mcp-server-rg \ --settings "SETTING_NAME=value" ``` ### Application Insights Enable monitoring (recommended): ```bash az monitor app-insights component create \ --app mcp-server-insights \ --location eastus \ --resource-group mcp-server-rg # Get instrumentation key INSTRUMENTATION_KEY=$(az monitor app-insights component show \ --app mcp-server-insights \ --resource-group mcp-server-rg \ --query instrumentationKey -o tsv) # Configure function app to use it az functionapp config appsettings set \ --name mcp-server \ --resource-group mcp-server-rg \ --settings "APPINSIGHTS_INSTRUMENTATIONKEY=$INSTRUMENTATION_KEY" ``` ## Endpoints After deployment, your MCP server will be available at: ``` https://<function-app-name>.azurewebsites.net/ ``` Available endpoints: - `GET /` - Server information - `GET /health` - Health check - `POST /mcp` - MCP protocol endpoint - `OPTIONS /*` - CORS preflight ## Monitoring ### View Logs ```bash az functionapp log tail \ --name mcp-server \ --resource-group mcp-server-rg ``` ### View in Portal 1. Go to https://portal.azure.com 2. Navigate to your Function App 3. Select "Functions" → your function 4. Click "Monitor" to view logs and metrics ### Application Insights If configured, view detailed telemetry at: 1. Azure Portal → Application Insights → mcp-server-insights 2. View metrics, logs, and performance data ## Scaling Azure Functions automatically scales based on demand. Configure scaling limits: ```bash az functionapp plan update \ --name ASP-mcpserverrg \ --resource-group mcp-server-rg \ --max-burst 10 ``` ## Security ### Enable Authentication ```bash az functionapp auth update \ --name mcp-server \ --resource-group mcp-server-rg \ --enabled true \ --action LoginWithAzureActiveDirectory ``` ### Function Keys Azure Functions supports function-level keys for authentication: 1. Get the function key: ```bash az functionapp function keys list \ --name mcp-server \ --resource-group mcp-server-rg \ --function-name httpTrigger ``` 2. Use in requests: ```bash curl https://mcp-server.azurewebsites.net/api/mcp?code=<function-key> ``` ## Custom Domain ### Add Custom Domain ```bash az functionapp config hostname add \ --webapp-name mcp-server \ --resource-group mcp-server-rg \ --hostname mcp.yourdomain.com ``` ### Enable HTTPS Azure Functions automatically provides HTTPS. For custom domains: ```bash az functionapp config ssl bind \ --name mcp-server \ --resource-group mcp-server-rg \ --certificate-thumbprint <thumbprint> \ --ssl-type SNI ``` ## Troubleshooting ### Check Deployment Status ```bash az functionapp deployment list-publishing-profiles \ --name mcp-server \ --resource-group mcp-server-rg ``` ### View Application Settings ```bash az functionapp config appsettings list \ --name mcp-server \ --resource-group mcp-server-rg ``` ### Restart Function App ```bash az functionapp restart \ --name mcp-server \ --resource-group mcp-server-rg ``` ### Common Issues 1. **Deployment fails**: Ensure you have the latest Azure Functions Core Tools ```bash npm install -g azure-functions-core-tools@4 ``` 2. **Function not responding**: Check logs and verify the function app is running ```bash az functionapp show \ --name mcp-server \ --resource-group mcp-server-rg \ --query state ``` 3. **Module not found errors**: Ensure all dependencies are in `dependencies`, not `devDependencies` ## Cost Optimization ### Consumption Plan (Recommended for Development) The default Consumption plan charges per execution: - 1M free requests/month - 400,000 GB-s free compute/month - After that: $0.20 per million executions ### Premium Plan (Recommended for Production) For better performance and always-on availability: ```bash az functionapp plan create \ --name mcp-server-premium \ --resource-group mcp-server-rg \ --location eastus \ --sku EP1 ``` ## Cleanup To delete all Azure resources: ```bash # Delete the entire resource group az group delete \ --name mcp-server-rg \ --yes --no-wait ``` ## Comparison: Azure vs Cloudflare | Feature | Azure Functions | Cloudflare Workers | |---------|----------------|-------------------| | Cold Start | 1-3 seconds | < 100ms | | Global Distribution | Available | Automatic (200+ locations) | | Free Tier | 1M requests/month | 100K requests/day | | Pricing | Pay per execution | $5/month for 10M+ | | Custom Domains | Yes (extra config) | Yes (included) | | WebSocket Support | Yes | Yes | | Max Execution Time | 5 min (Consumption) | 30 sec (free), 15 min (paid) | ## Next Steps 1. ✅ Deploy to Azure Functions 2. ✅ Set up monitoring with Application Insights 3. ✅ Configure custom domain 4. ✅ Enable authentication if needed 5. ✅ Set up CI/CD pipeline (see Azure DevOps or GitHub Actions) ## References - [Azure Functions Documentation](https://docs.microsoft.com/en-us/azure/azure-functions/) - [Azure CLI Documentation](https://docs.microsoft.com/en-us/cli/azure/) - [Azure Functions Core Tools](https://github.com/Azure/azure-functions-core-tools) - [Azure Pricing Calculator](https://azure.microsoft.com/en-us/pricing/calculator/)

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/TedTschopp/MCP-Server-on-CloudFlare'

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