Skip to main content
Glama

read_backtest

Retrieve backtest results and statistics from QuantConnect projects to analyze trading strategy performance and review historical data.

Instructions

Read backtest results and statistics from a project.

Args: project_id: ID of the project containing the backtest backtest_id: ID of the specific backtest to read chart: Optional chart name to include chart data in response

Returns: Dictionary containing backtest results, statistics, and optional chart data

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
project_idYes
backtest_idYes
chartNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The handler function implementing the 'read_backtest' tool logic. It authenticates with QuantConnect, makes an API request to fetch backtest data, and returns formatted results or errors.
    @mcp.tool()
    async def read_backtest(
        project_id: int, backtest_id: str, chart: Optional[str] = None
    ) -> Dict[str, Any]:
        """
        Read backtest results and statistics from a project.
    
        Args:
            project_id: ID of the project containing the backtest
            backtest_id: ID of the specific backtest to read
            chart: Optional chart name to include chart data in response
    
        Returns:
            Dictionary containing backtest results, statistics, and optional chart data
        """
        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}
    
            # Add chart parameter if provided
            if chart is not None:
                request_data["chart"] = chart
    
            # Make API request
            response = await auth.make_authenticated_request(
                endpoint="backtests/read", method="POST", json=request_data
            )
    
            # Parse response
            if response.status_code == 200:
                data = response.json()
    
                if data.get("success", False):
                    backtest_results = data.get("backtest", [])
                    debugging = data.get("debugging", False)
    
                    if backtest_results:
                        backtest = backtest_results[0]
                        return {
                            "status": "success",
                            "project_id": project_id,
                            "backtest_id": backtest_id,
                            "backtest": backtest,
                            "debugging": debugging,
                            "chart_included": chart is not None,
                            "message": f"Successfully read backtest {backtest_id} from project {project_id}",
                        }
                    else:
                        return {
                            "status": "error",
                            "error": f"Backtest {backtest_id} not found in project {project_id}",
                        }
                else:
                    # API returned success=false
                    errors = data.get("errors", ["Unknown error"])
                    return {
                        "status": "error",
                        "error": "Failed to read backtest",
                        "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: {str(e)}",
                "project_id": project_id,
                "backtest_id": backtest_id,
            }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden for behavioral disclosure. It states this is a read operation and describes the return format, but doesn't mention authentication requirements, rate limits, error conditions, or whether the data is cached/live. For a tool accessing potentially sensitive backtest results, this leaves significant gaps in understanding its behavior.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured with clear sections (purpose, args, returns) and uses minimal sentences. Every sentence adds value - the first establishes purpose, the args section documents parameters, and the returns section explains output. It could be slightly more concise by integrating the args/returns into flowing prose, but the structure is effective.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool has an output schema (so return values are documented elsewhere) but no annotations, the description does an adequate job. It covers parameters well and states the basic purpose, but doesn't provide enough behavioral context for a read operation that likely requires authentication and has specific usage patterns. The existence of multiple backtest-reading sibling tools makes the lack of differentiation more problematic.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

With 0% schema description coverage, the description must fully explain parameters. It successfully documents all three parameters (project_id, backtest_id, chart) with clear explanations of what they represent and which are required. The optional nature of 'chart' and its effect on the response is well explained. The only minor gap is not specifying the format/expected values for IDs.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Read backtest results and statistics') and resource ('from a project'), making the purpose immediately understandable. However, it doesn't explicitly differentiate this tool from sibling tools like 'read_backtest_chart', 'read_backtest_insights', or 'read_backtest_orders', which appear to read specific aspects of backtests rather than comprehensive results.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives like 'read_backtest_chart' or 'list_backtests'. It mentions the optional 'chart' parameter but doesn't explain when to include it or how it relates to the dedicated chart-reading sibling tool. No context about prerequisites or typical workflows is provided.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/taylorwilsdon/quantconnect-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server