create_file
Transfer local files to OneDrive using specified paths and account details. Simplify file management through integration with Microsoft Graph API.
Instructions
Upload a local file to OneDrive
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| account_id | Yes | ||
| local_file_path | Yes | ||
| onedrive_path | Yes |
Implementation Reference
- src/microsoft_mcp/tools.py:778-790 (handler)The main handler function for the 'create_file' tool. It reads the content of a local file and uploads it to the specified OneDrive path using the Microsoft Graph API via the graph.upload_large_file helper.@mcp.tool def create_file( onedrive_path: str, local_file_path: str, account_id: str ) -> dict[str, Any]: """Upload a local file to OneDrive""" path = pl.Path(local_file_path).expanduser().resolve() data = path.read_bytes() result = graph.upload_large_file( f"/me/drive/root:/{onedrive_path}:", data, account_id ) if not result: raise ValueError(f"Failed to create file at path: {onedrive_path}") return result
- src/microsoft_mcp/graph.py:214-234 (helper)Supporting helper function that performs the actual file upload to Microsoft Graph OneDrive. Handles both small files (direct PUT) and large files (via createUploadSession and chunked upload). Called directly by the create_file handler.def upload_large_file( path: str, data: bytes, account_id: str | None = None, item_properties: dict[str, Any] | None = None, ) -> dict[str, Any]: """Upload a large file using upload sessions""" file_size = len(data) if file_size <= UPLOAD_CHUNK_SIZE: result = request("PUT", f"{path}/content", account_id, data=data) if not result: raise ValueError("Failed to upload file") return result session = create_upload_session(path, account_id, item_properties) upload_url = session["uploadUrl"] headers = {"Authorization": f"Bearer {get_token(account_id)}"} return _do_chunked_upload(upload_url, data, headers)