update_file
Sync local file changes to OneDrive by updating file content using the Microsoft Graph API. Specify file ID, local file path, and account ID for seamless integration.
Instructions
Update OneDrive file content from a local file
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| account_id | Yes | ||
| file_id | Yes | ||
| local_file_path | Yes |
Implementation Reference
- src/microsoft_mcp/tools.py:793-801 (handler)The core handler function for the 'update_file' tool. It reads the local file content and uploads it to the specified OneDrive file ID using the graph helper. The @mcp.tool decorator handles registration and schema generation.@mcp.tool def update_file(file_id: str, local_file_path: str, account_id: str) -> dict[str, Any]: """Update OneDrive file content from a local file""" path = pl.Path(local_file_path).expanduser().resolve() data = path.read_bytes() result = graph.upload_large_file(f"/me/drive/items/{file_id}", data, account_id) if not result: raise ValueError(f"Failed to update file with ID: {file_id}") return result
- src/microsoft_mcp/graph.py:214-234 (helper)Supporting utility function called by the update_file handler to perform the actual large file upload to Microsoft Graph API, handling both small and large files with chunked upload sessions.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)
- src/microsoft_mcp/tools.py:8-8 (registration)Creation of the FastMCP server instance named 'microsoft-mcp'. All tools decorated with @mcp.tool, including update_file, are automatically registered to this instance upon module import.mcp = FastMCP("microsoft-mcp")