datarobot-genai 0.2.5__tar.gz → 0.2.8__tar.gz

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.
Files changed (113) hide show
  1. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/PKG-INFO +2 -1
  2. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/pyproject.toml +5 -1
  3. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/core/utils/auth.py +188 -31
  4. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/nat/agent.py +4 -0
  5. datarobot_genai-0.2.8/src/datarobot_genai/nat/datarobot_auth_provider.py +110 -0
  6. datarobot_genai-0.2.8/src/datarobot_genai/nat/datarobot_mcp_client.py +234 -0
  7. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/.gitignore +0 -0
  8. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/AUTHORS +0 -0
  9. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/LICENSE +0 -0
  10. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/README.md +0 -0
  11. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/__init__.py +0 -0
  12. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/core/__init__.py +0 -0
  13. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/core/agents/__init__.py +0 -0
  14. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/core/agents/base.py +0 -0
  15. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/core/chat/__init__.py +0 -0
  16. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/core/chat/auth.py +0 -0
  17. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/core/chat/client.py +0 -0
  18. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/core/chat/responses.py +0 -0
  19. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/core/cli/__init__.py +0 -0
  20. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/core/cli/agent_environment.py +0 -0
  21. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/core/cli/agent_kernel.py +0 -0
  22. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/core/custom_model.py +0 -0
  23. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/core/mcp/__init__.py +0 -0
  24. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/core/mcp/common.py +0 -0
  25. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/core/telemetry_agent.py +0 -0
  26. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/core/utils/__init__.py +0 -0
  27. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/core/utils/urls.py +0 -0
  28. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/crewai/__init__.py +0 -0
  29. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/crewai/agent.py +0 -0
  30. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/crewai/base.py +0 -0
  31. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/crewai/events.py +0 -0
  32. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/crewai/mcp.py +0 -0
  33. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/drmcp/__init__.py +0 -0
  34. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/drmcp/core/__init__.py +0 -0
  35. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/drmcp/core/auth.py +0 -0
  36. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/drmcp/core/clients.py +0 -0
  37. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/drmcp/core/config.py +0 -0
  38. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/drmcp/core/config_utils.py +0 -0
  39. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/drmcp/core/constants.py +0 -0
  40. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/drmcp/core/credentials.py +0 -0
  41. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/drmcp/core/dr_mcp_server.py +0 -0
  42. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/drmcp/core/dr_mcp_server_logo.py +0 -0
  43. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/drmcp/core/dynamic_prompts/__init__.py +0 -0
  44. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/drmcp/core/dynamic_prompts/controllers.py +0 -0
  45. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/drmcp/core/dynamic_prompts/dr_lib.py +0 -0
  46. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/drmcp/core/dynamic_prompts/register.py +0 -0
  47. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/drmcp/core/dynamic_prompts/utils.py +0 -0
  48. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/drmcp/core/dynamic_tools/__init__.py +0 -0
  49. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/drmcp/core/dynamic_tools/deployment/__init__.py +0 -0
  50. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/drmcp/core/dynamic_tools/deployment/adapters/__init__.py +0 -0
  51. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/drmcp/core/dynamic_tools/deployment/adapters/base.py +0 -0
  52. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/drmcp/core/dynamic_tools/deployment/adapters/default.py +0 -0
  53. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/drmcp/core/dynamic_tools/deployment/adapters/drum.py +0 -0
  54. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/drmcp/core/dynamic_tools/deployment/config.py +0 -0
  55. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/drmcp/core/dynamic_tools/deployment/controllers.py +0 -0
  56. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/drmcp/core/dynamic_tools/deployment/metadata.py +0 -0
  57. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/drmcp/core/dynamic_tools/deployment/register.py +0 -0
  58. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/drmcp/core/dynamic_tools/deployment/schemas/drum_agentic_fallback_schema.json +0 -0
  59. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/drmcp/core/dynamic_tools/deployment/schemas/drum_prediction_fallback_schema.json +0 -0
  60. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/drmcp/core/dynamic_tools/register.py +0 -0
  61. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/drmcp/core/dynamic_tools/schema.py +0 -0
  62. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/drmcp/core/exceptions.py +0 -0
  63. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/drmcp/core/logging.py +0 -0
  64. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/drmcp/core/mcp_instance.py +0 -0
  65. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/drmcp/core/mcp_server_tools.py +0 -0
  66. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/drmcp/core/memory_management/__init__.py +0 -0
  67. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/drmcp/core/memory_management/manager.py +0 -0
  68. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/drmcp/core/memory_management/memory_tools.py +0 -0
  69. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/drmcp/core/routes.py +0 -0
  70. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/drmcp/core/routes_utils.py +0 -0
  71. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/drmcp/core/server_life_cycle.py +0 -0
  72. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/drmcp/core/telemetry.py +0 -0
  73. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/drmcp/core/tool_config.py +0 -0
  74. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/drmcp/core/tool_filter.py +0 -0
  75. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/drmcp/core/utils.py +0 -0
  76. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/drmcp/server.py +0 -0
  77. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/drmcp/test_utils/__init__.py +0 -0
  78. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/drmcp/test_utils/integration_mcp_server.py +0 -0
  79. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/drmcp/test_utils/mcp_utils_ete.py +0 -0
  80. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/drmcp/test_utils/mcp_utils_integration.py +0 -0
  81. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/drmcp/test_utils/openai_llm_mcp_client.py +0 -0
  82. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/drmcp/test_utils/tool_base_ete.py +0 -0
  83. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/drmcp/test_utils/utils.py +0 -0
  84. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/drmcp/tools/__init__.py +0 -0
  85. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/drmcp/tools/clients/__init__.py +0 -0
  86. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/drmcp/tools/clients/atlassian.py +0 -0
  87. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/drmcp/tools/clients/confluence.py +0 -0
  88. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/drmcp/tools/clients/jira.py +0 -0
  89. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/drmcp/tools/clients/s3.py +0 -0
  90. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/drmcp/tools/confluence/__init__.py +0 -0
  91. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/drmcp/tools/confluence/tools.py +0 -0
  92. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/drmcp/tools/jira/__init__.py +0 -0
  93. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/drmcp/tools/jira/tools.py +0 -0
  94. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/drmcp/tools/predictive/__init__.py +0 -0
  95. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/drmcp/tools/predictive/data.py +0 -0
  96. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/drmcp/tools/predictive/deployment.py +0 -0
  97. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/drmcp/tools/predictive/deployment_info.py +0 -0
  98. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/drmcp/tools/predictive/model.py +0 -0
  99. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/drmcp/tools/predictive/predict.py +0 -0
  100. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/drmcp/tools/predictive/predict_realtime.py +0 -0
  101. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/drmcp/tools/predictive/project.py +0 -0
  102. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/drmcp/tools/predictive/training.py +0 -0
  103. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/langgraph/__init__.py +0 -0
  104. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/langgraph/agent.py +0 -0
  105. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/langgraph/mcp.py +0 -0
  106. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/llama_index/__init__.py +0 -0
  107. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/llama_index/agent.py +0 -0
  108. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/llama_index/base.py +0 -0
  109. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/llama_index/mcp.py +0 -0
  110. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/nat/__init__.py +0 -0
  111. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/nat/datarobot_llm_clients.py +0 -0
  112. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/nat/datarobot_llm_providers.py +0 -0
  113. {datarobot_genai-0.2.5 → datarobot_genai-0.2.8}/src/datarobot_genai/py.typed +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: datarobot-genai
