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
| Name | Required | Description | Default |
|---|---|---|---|
| project_id | Yes | ||
| name | Yes | ||
| content | Yes |
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, }
- quantconnect_mcp/main.py:46-52 (registration)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)
- quantconnect_mcp/src/server.py:73-79 (registration)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)
- quantconnect_mcp/src/tools/file_tools.py:8-8 (registration)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):