Production-Ready Settings
Production-Ready Settings
This guide outlines the essential configuration and deployment settings required to run the MCP Weather Server in production environments.
Configuration Management
Environment Variables
The application supports flexible configuration through environment variables and appsettings.json:
# Weather service configuration
WEATHER_CHOICES="sunny,cloudy,rainy,stormy,snowy,windy,foggy"
# Logging configuration
ASPNETCORE_ENVIRONMENT=Production
Logging__LogLevel__Default=Information
Logging__LogLevel__Microsoft=Warning
Application Settings
Create an appsettings.Production.json for production-specific settings:
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
},
"Console": {
"LogToStandardErrorThreshold": "Error"
}
},
"WeatherChoices": "sunny,partly-cloudy,cloudy,overcast,light-rain,heavy-rain,thunderstorm,snow,fog,windy",
"RandomNumber": {
"DefaultMin": 0,
"DefaultMax": 100
}
}
Docker Configuration
Multi-Stage Dockerfile
# Build stage
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /src
COPY ["SampleMcpServer.csproj", "./"]
RUN dotnet restore "SampleMcpServer.csproj"
COPY . .
RUN dotnet build "SampleMcpServer.csproj" -c Release -o /app/build
# Test stage
FROM build AS test
RUN dotnet test --no-build --verbosity normal --collect:"XPlat Code Coverage"
# Publish stage
FROM build AS publish
RUN dotnet publish "SampleMcpServer.csproj" -c Release -o /app/publish /p:UseAppHost=false
# Runtime stage
FROM mcr.microsoft.com/dotnet/aspnet:8.0-alpine AS final
WORKDIR /app
COPY --from=publish /app/publish .
# Create non-root user
RUN adduser -D -s /bin/sh appuser
USER appuser
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD dotnet SampleMcpServer.dll --health-check || exit 1
ENTRYPOINT ["dotnet", "SampleMcpServer.dll"]
Docker Compose for Production
version: '3.8'
services:
mcp-server:
build:
context: .
dockerfile: Dockerfile
target: final
image: mcp-server:latest
container_name: mcp-server-prod
restart: unless-stopped
environment:
- ASPNETCORE_ENVIRONMENT=Production
- WEATHER_CHOICES=sunny,cloudy,rainy,stormy,snowy,windy,foggy,clear,overcast
- Logging__LogLevel__Default=Information
volumes:
- ./logs:/app/logs:rw
networks:
- mcp-network
deploy:
resources:
limits:
cpus: '0.5'
memory: 256M
reservations:
cpus: '0.25'
memory: 128M
networks:
mcp-network:
driver: bridge
Security Considerations
Application Security
Input Validation