Enable Request Payload Logging in ContextForge
This guide shows how to enable request payload logging to debug and validate tool registration requests and other API calls.
Quick Setup
To enable request payload logging, set these environment variables:
# Enable request logging
LOG_REQUESTS=true
# Set log level to INFO or DEBUG to see request payloads
LOG_LEVEL=INFO
# Optional: Enable file logging to persist logs
LOG_TO_FILE=true
LOG_FILE=mcpgateway.log
LOG_FOLDER=logs
LOG_FILEMODE=a+
Configuration Options
Required Settings
LOG_REQUESTS=true- Enables the request logging middlewareLOG_LEVEL=INFO- Ensures request logs are visible (INFO or DEBUG)
Optional Settings
LOG_TO_FILE=true- Saves logs to file (default: console only)LOG_FILE=mcpgateway.log- Log file nameLOG_FOLDER=logs- Log folder pathLOG_FILEMODE=a+- File mode (append)LOG_MAX_SIZE_MB=1- Maximum request body size to log (in MB)
Example .env Configuration
# Request Logging
LOG_REQUESTS=true
LOG_LEVEL=INFO
# File Logging (optional)
LOG_TO_FILE=true
LOG_FILE=mcpgateway.log
LOG_FOLDER=logs
LOG_FILEMODE=a+
LOG_MAX_SIZE_MB=4
# Other settings
MCPGATEWAY_UI_ENABLED=true
MCPGATEWAY_ADMIN_API_ENABLED=true
PLATFORM_ADMIN_EMAIL=admin@example.com
PLATFORM_ADMIN_PASSWORD=changeme
PLATFORM_ADMIN_FULL_NAME="Platform Administrator"
What Gets Logged
When enabled, you'll see detailed request information including:
- HTTP method and path
- Query parameters
- Request headers (with sensitive data masked)
- Request body/payload (with sensitive fields masked)
- Truncation notice if body exceeds size limit
Example Log Output
📩 Incoming request: POST /tools
Query params: {}
Headers: {'host': 'localhost:4444', 'content-type': 'application/json', 'authorization': '******'}
Body: {
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"name": "get_system_time",
"arguments": {
"timezone": "Europe/Dublin"
}
},
"id": 1758624387514
}
Security Features
The logging middleware automatically masks sensitive information:
- Headers: Authorization, authentication tokens
- Body fields: password, secret, token, apikey, access_token, refresh_token, client_secret
- Large payloads: Truncated with notice if they exceed the size limit
Troubleshooting
No Request Logs Appearing
- Check that
LOG_REQUESTS=trueis set - Verify
LOG_LEVELis set toINFOorDEBUG - Restart the gateway after changing configuration
Logs Not Saved to File
- Ensure
LOG_TO_FILE=trueis set - Check that the log folder exists and is writable
- Verify
LOG_FILEandLOG_FOLDERpaths are correct
Request Bodies Truncated
- Increase
LOG_MAX_SIZE_MBif you need to see larger payloads - Default is 1MB to prevent log files from becoming too large
Performance Considerations
- Request logging adds minimal overhead
- Large request bodies are automatically truncated
- Sensitive data is masked, not removed, so original functionality is preserved
- Logging is skipped entirely if
LOG_REQUESTS=false
Example Usage
Set environment variables:
export LOG_REQUESTS=true export LOG_LEVEL=INFO export LOG_TO_FILE=true export LOG_FOLDER=logsStart the gateway:
mcpgateway --host 0.0.0.0 --port 4444Make a request and check the logs:
# Check console output or log file tail -f logs/mcpgateway.log
Now you can see the full request payloads (with sensitive data masked) to debug tool registration and other API issues.