update_backtest
Modify a backtest's name or notes to organize and document trading strategy results in the QuantConnect platform.
Instructions
Update a backtest's name or note.
Args: project_id: ID of the project containing the backtest backtest_id: ID of the backtest to update name: Optional new name for the backtest note: Optional new note for the backtest
Returns: Dictionary containing update result
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| project_id | Yes | ||
| backtest_id | Yes | ||
| name | No | ||
| note | No |
Implementation Reference
- The core handler function for the 'update_backtest' tool. It authenticates, validates input, makes an authenticated POST request to QuantConnect's 'backtests/update' endpoint, and handles the response with detailed success/error messages.@mcp.tool() async def update_backtest( project_id: int, backtest_id: str, name: Optional[str] = None, note: Optional[str] = None ) -> Dict[str, Any]: """ Update a backtest's name or note. Args: project_id: ID of the project containing the backtest backtest_id: ID of the backtest to update name: Optional new name for the backtest note: Optional new note for the backtest Returns: Dictionary containing update result """ auth = get_auth_instance() if auth is None: return { "status": "error", "error": "QuantConnect authentication not configured. Use configure_auth() first.", } # Validate at least one field is provided if name is None and note is None: return { "status": "error", "error": "At least one of 'name' or 'note' must be provided for update", } try: # Prepare request data request_data: Dict[str, Any] = { "projectId": project_id, "backtestId": backtest_id } if name is not None: request_data["name"] = name if note is not None: request_data["note"] = note # Make API request response = await auth.make_authenticated_request( endpoint="backtests/update", method="POST", json=request_data ) # Parse response if response.status_code == 200: data = response.json() if data.get("success", False): update_fields = [] if name is not None: update_fields.append(f"name to '{name}'") if note is not None: update_fields.append("note") return { "status": "success", "project_id": project_id, "backtest_id": backtest_id, "updated_fields": update_fields, "message": f"Successfully updated backtest {backtest_id}: {', '.join(update_fields)}", } else: # API returned success=false errors = data.get("errors", ["Unknown error"]) return { "status": "error", "error": "Backtest update 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 update backtest: {str(e)}", "project_id": project_id, "backtest_id": backtest_id, }
- quantconnect_mcp/main.py:47-52 (registration)Registration block in the main entrypoint where register_backtest_tools(mcp) is called at line 50, which in turn defines and registers the update_backtest handler using @mcp.tool().register_auth_tools(mcp) register_project_tools(mcp) register_file_tools(mcp) register_backtest_tools(mcp) register_live_tools(mcp) register_optimization_tools(mcp)
- quantconnect_mcp/src/tools/backtest_tools.py:8-10 (registration)The registration function that contains the definition of all backtest tools, including the nested update_backtest function decorated with @mcp.tool() for automatic registration.def register_backtest_tools(mcp: FastMCP): """Register backtest management tools with the MCP server."""