from golf.utilities import get_current_context, sample, elicit
from golf.auth import get_auth_token
async def production_ready_tool(task: str):
try:
# Verify context availability
context = get_current_context()
# Check authentication
auth_token = get_auth_token()
if not auth_token:
confirmation = await elicit_confirmation(
"No authentication found. Continue with limited functionality?"
)
if not confirmation:
return {"error": "Authentication required"}
# Perform main task
result = await sample(f"Complete this task: {task}")
# Log success
context.logger.info(f"Task completed: {task}")
return {
"task": task,
"result": result,
"authenticated": bool(auth_token)
}
except ImportError:
return {
"error": "FastMCP >=2.11.0 required",
"task": task
}
except RuntimeError as e:
if "Context" in str(e):
return {
"error": "Must be called from MCP tool context",
"task": task
}
elif "declined" in str(e):
return {
"error": "User declined operation",
"task": task
}
else:
return {
"error": f"Operation failed: {str(e)}",
"task": task
}