datarobot-genai 0.2.3__py3-none-any.whl → 0.2.11__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.
- datarobot_genai/drmcp/core/config.py +52 -0
- datarobot_genai/drmcp/core/dr_mcp_server.py +11 -8
- datarobot_genai/drmcp/core/tool_config.py +95 -0
- datarobot_genai/drmcp/test_utils/openai_llm_mcp_client.py +6 -1
- datarobot_genai/drmcp/tools/clients/__init__.py +14 -0
- datarobot_genai/drmcp/tools/clients/atlassian.py +188 -0
- datarobot_genai/drmcp/tools/clients/confluence.py +196 -0
- datarobot_genai/drmcp/tools/clients/jira.py +147 -0
- datarobot_genai/drmcp/tools/clients/s3.py +28 -0
- datarobot_genai/drmcp/tools/confluence/__init__.py +14 -0
- datarobot_genai/drmcp/tools/confluence/tools.py +81 -0
- datarobot_genai/drmcp/tools/jira/__init__.py +14 -0
- datarobot_genai/drmcp/tools/jira/tools.py +52 -0
- datarobot_genai/drmcp/tools/predictive/predict.py +1 -1
- datarobot_genai/drmcp/tools/predictive/predict_realtime.py +1 -1
- datarobot_genai/nat/agent.py +4 -0
- datarobot_genai/nat/datarobot_auth_provider.py +110 -0
- datarobot_genai/nat/datarobot_mcp_client.py +234 -0
- {datarobot_genai-0.2.3.dist-info → datarobot_genai-0.2.11.dist-info}/METADATA +6 -1
- {datarobot_genai-0.2.3.dist-info → datarobot_genai-0.2.11.dist-info}/RECORD +24 -12
- {datarobot_genai-0.2.3.dist-info → datarobot_genai-0.2.11.dist-info}/entry_points.txt +2 -0
- {datarobot_genai-0.2.3.dist-info → datarobot_genai-0.2.11.dist-info}/WHEEL +0 -0
- {datarobot_genai-0.2.3.dist-info → datarobot_genai-0.2.11.dist-info}/licenses/AUTHORS +0 -0
- {datarobot_genai-0.2.3.dist-info → datarobot_genai-0.2.11.dist-info}/licenses/LICENSE +0 -0
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
# Copyright 2025 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
|
+
import logging
|
|
16
|
+
from http import HTTPStatus
|
|
17
|
+
from typing import Any
|
|
18
|
+
|
|
19
|
+
import httpx
|
|
20
|
+
from pydantic import BaseModel
|
|
21
|
+
from pydantic import Field
|
|
22
|
+
|
|
23
|
+
from .atlassian import ATLASSIAN_API_BASE
|
|
24
|
+
from .atlassian import get_atlassian_cloud_id
|
|
25
|
+
|
|
26
|
+
logger = logging.getLogger(__name__)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class _IssuePerson(BaseModel):
|
|
30
|
+
email_address: str = Field(alias="emailAddress")
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class _IssueStatus(BaseModel):
|
|
34
|
+
name: str
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class _IssueFields(BaseModel):
|
|
38
|
+
summary: str
|
|
39
|
+
status: _IssueStatus
|
|
40
|
+
reporter: _IssuePerson
|
|
41
|
+
assignee: _IssuePerson
|
|
42
|
+
created: str
|
|
43
|
+
updated: str
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
class Issue(BaseModel):
|
|
47
|
+
id: str
|
|
48
|
+
key: str
|
|
49
|
+
fields: _IssueFields
|
|
50
|
+
|
|
51
|
+
def as_flat_dict(self) -> dict[str, Any]:
|
|
52
|
+
return {
|
|
53
|
+
"id": self.id,
|
|
54
|
+
"key": self.key,
|
|
55
|
+
"summary": self.fields.summary,
|
|
56
|
+
"reporterEmailAddress": self.fields.reporter.email_address,
|
|
57
|
+
"assigneeEmailAddress": self.fields.assignee.email_address,
|
|
58
|
+
"created": self.fields.created,
|
|
59
|
+
"updated": self.fields.updated,
|
|
60
|
+
"status": self.fields.status.name,
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
class JiraClient:
|
|
65
|
+
"""
|
|
66
|
+
Client for interacting with Jira API using OAuth access token.
|
|
67
|
+
|
|
68
|
+
At the moment of creating this client, official Jira SDK is not supporting async.
|
|
69
|
+
"""
|
|
70
|
+
|
|
71
|
+
def __init__(self, access_token: str) -> None:
|
|
72
|
+
"""
|
|
73
|
+
Initialize Jira client with access token.
|
|
74
|
+
|
|
75
|
+
Args:
|
|
76
|
+
access_token: OAuth access token for Atlassian API
|
|
77
|
+
"""
|
|
78
|
+
self.access_token = access_token
|
|
79
|
+
self._client = httpx.AsyncClient(
|
|
80
|
+
headers={
|
|
81
|
+
"Authorization": f"Bearer {access_token}",
|
|
82
|
+
"Accept": "application/json",
|
|
83
|
+
"Content-Type": "application/json",
|
|
84
|
+
},
|
|
85
|
+
timeout=30.0,
|
|
86
|
+
)
|
|
87
|
+
self._cloud_id: str | None = None
|
|
88
|
+
|
|
89
|
+
async def _get_cloud_id(self) -> str:
|
|
90
|
+
"""
|
|
91
|
+
Get the cloud ID for the authenticated Atlassian Jira instance.
|
|
92
|
+
|
|
93
|
+
According to Atlassian OAuth 2.0 documentation, API calls should use:
|
|
94
|
+
https://api.atlassian.com/ex/jira/{cloudId}/rest/api/3/...
|
|
95
|
+
|
|
96
|
+
Returns
|
|
97
|
+
-------
|
|
98
|
+
Cloud ID string
|
|
99
|
+
|
|
100
|
+
Raises
|
|
101
|
+
------
|
|
102
|
+
ValueError: If cloud ID cannot be retrieved
|
|
103
|
+
"""
|
|
104
|
+
if self._cloud_id:
|
|
105
|
+
return self._cloud_id
|
|
106
|
+
|
|
107
|
+
self._cloud_id = await get_atlassian_cloud_id(self._client, service_type="jira")
|
|
108
|
+
return self._cloud_id
|
|
109
|
+
|
|
110
|
+
async def get_jira_issue(self, issue_key: str) -> Issue:
|
|
111
|
+
"""
|
|
112
|
+
Get a Jira issue by its key.
|
|
113
|
+
|
|
114
|
+
Args:
|
|
115
|
+
issue_key: The key of the Jira issue, e.g., 'PROJ-123'
|
|
116
|
+
|
|
117
|
+
Returns
|
|
118
|
+
-------
|
|
119
|
+
Jira issue
|
|
120
|
+
|
|
121
|
+
Raises
|
|
122
|
+
------
|
|
123
|
+
httpx.HTTPStatusError: If the API request fails
|
|
124
|
+
"""
|
|
125
|
+
cloud_id = await self._get_cloud_id()
|
|
126
|
+
url = f"{ATLASSIAN_API_BASE}/ex/jira/{cloud_id}/rest/api/3/issue/{issue_key}"
|
|
127
|
+
|
|
128
|
+
response = await self._client.get(
|
|
129
|
+
url, params={"fields": "id,key,summary,status,reporter,assignee,created,updated"}
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
if response.status_code == HTTPStatus.NOT_FOUND:
|
|
133
|
+
raise ValueError(f"{issue_key} not found")
|
|
134
|
+
|
|
135
|
+
response.raise_for_status()
|
|
136
|
+
issue = Issue(**response.json())
|
|
137
|
+
return issue
|
|
138
|
+
|
|
139
|
+
async def __aenter__(self) -> "JiraClient":
|
|
140
|
+
"""Async context manager entry."""
|
|
141
|
+
return self
|
|
142
|
+
|
|
143
|
+
async def __aexit__(
|
|
144
|
+
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: Any
|
|
145
|
+
) -> None:
|
|
146
|
+
"""Async context manager exit."""
|
|
147
|
+
await self._client.aclose()
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Copyright 2025 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
|
+
import logging
|
|
16
|
+
|
|
17
|
+
from datarobot_genai.drmcp.core.credentials import get_credentials
|
|
18
|
+
|
|
19
|
+
logger = logging.getLogger(__name__)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def get_s3_bucket_info() -> dict[str, str]:
|
|
23
|
+
"""Get S3 bucket configuration."""
|
|
24
|
+
credentials = get_credentials()
|
|
25
|
+
return {
|
|
26
|
+
"bucket": credentials.aws_predictions_s3_bucket,
|
|
27
|
+
"prefix": credentials.aws_predictions_s3_prefix,
|
|
28
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# Copyright 2025 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
|
+
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# Copyright 2025 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
|
+
"""Confluence MCP tools for interacting with Confluence Cloud."""
|
|
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.atlassian import get_atlassian_access_token
|
|
25
|
+
from datarobot_genai.drmcp.tools.clients.confluence import ConfluenceClient
|
|
26
|
+
|
|
27
|
+
logger = logging.getLogger(__name__)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
@dr_mcp_tool(tags={"confluence", "read", "get", "page"})
|
|
31
|
+
async def confluence_get_page(
|
|
32
|
+
*,
|
|
33
|
+
page_id_or_title: Annotated[str, "The ID or the exact title of the Confluence page."],
|
|
34
|
+
space_key: Annotated[
|
|
35
|
+
str | None,
|
|
36
|
+
"Required if identifying the page by title. The space key (e.g., 'PROJ').",
|
|
37
|
+
] = None,
|
|
38
|
+
) -> ToolResult | ToolError:
|
|
39
|
+
"""Retrieve the content of a specific Confluence page.
|
|
40
|
+
|
|
41
|
+
Use this tool to fetch Confluence pages by their numeric ID or by title.
|
|
42
|
+
Returns page content in HTML storage format.
|
|
43
|
+
|
|
44
|
+
Usage:
|
|
45
|
+
- By ID: page_id_or_title="856391684"
|
|
46
|
+
- By title: page_id_or_title="Meeting Notes", space_key="TEAM"
|
|
47
|
+
|
|
48
|
+
When using a page title, the space_key parameter is required.
|
|
49
|
+
"""
|
|
50
|
+
if not page_id_or_title:
|
|
51
|
+
raise ToolError("Argument validation error: 'page_id_or_title' cannot be empty.")
|
|
52
|
+
|
|
53
|
+
access_token = await get_atlassian_access_token()
|
|
54
|
+
if isinstance(access_token, ToolError):
|
|
55
|
+
raise access_token
|
|
56
|
+
|
|
57
|
+
try:
|
|
58
|
+
async with ConfluenceClient(access_token) as client:
|
|
59
|
+
if page_id_or_title.isdigit():
|
|
60
|
+
page_response = await client.get_page_by_id(page_id_or_title)
|
|
61
|
+
else:
|
|
62
|
+
if not space_key:
|
|
63
|
+
raise ToolError(
|
|
64
|
+
"Argument validation error: "
|
|
65
|
+
"'space_key' is required when identifying a page by title."
|
|
66
|
+
)
|
|
67
|
+
page_response = await client.get_page_by_title(page_id_or_title, space_key)
|
|
68
|
+
except ValueError as e:
|
|
69
|
+
logger.error(f"Value error getting Confluence page: {e}")
|
|
70
|
+
raise ToolError(str(e))
|
|
71
|
+
except Exception as e:
|
|
72
|
+
logger.error(f"Unexpected error getting Confluence page: {e}")
|
|
73
|
+
raise ToolError(
|
|
74
|
+
f"An unexpected error occurred while getting Confluence page "
|
|
75
|
+
f"'{page_id_or_title}': {str(e)}"
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
return ToolResult(
|
|
79
|
+
content=f"Successfully retrieved page '{page_response.title}'.",
|
|
80
|
+
structured_content=page_response.as_flat_dict(),
|
|
81
|
+
)
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# Copyright 2025 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
|
+
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# Copyright 2025 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
|
+
import logging
|
|
16
|
+
from typing import Annotated
|
|
17
|
+
|
|
18
|
+
from fastmcp.exceptions import ToolError
|
|
19
|
+
from fastmcp.tools.tool import ToolResult
|
|
20
|
+
|
|
21
|
+
from datarobot_genai.drmcp.core.mcp_instance import dr_mcp_tool
|
|
22
|
+
from datarobot_genai.drmcp.tools.clients.atlassian import get_atlassian_access_token
|
|
23
|
+
from datarobot_genai.drmcp.tools.clients.jira import JiraClient
|
|
24
|
+
|
|
25
|
+
logger = logging.getLogger(__name__)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
@dr_mcp_tool(tags={"jira", "read", "get", "issue"})
|
|
29
|
+
async def jira_get_issue(
|
|
30
|
+
*, issue_key: Annotated[str, "The key (ID) of the Jira issue to retrieve, e.g., 'PROJ-123'."]
|
|
31
|
+
) -> ToolResult:
|
|
32
|
+
"""Retrieve all fields and details for a single Jira issue by its key."""
|
|
33
|
+
if not issue_key:
|
|
34
|
+
raise ToolError("Argument validation error: 'issue_key' cannot be empty.")
|
|
35
|
+
|
|
36
|
+
access_token = await get_atlassian_access_token()
|
|
37
|
+
if isinstance(access_token, ToolError):
|
|
38
|
+
raise access_token
|
|
39
|
+
|
|
40
|
+
try:
|
|
41
|
+
async with JiraClient(access_token) as client:
|
|
42
|
+
issue = await client.get_jira_issue(issue_key)
|
|
43
|
+
except Exception as e:
|
|
44
|
+
logger.error(f"Unexpected error getting Jira issue: {e}")
|
|
45
|
+
raise ToolError(
|
|
46
|
+
f"An unexpected error occurred while getting Jira issue '{issue_key}': {str(e)}"
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
return ToolResult(
|
|
50
|
+
content=f"Successfully retrieved details for issue '{issue_key}'.",
|
|
51
|
+
structured_content=issue.as_flat_dict(),
|
|
52
|
+
)
|
|
@@ -22,10 +22,10 @@ from fastmcp.resources import HttpResource
|
|
|
22
22
|
from fastmcp.resources import ResourceManager
|
|
23
23
|
|
|
24
24
|
from datarobot_genai.drmcp.core.clients import get_credentials
|
|
25
|
-
from datarobot_genai.drmcp.core.clients import get_s3_bucket_info
|
|
26
25
|
from datarobot_genai.drmcp.core.clients import get_sdk_client
|
|
27
26
|
from datarobot_genai.drmcp.core.mcp_instance import dr_mcp_tool
|
|
28
27
|
from datarobot_genai.drmcp.core.utils import generate_presigned_url
|
|
28
|
+
from datarobot_genai.drmcp.tools.clients.s3 import get_s3_bucket_info
|
|
29
29
|
|
|
30
30
|
logger = logging.getLogger(__name__)
|
|
31
31
|
|
|
@@ -23,11 +23,11 @@ from datarobot_predict import TimeSeriesType
|
|
|
23
23
|
from datarobot_predict.deployment import predict as dr_predict
|
|
24
24
|
from pydantic import BaseModel
|
|
25
25
|
|
|
26
|
-
from datarobot_genai.drmcp.core.clients import get_s3_bucket_info
|
|
27
26
|
from datarobot_genai.drmcp.core.clients import get_sdk_client
|
|
28
27
|
from datarobot_genai.drmcp.core.mcp_instance import dr_mcp_tool
|
|
29
28
|
from datarobot_genai.drmcp.core.utils import PredictionResponse
|
|
30
29
|
from datarobot_genai.drmcp.core.utils import predictions_result_response
|
|
30
|
+
from datarobot_genai.drmcp.tools.clients.s3 import get_s3_bucket_info
|
|
31
31
|
|
|
32
32
|
logger = logging.getLogger(__name__)
|
|
33
33
|
|
datarobot_genai/nat/agent.py
CHANGED
|
@@ -123,6 +123,8 @@ class NatAgent(BaseAgent[None]):
|
|
|
123
123
|
model: str | None = None,
|
|
124
124
|
verbose: bool | str | None = True,
|
|
125
125
|
timeout: int | None = 90,
|
|
126
|
+
authorization_context: dict[str, Any] | None = None,
|
|
127
|
+
forwarded_headers: dict[str, str] | None = None,
|
|
126
128
|
**kwargs: Any,
|
|
127
129
|
) -> None:
|
|
128
130
|
super().__init__(
|
|
@@ -131,6 +133,8 @@ class NatAgent(BaseAgent[None]):
|
|
|
131
133
|
model=model,
|
|
132
134
|
verbose=verbose,
|
|
133
135
|
timeout=timeout,
|
|
136
|
+
authorization_context=authorization_context,
|
|
137
|
+
forwarded_headers=forwarded_headers,
|
|
134
138
|
**kwargs,
|
|
135
139
|
)
|
|
136
140
|
self.workflow_path = workflow_path
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# Copyright 2025 DataRobot, Inc. and its affiliates.
|
|
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
|
+
from collections.abc import AsyncGenerator
|
|
15
|
+
from typing import Any
|
|
16
|
+
|
|
17
|
+
from datarobot.core.config import DataRobotAppFrameworkBaseSettings
|
|
18
|
+
from nat.authentication.api_key.api_key_auth_provider import APIKeyAuthProvider
|
|
19
|
+
from nat.authentication.api_key.api_key_auth_provider_config import APIKeyAuthProviderConfig
|
|
20
|
+
from nat.authentication.interfaces import AuthProviderBase
|
|
21
|
+
from nat.builder.builder import Builder
|
|
22
|
+
from nat.cli.register_workflow import register_auth_provider
|
|
23
|
+
from nat.data_models.authentication import AuthProviderBaseConfig
|
|
24
|
+
from nat.data_models.authentication import AuthResult
|
|
25
|
+
from nat.data_models.authentication import HeaderCred
|
|
26
|
+
from pydantic import Field
|
|
27
|
+
|
|
28
|
+
from datarobot_genai.core.mcp.common import MCPConfig
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class Config(DataRobotAppFrameworkBaseSettings):
|
|
32
|
+
"""
|
|
33
|
+
Finds variables in the priority order of: env
|
|
34
|
+
variables (including Runtime Parameters), .env, file_secrets, then
|
|
35
|
+
Pulumi output variables.
|
|
36
|
+
"""
|
|
37
|
+
|
|
38
|
+
datarobot_api_token: str | None = None
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
config = Config()
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
class DataRobotAPIKeyAuthProviderConfig(APIKeyAuthProviderConfig, name="datarobot_api_key"): # type: ignore[call-arg]
|
|
45
|
+
raw_key: str = Field(
|
|
46
|
+
description=(
|
|
47
|
+
"Raw API token or credential to be injected into the request parameter. "
|
|
48
|
+
"Used for 'bearer','x-api-key','custom', and other schemes. "
|
|
49
|
+
),
|
|
50
|
+
default=config.datarobot_api_token,
|
|
51
|
+
)
|
|
52
|
+
default_user_id: str | None = Field(default="default-user", description="Default user ID")
|
|
53
|
+
allow_default_user_id_for_tool_calls: bool = Field(
|
|
54
|
+
default=True, description="Allow default user ID for tool calls"
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
@register_auth_provider(config_type=DataRobotAPIKeyAuthProviderConfig)
|
|
59
|
+
async def datarobot_api_key_client(
|
|
60
|
+
config: DataRobotAPIKeyAuthProviderConfig, builder: Builder
|
|
61
|
+
) -> AsyncGenerator[APIKeyAuthProvider]:
|
|
62
|
+
yield APIKeyAuthProvider(config=config)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
mcp_config = MCPConfig().server_config
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
class DataRobotMCPAuthProviderConfig(AuthProviderBaseConfig, name="datarobot_mcp_auth"): # type: ignore[call-arg]
|
|
69
|
+
headers: dict[str, str] | None = Field(
|
|
70
|
+
description=("Headers to be used for authentication. "),
|
|
71
|
+
default=mcp_config["headers"] if mcp_config else None,
|
|
72
|
+
)
|
|
73
|
+
default_user_id: str | None = Field(default="default-user", description="Default user ID")
|
|
74
|
+
allow_default_user_id_for_tool_calls: bool = Field(
|
|
75
|
+
default=True, description="Allow default user ID for tool calls"
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
class DataRobotMCPAuthProvider(AuthProviderBase[DataRobotMCPAuthProviderConfig]):
|
|
80
|
+
def __init__(
|
|
81
|
+
self, config: DataRobotMCPAuthProviderConfig, config_name: str | None = None
|
|
82
|
+
) -> None:
|
|
83
|
+
assert isinstance(config, DataRobotMCPAuthProviderConfig), (
|
|
84
|
+
"Config is not DataRobotMCPAuthProviderConfig"
|
|
85
|
+
)
|
|
86
|
+
super().__init__(config)
|
|
87
|
+
|
|
88
|
+
async def authenticate(self, user_id: str | None = None, **kwargs: Any) -> AuthResult | None:
|
|
89
|
+
"""
|
|
90
|
+
Authenticate the user using the API key credentials.
|
|
91
|
+
|
|
92
|
+
Args:
|
|
93
|
+
user_id (str): The user ID to authenticate.
|
|
94
|
+
|
|
95
|
+
Returns
|
|
96
|
+
-------
|
|
97
|
+
AuthenticatedContext: The authenticated context containing headers
|
|
98
|
+
"""
|
|
99
|
+
return AuthResult(
|
|
100
|
+
credentials=[
|
|
101
|
+
HeaderCred(name=name, value=value) for name, value in self.config.headers.items()
|
|
102
|
+
]
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
@register_auth_provider(config_type=DataRobotMCPAuthProviderConfig)
|
|
107
|
+
async def datarobot_mcp_auth_provider(
|
|
108
|
+
config: DataRobotMCPAuthProviderConfig, builder: Builder
|
|
109
|
+
) -> AsyncGenerator[DataRobotMCPAuthProvider]:
|
|
110
|
+
yield DataRobotMCPAuthProvider(config=config)
|