universal-mcp-applications 0.1.25__py3-none-any.whl → 0.1.27rc1__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.

Potentially problematic release.


This version of universal-mcp-applications might be problematic. Click here for more details.

@@ -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 file specified by its ID. It automatically detects if the file is text or binary; text content is returned as a string, while binary content is returned base64-encoded. This differs from `download_file`, which only provides a 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 universal_mcp.applications.application import APIApplication
6
+ from universal_mcp.integrations import Integration
7
+
8
+
9
+ class OneDriveApp(APIApplication):
10
+ """
11
+ Application for interacting with Microsoft OneDrive API (via Microsoft Graph).
12
+ Provides tools to manage files, folders, and access Drive information.
13
+ """
14
+
15
+ def __init__(self, integration: Integration | None = None, **kwargs) -> None:
16
+ super().__init__(name="onedrive", integration=integration, **kwargs)
17
+ self.base_url = "https://graph.microsoft.com/v1.0"
18
+
19
+ def get_my_profile(self) -> dict[str, Any]:
20
+ """
21
+ 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.
22
+
23
+ Returns:
24
+ dict[str, Any]: A dictionary containing the user's id and userPrincipalName.
25
+
26
+ Raises:
27
+ HTTPStatusError: If the API request fails.
28
+
29
+ Tags:
30
+ profile, user, account
31
+ """
32
+ url = f"{self.base_url}/me"
33
+ query_params = {"$select": "id,userPrincipalName"}
34
+ response = self._get(url, params=query_params)
35
+ return self._handle_response(response)
36
+
37
+ def get_drive_info(self) -> dict[str, Any]:
38
+ """
39
+ 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.
40
+
41
+ Returns:
42
+ A dictionary containing drive information.
43
+
44
+ Tags:
45
+ drive, storage, quota, info
46
+ """
47
+ url = f"{self.base_url}/me/drive"
48
+ response = self._get(url)
49
+ return self._handle_response(response)
50
+
51
+ def _list_drive_items(self, item_id: str = "root") -> dict[str, Any]:
52
+ """
53
+ Lists the files and folders in the current user's OneDrive.
54
+
55
+ Args:
56
+ item_id (str, optional): The ID of the folder to list. Defaults to 'root'.
57
+
58
+ Returns:
59
+ A dictionary containing the list of files and folders.
60
+ """
61
+ url = f"{self.base_url}/me/drive/items/{item_id}/children"
62
+ response = self._get(url)
63
+ return self._handle_response(response)
64
+
65
+ def search_files(self, query: str) -> dict[str, Any]:
66
+ """
67
+ 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.
68
+
69
+ Args:
70
+ query (str): The search query.
71
+
72
+ Returns:
73
+ A dictionary containing the search results.
74
+
75
+ Tags:
76
+ search, find, query, files, important
77
+ """
78
+ if not query:
79
+ raise ValueError("Search query cannot be empty.")
80
+
81
+ url = f"{self.base_url}/me/drive/root/search(q='{query}')"
82
+ response = self._get(url)
83
+ return self._handle_response(response)
84
+
85
+ def get_item_metadata(self, item_id: str) -> dict[str, Any]:
86
+ """
87
+ 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.
88
+
89
+ Args:
90
+ item_id (str): The ID of the file or folder.
91
+
92
+ Returns:
93
+ A dictionary containing the item's metadata.
94
+
95
+ Tags:
96
+ metadata, info, file, folder
97
+ """
98
+ if not item_id:
99
+ raise ValueError("Missing required parameter 'item_id'.")
100
+
101
+ url = f"{self.base_url}/me/drive/items/{item_id}"
102
+ response = self._get(url)
103
+ return self._handle_response(response)
104
+
105
+ def create_folder(self, name: str, parent_id: str = "root") -> dict[str, Any]:
106
+ """
107
+ 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.
108
+
109
+ Args:
110
+ name (str): The name of the new folder.
111
+ parent_id (str, optional): The ID of the parent folder. Defaults to 'root'.
112
+
113
+ Returns:
114
+ A dictionary containing the new folder's metadata.
115
+
116
+ Tags:
117
+ create, folder, directory, important
118
+ """
119
+ if not name:
120
+ raise ValueError("Folder name cannot be empty.")
121
+
122
+ url = f"{self.base_url}/me/drive/items/{parent_id}/children"
123
+ data = {"name": name, "folder": {}, "@microsoft.graph.conflictBehavior": "rename"}
124
+ response = self._post(url, data=data)
125
+ return self._handle_response(response)
126
+
127
+ def delete_item(self, item_id: str) -> dict[str, Any]:
128
+ """
129
+ 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.
130
+
131
+ Args:
132
+ item_id (str): The ID of the item to delete.
133
+
134
+ Returns:
135
+ An empty dictionary if successful.
136
+
137
+ Tags:
138
+ delete, remove, file, folder, important
139
+ """
140
+ if not item_id:
141
+ raise ValueError("Missing required parameter 'item_id'.")
142
+
143
+ url = f"{self.base_url}/me/drive/items/{item_id}"
144
+ response = self._delete(url)
145
+ return self._handle_response(response)
146
+
147
+ def download_file(self, item_id: str) -> dict[str, Any]:
148
+ """
149
+ 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.
150
+
151
+ Args:
152
+ item_id (str): The ID of the file to download.
153
+
154
+ Returns:
155
+ A dictionary containing the download URL for the file under the key '@microsoft.graph.downloadUrl'.
156
+
157
+ Tags:
158
+ download, file, get, important
159
+ """
160
+ if not item_id:
161
+ raise ValueError("Missing required parameter 'item_id'.")
162
+
163
+ url = f"{self.base_url}/me/drive/items/{item_id}"
164
+ response = self._get(url)
165
+ metadata = self._handle_response(response)
166
+ download_url = metadata.get("@microsoft.graph.downloadUrl")
167
+ if not download_url:
168
+ raise ValueError("Could not retrieve download URL for the item.")
169
+ return {"download_url": download_url}
170
+
171
+ def upload_file(self, file_path: str, parent_id: str = "root", file_name: str | None = None) -> dict[str, Any]:
172
+ """
173
+ 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.
174
+
175
+ Args:
176
+ file_path (str): The local path to the file to upload.
177
+ parent_id (str, optional): The ID of the folder to upload the file to. Defaults to 'root'.
178
+ file_name (str, optional): The name to give the uploaded file. If not provided, the local filename is used.
179
+
180
+ Returns:
181
+ A dictionary containing the uploaded file's metadata.
182
+
183
+ Tags:
184
+ upload, file, put, important
185
+ """
186
+ if not os.path.exists(file_path):
187
+ raise FileNotFoundError(f"The file was not found at path: {file_path}")
188
+
189
+ if not file_name:
190
+ file_name = os.path.basename(file_path)
191
+
192
+ url = f"{self.base_url}/me/drive/items/{parent_id}:/{file_name}:/content"
193
+ with open(file_path, "rb") as f:
194
+ data = f.read()
195
+ response = self._put(url, data=data, content_type="application/octet-stream")
196
+ return self._handle_response(response)
197
+
198
+ def list_folders(self, item_id: str = "root") -> dict[str, Any]:
199
+ """
200
+ 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.
201
+
202
+ Args:
203
+ item_id (str, optional): The ID of the folder to list from. Defaults to 'root'.
204
+
205
+ Returns:
206
+ A dictionary containing the list of folders.
207
+
208
+ Tags:
209
+ list, folders, directories, important
210
+ """
211
+ all_items = self._list_drive_items(item_id=item_id)
212
+ folders = [item for item in all_items.get("value", []) if "folder" in item]
213
+ return {"value": folders}
214
+
215
+ def list_files(self, item_id: str = "root") -> dict[str, Any]:
216
+ """
217
+ 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.
218
+
219
+ Args:
220
+ item_id (str, optional): The ID of the folder to list files from. Defaults to 'root'.
221
+
222
+ Returns:
223
+ A dictionary containing the list of files.
224
+
225
+ Tags:
226
+ list, files, documents, important
227
+ """
228
+ all_items = self._list_drive_items(item_id=item_id)
229
+ files = [item for item in all_items.get("value", []) if "file" in item]
230
+ return {"value": files}
231
+
232
+ def create_folder_and_list(self, name: str, parent_id: str = "root") -> dict[str, Any]:
233
+ """
234
+ 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.
235
+
236
+ Args:
237
+ name (str): The name of the new folder.
238
+ parent_id (str, optional): The ID of the parent folder. Defaults to 'root'.
239
+
240
+ Returns:
241
+ A dictionary containing the list of items in the parent folder after creation.
242
+
243
+ Tags:
244
+ create, folder, list, important
245
+ """
246
+ self.create_folder(name=name, parent_id=parent_id)
247
+ return self._list_drive_items(item_id=parent_id)
248
+
249
+ def upload_text_file(self, content: str, parent_id: str = "root", file_name: str = "new_file.txt") -> dict[str, Any]:
250
+ """
251
+ 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.
252
+
253
+ Args:
254
+ content (str): The text content to upload.
255
+ parent_id (str, optional): The ID of the folder to upload the file to. Defaults to 'root'.
256
+ file_name (str, optional): The name to give the uploaded file. Defaults to 'new_file.txt'.
257
+
258
+ Returns:
259
+ A dictionary containing the uploaded file's metadata.
260
+
261
+ Tags:
262
+ upload, text, file, create, important
263
+ """
264
+ if not file_name:
265
+ raise ValueError("File name cannot be empty.")
266
+
267
+ url = f"{self.base_url}/me/drive/items/{parent_id}:/{file_name}:/content"
268
+ data = content.encode("utf-8")
269
+ response = self._put(url, data=data, content_type="text/plain")
270
+ return self._handle_response(response)
271
+
272
+ def get_document_content(self, item_id: str) -> dict[str, Any]:
273
+ """
274
+ Retrieves the content of a file specified by its ID. It automatically detects if the file is text or binary; text content is returned as a string, while binary content is returned base64-encoded. This differs from `download_file`, which only provides a URL.
275
+
276
+ Args:
277
+ item_id (str): The ID of the file.
278
+
279
+ Returns:
280
+ A dictionary containing the file content. For text files, content is string. For binary, it's base64 encoded.
281
+
282
+ Tags:
283
+ get, content, read, file, important
284
+ """
285
+ if not item_id:
286
+ raise ValueError("Missing required parameter 'item_id'.")
287
+
288
+ metadata = self.get_item_metadata(item_id=item_id)
289
+ file_metadata = metadata.get("file")
290
+ if not file_metadata:
291
+ raise ValueError(f"Item with ID '{item_id}' is not a file.")
292
+
293
+ file_mime_type = file_metadata.get("mimeType", "")
294
+
295
+ url = f"{self.base_url}/me/drive/items/{item_id}/content"
296
+ response = self._get(url)
297
+
298
+ if response.status_code >= 400:
299
+ # Try to handle as JSON error response from Graph API
300
+ return self._handle_response(response)
301
+
302
+ content = response.content
303
+
304
+ is_text = file_mime_type.startswith("text/") or any(t in file_mime_type for t in ["json", "xml", "csv", "javascript", "html"])
305
+
306
+ content_dict = {}
307
+ if is_text:
308
+ try:
309
+ content_dict["content"] = content.decode("utf-8")
310
+ except UnicodeDecodeError:
311
+ is_text = False
312
+
313
+ if not is_text:
314
+ content_dict["content_base64"] = base64.b64encode(content).decode("ascii")
315
+
316
+ return {
317
+ "name": metadata.get("name"),
318
+ "content_type": "text" if is_text else "binary",
319
+ **content_dict,
320
+ "size": len(content),
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
+ ]