datarobot-genai 0.2.24__py3-none-any.whl → 0.2.29__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.
@@ -21,6 +21,7 @@ from fastmcp.exceptions import ToolError
21
21
  from fastmcp.tools.tool import ToolResult
22
22
 
23
23
  from datarobot_genai.drmcp.core.mcp_instance import dr_mcp_tool
24
+ from datarobot_genai.drmcp.tools.clients.gdrive import GOOGLE_DRIVE_FOLDER_MIME
24
25
  from datarobot_genai.drmcp.tools.clients.gdrive import LIMIT
25
26
  from datarobot_genai.drmcp.tools.clients.gdrive import MAX_PAGE_SIZE
26
27
  from datarobot_genai.drmcp.tools.clients.gdrive import SUPPORTED_FIELDS
@@ -60,7 +61,7 @@ async def gdrive_find_contents(
60
61
  "Optional list of metadata fields to include. Ex. id, name, mimeType. "
61
62
  f"Default = {SUPPORTED_FIELDS_STR}",
62
63
  ] = None,
63
- ) -> ToolResult | ToolError:
64
+ ) -> ToolResult:
64
65
  """
65
66
  Search or list files in the user's Google Drive with pagination and filtering support.
66
67
  Use this tool to discover file names and IDs for use with other tools.
@@ -121,7 +122,7 @@ async def gdrive_read_content(
121
122
  "(e.g., 'text/markdown' for Docs, 'text/csv' for Sheets). "
122
123
  "If not specified, uses sensible defaults. Has no effect on regular files.",
123
124
  ] = None,
124
- ) -> ToolResult | ToolError:
125
+ ) -> ToolResult:
125
126
  """
126
127
  Retrieve the content of a specific file by its ID. Google Workspace files are
127
128
  automatically exported to LLM-readable formats (Push-Down).
@@ -175,3 +176,95 @@ async def gdrive_read_content(
175
176
  ),
176
177
  structured_content=file_content.as_flat_dict(),
177
178
  )
