get_file
Download files from OneDrive to a specified local path by providing the file ID, account ID, and download path. Enables efficient file management through Microsoft Graph API integration.
Instructions
Download a file from OneDrive to local path
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| account_id | Yes | ||
| download_path | Yes | ||
| file_id | Yes |
Implementation Reference
- src/microsoft_mcp/tools.py:748-776 (handler)The handler function for the 'get_file' tool. It fetches file metadata from Microsoft Graph, retrieves the download URL, downloads the file using curl to the specified local path, and returns file information including path, name, size, and MIME type. The @mcp.tool decorator registers this function as an MCP tool.@mcp.tool def get_file(file_id: str, account_id: str, download_path: str) -> dict[str, Any]: """Download a file from OneDrive to local path""" import subprocess metadata = graph.request("GET", f"/me/drive/items/{file_id}", account_id) if not metadata: raise ValueError(f"File with ID {file_id} not found") download_url = metadata.get("@microsoft.graph.downloadUrl") if not download_url: raise ValueError("No download URL available for this file") try: subprocess.run( ["curl", "-L", "-o", download_path, download_url], check=True, capture_output=True, ) return { "path": download_path, "name": metadata.get("name", "unknown"), "size_mb": round(metadata.get("size", 0) / (1024 * 1024), 2), "mime_type": metadata.get("file", {}).get("mimeType") if metadata else None, } except subprocess.CalledProcessError as e: raise RuntimeError(f"Failed to download file: {e.stderr.decode()}")