"""
Example Lambda Function: Weather Lookup Tool
This Lambda function can be wrapped as an MCP tool via the gateway
"""
import json
import logging
logger = logging.getLogger()
logger.setLevel(logging.INFO)
def lambda_handler(event, context):
"""
Weather lookup Lambda function
Expected input:
{
"location": "New York, NY",
"units": "celsius" # optional
}
Returns:
{
"location": "New York, NY",
"temperature": 22,
"units": "celsius",
"condition": "Partly Cloudy",
"humidity": 65
}
"""
try:
# Parse input
if isinstance(event, str):
event = json.loads(event)
location = event.get('location', 'Unknown')
units = event.get('units', 'celsius')
logger.info(f"Weather lookup requested for: {location}")
# Mock weather data (in production, call actual weather API)
weather_data = {
"location": location,
"temperature": 22 if units == "celsius" else 72,
"units": units,
"condition": "Partly Cloudy",
"humidity": 65,
"wind_speed": 15,
"description": f"Weather in {location}: Partly cloudy, {22 if units == 'celsius' else 72}°"
}
return {
'statusCode': 200,
'body': json.dumps(weather_data)
}
except Exception as e:
logger.error(f"Error in weather lookup: {e}")
return {
'statusCode': 500,
'body': json.dumps({
'error': str(e)
})
}