179
+
180
+
181
+ @dr_mcp_tool(tags={"google", "gdrive", "create", "write", "file", "folder"}, enabled=False)
182
+ async def gdrive_create_file(
183
+ *,
184
+ name: Annotated[str, "The name for the new file or folder."],
185
+ mime_type: Annotated[
186
+ str,
187
+ "The MIME type of the file (e.g., 'text/plain', "
188
+ "'application/vnd.google-apps.document', 'application/vnd.google-apps.folder').",
189
+ ],
190
+ parent_id: Annotated[
191
+ str | None, "The ID of the parent folder where the file should be created."
192
+ ] = None,
193
+ initial_content: Annotated[
194
+ str | None, "Text content to populate the new file, if applicable."
195
+ ] = None,
196
+ ) -> ToolResult:
197
+ """
198
+ Create a new file or folder in Google Drive.
199
+
200
+ This tool is essential for an AI agent to generate new output (like reports or
201
+ documentation) directly into the Drive structure.
202
+
203
+ Usage:
204
+ - Create empty file: gdrive_create_file(name="report.txt", mime_type="text/plain")
205
+ - Create Google Doc: gdrive_create_file(
206
+ name="My Report",
207
+ mime_type="application/vnd.google-apps.document",
208
+ initial_content="# Report Title"
209
+ )
210
+ - Create folder: gdrive_create_file(
211
+ name="Reports",
212
+ mime_type="application/vnd.google-apps.folder"
213
+ )
214
+ - Create in subfolder: gdrive_create_file(
215
+ name="file.txt",
216
+ mime_type="text/plain",
217
+ parent_id="folder_id_here",
218
+ initial_content="File content"
219
+ )
220
+
221
+ Supported MIME types:
222
+ - text/plain: Plain text file
223
+ - application/vnd.google-apps.document: Google Doc (content auto-converted)
224
+ - application/vnd.google-apps.spreadsheet: Google Sheet (CSV content works best)
225
+ - application/vnd.google-apps.folder: Folder (initial_content is ignored)
226
+
227
+ Note: For Google Workspace files, the Drive API automatically converts plain text
228
+ content to the appropriate format.
229
+ """
230
+ if not name or not name.strip():
231
+ raise ToolError("Argument validation error: 'name' cannot be empty.")
232
+
233
+ if not mime_type or not mime_type.strip():
234
+ raise ToolError("Argument validation error: 'mime_type' cannot be empty.")
235
+
236
+ access_token = await get_gdrive_access_token()
237
+ if isinstance(access_token, ToolError):
238
+ raise access_token
239
+
240
+ try:
241
+ async with GoogleDriveClient(access_token) as client:
242
+ created_file = await client.create_file(
243
+ name=name,
244
+ mime_type=mime_type,
245
+ parent_id=parent_id,
246
+ initial_content=initial_content,
247
+ )
248
+ except GoogleDriveError as e:
249
+ logger.error(f"Google Drive error creating file: {e}")
250
+ raise ToolError(str(e))
251
+ except Exception as e:
252
+ logger.error(f"Unexpected error creating Google Drive file: {e}")
253
+ raise ToolError(f"An unexpected error occurred while creating Google Drive file: {str(e)}")
254
+
255
+ # Build response message
256
+ file_type = "folder" if mime_type == GOOGLE_DRIVE_FOLDER_MIME else "file"
257
+ content_info = ""
258
+ if initial_content and mime_type != GOOGLE_DRIVE_FOLDER_MIME:
259
+ content_info = " with initial content"
260
+
261
+ return ToolResult(
262
+ content=f"Successfully created {file_type} '{created_file.name}'{content_info}.",
263
+ structured_content={
264
+ "id": created_file.id,
265
+ "name": created_file.name,
266
+ "mimeType": created_file.mime_type,
267
+ "webViewLink": created_file.web_view_link,
268
+ "createdTime": created_file.created_time,
269
+ },
270
+ )
@@ -0,0 +1,13 @@
1
+ # Copyright 2026 DataRobot, Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
@@ -0,0 +1,198 @@
1
+ # Copyright 2026 DataRobot, Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ """Microsoft Graph MCP tools for searching SharePoint and OneDrive content."""
16
+
17
+ import logging
18
+ from typing import Annotated
19
+
20
+ from fastmcp.exceptions import ToolError
21
+ from fastmcp.tools.tool import ToolResult
22
+
23
+ from datarobot_genai.drmcp.core.mcp_instance import dr_mcp_tool
24
+ from datarobot_genai.drmcp.tools.clients.microsoft_graph import MicrosoftGraphClient
25
+ from datarobot_genai.drmcp.tools.clients.microsoft_graph import MicrosoftGraphError
26
+ from datarobot_genai.drmcp.tools.clients.microsoft_graph import get_microsoft_graph_access_token
27
+ from datarobot_genai.drmcp.tools.clients.microsoft_graph import validate_site_url
28
+
29
+ logger = logging.getLogger(__name__)
30
+
31
+
32
+ @dr_mcp_tool(
33
+ tags={
34
+ "microsoft",
35
+ "graph api",
36
+ "sharepoint",
37
+ "drive",
38
+ "list",
39
+ "search",
40
+ "files",
41
+ "find",
42
+ "contents",
43
+ }
44
+ )
45
+ async def microsoft_graph_search_content(
46
+ *,
47
+ search_query: Annotated[str, "The search string to find files, folders, or list items."],
48
+ site_url: Annotated[
49
+ str | None,
50
+ "Optional SharePoint site URL to scope the search "
51
+ "(e.g., https://tenant.sharepoint.com/sites/sitename). "
52
+ "If not provided, searches across all accessible sites.",
53
+ ] = None,
54
+ site_id: Annotated[
55
+ str | None,
56
+ "Optional ID of the site to scope the search. If provided, takes precedence over site_url.",
57
+ ] = None,
58
+ from_offset: Annotated[
59
+ int,
60
+ "The zero-based index of the first result to return. Use this for pagination. "
61
+ "Default: 0 (start from the beginning). To get the next page, increment by the size "
62
+ "value (e.g., first page: from=0 size=250, second page: from=250 size=250, "
63
+ "third page: from=500 size=250).",
64
+ ] = 0,
65
+ size: Annotated[
66
+ int,
67
+ "Maximum number of results to return in this request. Default is 250, max is 250. "
68
+ "The LLM should control pagination by making multiple calls with different 'from' values.",
69
+ ] = 250,
70
+ entity_types: Annotated[
71
+ list[str] | None,
72
+ "Optional list of entity types to search. Valid values: 'driveItem', 'listItem', "
73
+ "'site', 'list', 'drive'. Default: ['driveItem', 'listItem']. "
74
+ "Multiple types can be specified.",
75
+ ] = None,
76
+ filters: Annotated[
77
+ list[str] | None,
78
+ "Optional list of KQL filter expressions to refine search results "
79
+ "(e.g., ['fileType:docx', 'size>1000']).",
80
+ ] = None,
81
+ include_hidden_content: Annotated[
82
+ bool,
83
+ "Whether to include hidden content in search results. Only works with delegated "
84
+ "permissions, not application permissions. Default: False.",
85
+ ] = False,
86
+ region: Annotated[
87
+ str | None,
88
+ "Optional region code for application permissions (e.g., 'NAM', 'EUR', 'APC'). "
89
+ "Required when using application permissions to search SharePoint content in "
90
+ "specific regions.",
91
+ ] = None,
92
+ ) -> ToolResult | ToolError:
93
+ """
94
+ Search for SharePoint and OneDrive content using Microsoft Graph Search API.
95
+
96
+ Search Scope:
97
+ - When site_url or site_id is provided: searches within the specified SharePoint site
98
+ - When neither is provided: searches across all accessible SharePoint sites and OneDrive
99
+
100
+ Supported Entity Types:
101
+ - driveItem: Files and folders in document libraries and OneDrive
102
+ - listItem: Items in SharePoint lists
103
+ - site: SharePoint sites
104
+ - list: SharePoint lists
105
+ - drive: Document libraries/drives
106
+
107
+ Filtering:
108
+ - Filters use KQL (Keyword Query Language) syntax
109
+ - Multiple filters are combined with AND operators
110
+ - Examples: ['fileType:docx', 'size>1000', 'lastModifiedTime>2024-01-01']
111
+ - Filters are applied in addition to the search query
112
+
113
+ Pagination:
114
+ - Controlled via from_offset (zero-based index) and size parameters
115
+ - Maximum size per request: 250 results
116
+ - To paginate: increment from_offset by size value for each subsequent page
117
+ - Example pagination sequence:
118
+ * Page 1: from_offset=0, size=250 (returns results 0-249)
119
+ * Page 2: from_offset=250, size=250 (returns results 250-499)
120
+ * Page 3: from_offset=500, size=250 (returns results 500-749)
121
+
122
+ API Reference:
123
+ - Endpoint: POST /search/query
124
+ - Documentation: https://learn.microsoft.com/en-us/graph/api/search-query
125
+ - Search concepts: https://learn.microsoft.com/en-us/graph/search-concept-files
126
+
127
+ Permissions:
128
+ - Requires Sites.Read.All or Sites.Search.All permission
129
+ - include_hidden_content only works with delegated permissions
130
+ - region parameter is required for application permissions in multi-region environments
131
+ """
132
+ if not search_query:
133
+ raise ToolError("Argument validation error: 'search_query' cannot be empty.")
134
+
135
+ # Validate site_url if provided
136
+ if site_url:
137
+ validation_error = validate_site_url(site_url)
138
+ if validation_error:
139
+ raise ToolError(validation_error)
140
+
141
+ access_token = await get_microsoft_graph_access_token()
142
+ if isinstance(access_token, ToolError):
143
+ raise access_token
144
+
145
+ try:
146
+ async with MicrosoftGraphClient(access_token=access_token, site_url=site_url) as client:
147
+ items = await client.search_content(
148
+ search_query=search_query,
149
+ site_id=site_id,
150
+ from_offset=from_offset,
151
+ size=size,
152
+ entity_types=entity_types,
153
+ filters=filters,
154
+ include_hidden_content=include_hidden_content,
155
+ region=region,
156
+ )
157
+ except MicrosoftGraphError as e:
158
+ logger.error(f"Microsoft Graph error searching content: {e}")
159
+ raise ToolError(str(e))
160
+ except Exception as e:
161
+ logger.error(f"Unexpected error searching Microsoft Graph content: {e}", exc_info=True)
162
+ raise ToolError(
163
+ f"An unexpected error occurred while searching Microsoft Graph content: {str(e)}"
164
+ )
165
+
166
+ results = []
167
+ for item in items:
168
+ result_dict = {
169
+ "id": item.id, # Unique ID of the file, folder, or list item
170
+ "name": item.name,
171
+ "webUrl": item.web_url,
172
+ "size": item.size,
173
+ "createdDateTime": item.created_datetime,
174
+ "lastModifiedDateTime": item.last_modified_datetime,
175
+ "isFolder": item.is_folder,
176
+ "mimeType": item.mime_type,
177
+ # Document library/drive ID (driveId in Microsoft Graph API)
178
+ "documentLibraryId": item.drive_id,
179
+ "parentFolderId": item.parent_folder_id, # Parent folder ID
180
+ }
181
+ results.append(result_dict)
182
+
183
+ n = len(results)
184
+ return ToolResult(
185
+ content=(
186
+ f"Successfully searched Microsoft Graph and retrieved {n} result(s) for "
187
+ f"'{search_query}' (from={from_offset}, size={size})."
188
+ ),
189
+ structured_content={
190
+ "query": search_query,
191
+ "siteUrl": site_url,
192
+ "siteId": site_id,
193
+ "from": from_offset,
194
+ "size": size,
195
+ "results": results,
196
+ "count": n,
197
+ },
198
+ )
@@ -12,6 +12,7 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
+ import json
15
16
  import logging
