delete_backtest
Remove a specific backtest from a QuantConnect project by providing the project ID and backtest ID to manage testing data and optimize storage.
Instructions
Delete a backtest from a project.
Args: project_id: ID of the project containing the backtest backtest_id: ID of the backtest to delete
Returns: Dictionary containing deletion result
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| project_id | Yes | ||
| backtest_id | Yes |
Implementation Reference
- The core handler function implementing the 'delete_backtest' tool. It uses @mcp.tool() decorator for registration, authenticates with QuantConnect, sends a POST request to the 'backtests/delete' endpoint with project_id and backtest_id, parses the response, and returns a standardized success or error dictionary.@mcp.tool() async def delete_backtest(project_id: int, backtest_id: str) -> Dict[str, Any]: """ Delete a backtest from a project. Args: project_id: ID of the project containing the backtest backtest_id: ID of the backtest to delete Returns: Dictionary containing deletion result """ auth = get_auth_instance() if auth is None: return { "status": "error", "error": "QuantConnect authentication not configured. Use configure_auth() first.", } try: # Prepare request data request_data = {"projectId": project_id, "backtestId": backtest_id} # Make API request response = await auth.make_authenticated_request( endpoint="backtests/delete", method="POST", json=request_data ) # Parse response if response.status_code == 200: data = response.json() if data.get("success", False): return { "status": "success", "project_id": project_id, "backtest_id": backtest_id, "message": f"Successfully deleted backtest {backtest_id} from project {project_id}", } else: # API returned success=false errors = data.get("errors", ["Unknown error"]) return { "status": "error", "error": "Backtest deletion failed", "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 delete backtest: {str(e)}", "project_id": project_id, "backtest_id": backtest_id, }