datarobot-genai 0.2.9__py3-none-any.whl → 0.2.10__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/tools/clients/confluence.py +182 -0
- datarobot_genai/drmcp/tools/confluence/tools.py +68 -0
- {datarobot_genai-0.2.9.dist-info → datarobot_genai-0.2.10.dist-info}/METADATA +1 -1
- {datarobot_genai-0.2.9.dist-info → datarobot_genai-0.2.10.dist-info}/RECORD +8 -8
- {datarobot_genai-0.2.9.dist-info → datarobot_genai-0.2.10.dist-info}/WHEEL +0 -0
- {datarobot_genai-0.2.9.dist-info → datarobot_genai-0.2.10.dist-info}/entry_points.txt +0 -0
- {datarobot_genai-0.2.9.dist-info → datarobot_genai-0.2.10.dist-info}/licenses/AUTHORS +0 -0
- {datarobot_genai-0.2.9.dist-info → datarobot_genai-0.2.10.dist-info}/licenses/LICENSE +0 -0
|
@@ -12,3 +12,185 @@
|
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
|
|
15
|
+
"""Async client for interacting with Confluence Cloud REST API.
|
|
16
|
+
|
|
17
|
+
At the moment of creating this client, official Confluence SDK is not supporting async.
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
import logging
|
|
21
|
+
from http import HTTPStatus
|
|
22
|
+
from typing import Any
|
|
23
|
+
|
|
24
|
+
import httpx
|
|
25
|
+
from pydantic import BaseModel
|
|
26
|
+
from pydantic import Field
|
|
27
|
+
|
|
28
|
+
from .atlassian import ATLASSIAN_API_BASE
|
|
29
|
+
from .atlassian import get_atlassian_cloud_id
|
|
30
|
+
|
|
31
|
+
logger = logging.getLogger(__name__)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class ConfluencePage(BaseModel):
|
|
35
|
+
"""Pydantic model for Confluence page."""
|
|
36
|
+
|
|
37
|
+
page_id: str = Field(..., description="The unique page ID")
|
|
38
|
+
title: str = Field(..., description="Page title")
|
|
39
|
+
space_id: str = Field(..., description="Space ID where the page resides")
|
|
40
|
+
space_key: str | None = Field(None, description="Space key (if available)")
|
|
41
|
+
body: str = Field(..., description="Page content in storage format (HTML-like)")
|
|
42
|
+
|
|
43
|
+
def as_flat_dict(self) -> dict[str, Any]:
|
|
44
|
+
"""Return a flat dictionary representation of the page."""
|
|
45
|
+
return {
|
|
46
|
+
"page_id": self.page_id,
|
|
47
|
+
"title": self.title,
|
|
48
|
+
"space_id": self.space_id,
|
|
49
|
+
"space_key": self.space_key,
|
|
50
|
+
"body": self.body,
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
class ConfluenceClient:
|
|
55
|
+
"""
|
|
56
|
+
Client for interacting with Confluence API using OAuth access token.
|
|
57
|
+
|
|
58
|
+
At the moment of creating this client, official Confluence SDK is not supporting async.
|
|
59
|
+
"""
|
|
60
|
+
|
|
61
|
+
EXPAND_FIELDS = "body.storage,space"
|
|
62
|
+
|
|
63
|
+
def __init__(self, access_token: str) -> None:
|
|
64
|
+
"""
|
|
65
|
+
Initialize Confluence client with access token.
|
|
66
|
+
|
|
67
|
+
Args:
|
|
68
|
+
access_token: OAuth access token for Atlassian API
|
|
69
|
+
"""
|
|
70
|
+
self.access_token = access_token
|
|
71
|
+
self._client = httpx.AsyncClient(
|
|
72
|
+
headers={
|
|
73
|
+
"Authorization": f"Bearer {access_token}",
|
|
74
|
+
"Accept": "application/json",
|
|
75
|
+
"Content-Type": "application/json",
|
|
76
|
+
},
|
|
77
|
+
timeout=30.0,
|
|
78
|
+
)
|
|
79
|
+
self._cloud_id: str | None = None
|
|
80
|
+
|
|
81
|
+
async def _get_cloud_id(self) -> str:
|
|
82
|
+
"""
|
|
83
|
+
Get the cloud ID for the authenticated Atlassian Confluence instance.
|
|
84
|
+
|
|
85
|
+
According to Atlassian OAuth 2.0 documentation, API calls should use:
|
|
86
|
+
https://api.atlassian.com/ex/confluence/{cloudId}/wiki/rest/api/...
|
|
87
|
+
|
|
88
|
+
Returns
|
|
89
|
+
-------
|
|
90
|
+
Cloud ID string
|
|
91
|
+
|
|
92
|
+
Raises
|
|
93
|
+
------
|
|
94
|
+
ValueError: If cloud ID cannot be retrieved
|
|
95
|
+
"""
|
|
96
|
+
if self._cloud_id:
|
|
97
|
+
return self._cloud_id
|
|
98
|
+
|
|
99
|
+
self._cloud_id = await get_atlassian_cloud_id(self._client, service_type="confluence")
|
|
100
|
+
return self._cloud_id
|
|
101
|
+
|
|
102
|
+
def _parse_response(self, data: dict) -> ConfluencePage:
|
|
103
|
+
"""Parse API response into ConfluencePage."""
|
|
104
|
+
body_content = ""
|
|
105
|
+
body = data.get("body", {})
|
|
106
|
+
if isinstance(body, dict):
|
|
107
|
+
storage = body.get("storage", {})
|
|
108
|
+
if isinstance(storage, dict):
|
|
109
|
+
body_content = storage.get("value", "")
|
|
110
|
+
|
|
111
|
+
space = data.get("space", {})
|
|
112
|
+
space_key = space.get("key") if isinstance(space, dict) else None
|
|
113
|
+
space_id = space.get("id", "") if isinstance(space, dict) else data.get("spaceId", "")
|
|
114
|
+
|
|
115
|
+
return ConfluencePage(
|
|
116
|
+
page_id=str(data.get("id", "")),
|
|
117
|
+
title=data.get("title", ""),
|
|
118
|
+
space_id=str(space_id),
|
|
119
|
+
space_key=space_key,
|
|
120
|
+
body=body_content,
|
|
121
|
+
)
|
|
122
|
+
|
|
123
|
+
async def get_page_by_id(self, page_id: str) -> ConfluencePage:
|
|
124
|
+
"""
|
|
125
|
+
Get a Confluence page by its ID.
|
|
126
|
+
|
|
127
|
+
Args:
|
|
128
|
+
page_id: The numeric page ID
|
|
129
|
+
|
|
130
|
+
Returns
|
|
131
|
+
-------
|
|
132
|
+
ConfluencePage with page data
|
|
133
|
+
|
|
134
|
+
Raises
|
|
135
|
+
------
|
|
136
|
+
ValueError: If page is not found
|
|
137
|
+
httpx.HTTPStatusError: If the API request fails
|
|
138
|
+
"""
|
|
139
|
+
cloud_id = await self._get_cloud_id()
|
|
140
|
+
url = f"{ATLASSIAN_API_BASE}/ex/confluence/{cloud_id}/wiki/rest/api/content/{page_id}"
|
|
141
|
+
|
|
142
|
+
response = await self._client.get(url, params={"expand": self.EXPAND_FIELDS})
|
|
143
|
+
|
|
144
|
+
if response.status_code == HTTPStatus.NOT_FOUND:
|
|
145
|
+
raise ValueError(f"Page with ID '{page_id}' not found")
|
|
146
|
+
|
|
147
|
+
response.raise_for_status()
|
|
148
|
+
return self._parse_response(response.json())
|
|
149
|
+
|
|
150
|
+
async def get_page_by_title(self, title: str, space_key: str) -> ConfluencePage:
|
|
151
|
+
"""
|
|
152
|
+
Get a Confluence page by its title within a specific space.
|
|
153
|
+
|
|
154
|
+
Args:
|
|
155
|
+
title: The exact page title
|
|
156
|
+
space_key: The space key where the page resides
|
|
157
|
+
|
|
158
|
+
Returns
|
|
159
|
+
-------
|
|
160
|
+
ConfluencePage with page data
|
|
161
|
+
|
|
162
|
+
Raises
|
|
163
|
+
------
|
|
164
|
+
ValueError: If the page is not found
|
|
165
|
+
httpx.HTTPStatusError: If the API request fails
|
|
166
|
+
"""
|
|
167
|
+
cloud_id = await self._get_cloud_id()
|
|
168
|
+
url = f"{ATLASSIAN_API_BASE}/ex/confluence/{cloud_id}/wiki/rest/api/content"
|
|
169
|
+
|
|
170
|
+
response = await self._client.get(
|
|
171
|
+
url,
|
|
172
|
+
params={
|
|
173
|
+
"title": title,
|
|
174
|
+
"spaceKey": space_key,
|
|
175
|
+
"expand": self.EXPAND_FIELDS,
|
|
176
|
+
},
|
|
177
|
+
)
|
|
178
|
+
response.raise_for_status()
|
|
179
|
+
|
|
180
|
+
data = response.json()
|
|
181
|
+
results = data.get("results", [])
|
|
182
|
+
|
|
183
|
+
if not results:
|
|
184
|
+
raise ValueError(f"Page with title '{title}' not found in space '{space_key}'")
|
|
185
|
+
|
|
186
|
+
return self._parse_response(results[0])
|
|
187
|
+
|
|
188
|
+
async def __aenter__(self) -> "ConfluenceClient":
|
|
189
|
+
"""Async context manager entry."""
|
|
190
|
+
return self
|
|
191
|
+
|
|
192
|
+
async def __aexit__(
|
|
193
|
+
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: Any
|
|
194
|
+
) -> None:
|
|
195
|
+
"""Async context manager exit."""
|
|
196
|
+
await self._client.aclose()
|
|
@@ -11,3 +11,71 @@
|
|
|
11
11
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
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
|
+
)
|
|
@@ -76,11 +76,11 @@ datarobot_genai/drmcp/test_utils/utils.py,sha256=esGKFv8aO31-Qg3owayeWp32BYe1CdY
|
|
|
76
76
|
datarobot_genai/drmcp/tools/__init__.py,sha256=0kq9vMkF7EBsS6lkEdiLibmUrghTQqosHbZ5k-V9a5g,578
|
|
77
77
|
datarobot_genai/drmcp/tools/clients/__init__.py,sha256=0kq9vMkF7EBsS6lkEdiLibmUrghTQqosHbZ5k-V9a5g,578
|
|
78
78
|
datarobot_genai/drmcp/tools/clients/atlassian.py,sha256=__M_uz7FrcbKCYRzeMn24DCEYD6OmFx_LuywHCxgXsA,6472
|
|
79
|
-
datarobot_genai/drmcp/tools/clients/confluence.py,sha256=
|
|
79
|
+
datarobot_genai/drmcp/tools/clients/confluence.py,sha256=gbVxeBe7RDEEQt5UMGGW6GoAXsYLhL009dOejYIaIiQ,6325
|
|
80
80
|
datarobot_genai/drmcp/tools/clients/jira.py,sha256=JjvssdMAWgZ3HWZkQg0a3HjpE7yz7jfRtzO4LOp47Uw,3080
|
|
81
81
|
datarobot_genai/drmcp/tools/clients/s3.py,sha256=GmwzvurFdNfvxOooA8g5S4osRysHYU0S9ypg_177Glg,953
|
|
82
82
|
datarobot_genai/drmcp/tools/confluence/__init__.py,sha256=0kq9vMkF7EBsS6lkEdiLibmUrghTQqosHbZ5k-V9a5g,578
|
|
83
|
-
datarobot_genai/drmcp/tools/confluence/tools.py,sha256=
|
|
83
|
+
datarobot_genai/drmcp/tools/confluence/tools.py,sha256=t5OqXIhUm6y9bAWymyqwEMElwTxGw1xRnkW2MgJrNF8,3106
|
|
84
84
|
datarobot_genai/drmcp/tools/jira/__init__.py,sha256=0kq9vMkF7EBsS6lkEdiLibmUrghTQqosHbZ5k-V9a5g,578
|
|
85
85
|
datarobot_genai/drmcp/tools/jira/tools.py,sha256=EBf8T_VwKXNticorRN8ut9ktEMS0XFeb0Uj_6TKwMio,2191
|
|
86
86
|
datarobot_genai/drmcp/tools/predictive/__init__.py,sha256=WuOHlNNEpEmcF7gVnhckruJRKU2qtmJLE3E7zoCGLDo,1030
|
|
@@ -105,9 +105,9 @@ datarobot_genai/nat/datarobot_auth_provider.py,sha256=Z4NSsrHxK8hUeiqtK_lryHsUuZ
|
|
|
105
105
|
datarobot_genai/nat/datarobot_llm_clients.py,sha256=STzAZ4OF8U-Y_cUTywxmKBGVotwsnbGP6vTojnu6q0g,9921
|
|
106
106
|
datarobot_genai/nat/datarobot_llm_providers.py,sha256=aDoQcTeGI-odqydPXEX9OGGNFbzAtpqzTvHHEkmJuEQ,4963
|
|
107
107
|
datarobot_genai/nat/datarobot_mcp_client.py,sha256=35FzilxNp4VqwBYI0NsOc91-xZm1C-AzWqrOdDy962A,9612
|
|
108
|
-
datarobot_genai-0.2.
|
|
109
|
-
datarobot_genai-0.2.
|
|
110
|
-
datarobot_genai-0.2.
|
|
111
|
-
datarobot_genai-0.2.
|
|
112
|
-
datarobot_genai-0.2.
|
|
113
|
-
datarobot_genai-0.2.
|
|
108
|
+
datarobot_genai-0.2.10.dist-info/METADATA,sha256=AYl5uILzc_myorpYgMkAhbm6BZIGQaaHuMNQik6rdCE,6173
|
|
109
|
+
datarobot_genai-0.2.10.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
|
|
110
|
+
datarobot_genai-0.2.10.dist-info/entry_points.txt,sha256=jEW3WxDZ8XIK9-ISmTyt5DbmBb047rFlzQuhY09rGrM,284
|
|
111
|
+
datarobot_genai-0.2.10.dist-info/licenses/AUTHORS,sha256=isJGUXdjq1U7XZ_B_9AH8Qf0u4eX0XyQifJZ_Sxm4sA,80
|
|
112
|
+
datarobot_genai-0.2.10.dist-info/licenses/LICENSE,sha256=U2_VkLIktQoa60Nf6Tbt7E4RMlfhFSjWjcJJfVC-YCE,11341
|
|
113
|
+
datarobot_genai-0.2.10.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|