16
17
  import os
17
18
  from typing import Annotated
@@ -28,6 +29,7 @@ logger = logging.getLogger(__name__)
28
29
 
29
30
  @dr_mcp_tool(tags={"predictive", "data", "write", "upload", "catalog"})
30
31
  async def upload_dataset_to_ai_catalog(
32
+ *,
31
33
  file_path: Annotated[str, "The path to the dataset file to upload."] | None = None,
32
34
  file_url: Annotated[str, "The URL to the dataset file to upload."] | None = None,
33
35
  ) -> ToolError | ToolResult:
@@ -80,11 +82,17 @@ async def list_ai_catalog_items() -> ToolResult:
80
82
  structured_content={"datasets": []},
81
83
  )
82
84
 
85
+ datasets_dict = {ds.id: ds.name for ds in datasets}
86
+ datasets_count = len(datasets)
87
+
83
88
  return ToolResult(
84
- content=f"Found {len(datasets)} AI Catalog items.",
89
+ content=(
90
+ f"Found {datasets_count} AI Catalog items, here are the details:\n"
91
+ f"{json.dumps(datasets_dict, indent=2)}"
92
+ ),
85
93
  structured_content={
86
- "datasets": [{"id": ds.id, "name": ds.name} for ds in datasets],
87
- "count": len(datasets),
94
+ "datasets": datasets_dict,
95
+ "count": datasets_count,
88
96
  },
89
97
  )
