read_file
Access specific or all files within a project by providing the project ID. Returns file content(s) or error details for analysis on the QuantConnect MCP Server.
Instructions
Read a specific file from a project or all files if no name provided.
Args: project_id: ID of the project to read files from name: Optional name of specific file to read. If not provided, reads all files.
Returns: Dictionary containing file content(s) or error information
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | No | ||
| project_id | Yes |
Implementation Reference
- The handler function for the 'read_file' MCP tool. It handles reading a specific file or all files from a QuantConnect project by making authenticated API calls to the QuantConnect endpoint 'files/read'. Includes error handling for auth, API failures, etc.@mcp.tool() async def read_file(project_id: int, name: Optional[str] = None) -> Dict[str, Any]: """ Read a specific file from a project or all files if no name provided. Args: project_id: ID of the project to read files from name: Optional name of specific file to read. If not provided, reads all files. Returns: Dictionary containing file content(s) or error information """ 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: Dict[str, Any] = {"projectId": project_id} if name is not None: request_data["name"] = name # Make API request response = await auth.make_authenticated_request( endpoint="files/read", method="POST", json=request_data ) # Parse response if response.status_code == 200: data = response.json() if data.get("success", False): files = data.get("files", []) # If specific file was requested if name is not None: if files: file_data = files[0] return { "status": "success", "project_id": project_id, "file": file_data, "message": f"Successfully read file '{name}' from project {project_id}", } else: return { "status": "error", "error": f"File '{name}' not found in project {project_id}", } # If all files were requested else: return { "status": "success", "project_id": project_id, "files": files, "total_files": len(files), "message": f"Successfully read {len(files)} files from project {project_id}", } else: # API returned success=false errors = data.get("errors", ["Unknown error"]) return { "status": "error", "error": "File read 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 read file(s): {str(e)}", "project_id": project_id, "file_name": name, }
- quantconnect_mcp/main.py:46-52 (registration)Registration of the file_tools module (containing read_file) by calling register_file_tools(mcp) in the main entry point.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)Alternative registration of the file_tools module in the server module, called via register_file_tools(mcp).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)
- Import of register_file_tools from file_tools.py in the tools package __init__.from .file_tools import register_file_tools