Skip to main content
Glama

create_file

Add a new file to a QuantConnect project by specifying project ID, filename, and content for algorithmic trading strategy development.

Instructions

Create a new file in a QuantConnect project.

Args: project_id: ID of the project to add the file to name: Name of the file (e.g., "main.py", "algorithm.cs") content: Content of the file

Returns: Dictionary containing file creation result

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
project_idYes
nameYes
contentYes

Implementation Reference

  • The core handler function for the 'create_file' tool. It authenticates with QuantConnect, sends a POST request to the 'files/create' endpoint with project_id, name, and content, and returns a status dictionary based on the response.
    @mcp.tool()
    async def create_file(project_id: int, name: str, content: str) -> Dict[str, Any]:
        """
        Create a new file in a QuantConnect project.
    
        Args:
            project_id: ID of the project to add the file to
            name: Name of the file (e.g., "main.py", "algorithm.cs")
            content: Content of the file
    
        Returns:
            Dictionary containing file 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, "name": name, "content": content}
    
            # Make API request
            response = await auth.make_authenticated_request(
                endpoint="files/create", 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,
                        "file_name": name,
                        "content_length": len(content),
                        "message": f"Successfully created file '{name}' in project {project_id}",
                    }
                else:
                    # API returned success=false
                    errors = data.get("errors", ["Unknown error"])
                    return {
                        "status": "error",
                        "error": "File creation failed",
                        "details": errors,
                        "project_id": project_id,
                        "file_name": name,
                    }
    
            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 file: {str(e)}",
                "project_id": project_id,
                "file_name": name,
            }
  • Top-level registration call in the main entry point that invokes register_file_tools to add the create_file tool (among others) to the MCP server.
    register_file_tools(mcp)
  • Registration call in the server module's main function, which registers the file tools including create_file.
    register_file_tools(mcp)

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