90
98
 
@@ -14,6 +14,10 @@
14
14
 
15
15
  import json
16
16
  import logging
17
+ from typing import Annotated
18
+
19
+ from fastmcp.exceptions import ToolError
20
+ from fastmcp.tools.tool import ToolResult
17
21
 
18
22
  from datarobot_genai.drmcp.core.clients import get_sdk_client
19
23
  from datarobot_genai.drmcp.core.mcp_instance import dr_mcp_tool
@@ -21,35 +25,39 @@ from datarobot_genai.drmcp.core.mcp_instance import dr_mcp_tool
21
25
  logger = logging.getLogger(__name__)
22
26
 
23
27
 
24
- @dr_mcp_tool(tags={"project", "management", "list"})
25
- async def list_projects() -> str:
26
- """
27
- List all DataRobot projects for the authenticated user.
28
-
29
- Returns
30
- -------
31
- A string summary of the user's DataRobot projects.
32
- """
28
+ @dr_mcp_tool(tags={"predictive", "project", "read", "management", "list"})
29
+ async def list_projects() -> ToolResult:
30
+ """List all DataRobot projects for the authenticated user."""
33
31
  client = get_sdk_client()
34
32
  projects = client.Project.list()
35
- if not projects:
36
- return "No projects found."
37
- return "\n".join(f"{p.id}: {p.project_name}" for p in projects)
33
+ projects = {p.id: p.project_name for p in projects}
38
34
 
