update_file_content
Modifies file content within a QuantConnect project by specifying the project ID, file name, and updated content. Streamlines file management for strategy design and implementation.
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 |
|---|---|---|---|
| content | Yes | ||
| name | Yes | ||
| project_id | Yes |
Implementation Reference
- The core handler function for the 'update_file_content' tool, decorated with @mcp.tool(). It authenticates with QuantConnect, prepares a POST request to the 'files/update' endpoint with project_id, file name, and new content, and handles the response, returning success or error details.@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/src/server.py:76-76 (registration)Calls register_file_tools(mcp) to register all file management tools, including 'update_file_content', to the FastMCP instance.register_file_tools(mcp)
- quantconnect_mcp/main.py:49-49 (registration)Alternative entry point that calls register_file_tools(mcp) to register the file tools including 'update_file_content'.register_file_tools(mcp)