analyze_data_tool
Analyze Strava activity data by executing custom Python code to calculate metrics, summarize workouts, and extract insights from athlete statistics.
Instructions
Execute Python code to analyze Strava data safely using Monty.
Args: code: Python code to execute. The data is available as a variable named 'data'. Example: "sum(activity['distance'] for activity in data) / 1000" data: The data to analyze (e.g. list of activities, athlete stats). Can be passed as a JSON object (list/dict) or a JSON string.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | ||
| data | Yes |
Implementation Reference
- strava_mcp/services/analysis.py:5-29 (helper)Core implementation using pydantic_monty to safely execute Python code. Injects data as a variable and returns the execution result with error handling.
def analyze_data(code: str, data: Any) -> Any: """ Executes Python code safely using Monty, passing 'data' as a variable. Args: code: The Python code snippet to execute. data: The data structure (dict, list, etc.) to inject as the 'data' variable. """ # Always inject data as 'data' variable inputs = {"data": data} input_names = ["data"] try: # Initialize Monty with the code and expected input variables # Using strict limits by default for safety m = pydantic_monty.Monty(code, inputs=input_names) # Execute the code result = m.run(inputs=inputs) return result except Exception as e: # Raise a clear error message that the MCP client can display raise RuntimeError(f"Analysis failed: {str(e)}") from e