35
+ return ToolResult(
36
+ content=(
37
+ json.dumps(projects, indent=2)
38
+ if projects
39
+ else json.dumps({"message": "No projects found."}, indent=2)
40
+ ),
41
+ structured_content=projects,
42
+ )
39
43
 
40
- @dr_mcp_tool(tags={"project", "data", "info"})
41
- async def get_project_dataset_by_name(project_id: str, dataset_name: str) -> str:
42
- """
43
- Get a dataset ID by name for a given project.
44
44
 
45
- Args:
46
- project_id: The ID of the DataRobot project.
47
- dataset_name: The name of the dataset to find (e.g., 'training', 'holdout').
45
+ @dr_mcp_tool(tags={"predictive", "project", "read", "data", "info"})
46
+ async def get_project_dataset_by_name(
47
+ *,
48
+ project_id: Annotated[str, "The ID of the DataRobot project."] | None = None,
49
+ dataset_name: Annotated[str, "The name of the dataset to find (e.g., 'training', 'holdout')."]
50
+ | None = None,
51
+ ) -> ToolError | ToolResult:
52
+ """Get a dataset ID by name for a given project.
48
53
 
49
- Returns
50
- -------
51
- The dataset ID and the dataset type (source or prediction) as a string, or an error message.
54
+ The dataset ID and the dataset type (source or prediction) as a string, or an error message.
52
55
  """
56
+ if not project_id:
57
+ return ToolError("Project ID is required.")
58
+ if not dataset_name:
59
+ return ToolError("Dataset name is required.")
60
+
53
61
  client = get_sdk_client()
54
62
  project = client.Project.get(project_id)
55
63
  all_datasets = []
@@ -61,12 +69,22 @@ async def get_project_dataset_by_name(project_id: str, dataset_name: str) -> str
61
69
  all_datasets.extend([{"type": "prediction", "dataset": ds} for ds in prediction_datasets])
62
70
  for ds in all_datasets:
63
71
  if dataset_name.lower() in ds["dataset"].name.lower():
64
- return json.dumps(
65
- {
72
+ return ToolResult(
73
+ content=(
74
+ json.dumps(
75
+ {
76
+ "dataset_id": ds["dataset"].id,
77
+ "dataset_type": ds["type"],
78
+ },
79
+ indent=2,
80
+ )
81
+ ),
82
+ structured_content={
66
83
  "dataset_id": ds["dataset"].id,
67
84
  "dataset_type": ds["type"],
68
- "ui_panel": ["dataset"],
69
85
  },
70
- indent=2,
71
86
  )
72
- return f"Dataset with name containing '{dataset_name}' not found in project {project_id}."
87
+ return ToolResult(
88
+ content=f"Dataset with name containing '{dataset_name}' not found in project {project_id}.",
89
+ structured_content={},
90
+ )
@@ -617,6 +617,7 @@ async def get_model_feature_impact(
617
617
 
618
618
  @dr_mcp_tool(tags={"predictive", "training", "read", "model", "evaluation"})
619
619
  async def get_model_lift_chart(
620
+ *,
620
621
  project_id: Annotated[str, "The ID of the DataRobot project"] | None = None,
621
622
  model_id: Annotated[str, "The ID of the model to analyze"] | None = None,
622
623
  source: Annotated[