universal-mcp-applications 0.1.25__py3-none-any.whl → 0.1.32__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,24 @@
1
+ # OnedriveApp MCP Server
2
+
3
+ An MCP Server for the OnedriveApp API.
4
+
5
+ ## 🛠️ Tool List
6
+
7
+ This is automatically generated from OpenAPI schema for the OnedriveApp API.
8
+
9
+
10
+ | Tool | Description |
11
+ |------|-------------|
12
+ | `get_drive_info` | Fetches high-level information about the user's entire OneDrive. It returns drive-wide details like the owner and storage quota, differing from `get_item_metadata` which describes a specific item, and `get_my_profile` which retrieves general user account information. |
13
+ | `search_files` | Searches the user's entire OneDrive for files and folders matching a specified text query. This function performs a comprehensive search from the drive's root, distinguishing it from `list_files` or `list_folders` which only browse the contents of a single directory. |
14
+ | `get_item_metadata` | Fetches detailed metadata for a specific file or folder using its unique ID. It returns properties like name, size, and type. Unlike `get_document_content`, it doesn't retrieve the file's actual content, focusing solely on the item's attributes for quick inspection without a full download. |
15
+ | `create_folder` | Creates a new folder with a specified name within a parent directory, which defaults to the root. Returns metadata for the new folder. Unlike `create_folder_and_list`, this function only creates the folder and returns its specific metadata, not the parent directory's contents. |
16
+ | `delete_item` | Permanently deletes a specified file or folder from OneDrive using its unique item ID. This versatile function can remove any type of drive item, distinguished from functions that only list or create specific types. A successful deletion returns an empty response, confirming the item's removal. |
17
+ | `download_file` | Retrieves a temporary, pre-authenticated download URL for a specific file using its item ID. This function provides a link for subsequent download, differing from `get_document_content` which directly fetches the file's raw content. The URL is returned within a dictionary. |
18
+ | `upload_file` | Uploads a local binary file (under 4MB) from a given path to a specified OneDrive folder. Unlike `upload_text_file`, which uploads string content, this function reads from the filesystem. The destination filename can be customized, and it returns the new file's metadata upon completion. |
19
+ | `get_my_profile` | Fetches the profile for the currently authenticated user, specifically retrieving their ID and user principal name. This function confirms user identity, distinguishing it from `get_drive_info`, which returns details about the OneDrive storage space (e.g., quota) rather than the user's personal profile. |
20
+ | `list_folders` | Retrieves a list of only the folders within a specified parent directory in OneDrive. Unlike `_list_drive_items` which returns all items, this function filters the results to exclude files. Defaults to the root directory if no parent `item_id` is provided. |
21
+ | `list_files` | Retrieves a list of files within a specified OneDrive folder, defaulting to the root. Unlike `_list_drive_items` which fetches all items, this function filters the results to exclusively return items identified as files, excluding any subdirectories. |
22
+ | `create_folder_and_list` | Performs a composite action: creates a new folder, then lists all items (files and folders) within that parent directory. This confirms creation by returning the parent's updated contents, distinct from `create_folder` which only returns the new folder's metadata. |
23
+ | `upload_text_file` | Creates and uploads a new file to OneDrive directly from a string of text content. Unlike `upload_file`, which requires a local file path, this function is specifically for creating a text file from in-memory string data, with a customizable name and destination folder. |
24
+ | `get_document_content` | Retrieves the content of a specific file by its item ID and returns it directly as base64-encoded data. This function is distinct from `download_file`, which only provides a temporary URL for the content, and from `get_item_metadata`, which returns file attributes without the content itself. The function fetches the content by following the file's pre-authenticated download URL. |
@@ -0,0 +1 @@
1
+ from .app import OnedriveApp
@@ -0,0 +1,338 @@
1
+ import base64
2
+ import os
3
+ from typing import Any
4
+
5
+ from loguru import logger
6
+ from universal_mcp.applications.application import APIApplication
7
+ from universal_mcp.integrations import Integration
8
+
9
+
10
+ class OnedriveApp(APIApplication):
11
+ """
12
+ Application for interacting with Microsoft OneDrive API (via Microsoft Graph).
13
+ Provides tools to manage files, folders, and access Drive information.
14
+ """
15
+
16
+ def __init__(self, integration: Integration | None = None, **kwargs) -> None:
17
+ super().__init__(name="onedrive", integration=integration, **kwargs)
18
+ self.base_url = "https://graph.microsoft.com/v1.0"
19
+
20
+ def get_my_profile(self) -> dict[str, Any]:
21
+ """
22
+ Fetches the profile for the currently authenticated user, specifically retrieving their ID and user principal name. This function confirms user identity, distinguishing it from `get_drive_info`, which returns details about the OneDrive storage space (e.g., quota) rather than the user's personal profile.
23
+
24
+ Returns:
25
+ dict[str, Any]: A dictionary containing the user's id and userPrincipalName.
26
+
27
+ Raises:
28
+ HTTPStatusError: If the API request fails.
29
+
30
+ Tags:
31
+ profile, user, account
32
+ """
33
+ url = f"{self.base_url}/me"
34
+ query_params = {"$select": "id,userPrincipalName"}
35
+ response = self._get(url, params=query_params)
36
+ return self._handle_response(response)
37
+
38
+ def get_drive_info(self) -> dict[str, Any]:
39
+ """
40
+ Fetches high-level information about the user's entire OneDrive. It returns drive-wide details like the owner and storage quota, differing from `get_item_metadata` which describes a specific item, and `get_my_profile` which retrieves general user account information.
41
+
42
+ Returns:
43
+ A dictionary containing drive information.
44
+
45
+ Tags:
46
+ drive, storage, quota, info
47
+ """
48
+ url = f"{self.base_url}/me/drive"
49
+ response = self._get(url)
50
+ return self._handle_response(response)
51
+
52
+ def _list_drive_items(self, item_id: str = "root") -> dict[str, Any]:
53
+ """
54
+ Lists the files and folders in the current user's OneDrive.
55
+
56
+ Args:
57
+ item_id (str, optional): The ID of the folder to list. Defaults to 'root'.
58
+
59
+ Returns:
60
+ A dictionary containing the list of files and folders.
61
+ """
62
+ url = f"{self.base_url}/me/drive/items/{item_id}/children"
63
+ response = self._get(url)
64
+ return self._handle_response(response)
65
+
66
+ def search_files(self, query: str) -> dict[str, Any]:
67
+ """
68
+ Searches the user's entire OneDrive for files and folders matching a specified text query. This function performs a comprehensive search from the drive's root, distinguishing it from `list_files` or `list_folders` which only browse the contents of a single directory.
69
+
70
+ Args:
71
+ query (str): The search query.
72
+
73
+ Returns:
74
+ A dictionary containing the search results.
75
+
76
+ Tags:
77
+ search, find, query, files, important
78
+ """
79
+ if not query:
80
+ raise ValueError("Search query cannot be empty.")
81
+
82
+ url = f"{self.base_url}/me/drive/root/search(q='{query}')"
83
+ response = self._get(url)
84
+ return self._handle_response(response)
85
+
86
+ def get_item_metadata(self, item_id: str) -> dict[str, Any]:
87
+ """
88
+ Fetches detailed metadata for a specific file or folder using its unique ID. It returns properties like name, size, and type. Unlike `get_document_content`, it doesn't retrieve the file's actual content, focusing solely on the item's attributes for quick inspection without a full download.
89
+
90
+ Args:
91
+ item_id (str): The ID of the file or folder.
92
+
93
+ Returns:
94
+ A dictionary containing the item's metadata.
95
+
96
+ Tags:
97
+ metadata, info, file, folder
98
+ """
99
+ if not item_id:
100
+ raise ValueError("Missing required parameter 'item_id'.")
101
+
102
+ url = f"{self.base_url}/me/drive/items/{item_id}"
103
+ response = self._get(url)
104
+ return self._handle_response(response)
105
+
106
+ def create_folder(self, name: str, parent_id: str = "root") -> dict[str, Any]:
107
+ """
108
+ Creates a new folder with a specified name within a parent directory, which defaults to the root. Returns metadata for the new folder. Unlike `create_folder_and_list`, this function only creates the folder and returns its specific metadata, not the parent directory's contents.
109
+
110
+ Args:
111
+ name (str): The name of the new folder.
112
+ parent_id (str, optional): The ID of the parent folder. Defaults to 'root'.
113
+
114
+ Returns:
115
+ A dictionary containing the new folder's metadata.
116
+
117
+ Tags:
118
+ create, folder, directory, important
119
+ """
120
+ if not name:
121
+ raise ValueError("Folder name cannot be empty.")
122
+
123
+ url = f"{self.base_url}/me/drive/items/{parent_id}/children"
124
+ data = {"name": name, "folder": {}, "@microsoft.graph.conflictBehavior": "rename"}
125
+ response = self._post(url, data=data)
126
+ return self._handle_response(response)
127
+
128
+ def delete_item(self, item_id: str) -> dict[str, Any]:
129
+ """
130
+ Permanently deletes a specified file or folder from OneDrive using its unique item ID. This versatile function can remove any type of drive item, distinguished from functions that only list or create specific types. A successful deletion returns an empty response, confirming the item's removal.
131
+
132
+ Args:
133
+ item_id (str): The ID of the item to delete.
134
+
135
+ Returns:
136
+ An empty dictionary if successful.
137
+
138
+ Tags:
139
+ delete, remove, file, folder, important
140
+ """
141
+ if not item_id:
142
+ raise ValueError("Missing required parameter 'item_id'.")
143
+
144
+ url = f"{self.base_url}/me/drive/items/{item_id}"
145
+ response = self._delete(url)
146
+ return self._handle_response(response)
147
+
148
+ def download_file(self, item_id: str) -> dict[str, Any]:
149
+ """
150
+ Retrieves a temporary, pre-authenticated download URL for a specific file using its item ID. This function provides a link for subsequent download, differing from `get_document_content` which directly fetches the file's raw content. The URL is returned within a dictionary.
151
+
152
+ Args:
153
+ item_id (str): The ID of the file to download.
154
+
155
+ Returns:
156
+ A dictionary containing the download URL for the file under the key '@microsoft.graph.downloadUrl'.
157
+
158
+ Tags:
159
+ download, file, get, important
160
+ """
161
+ if not item_id:
162
+ raise ValueError("Missing required parameter 'item_id'.")
163
+
164
+ url = f"{self.base_url}/me/drive/items/{item_id}"
165
+ response = self._get(url)
166
+ metadata = self._handle_response(response)
167
+ download_url = metadata.get("@microsoft.graph.downloadUrl")
168
+ if not download_url:
169
+ raise ValueError("Could not retrieve download URL for the item.")
170
+ return {"download_url": download_url}
171
+
172
+ def upload_file(self, file_path: str, parent_id: str = "root", file_name: str | None = None) -> dict[str, Any]:
173
+ """
174
+ Uploads a local binary file (under 4MB) from a given path to a specified OneDrive folder. Unlike `upload_text_file`, which uploads string content, this function reads from the filesystem. The destination filename can be customized, and it returns the new file's metadata upon completion.
175
+
176
+ Args:
177
+ file_path (str): The local path to the file to upload.
178
+ parent_id (str, optional): The ID of the folder to upload the file to. Defaults to 'root'.
179
+ file_name (str, optional): The name to give the uploaded file. If not provided, the local filename is used.
180
+
181
+ Returns:
182
+ A dictionary containing the uploaded file's metadata.
183
+
184
+ Tags:
185
+ upload, file, put, important
186
+ """
187
+ if not os.path.exists(file_path):
188
+ raise FileNotFoundError(f"The file was not found at path: {file_path}")
189
+
190
+ if not file_name:
191
+ file_name = os.path.basename(file_path)
192
+
193
+ url = f"{self.base_url}/me/drive/items/{parent_id}:/{file_name}:/content"
194
+ with open(file_path, "rb") as f:
195
+ data = f.read()
196
+ response = self._put(url, data=data, content_type="application/octet-stream")
197
+ return self._handle_response(response)
198
+
199
+ def list_folders(self, item_id: str = "root") -> dict[str, Any]:
200
+ """
201
+ Retrieves a list of only the folders within a specified parent directory in OneDrive. Unlike `_list_drive_items` which returns all items, this function filters the results to exclude files. Defaults to the root directory if no parent `item_id` is provided.
202
+
203
+ Args:
204
+ item_id (str, optional): The ID of the folder to list from. Defaults to 'root'.
205
+
206
+ Returns:
207
+ A dictionary containing the list of folders.
208
+
209
+ Tags:
210
+ list, folders, directories, important
211
+ """
212
+ all_items = self._list_drive_items(item_id=item_id)
213
+ folders = [item for item in all_items.get("value", []) if "folder" in item]
214
+ return {"value": folders}
215
+
216
+ def list_files(self, item_id: str = "root") -> dict[str, Any]:
217
+ """
218
+ Retrieves a list of files within a specified OneDrive folder, defaulting to the root. Unlike `_list_drive_items` which fetches all items, this function filters the results to exclusively return items identified as files, excluding any subdirectories.
219
+
220
+ Args:
221
+ item_id (str, optional): The ID of the folder to list files from. Defaults to 'root'.
222
+
223
+ Returns:
224
+ A dictionary containing the list of files.
225
+
226
+ Tags:
227
+ list, files, documents, important
228
+ """
229
+ all_items = self._list_drive_items(item_id=item_id)
230
+ files = [item for item in all_items.get("value", []) if "file" in item]
231
+ return {"value": files}
232
+
233
+ def create_folder_and_list(self, name: str, parent_id: str = "root") -> dict[str, Any]:
234
+ """
235
+ Performs a composite action: creates a new folder, then lists all items (files and folders) within that parent directory. This confirms creation by returning the parent's updated contents, distinct from `create_folder` which only returns the new folder's metadata.
236
+
237
+ Args:
238
+ name (str): The name of the new folder.
239
+ parent_id (str, optional): The ID of the parent folder. Defaults to 'root'.
240
+
241
+ Returns:
242
+ A dictionary containing the list of items in the parent folder after creation.
243
+
244
+ Tags:
245
+ create, folder, list, important
246
+ """
247
+ self.create_folder(name=name, parent_id=parent_id)
248
+ return self._list_drive_items(item_id=parent_id)
249
+
250
+ def upload_text_file(self, content: str, parent_id: str = "root", file_name: str = "new_file.txt") -> dict[str, Any]:
251
+ """
252
+ Creates and uploads a new file to OneDrive directly from a string of text content. Unlike `upload_file`, which requires a local file path, this function is specifically for creating a text file from in-memory string data, with a customizable name and destination folder.
253
+
254
+ Args:
255
+ content (str): The text content to upload.
256
+ parent_id (str, optional): The ID of the folder to upload the file to. Defaults to 'root'.
257
+ file_name (str, optional): The name to give the uploaded file. Defaults to 'new_file.txt'.
258
+
259
+ Returns:
260
+ A dictionary containing the uploaded file's metadata.
261
+
262
+ Tags:
263
+ upload, text, file, create, important
264
+ """
265
+ if not file_name:
266
+ raise ValueError("File name cannot be empty.")
267
+
268
+ url = f"{self.base_url}/me/drive/items/{parent_id}:/{file_name}:/content"
269
+ data = content.encode("utf-8")
270
+ response = self._put(url, data=data, content_type="text/plain")
271
+ return self._handle_response(response)
272
+
273
+ def get_document_content(self, item_id: str) -> dict[str, Any]:
274
+ """
275
+ Retrieves the content of a specific file by its item ID and returns it directly as base64-encoded data. This function is distinct from `download_file`, which only provides a temporary URL for the content, and from `get_item_metadata`, which returns file attributes without the content itself. The function fetches the content by following the file's pre-authenticated download URL.
276
+
277
+ Args:
278
+ item_id (str): The ID of the file.
279
+
280
+ Returns:
281
+ dict[str, Any]: A dictionary containing the file details:
282
+ - 'type' (str): The general type of the file (e.g., "image", "audio", "video", "file").
283
+ - 'data' (str): The base64 encoded content of the file.
284
+ - 'mime_type' (str): The MIME type of the file.
285
+ - 'file_name' (str): The name of the file.
286
+
287
+ Tags:
288
+ get, content, read, file, important
289
+ """
290
+ if not item_id:
291
+ raise ValueError("Missing required parameter 'item_id'.")
292
+
293
+ metadata = self.get_item_metadata(item_id=item_id)
294
+ file_metadata = metadata.get("file")
295
+ if not file_metadata:
296
+ raise ValueError(f"Item with ID '{item_id}' is not a file.")
297
+
298
+ file_mime_type = file_metadata.get("mimeType", "application/octet-stream")
299
+ file_name = metadata.get("name")
300
+
301
+ download_url = metadata.get("@microsoft.graph.downloadUrl")
302
+ if not download_url:
303
+ logger.error(f"Could not find @microsoft.graph.downloadUrl in metadata for item {item_id}")
304
+ raise ValueError("Could not retrieve download URL for the item.")
305
+
306
+ response = self._get(download_url)
307
+
308
+ response.raise_for_status()
309
+
310
+ content = response.content
311
+
312
+ attachment_type = file_mime_type.split("/")[0] if "/" in file_mime_type else "file"
313
+ if attachment_type not in ["image", "audio", "video", "text"]:
314
+ attachment_type = "file"
315
+
316
+ return {
317
+ "type": attachment_type,
318
+ "data": content,
319
+ "mime_type": file_mime_type,
320
+ "file_name": file_name,
321
+ }
322
+
323
+ def list_tools(self):
324
+ return [
325
+ self.get_drive_info,
326
+ self.search_files,
327
+ self.get_item_metadata,
328
+ self.create_folder,
329
+ self.delete_item,
330
+ self.download_file,
331
+ self.upload_file,
332
+ self.get_my_profile,
333
+ self.list_folders,
334
+ self.list_files,
335
+ self.create_folder_and_list,
336
+ self.upload_text_file,
337
+ self.get_document_content,
338
+ ]