Skip to main content
Glama

compile_project

Compile QuantConnect trading algorithms to validate code and prepare for backtesting or live deployment.

Instructions

Compile a project in QuantConnect.

Args: project_id: The ID of the project to compile.

Returns: A dictionary containing the compilation result with compile ID, state, and logs.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
project_idYes

Implementation Reference

  • Core handler for the 'compile_project' tool. Authenticates, sends POST to QuantConnect 'compile/create' API with projectId, parses response to return compileId, state, logs, or error details.
    @mcp.tool()
    async def compile_project(project_id: int) -> Dict[str, Any]:
        """
        Compile a project in QuantConnect.
    
        Args:
            project_id: The ID of the project to compile.
    
        Returns:
            A dictionary containing the compilation result with compile ID, state, and logs.
        """
        auth = get_auth_instance()
        if auth is None:
            return {
                "status": "error",
                "error": "QuantConnect authentication not configured. Use configure_auth() first.",
            }
    
        try:
            # Prepare request data with project ID in JSON payload
            request_data = {"projectId": project_id}
            
            response = await auth.make_authenticated_request(
                endpoint="compile/create", method="POST", json=request_data
            )
    
            if response.status_code == 200:
                data = response.json()
                if data.get("success"):
                    return {
                        "status": "success",
                        "compile_id": data.get("compileId"),
                        "state": data.get("state"),
                        "project_id": data.get("projectId"),
                        "signature": data.get("signature"),
                        "signature_order": data.get("signatureOrder", []),
                        "logs": data.get("logs", []),
                        "message": "Project compilation started successfully.",
                    }
                else:
                    return {
                        "status": "error",
                        "error": "Project compilation failed.",
                        "details": data.get("errors", []),
                        "project_id": project_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"An unexpected error occurred: {e}",
                "project_id": project_id,
            }
  • Docstring schema defining input 'project_id: int' and output Dict[str, Any] with compile_id, state, project_id, signature, logs, etc.
    """
    Compile a project in QuantConnect.
    
    Args:
        project_id: The ID of the project to compile.
    
    Returns:
        A dictionary containing the compilation result with compile ID, state, and logs.
    """
  • Registration function that defines and registers all project tools, including compile_project, using @mcp.tool() decorators when called.
    def register_project_tools(mcp: FastMCP):
        """Register project management tools with the MCP server."""
  • Explicit call to register_project_tools(mcp) during MCP server initialization in the main entry point.
    register_project_tools(mcp)
  • Helper tool that consumes the compile_id output from compile_project to fetch and analyze compilation results, detecting errors and warnings.
    @mcp.tool()
    async def read_compilation_result(project_id: int, compile_id: str) -> Dict[str, Any]:
        """
        Read the result of a compilation job in QuantConnect.
    
        Args:
            project_id: The ID of the project that was compiled.
            compile_id: The compile ID returned from compile_project.
    
        Returns:
            A dictionary containing the compilation result with state, logs, and errors.
        """
        auth = get_auth_instance()
        if auth is None:
            return {
                "status": "error",
                "error": "QuantConnect authentication not configured. Use configure_auth() first.",
            }
    
        try:
            # Prepare request data with project ID and compile ID in JSON payload
            request_data = {"projectId": project_id, "compileId": compile_id}
            
            response = await auth.make_authenticated_request(
                endpoint="compile/read", method="POST", json=request_data
            )
    
            if response.status_code == 200:
                data = response.json()
                if data.get("success"):
                    logs = data.get("logs", [])
                    errors = data.get("errors", [])
                    state = data.get("state")
                    
                    # Check for compilation warnings in logs that indicate issues
                    warnings = []
                    for log in logs:
                        if "Warning" in log:
                            warnings.append(log)
                    
                    # If there are warnings or explicit errors, treat as compilation failure
                    if warnings or errors:
                        return {
                            "status": "error",
                            "compile_id": data.get("compileId"),
                            "state": state,
                            "project_id": data.get("projectId"),
                            "signature": data.get("signature"),
                            "signature_order": data.get("signatureOrder", []),
                            "logs": logs,
                            "errors": errors,
                            "warnings": warnings,
                            "message": f"Compilation completed with {len(warnings)} warnings and {len(errors)} errors. Code issues must be fixed before proceeding.",
                            "error": f"Compilation failed: {len(warnings)} warnings, {len(errors)} errors found",
                        }
                    
                    return {
                        "status": "success",
                        "compile_id": data.get("compileId"),
                        "state": state,
                        "project_id": data.get("projectId"),
                        "signature": data.get("signature"),
                        "signature_order": data.get("signatureOrder", []),
                        "logs": logs,
                        "errors": errors,
                        "message": f"Compilation result retrieved successfully. State: {state}",
                    }
                else:
                    return {
                        "status": "error",
                        "error": "Failed to read compilation result.",
                        "details": data.get("errors", []),
                        "project_id": project_id,
                        "compile_id": compile_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"An unexpected error occurred: {e}",
                "project_id": project_id,
                "compile_id": compile_id,
            }

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