mcp-server-rc 0.1.0__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.
- mcp_server_rc/__init__.py +1 -0
- mcp_server_rc/client/__init__.py +4 -0
- mcp_server_rc/client/rc_client.py +569 -0
- mcp_server_rc/main.py +13 -0
- mcp_server_rc/server.py +7 -0
- mcp_server_rc/service/__init__.py +4 -0
- mcp_server_rc/service/resource_service.py +486 -0
- mcp_server_rc/tools/__init__.py +4 -0
- mcp_server_rc/tools/resource.py +538 -0
- mcp_server_rc-0.1.0.dist-info/METADATA +236 -0
- mcp_server_rc-0.1.0.dist-info/RECORD +13 -0
- mcp_server_rc-0.1.0.dist-info/WHEEL +4 -0
- mcp_server_rc-0.1.0.dist-info/entry_points.txt +2 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""MCP Server for Huawei Cloud RC (Resource Center)."""
|
|
@@ -0,0 +1,569 @@
|
|
|
1
|
+
"""Thin SDK wrapper for huaweicloudsdkrc. No business logic here.
|
|
2
|
+
|
|
3
|
+
SDK imports are lazy (inside the constructor and each method) so this module
|
|
4
|
+
can be imported without the SDK installed — this lets the service/tools test
|
|
5
|
+
layers inject fakes and run without `huaweicloudsdkrc` present. Real calls
|
|
6
|
+
(only reached when no fake is injected) require `uv sync` to install the SDK.
|
|
7
|
+
The SDK ships without type stubs; a mypy override in pyproject.toml silences
|
|
8
|
+
the resulting import-untyped diagnostics (spec §11.2).
|
|
9
|
+
|
|
10
|
+
The RC service is a *global* service: the region maps to the global endpoint
|
|
11
|
+
``https://rc.myhuaweicloud.com`` and authentication uses AK/SK signing only
|
|
12
|
+
(no project_id needed), so credentials use `CredentialScope.GLOBAL`.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
import asyncio
|
|
18
|
+
from typing import Any, cast
|
|
19
|
+
|
|
20
|
+
from huaweicloud_mcp_core.config import McpSettings
|
|
21
|
+
from huaweicloud_mcp_core.credentials import CredentialScope, build_credentials
|
|
22
|
+
from huaweicloud_mcp_core.errors import McpToolError, wrap_sdk_error
|
|
23
|
+
from huaweicloudsdkcore.exceptions.exceptions import ServiceResponseException
|
|
24
|
+
|
|
25
|
+
_SKIP_ATTRS = {"local_vars_configuration", "discriminator", "swagger_types"}
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def sdk_to_dict(obj: Any) -> Any:
|
|
29
|
+
"""Recursively convert an SDK response object into plain JSON-compatible data."""
|
|
30
|
+
result: Any
|
|
31
|
+
if obj is None or isinstance(obj, (str, int, float, bool)):
|
|
32
|
+
result = obj
|
|
33
|
+
elif isinstance(obj, bytes):
|
|
34
|
+
result = obj.decode("utf-8", errors="replace")
|
|
35
|
+
elif isinstance(obj, dict):
|
|
36
|
+
result = {str(key): sdk_to_dict(value) for key, value in obj.items()}
|
|
37
|
+
elif isinstance(obj, (list, tuple)):
|
|
38
|
+
result = [sdk_to_dict(item) for item in obj]
|
|
39
|
+
elif hasattr(obj, "to_dict"):
|
|
40
|
+
result = {str(key).lstrip("_"): sdk_to_dict(value) for key, value in obj.to_dict().items()}
|
|
41
|
+
elif not hasattr(obj, "__dict__"):
|
|
42
|
+
result = str(obj)
|
|
43
|
+
else:
|
|
44
|
+
result = {}
|
|
45
|
+
for key, value in vars(obj).items():
|
|
46
|
+
if key in _SKIP_ATTRS or key.startswith("__") or callable(value):
|
|
47
|
+
continue
|
|
48
|
+
result[key.lstrip("_")] = sdk_to_dict(value)
|
|
49
|
+
return result
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def _not_found(exc: ServiceResponseException) -> bool:
|
|
53
|
+
return bool(exc.status_code == 404)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
_PERMISSION_HINT = (
|
|
57
|
+
"The AK/SK has no permission for this RC action. Grant the required IAM "
|
|
58
|
+
"policy (e.g. ResourceCenter ReadOnlyAccess/FullAccess or the specific "
|
|
59
|
+
"action) to the user and retry."
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def _is_permission_error(err: McpToolError) -> bool:
|
|
64
|
+
message = err.message or ""
|
|
65
|
+
return "not authorized" in message or "no identity-based policy" in message
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def _wrap_error(exc: ServiceResponseException) -> McpToolError:
|
|
69
|
+
err = wrap_sdk_error(exc)
|
|
70
|
+
if _is_permission_error(err):
|
|
71
|
+
err.hint = _PERMISSION_HINT
|
|
72
|
+
return err
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
class RcClient:
|
|
76
|
+
"""Async wrapper around the synchronous huaweicloudsdkrc client."""
|
|
77
|
+
|
|
78
|
+
def __init__(
|
|
79
|
+
self,
|
|
80
|
+
settings: McpSettings | None = None,
|
|
81
|
+
sdk_client: Any = None,
|
|
82
|
+
) -> None:
|
|
83
|
+
self._settings = settings or McpSettings.from_env(require_credentials=False)
|
|
84
|
+
if not self._settings.access_key or not self._settings.secret_key:
|
|
85
|
+
raise McpToolError(
|
|
86
|
+
code="MCP_INVALID_ARGS",
|
|
87
|
+
message=(
|
|
88
|
+
"Missing required environment variables: "
|
|
89
|
+
"HUAWEICLOUD_ACCESS_KEY, HUAWEICLOUD_SECRET_KEY."
|
|
90
|
+
),
|
|
91
|
+
hint=(
|
|
92
|
+
"Export HUAWEICLOUD_ACCESS_KEY and HUAWEICLOUD_SECRET_KEY "
|
|
93
|
+
"(see the Configuration section of the README). RC is a global "
|
|
94
|
+
"service and does not require HUAWEICLOUD_REGION."
|
|
95
|
+
),
|
|
96
|
+
)
|
|
97
|
+
if sdk_client is not None:
|
|
98
|
+
self._client = sdk_client
|
|
99
|
+
else:
|
|
100
|
+
from huaweicloudsdkrc.v1 import RcClient as _SdkRcClient
|
|
101
|
+
from huaweicloudsdkrc.v1.region.rc_region import RcRegion
|
|
102
|
+
|
|
103
|
+
self._client = (
|
|
104
|
+
_SdkRcClient.new_builder()
|
|
105
|
+
.with_credentials(build_credentials(CredentialScope.GLOBAL, self._settings))
|
|
106
|
+
.with_region(RcRegion.CN_NORTH_4)
|
|
107
|
+
.build()
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
# -- resource list -------------------------------------------------
|
|
111
|
+
|
|
112
|
+
async def list_all_resources(
|
|
113
|
+
self,
|
|
114
|
+
*,
|
|
115
|
+
region_id: str | None = None,
|
|
116
|
+
ep_id: str | None = None,
|
|
117
|
+
resource_type: str | None = None,
|
|
118
|
+
limit: int | None = None,
|
|
119
|
+
marker: str | None = None,
|
|
120
|
+
id_: str | None = None,
|
|
121
|
+
group_id: str | None = None,
|
|
122
|
+
name: str | None = None,
|
|
123
|
+
tags: list[str] | None = None,
|
|
124
|
+
) -> dict[str, Any]:
|
|
125
|
+
def _call() -> dict[str, Any]:
|
|
126
|
+
from huaweicloudsdkrc.v1.model.list_all_resources_request import ListAllResourcesRequest
|
|
127
|
+
|
|
128
|
+
request = ListAllResourcesRequest(
|
|
129
|
+
region_id=region_id,
|
|
130
|
+
ep_id=ep_id,
|
|
131
|
+
type=resource_type,
|
|
132
|
+
limit=limit,
|
|
133
|
+
marker=marker,
|
|
134
|
+
id=id_,
|
|
135
|
+
group_id=group_id,
|
|
136
|
+
name=name,
|
|
137
|
+
tags=tags,
|
|
138
|
+
)
|
|
139
|
+
try:
|
|
140
|
+
response = self._client.list_all_resources(request)
|
|
141
|
+
except ServiceResponseException as exc:
|
|
142
|
+
raise _wrap_error(exc) from exc
|
|
143
|
+
return cast(dict[str, Any], sdk_to_dict(response))
|
|
144
|
+
|
|
145
|
+
return await asyncio.to_thread(_call)
|
|
146
|
+
|
|
147
|
+
async def show_resource_detail(self, *, resource_id: str) -> dict[str, Any] | None:
|
|
148
|
+
def _call() -> dict[str, Any] | None:
|
|
149
|
+
from huaweicloudsdkrc.v1.model.show_resource_detail_request import (
|
|
150
|
+
ShowResourceDetailRequest,
|
|
151
|
+
)
|
|
152
|
+
|
|
153
|
+
request = ShowResourceDetailRequest(resource_id=resource_id)
|
|
154
|
+
try:
|
|
155
|
+
response = self._client.show_resource_detail(request)
|
|
156
|
+
except ServiceResponseException as exc:
|
|
157
|
+
if _not_found(exc):
|
|
158
|
+
return None
|
|
159
|
+
raise _wrap_error(exc) from exc
|
|
160
|
+
return cast(dict[str, Any], sdk_to_dict(response))
|
|
161
|
+
|
|
162
|
+
return await asyncio.to_thread(_call)
|
|
163
|
+
|
|
164
|
+
async def list_all_tags(
|
|
165
|
+
self,
|
|
166
|
+
*,
|
|
167
|
+
key: str | None = None,
|
|
168
|
+
marker: str | None = None,
|
|
169
|
+
limit: int | None = None,
|
|
170
|
+
) -> dict[str, Any]:
|
|
171
|
+
def _call() -> dict[str, Any]:
|
|
172
|
+
from huaweicloudsdkrc.v1.model.list_all_tags_request import ListAllTagsRequest
|
|
173
|
+
|
|
174
|
+
request = ListAllTagsRequest(key=key, marker=marker, limit=limit)
|
|
175
|
+
try:
|
|
176
|
+
response = self._client.list_all_tags(request)
|
|
177
|
+
except ServiceResponseException as exc:
|
|
178
|
+
raise _wrap_error(exc) from exc
|
|
179
|
+
return cast(dict[str, Any], sdk_to_dict(response))
|
|
180
|
+
|
|
181
|
+
return await asyncio.to_thread(_call)
|
|
182
|
+
|
|
183
|
+
async def count_all_resources(
|
|
184
|
+
self,
|
|
185
|
+
*,
|
|
186
|
+
id_: str | None = None,
|
|
187
|
+
name: str | None = None,
|
|
188
|
+
group_id: str | None = None,
|
|
189
|
+
resource_type: list[str] | None = None,
|
|
190
|
+
region_id: list[str] | None = None,
|
|
191
|
+
ep_id: list[str] | None = None,
|
|
192
|
+
project_id: list[str] | None = None,
|
|
193
|
+
tags: list[str] | None = None,
|
|
194
|
+
) -> dict[str, Any]:
|
|
195
|
+
def _call() -> dict[str, Any]:
|
|
196
|
+
from huaweicloudsdkrc.v1.model.count_all_resources_request import (
|
|
197
|
+
CountAllResourcesRequest,
|
|
198
|
+
)
|
|
199
|
+
|
|
200
|
+
request = CountAllResourcesRequest(
|
|
201
|
+
id=id_,
|
|
202
|
+
name=name,
|
|
203
|
+
type=resource_type,
|
|
204
|
+
region_id=region_id,
|
|
205
|
+
ep_id=ep_id,
|
|
206
|
+
project_id=project_id,
|
|
207
|
+
tags=tags,
|
|
208
|
+
)
|
|
209
|
+
if group_id is not None and "group_id" in getattr(
|
|
210
|
+
CountAllResourcesRequest, "openapi_types", {}
|
|
211
|
+
):
|
|
212
|
+
request.group_id = group_id
|
|
213
|
+
try:
|
|
214
|
+
response = self._client.count_all_resources(request)
|
|
215
|
+
except ServiceResponseException as exc:
|
|
216
|
+
raise _wrap_error(exc) from exc
|
|
217
|
+
return cast(dict[str, Any], sdk_to_dict(response))
|
|
218
|
+
|
|
219
|
+
return await asyncio.to_thread(_call)
|
|
220
|
+
|
|
221
|
+
async def collect_all_resources_summary(
|
|
222
|
+
self,
|
|
223
|
+
*,
|
|
224
|
+
name: str | None = None,
|
|
225
|
+
resource_type: list[str] | None = None,
|
|
226
|
+
region_id: list[str] | None = None,
|
|
227
|
+
ep_id: list[str] | None = None,
|
|
228
|
+
project_id: list[str] | None = None,
|
|
229
|
+
tags: list[str] | None = None,
|
|
230
|
+
) -> dict[str, Any]:
|
|
231
|
+
def _call() -> dict[str, Any]:
|
|
232
|
+
from huaweicloudsdkrc.v1.model.collect_all_resources_summary_request import (
|
|
233
|
+
CollectAllResourcesSummaryRequest,
|
|
234
|
+
)
|
|
235
|
+
|
|
236
|
+
request = CollectAllResourcesSummaryRequest(
|
|
237
|
+
name=name,
|
|
238
|
+
type=resource_type,
|
|
239
|
+
region_id=region_id,
|
|
240
|
+
ep_id=ep_id,
|
|
241
|
+
project_id=project_id,
|
|
242
|
+
tags=tags,
|
|
243
|
+
)
|
|
244
|
+
try:
|
|
245
|
+
response = self._client.collect_all_resources_summary(request)
|
|
246
|
+
except ServiceResponseException as exc:
|
|
247
|
+
raise _wrap_error(exc) from exc
|
|
248
|
+
return cast(dict[str, Any], sdk_to_dict(response))
|
|
249
|
+
|
|
250
|
+
return await asyncio.to_thread(_call)
|
|
251
|
+
|
|
252
|
+
async def list_providers(
|
|
253
|
+
self,
|
|
254
|
+
*,
|
|
255
|
+
offset: int | None = None,
|
|
256
|
+
limit: int | None = None,
|
|
257
|
+
x_language: str | None = None,
|
|
258
|
+
) -> dict[str, Any]:
|
|
259
|
+
def _call() -> dict[str, Any]:
|
|
260
|
+
from huaweicloudsdkrc.v1.model.list_all_providers_request import ListAllProvidersRequest
|
|
261
|
+
|
|
262
|
+
request = ListAllProvidersRequest(
|
|
263
|
+
offset=offset,
|
|
264
|
+
limit=limit,
|
|
265
|
+
x_language=x_language,
|
|
266
|
+
)
|
|
267
|
+
try:
|
|
268
|
+
response = self._client.list_all_providers(request)
|
|
269
|
+
except ServiceResponseException as exc:
|
|
270
|
+
raise _wrap_error(exc) from exc
|
|
271
|
+
return cast(dict[str, Any], sdk_to_dict(response))
|
|
272
|
+
|
|
273
|
+
return await asyncio.to_thread(_call)
|
|
274
|
+
|
|
275
|
+
# -- resource groups ----------------------------------------------------
|
|
276
|
+
|
|
277
|
+
async def create_resource_group(
|
|
278
|
+
self,
|
|
279
|
+
*,
|
|
280
|
+
group_name: str,
|
|
281
|
+
description: str | None = None,
|
|
282
|
+
) -> dict[str, Any]:
|
|
283
|
+
def _call() -> dict[str, Any]:
|
|
284
|
+
from huaweicloudsdkrc.v1.model.create_resource_group_request import (
|
|
285
|
+
CreateResourceGroupRequest,
|
|
286
|
+
)
|
|
287
|
+
from huaweicloudsdkrc.v1.model.generic_resource_group_request_body import (
|
|
288
|
+
GenericResourceGroupRequestBody,
|
|
289
|
+
)
|
|
290
|
+
|
|
291
|
+
body = GenericResourceGroupRequestBody(group_name=group_name, description=description)
|
|
292
|
+
request = CreateResourceGroupRequest(body=body)
|
|
293
|
+
try:
|
|
294
|
+
response = self._client.create_resource_group(request)
|
|
295
|
+
except ServiceResponseException as exc:
|
|
296
|
+
raise _wrap_error(exc) from exc
|
|
297
|
+
return cast(dict[str, Any], sdk_to_dict(response))
|
|
298
|
+
|
|
299
|
+
return await asyncio.to_thread(_call)
|
|
300
|
+
|
|
301
|
+
async def delete_resource_group(self, *, group_id: str) -> dict[str, Any]:
|
|
302
|
+
def _call() -> dict[str, Any]:
|
|
303
|
+
from huaweicloudsdkrc.v1.model.delete_resource_group_request import (
|
|
304
|
+
DeleteResourceGroupRequest,
|
|
305
|
+
)
|
|
306
|
+
|
|
307
|
+
request = DeleteResourceGroupRequest(group_id=group_id)
|
|
308
|
+
try:
|
|
309
|
+
response = self._client.delete_resource_group(request)
|
|
310
|
+
except ServiceResponseException as exc:
|
|
311
|
+
raise _wrap_error(exc) from exc
|
|
312
|
+
return cast(dict[str, Any], sdk_to_dict(response))
|
|
313
|
+
|
|
314
|
+
return await asyncio.to_thread(_call)
|
|
315
|
+
|
|
316
|
+
async def update_resource_group(
|
|
317
|
+
self,
|
|
318
|
+
*,
|
|
319
|
+
group_id: str,
|
|
320
|
+
description: str | None = None,
|
|
321
|
+
) -> dict[str, Any]:
|
|
322
|
+
def _call() -> dict[str, Any]:
|
|
323
|
+
from huaweicloudsdkrc.v1.model.update_resource_group_request import (
|
|
324
|
+
UpdateResourceGroupRequest,
|
|
325
|
+
)
|
|
326
|
+
from huaweicloudsdkrc.v1.model.update_resource_group_request_body import (
|
|
327
|
+
UpdateResourceGroupRequestBody,
|
|
328
|
+
)
|
|
329
|
+
|
|
330
|
+
body = UpdateResourceGroupRequestBody(description=description)
|
|
331
|
+
request = UpdateResourceGroupRequest(group_id=group_id, body=body)
|
|
332
|
+
try:
|
|
333
|
+
response = self._client.update_resource_group(request)
|
|
334
|
+
except ServiceResponseException as exc:
|
|
335
|
+
raise _wrap_error(exc) from exc
|
|
336
|
+
return cast(dict[str, Any], sdk_to_dict(response))
|
|
337
|
+
|
|
338
|
+
return await asyncio.to_thread(_call)
|
|
339
|
+
|
|
340
|
+
async def show_resource_group(self, *, group_id: str) -> dict[str, Any] | None:
|
|
341
|
+
def _call() -> dict[str, Any] | None:
|
|
342
|
+
from huaweicloudsdkrc.v1.model.show_resource_group_request import (
|
|
343
|
+
ShowResourceGroupRequest,
|
|
344
|
+
)
|
|
345
|
+
|
|
346
|
+
request = ShowResourceGroupRequest(group_id=group_id)
|
|
347
|
+
try:
|
|
348
|
+
response = self._client.show_resource_group(request)
|
|
349
|
+
except ServiceResponseException as exc:
|
|
350
|
+
if _not_found(exc):
|
|
351
|
+
return None
|
|
352
|
+
raise _wrap_error(exc) from exc
|
|
353
|
+
return cast(dict[str, Any], sdk_to_dict(response))
|
|
354
|
+
|
|
355
|
+
return await asyncio.to_thread(_call)
|
|
356
|
+
|
|
357
|
+
async def list_resource_groups(
|
|
358
|
+
self,
|
|
359
|
+
*,
|
|
360
|
+
limit: int | None = None,
|
|
361
|
+
marker: str | None = None,
|
|
362
|
+
) -> dict[str, Any]:
|
|
363
|
+
def _call() -> dict[str, Any]:
|
|
364
|
+
from huaweicloudsdkrc.v1.model.list_resource_groups_request import (
|
|
365
|
+
ListResourceGroupsRequest,
|
|
366
|
+
)
|
|
367
|
+
|
|
368
|
+
request = ListResourceGroupsRequest(limit=limit, marker=marker)
|
|
369
|
+
try:
|
|
370
|
+
response = self._client.list_resource_groups(request)
|
|
371
|
+
except ServiceResponseException as exc:
|
|
372
|
+
raise _wrap_error(exc) from exc
|
|
373
|
+
return cast(dict[str, Any], sdk_to_dict(response))
|
|
374
|
+
|
|
375
|
+
return await asyncio.to_thread(_call)
|
|
376
|
+
|
|
377
|
+
async def add_resources_to_group(
|
|
378
|
+
self,
|
|
379
|
+
*,
|
|
380
|
+
group_id: str,
|
|
381
|
+
resource_ids: list[str],
|
|
382
|
+
) -> dict[str, Any]:
|
|
383
|
+
def _call() -> dict[str, Any]:
|
|
384
|
+
from huaweicloudsdkrc.v1.model.add_resources_request_body import AddResourcesRequestBody
|
|
385
|
+
from huaweicloudsdkrc.v1.model.add_resources_to_group_request import (
|
|
386
|
+
AddResourcesToGroupRequest,
|
|
387
|
+
)
|
|
388
|
+
|
|
389
|
+
body = AddResourcesRequestBody(resource_ids=resource_ids)
|
|
390
|
+
request = AddResourcesToGroupRequest(group_id=group_id, body=body)
|
|
391
|
+
try:
|
|
392
|
+
response = self._client.add_resources_to_group(request)
|
|
393
|
+
except ServiceResponseException as exc:
|
|
394
|
+
raise _wrap_error(exc) from exc
|
|
395
|
+
return cast(dict[str, Any], sdk_to_dict(response))
|
|
396
|
+
|
|
397
|
+
return await asyncio.to_thread(_call)
|
|
398
|
+
|
|
399
|
+
async def remove_resource_from_group(
|
|
400
|
+
self,
|
|
401
|
+
*,
|
|
402
|
+
group_id: str,
|
|
403
|
+
resource_id: str,
|
|
404
|
+
) -> dict[str, Any]:
|
|
405
|
+
def _call() -> dict[str, Any]:
|
|
406
|
+
from huaweicloudsdkrc.v1.model.remove_resource_from_group_request import (
|
|
407
|
+
RemoveResourceFromGroupRequest,
|
|
408
|
+
)
|
|
409
|
+
|
|
410
|
+
request = RemoveResourceFromGroupRequest(group_id=group_id, resource_id=resource_id)
|
|
411
|
+
try:
|
|
412
|
+
response = self._client.remove_resource_from_group(request)
|
|
413
|
+
except ServiceResponseException as exc:
|
|
414
|
+
raise _wrap_error(exc) from exc
|
|
415
|
+
return cast(dict[str, Any], sdk_to_dict(response))
|
|
416
|
+
|
|
417
|
+
return await asyncio.to_thread(_call)
|
|
418
|
+
|
|
419
|
+
# -- resource relationships --------------------------------------------------
|
|
420
|
+
|
|
421
|
+
async def show_resource_relations(
|
|
422
|
+
self,
|
|
423
|
+
*,
|
|
424
|
+
resource_id: str,
|
|
425
|
+
related_resource_id: str | None = None,
|
|
426
|
+
related_resource_type: str | None = None,
|
|
427
|
+
limit: int | None = None,
|
|
428
|
+
marker: str | None = None,
|
|
429
|
+
) -> dict[str, Any]:
|
|
430
|
+
def _call() -> dict[str, Any]:
|
|
431
|
+
from huaweicloudsdkrc.v1.model.show_resource_relations_request import (
|
|
432
|
+
ShowResourceRelationsRequest,
|
|
433
|
+
)
|
|
434
|
+
|
|
435
|
+
request = ShowResourceRelationsRequest(
|
|
436
|
+
resource_id=resource_id,
|
|
437
|
+
related_resource_id=related_resource_id,
|
|
438
|
+
related_resource_type=related_resource_type,
|
|
439
|
+
limit=limit,
|
|
440
|
+
marker=marker,
|
|
441
|
+
)
|
|
442
|
+
try:
|
|
443
|
+
response = self._client.show_resource_relations(request)
|
|
444
|
+
except ServiceResponseException as exc:
|
|
445
|
+
raise _wrap_error(exc) from exc
|
|
446
|
+
return cast(dict[str, Any], sdk_to_dict(response))
|
|
447
|
+
|
|
448
|
+
return await asyncio.to_thread(_call)
|
|
449
|
+
|
|
450
|
+
# -- advanced queries ------------------------------------------------------
|
|
451
|
+
|
|
452
|
+
async def create_stored_query(
|
|
453
|
+
self,
|
|
454
|
+
*,
|
|
455
|
+
name: str,
|
|
456
|
+
expression: str,
|
|
457
|
+
description: str | None = None,
|
|
458
|
+
) -> dict[str, Any]:
|
|
459
|
+
def _call() -> dict[str, Any]:
|
|
460
|
+
from huaweicloudsdkrc.v1.model.create_stored_query_request import (
|
|
461
|
+
CreateStoredQueryRequest,
|
|
462
|
+
)
|
|
463
|
+
from huaweicloudsdkrc.v1.model.stored_query_request_body import StoredQueryRequestBody
|
|
464
|
+
|
|
465
|
+
body = StoredQueryRequestBody(name=name, description=description, expression=expression)
|
|
466
|
+
request = CreateStoredQueryRequest(body=body)
|
|
467
|
+
try:
|
|
468
|
+
response = self._client.create_stored_query(request)
|
|
469
|
+
except ServiceResponseException as exc:
|
|
470
|
+
raise _wrap_error(exc) from exc
|
|
471
|
+
return cast(dict[str, Any], sdk_to_dict(response))
|
|
472
|
+
|
|
473
|
+
return await asyncio.to_thread(_call)
|
|
474
|
+
|
|
475
|
+
async def list_stored_queries(
|
|
476
|
+
self,
|
|
477
|
+
*,
|
|
478
|
+
limit: int | None = None,
|
|
479
|
+
marker: str | None = None,
|
|
480
|
+
name: str | None = None,
|
|
481
|
+
) -> dict[str, Any]:
|
|
482
|
+
def _call() -> dict[str, Any]:
|
|
483
|
+
from huaweicloudsdkrc.v1.model.list_stored_queries_request import (
|
|
484
|
+
ListStoredQueriesRequest,
|
|
485
|
+
)
|
|
486
|
+
|
|
487
|
+
request = ListStoredQueriesRequest(limit=limit, marker=marker, name=name)
|
|
488
|
+
try:
|
|
489
|
+
response = self._client.list_stored_queries(request)
|
|
490
|
+
except ServiceResponseException as exc:
|
|
491
|
+
raise _wrap_error(exc) from exc
|
|
492
|
+
return cast(dict[str, Any], sdk_to_dict(response))
|
|
493
|
+
|
|
494
|
+
return await asyncio.to_thread(_call)
|
|
495
|
+
|
|
496
|
+
async def show_stored_query(self, *, query_id: str) -> dict[str, Any] | None:
|
|
497
|
+
def _call() -> dict[str, Any] | None:
|
|
498
|
+
from huaweicloudsdkrc.v1.model.show_stored_query_request import ShowStoredQueryRequest
|
|
499
|
+
|
|
500
|
+
request = ShowStoredQueryRequest(query_id=query_id)
|
|
501
|
+
try:
|
|
502
|
+
response = self._client.show_stored_query(request)
|
|
503
|
+
except ServiceResponseException as exc:
|
|
504
|
+
if _not_found(exc):
|
|
505
|
+
return None
|
|
506
|
+
raise _wrap_error(exc) from exc
|
|
507
|
+
return cast(dict[str, Any], sdk_to_dict(response))
|
|
508
|
+
|
|
509
|
+
return await asyncio.to_thread(_call)
|
|
510
|
+
|
|
511
|
+
async def update_stored_query(
|
|
512
|
+
self,
|
|
513
|
+
*,
|
|
514
|
+
query_id: str,
|
|
515
|
+
name: str,
|
|
516
|
+
expression: str,
|
|
517
|
+
description: str | None = None,
|
|
518
|
+
) -> dict[str, Any]:
|
|
519
|
+
def _call() -> dict[str, Any]:
|
|
520
|
+
from huaweicloudsdkrc.v1.model.stored_query_request_body import StoredQueryRequestBody
|
|
521
|
+
from huaweicloudsdkrc.v1.model.update_stored_query_request import (
|
|
522
|
+
UpdateStoredQueryRequest,
|
|
523
|
+
)
|
|
524
|
+
|
|
525
|
+
body = StoredQueryRequestBody(name=name, description=description, expression=expression)
|
|
526
|
+
request = UpdateStoredQueryRequest(query_id=query_id, body=body)
|
|
527
|
+
try:
|
|
528
|
+
response = self._client.update_stored_query(request)
|
|
529
|
+
except ServiceResponseException as exc:
|
|
530
|
+
raise _wrap_error(exc) from exc
|
|
531
|
+
return cast(dict[str, Any], sdk_to_dict(response))
|
|
532
|
+
|
|
533
|
+
return await asyncio.to_thread(_call)
|
|
534
|
+
|
|
535
|
+
async def delete_stored_query(self, *, query_id: str) -> dict[str, Any]:
|
|
536
|
+
def _call() -> dict[str, Any]:
|
|
537
|
+
from huaweicloudsdkrc.v1.model.delete_stored_query_request import (
|
|
538
|
+
DeleteStoredQueryRequest,
|
|
539
|
+
)
|
|
540
|
+
|
|
541
|
+
request = DeleteStoredQueryRequest(query_id=query_id)
|
|
542
|
+
try:
|
|
543
|
+
response = self._client.delete_stored_query(request)
|
|
544
|
+
except ServiceResponseException as exc:
|
|
545
|
+
raise _wrap_error(exc) from exc
|
|
546
|
+
return cast(dict[str, Any], sdk_to_dict(response))
|
|
547
|
+
|
|
548
|
+
return await asyncio.to_thread(_call)
|
|
549
|
+
|
|
550
|
+
async def run_query(self, *, expression: str) -> dict[str, Any]:
|
|
551
|
+
def _call() -> dict[str, Any]:
|
|
552
|
+
from huaweicloudsdkrc.v1.model.query_run_request_body import QueryRunRequestBody
|
|
553
|
+
from huaweicloudsdkrc.v1.model.run_query_request import RunQueryRequest
|
|
554
|
+
|
|
555
|
+
body = QueryRunRequestBody(expression=expression)
|
|
556
|
+
request = RunQueryRequest(body=body)
|
|
557
|
+
try:
|
|
558
|
+
response = self._client.run_query(request)
|
|
559
|
+
except ServiceResponseException as exc:
|
|
560
|
+
err = _wrap_error(exc)
|
|
561
|
+
if err.hint is None and exc.status_code >= 500:
|
|
562
|
+
err.hint = (
|
|
563
|
+
"The RC service failed to execute the query. Check the "
|
|
564
|
+
"ResourceQL syntax and retry with a simpler expression."
|
|
565
|
+
)
|
|
566
|
+
raise err from exc
|
|
567
|
+
return cast(dict[str, Any], sdk_to_dict(response))
|
|
568
|
+
|
|
569
|
+
return await asyncio.to_thread(_call)
|
mcp_server_rc/main.py
ADDED
mcp_server_rc/server.py
ADDED