Skip to main content
Glama

update_file_content

Modify file content in QuantConnect projects to update trading strategies, algorithms, or research documents.

Instructions

Update the content of a file in a QuantConnect project.

Args: project_id: ID of the project containing the file name: Name of the file to update content: New content for the file

Returns: Dictionary containing update result

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
project_idYes
nameYes
contentYes

Implementation Reference

  • The core handler function for the 'update_file_content' tool, decorated with @mcp.tool() and implementing the logic to update file content in a QuantConnect project via authenticated API request.
    @mcp.tool()
    async def update_file_content(
        project_id: int, name: str, content: str
    ) -> Dict[str, Any]:
        """
        Update the content of a file in a QuantConnect project.
    
        Args:
            project_id: ID of the project containing the file
            name: Name of the file to update
            content: New content for the file
    
        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.",
            }
    
        try:
            # Prepare request data
            request_data = {"projectId": project_id, "name": name, "content": content}
    
            # Make API request
            response = await auth.make_authenticated_request(
                endpoint="files/update", 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 updated content of file '{name}' in project {project_id}",
                    }
                else:
                    # API returned success=false
                    errors = data.get("errors", ["Unknown error"])
                    return {
                        "status": "error",
                        "error": "File content update 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 update file content: {str(e)}",
                "project_id": project_id,
                "file_name": name,
            }
  • Entry point registration block calling register_file_tools(mcp), which registers the update_file_content tool among file 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)
  • Server core registration block calling register_file_tools(mcp) to register the file tools including update_file_content.
    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)
  • The register_file_tools function definition, which contains the @mcp.tool() decorators for all file tools including update_file_content.
    def register_file_tools(mcp: FastMCP):

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