Skip to main content
Glama

create_optimization

Configure and launch optimization runs for algorithmic trading strategies by specifying parameters like node type, runtime limits, and performance targets.

Instructions

Create an optimization with the specified parameters.

Args: project_id: ID of the project to optimize compile_id: Compile ID from successful project compilation node_type: Type of node to use for optimization parameters: Dictionary of optimization parameters name: Optional name for the optimization maximum_runtime: Optional maximum runtime in seconds output_target: Optional optimization target (e.g., "Sharpe Ratio")

Returns: Dictionary containing optimization creation result

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
project_idYes
compile_idYes
node_typeYes
parametersYes
nameNo
maximum_runtimeNo
output_targetNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The core handler function for the 'create_optimization' MCP tool. It handles authentication, prepares the request data with project details and parameters, makes a POST request to the QuantConnect 'optimizations/create' endpoint, and parses the response to return success or error details including the new optimization ID.
    @mcp.tool()
    async def create_optimization(
        project_id: int,
        compile_id: str,
        node_type: str,
        parameters: Dict[str, Any],
        name: Optional[str] = None,
        maximum_runtime: Optional[int] = None,
        output_target: Optional[str] = None,
    ) -> Dict[str, Any]:
        """
        Create an optimization with the specified parameters.
    
        Args:
            project_id: ID of the project to optimize
            compile_id: Compile ID from successful project compilation
            node_type: Type of node to use for optimization
            parameters: Dictionary of optimization parameters
            name: Optional name for the optimization
            maximum_runtime: Optional maximum runtime in seconds
            output_target: Optional optimization target (e.g., "Sharpe Ratio")
    
        Returns:
            Dictionary containing optimization creation 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,
                "compileId": compile_id,
                "nodeType": node_type,
                "parameters": parameters,
            }
    
            # Add optional parameters
            if name is not None:
                request_data["name"] = name
            if maximum_runtime is not None:
                request_data["maximumRuntime"] = maximum_runtime
            if output_target is not None:
                request_data["outputTarget"] = output_target
    
            # Make API request
            response = await auth.make_authenticated_request(
                endpoint="optimizations/create", method="POST", json=request_data
            )
    
            # Parse response
            if response.status_code == 200:
                data = response.json()
    
                if data.get("success", False):
                    optimization = data.get("optimization", {})
                    optimization_id = optimization.get("optimizationId")
                    
                    return {
                        "status": "success",
                        "project_id": project_id,
                        "compile_id": compile_id,
                        "optimization_id": optimization_id,
                        "optimization": optimization,
                        "message": f"Successfully created optimization {optimization_id} for project {project_id}",
                    }
                else:
                    # API returned success=false
                    errors = data.get("errors", ["Unknown error"])
                    return {
                        "status": "error",
                        "error": "Optimization creation failed",
                        "details": 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"Failed to create optimization: {str(e)}",
                "project_id": project_id,
                "compile_id": compile_id,
            }
  • Calls register_optimization_tools(mcp) as part of initializing the FastMCP server, which registers the create_optimization tool along with other optimization tools.
    safe_print("🔧 Registering QuantConnect tools...")
    register_auth_tools(mcp)
    register_project_tools(mcp)
    register_file_tools(mcp)
    register_backtest_tools(mcp)
    register_live_tools(mcp)
    register_optimization_tools(mcp)
Behavior2/5

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

With no annotations provided, the description carries full burden but offers minimal behavioral context. It states this creates something but doesn't disclose permissions needed, whether this is an asynchronous/long-running operation, rate limits, or what happens if optimization fails. The 'Returns' section mentions a dictionary result but gives no details about success/error responses.

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 (Args, Returns) and reasonably concise. However, the parameter explanations could be more efficient - some are overly brief ('ID of the project to optimize') while others could benefit from examples or constraints.

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 7 parameters with 0% schema coverage, no annotations, but with an output schema present, the description is moderately complete. It covers all parameters at a basic level and acknowledges the return type, but doesn't provide enough context about optimization behavior, dependencies, or error conditions for a complex creation tool.

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

Parameters3/5

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

With 0% schema description coverage, the description partially compensates by listing all 7 parameters with brief explanations. However, it doesn't provide crucial semantic details: what valid node_type values are, what parameters dictionary should contain, format of compile_id, or examples of output_target values like 'Sharpe Ratio'. The explanations are too basic for such complex parameters.

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 tool creates an optimization with specified parameters, providing a specific verb ('create') and resource ('optimization'). It distinguishes from siblings like 'create_backtest' or 'create_project' by focusing on optimization, but doesn't explicitly differentiate from 'update_optimization' or 'estimate_optimization_time'.

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?

No guidance is provided about when to use this tool versus alternatives. The description doesn't mention prerequisites (like needing a compiled project), when to choose optimization over backtesting, or relationships with sibling tools like 'compile_project' (which provides compile_id) or 'list_optimizations'.

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