3
- Version: 0.2.5
3
+ Version: 0.2.8
4
4
  Summary: Generic helpers for GenAI
5
5
  Project-URL: Homepage, https://github.com/datarobot-oss/datarobot-genai
6
6
  Author: DataRobot, Inc.
@@ -63,6 +63,7 @@ Requires-Dist: anyio==4.11.0; extra == 'nat'
63
63
  Requires-Dist: crewai>=1.1.0; (python_version >= '3.11') and extra == 'nat'
64
64
  Requires-Dist: llama-index-llms-litellm<0.7.0,>=0.4.1; extra == 'nat'
65
65
  Requires-Dist: nvidia-nat-langchain==1.3.0; (python_version >= '3.11') and extra == 'nat'
66
+ Requires-Dist: nvidia-nat-mcp==1.3.0; (python_version >= '3.11') and extra == 'nat'
66
67
  Requires-Dist: nvidia-nat-opentelemetry==1.3.0; (python_version >= '3.11') and extra == 'nat'
67
68
  Requires-Dist: nvidia-nat==1.3.0; (python_version >= '3.11') and extra == 'nat'
68
69
  Requires-Dist: opentelemetry-instrumentation-crewai<1.0.0,>=0.40.5; extra == 'nat'
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "datarobot-genai"
7
- version = "0.2.5"
7
+ version = "0.2.8"
8
8
  description = "Generic helpers for GenAI"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10, <3.13"
