read_backtest_insights
Extract and analyze insights from a backtest by specifying project and backtest IDs, with customizable index ranges for targeted data retrieval.
Instructions
Read insights from a backtest.
Args: project_id: ID of the project containing the backtest backtest_id: ID of the backtest to read insights from start: Starting index of insights to fetch (default: 0) end: Last index of insights to fetch (default: 100, max range: 100)
Returns: Dictionary containing insights data and total count
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| backtest_id | Yes | ||
| end | No | ||
| project_id | Yes | ||
| start | No |
Implementation Reference
- The core handler function that implements the 'read_backtest_insights' tool logic. It validates input parameters, authenticates with QuantConnect API, makes a POST request to 'backtests/read/insights' endpoint, parses the response, and returns insights data or error details.@mcp.tool() async def read_backtest_insights( project_id: int, backtest_id: str, start: int = 0, end: int = 100 ) -> Dict[str, Any]: """ Read insights from a backtest. Args: project_id: ID of the project containing the backtest backtest_id: ID of the backtest to read insights from start: Starting index of insights to fetch (default: 0) end: Last index of insights to fetch (default: 100, max range: 100) Returns: Dictionary containing insights data and total count """ auth = get_auth_instance() if auth is None: return { "status": "error", "error": "QuantConnect authentication not configured. Use configure_auth() first.", } # Validate range if end - start > 100: return { "status": "error", "error": "Range too large: end - start must be less than or equal to 100", } if start < 0 or end < 0: return { "status": "error", "error": "Start and end indices must be non-negative", } if start >= end: return { "status": "error", "error": "Start index must be less than end index", } try: # Prepare request data request_data = { "projectId": project_id, "backtestId": backtest_id, "start": start, "end": end, } # Make API request response = await auth.make_authenticated_request( endpoint="backtests/read/insights", method="POST", json=request_data ) # Parse response if response.status_code == 200: data = response.json() if data.get("success", False): insights = data.get("insights", []) length = data.get("length", 0) return { "status": "success", "project_id": project_id, "backtest_id": backtest_id, "start": start, "end": end, "insights": insights, "length": length, "message": f"Successfully retrieved {length} insights from backtest {backtest_id} (range: {start}-{end})", } else: # API returned success=false errors = data.get("errors", ["Unknown error"]) return { "status": "error", "error": "Failed to read backtest insights", "details": errors, "project_id": project_id, "backtest_id": backtest_id, } elif response.status_code == 401: return { "status": "error", "error": "Authentication failed. Check your credentials and ensure they haven't expired.", } else: return { "status": "error", "error": f"API request failed with status {response.status_code}", "response_text": ( response.text[:500] if hasattr(response, "text") else "No response text" ), } except Exception as e: return { "status": "error", "error": f"Failed to read backtest insights: {str(e)}", "project_id": project_id, "backtest_id": backtest_id, "start": start, "end": end, }
- quantconnect_mcp/src/server.py:77-77 (registration)Registers the backtest tools module (including read_backtest_insights) with the MCP server instance by calling register_backtest_tools(mcp). This is part of the server initialization in main().register_backtest_tools(mcp)