@@ -35,6 +35,8 @@ Homepage = "https://github.com/datarobot-oss/datarobot-genai"
35
35
  [project.entry-points.'nat.plugins']
36
36
  datarobot_llm_providers = "datarobot_genai.nat.datarobot_llm_providers"
37
37
  datarobot_llm_clients = "datarobot_genai.nat.datarobot_llm_clients"
38
+ datarobot_mcp_client = "datarobot_genai.nat.datarobot_mcp_client"
39
+ datarobot_auth_provider = "datarobot_genai.nat.datarobot_auth_provider"
38
40
 
39
41
  [project.optional-dependencies]
40
42
  crewai = [
@@ -63,6 +65,7 @@ nat = [
63
65
  "nvidia-nat==1.3.0; python_version >= '3.11'",
64
66
  "nvidia-nat-opentelemetry==1.3.0; python_version >= '3.11'",
65
67
  "nvidia-nat-langchain==1.3.0; python_version >= '3.11'",
68
+ "nvidia-nat-mcp==1.3.0; python_version >= '3.11'",
66
69
  "crewai>=1.1.0; python_version >= '3.11'",
67
70
  "llama-index-llms-litellm>=0.4.1,<0.7.0", # Need this to support datarobot-llm plugin
68
71
  "opentelemetry-instrumentation-crewai>=0.40.5,<1.0.0",
@@ -125,6 +128,7 @@ dev = [
125
128
  "pytest-asyncio>=0.23.5",
126
129
  "responses>=0.25.8",
127
130
  "ipdb>=0.13.13",
131
+ "aioresponses>=0.7.8",
128
132
  ]
129
133
 
130
134
 
@@ -12,17 +12,23 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
  import logging
15
+ import os
15
16
  import warnings
16
17
  from typing import Any
18
+ from typing import Protocol
17
19
 
20
+ import aiohttp
18
21
  import jwt
19
- from datarobot.auth.datarobot.oauth import AsyncOAuth as DatarobotAsyncOAuthClient
22
+ from datarobot.auth.datarobot.oauth import AsyncOAuth as DatarobotOAuthClient
23
+ from datarobot.auth.exceptions import OAuthProviderNotFound
24
+ from datarobot.auth.exceptions import OAuthValidationErr
20
25
  from datarobot.auth.identity import Identity
21
- from datarobot.auth.oauth import AsyncOAuthComponent
26
+ from datarobot.auth.oauth import OAuthToken
22
27
  from datarobot.auth.session import AuthCtx
23
28
  from datarobot.core.config import DataRobotAppFrameworkBaseSettings
24
29
  from datarobot.models.genai.agent.auth import ToolAuth
25
30
  from datarobot.models.genai.agent.auth import get_authorization_context
31
+ from mypyc.ir.ops import Sequence
26
32
  from pydantic import BaseModel
27
33
 
28
34
  logger = logging.getLogger(__name__)
@@ -183,52 +189,203 @@ class AuthContextHeaderHandler:
183
189
  return None
184
190
 
185
191
 
192
+ # --- OAuth Token Provider Implementation ---
193
+
194
+
195
+ class TokenRetriever(Protocol):
196
+ """Protocol for OAuth token retrievers."""
197
+
198
+ def filter_identities(self, identities: Sequence[Identity]) -> list[Identity]:
199
+ """Filter identities to only those valid for this retriever implementation."""
200
+ ...
201
+
202
+ async def refresh_access_token(self, identity: Identity) -> OAuthToken:
203
+ """Refresh the access token for the given identity ID.
204
+
205
+ Parameters
206
+ ----------
207
+ identity_id : str
208
+ The provider identity ID to refresh the token for.
209
+
210
+ Returns
211
+ -------
212
+ OAuthToken
213
+ The refreshed OAuth token.
214
+ """
215
+ ...
216
+
217
+
218
+ class DatarobotTokenRetriever:
219
+ """Retrieves OAuth tokens using the DataRobot platform."""
220
+
221
+ def __init__(self) -> None:
222
+ self._client = DatarobotOAuthClient()
223
+
224
+ def filter_identities(self, identities: Sequence[Identity]) -> list[Identity]:
225
+ """Filter oauth2 identities to only those with provider_identity_id.
226
+
227
+ The `provider_identity_id` is required in order to identify the provider
228
+ and retrieve the access token from DataRobot OAuth Providers service.
229
+ """
230
+ return [i for i in identities if i.type == "oauth2" and i.provider_identity_id]
231
+
232
+ async def refresh_access_token(self, identity: Identity) -> OAuthToken:
233
+ """Refresh the access token using DataRobot's OAuth client."""
234
+ return await self._client.refresh_access_token(provider_id=identity.provider_identity_id)
235
+
236
+
237
+ class AuthlibTokenRetriever:
238
+ """Retrieves OAuth tokens from a generic Authlib-based endpoint."""
239
+
240
+ def __init__(self, application_endpoint: str) -> None:
241
+ if not application_endpoint:
242
+ raise ValueError("AuthlibTokenRetriever requires 'application_endpoint'.")
243
+ self.application_endpoint = application_endpoint.rstrip("/")
244
+
245
+ def filter_identities(self, identities: Sequence[Identity]) -> list[Identity]:
246
+ """Filter identities to only OAuth2 identities."""
247
+ return [i for i in identities if i.type == "oauth2" and i.provider_identity_id is None]
248
+
249
+ async def refresh_access_token(self, identity: Identity) -> OAuthToken:
250
+ """Retrieve an OAuth token via an HTTP POST request.
251
+
252
+ Parameters
253
+ ----------
254
+ identity : Identity
255
+ The identity to retrieve the token for.
256
+
257
+ Returns
258
+ -------
259
+ OAuthToken
260
+ The retrieved OAuth token.
261
+ """
262
+ api_token = os.environ.get("DATAROBOT_API_TOKEN")
263
+ if not api_token:
264
+ raise ValueError("DATAROBOT_API_TOKEN environment variable is required but not set.")
265
+
266
+ token_url = f"{self.application_endpoint}/oauth/token/"
267
+ headers = {"Authorization": f"Bearer {api_token}"}
268
+ payload = {"identity_id": identity.id}
269
+ timeout = aiohttp.ClientTimeout(total=30)
270
+
271
+ try:
272
+ async with aiohttp.ClientSession(timeout=timeout) as session:
273
+ async with session.post(token_url, headers=headers, json=payload) as response:
274
+ response.raise_for_status()
275
+ data = await response.json()
276
+ logger.debug(f"Retrieved access token from {token_url}")
277
+ return OAuthToken(**data)
278
+ except aiohttp.ClientError as e:
279
+ logger.error(f"Error retrieving token from {token_url}: {e}")
280
+ raise
281
+
282
+
283
+ class OAuthConfig(BaseModel):
284
+ """Configuration extracted from AuthCtx metadata for OAuth operations."""
285
+
286
+ implementation: str = "datarobot"
287
+ application_endpoint: str | None = None
288
+
289
+ @classmethod
290
+ def from_auth_ctx(cls, auth_ctx: AuthCtx) -> "OAuthConfig":
291
+ metadata = auth_ctx.metadata or {}
292
+ return cls(
293
+ implementation=metadata.get("oauth_implementation", "datarobot"),
294
+ application_endpoint=metadata.get("application_endpoint"),
295
+ )
296
+
297
+
298
+ def create_token_retriever(config: OAuthConfig) -> TokenRetriever:
299
+ """Create a token retriever based on the OAuth configuration.
300
+
301
+ Parameters
302
+ ----------
303
+ config : OAuthConfig
304
+ The OAuth configuration specifying implementation type and endpoints.
305
+
306
+ Returns
307
+ -------
308
+ TokenRetriever
309
+ The configured token retriever instance.
310
+ """
311
+ if config.implementation == "datarobot":
312
+ return DatarobotTokenRetriever()
313
+
314
+ if config.implementation == "authlib":
315
+ if not config.application_endpoint:
316
+ raise ValueError("Required 'application_endpoint' not found in metadata.")
317
+ return AuthlibTokenRetriever(config.application_endpoint)
318
+
319
+ raise ValueError(
320
+ f"Unsupported OAuth implementation: '{config.implementation}'. "
321
+ f"Supported values: datarobot, authlib."
322
+ )
323
+
324
+
186
325
  class AsyncOAuthTokenProvider:
187
- """Manages OAuth access tokens using generic OAuth client."""
326
+ """Provides OAuth tokens for authorized users.
327
+
328
+ This class manages OAuth token retrieval for users with multiple identity providers.
329
+ It uses either DataRobot or Authlib as the OAuth token storage and refresh backend
330
+ based on the auth context metadata.
331
+ """
188
332
 
189
333
  def __init__(self, auth_ctx: AuthCtx) -> None:
334
+ """Initialize the provider with an authorization context.
335
+
336
+ Parameters
337
+ ----------
338
+ auth_ctx : AuthCtx
339
+ The authorization context containing user identities and metadata.
340
+ """
190
341
  self.auth_ctx = auth_ctx
191
- self.oauth_client = self._create_oauth_client()
342
+ config = OAuthConfig.from_auth_ctx(auth_ctx)
343
+ self._retriever = create_token_retriever(config)
192
344
 
193
345
  def _get_identity(self, provider_type: str | None) -> Identity:
194
- """Retrieve the appropriate identity from the authentication context."""
195
- identities = [x for x in self.auth_ctx.identities if x.provider_identity_id is not None]
196
-
197
- if not identities:
198
- raise ValueError("No identities found in authorization context.")
346
+ """Get identity from auth context, filtered by provider_type if specified."""
347
+ oauth_identities = self._retriever.filter_identities(self.auth_ctx.identities)
348
+ if not oauth_identities:
349
+ raise OAuthProviderNotFound("No OAuth provider found.")
199
350
 
200
351
  if provider_type is None:
201
- if len(identities) > 1:
202
- raise ValueError(
203
- "Multiple identities found. Please specify 'provider_type' parameter."
352
+ if len(oauth_identities) > 1:
353
+ raise OAuthValidationErr(
354
+ "Multiple OAuth providers found. Specify 'provider_type' parameter."
204
355
  )
205
- return identities[0]
206
-
207
- identity = next((id for id in identities if id.provider_type == provider_type), None)
356
+ return oauth_identities[0]
208
357
 
358
+ identity = next((i for i in oauth_identities if i.provider_type == provider_type), None)
209
359
  if identity is None:
210
- raise ValueError(f"No identity found for provider '{provider_type}'.")
211
-
360
+ raise OAuthValidationErr(f"No identity found for provider '{provider_type}'.")
212
361
  return identity
213
362
 
214
363
  async def get_token(self, auth_type: ToolAuth, provider_type: str | None = None) -> str:
215
- """Get OAuth access token using the specified method."""
364
+ """Get an OAuth access token for the specified auth type and provider.
365
+
366
+ Parameters
367
+ ----------
368
+ auth_type : ToolAuth
369
+ Authentication type (only OBO is supported).
370
+ provider_type : str, optional
371
+ The specific provider to use (e.g., 'google'). Required if multiple
372
+ identities are available.
373
+
374
+ Returns
375
+ -------
376
+ str
377
+ The retrieved OAuth access token.
378
+
379
+ Raises
380
+ ------
381
+ ValueError
382
+ If the auth type is unsupported or if a suitable identity cannot be found.
383
+ """
216
384
  if auth_type != ToolAuth.OBO:
217
385
  raise ValueError(
218
- f"Unsupported auth type: {auth_type}. Only {ToolAuth.OBO} is supported."
386
+ f"Unsupported auth type: {auth_type}. Only OBO (on-behalf-of) is supported."
219
387
  )
220
388
 
221
389
  identity = self._get_identity(provider_type)
222
- token_data = await self.oauth_client.refresh_access_token(
223
- identity_id=identity.provider_identity_id
224
- )
390
+ token_data = await self._retriever.refresh_access_token(identity)
225
391
  return token_data.access_token
226
-
227
- def _create_oauth_client(self) -> AsyncOAuthComponent:
228
- """Create either DataRobot or Authlib OAuth client based on
229
- authorization context.
230
-
231
- Note: at the moment, only DataRobot OAuth client is supported.
232
- """
233
- logger.debug("Using DataRobot OAuth client")
234
- return DatarobotAsyncOAuthClient()
@@ -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)
@@ -0,0 +1,234 @@
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
+
15
+ import logging
16
+ from datetime import timedelta
17
+ from typing import Literal
18
+
19
+ import httpx
20
+ from nat.authentication.interfaces import AuthProviderBase
21
+ from nat.builder.builder import Builder
22
+ from nat.cli.register_workflow import register_function_group
23
+ from nat.data_models.component_ref import AuthenticationRef
24
+ from nat.plugins.mcp.client_base import AuthAdapter
25
+ from nat.plugins.mcp.client_base import MCPSSEClient
26
+ from nat.plugins.mcp.client_base import MCPStdioClient
27
+ from nat.plugins.mcp.client_base import MCPStreamableHTTPClient
28
+ from nat.plugins.mcp.client_config import MCPServerConfig
29
+ from nat.plugins.mcp.client_impl import MCPClientConfig
30
+ from nat.plugins.mcp.client_impl import MCPFunctionGroup
31
+ from nat.plugins.mcp.client_impl import mcp_apply_tool_alias_and_description
32
+ from nat.plugins.mcp.client_impl import mcp_session_tool_function
33
+ from pydantic import Field
34
+ from pydantic import HttpUrl
35
+
36
+ from datarobot_genai.core.mcp.common import MCPConfig
37
+
38
+ logger = logging.getLogger(__name__)
39
+
40
+ config = MCPConfig().server_config
41
+
42
+
43
+ class DataRobotMCPServerConfig(MCPServerConfig):
44
+ transport: Literal["streamable-http", "sse", "stdio"] = Field(
45
+ default=config["transport"] if config else "stdio",
46
+ description="Transport type to connect to the MCP server (sse or streamable-http)",
47
+ )
48
+ url: HttpUrl | None = Field(
49
+ default=config["url"] if config else None,
50
+ description="URL of the MCP server (for sse or streamable-http transport)",
51
+ )
52
+ # Authentication configuration
53
+ auth_provider: str | AuthenticationRef | None = Field(
54
+ default="datarobot_mcp_auth" if config else None,
55
+ description="Reference to authentication provider",
56
+ )
57
+ command: str | None = Field(
58
+ default=None if config else "docker",
59
+ description="Command to run for stdio transport (e.g. 'python' or 'docker')",
60
+ )
61
+
62
+
63
+ class DataRobotMCPClientConfig(MCPClientConfig, name="datarobot_mcp_client"): # type: ignore[call-arg]
64
+ server: DataRobotMCPServerConfig = Field(
65
+ default=DataRobotMCPServerConfig(), description="DataRobot MCP Server configuration"
66
+ )
67
+
68
+
69
+ class DataRobotAuthAdapter(AuthAdapter):
70
+ async def _get_auth_headers(
71
+ self, request: httpx.Request | None = None, response: httpx.Response | None = None
72
+ ) -> dict[str, str]:
73
+ """Get authentication headers from the NAT auth provider."""
74
+ try:
75
+ # Use the user_id passed to this AuthAdapter instance
76
+ auth_result = await self.auth_provider.authenticate(
77
+ user_id=self.user_id, response=response
78
+ )
79
+ as_kwargs = auth_result.as_requests_kwargs()
80
+ return as_kwargs["headers"]
81
+ except Exception as e:
82
+ logger.warning("Failed to get auth token: %s", e)
83
+ return {}
84
+
85
+
86
+ class DataRobotMCPStreamableHTTPClient(MCPStreamableHTTPClient):
87
+ def __init__(
88
+ self,
89
+ url: str,
90
+ auth_provider: AuthProviderBase | None = None,
91
+ user_id: str | None = None,
92
+ tool_call_timeout: timedelta = timedelta(seconds=60),
93
+ auth_flow_timeout: timedelta = timedelta(seconds=300),
94
+ reconnect_enabled: bool = True,
95
+ reconnect_max_attempts: int = 2,
96
+ reconnect_initial_backoff: float = 0.5,
97
+ reconnect_max_backoff: float = 50.0,
98
+ ):
99
+ super().__init__(
100
+ url=url,
101
+ auth_provider=auth_provider,
102
+ user_id=user_id,
103
+ tool_call_timeout=tool_call_timeout,
104
+ auth_flow_timeout=auth_flow_timeout,
105
+ reconnect_enabled=reconnect_enabled,
106
+ reconnect_max_attempts=reconnect_max_attempts,
107
+ reconnect_initial_backoff=reconnect_initial_backoff,
108
+ reconnect_max_backoff=reconnect_max_backoff,
109
+ )
110
+ effective_user_id = user_id or (
111
+ auth_provider.config.default_user_id if auth_provider else None
112
+ )
113
+ self._httpx_auth = (
114
+ DataRobotAuthAdapter(auth_provider, effective_user_id) if auth_provider else None
115
+ )
116
+
117
+
118
+ @register_function_group(config_type=DataRobotMCPClientConfig)
119
+ async def datarobot_mcp_client_function_group(
120
+ config: DataRobotMCPClientConfig, _builder: Builder
121
+ ) -> MCPFunctionGroup:
122
+ """
123
+ Connect to an MCP server and expose tools as a function group.
124
+
125
+ Args:
126
+ config: The configuration for the MCP client
127
+ _builder: The builder
128
+ Returns:
129
+ The function group
130
+ """
131
+ # Resolve auth provider if specified
132
+ auth_provider = None
133
+ if config.server.auth_provider:
134
+ auth_provider = await _builder.get_auth_provider(config.server.auth_provider)
135
+
136
+ # Build the appropriate client
137
+ if config.server.transport == "stdio":
138
+ if not config.server.command:
139
+ raise ValueError("command is required for stdio transport")
140
+ client = MCPStdioClient(
141
+ config.server.command,
142
+ config.server.args,
143
+ config.server.env,
144
+ tool_call_timeout=config.tool_call_timeout,
145
+ auth_flow_timeout=config.auth_flow_timeout,
146
+ reconnect_enabled=config.reconnect_enabled,
147
+ reconnect_max_attempts=config.reconnect_max_attempts,
148
+ reconnect_initial_backoff=config.reconnect_initial_backoff,
149
+ reconnect_max_backoff=config.reconnect_max_backoff,
150
+ )
151
+ elif config.server.transport == "sse":
152
+ client = MCPSSEClient(
153
+ str(config.server.url),
154
+ tool_call_timeout=config.tool_call_timeout,
155
+ auth_flow_timeout=config.auth_flow_timeout,
156
+ reconnect_enabled=config.reconnect_enabled,
157
+ reconnect_max_attempts=config.reconnect_max_attempts,
158
+ reconnect_initial_backoff=config.reconnect_initial_backoff,
159
+ reconnect_max_backoff=config.reconnect_max_backoff,
160
+ )
161
+ elif config.server.transport == "streamable-http":
162
+ # Use default_user_id for the base client
163
+ base_user_id = auth_provider.config.default_user_id if auth_provider else None
164
+ client = DataRobotMCPStreamableHTTPClient(
165
+ str(config.server.url),
166
+ auth_provider=auth_provider,
167
+ user_id=base_user_id,
168
+ tool_call_timeout=config.tool_call_timeout,
169
+ auth_flow_timeout=config.auth_flow_timeout,
170
+ reconnect_enabled=config.reconnect_enabled,
171
+ reconnect_max_attempts=config.reconnect_max_attempts,
172
+ reconnect_initial_backoff=config.reconnect_initial_backoff,
173
+ reconnect_max_backoff=config.reconnect_max_backoff,
174
+ )
175
+ else:
176
+ raise ValueError(f"Unsupported transport: {config.server.transport}")
177
+
178
+ logger.info("Configured to use MCP server at %s", client.server_name)
179
+
180
+ # Create the MCP function group
181
+ group = MCPFunctionGroup(config=config)
182
+
183
+ # Store shared components for session client creation
184
+ group._shared_auth_provider = auth_provider
185
+ group._client_config = config
186
+
187
+ async with client:
188
+ # Expose the live MCP client on the function group instance so other components
189
+ # (e.g., HTTP endpoints) can reuse the already-established session instead of creating a
190
+ # new client per request.
191
+ group.mcp_client = client
192
+ group.mcp_client_server_name = client.server_name
193
+ group.mcp_client_transport = client.transport
194
+
195
+ all_tools = await client.get_tools()
196
+ tool_overrides = mcp_apply_tool_alias_and_description(all_tools, config.tool_overrides)
197
+
198
+ # Add each tool as a function to the group
199
+ for tool_name, tool in all_tools.items():
200
+ # Get override if it exists
201
+ override = tool_overrides.get(tool_name)
202
+
203
+ # Use override values or defaults
204
+ function_name = override.alias if override and override.alias else tool_name
205
+ description = (
206
+ override.description if override and override.description else tool.description
207
+ )
208
+
209
+ # Create the tool function according to configuration
210
+ tool_fn = mcp_session_tool_function(tool, group)
211
+
212
+ # Normalize optional typing for linter/type-checker compatibility
213
+ single_fn = tool_fn.single_fn
214
+ if single_fn is None:
215
+ # Should not happen because FunctionInfo always sets a single_fn
216
+ logger.warning("Skipping tool %s because single_fn is None", function_name)
217
+ continue
218
+
219
+ input_schema = tool_fn.input_schema
220
+ # Convert NoneType sentinel to None for FunctionGroup.add_function signature
221
+ if input_schema is type(None): # noqa: E721
222
+ input_schema = None
223
+
224
+ # Add to group
225
+ logger.info("Adding tool %s to group", function_name)
226
+ group.add_function(
227
+ name=function_name,
228
+ description=description,
229
+ fn=single_fn,
230
+ input_schema=input_schema,
231
+ converters=tool_fn.converters,
232
+ )
233
+
234
+ yield group
File without changes
File without changes