alibaba-cloud-ops-mcp-server 0.8.9__py3-none-any.whl → 0.9.1__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.
@@ -47,9 +47,16 @@ class ApiMetaClient:
47
47
  @classmethod
48
48
  def get_service_version(cls, service):
49
49
  data = cls.get_response_from_pop_api(cls.GET_PRODUCT_LIST)
50
- version = next((item.get(DEFAULT_VERSION) for item in data if item.get(CODE).lower() == service), None)
50
+ version = next((item.get(DEFAULT_VERSION) for item in data if item.get(CODE).lower() == service.lower()), None)
51
51
  return version
52
52
 
53
+ @classmethod
54
+ def get_all_service_info(cls):
55
+ data = cls.get_response_from_pop_api(cls.GET_PRODUCT_LIST)
56
+ filtered_data = [{"code": item["code"], "name": item["name"]} for item in data]
57
+
58
+ return filtered_data
59
+
53
60
  @classmethod
54
61
  def get_service_style(cls, service):
55
62
  data = cls.get_response_from_pop_api(cls.GET_PRODUCT_LIST)
@@ -147,7 +154,8 @@ class ApiMetaClient:
147
154
  return combined_params
148
155
 
149
156
  @classmethod
150
- def get_apis_in_service(cls, service, version):
157
+ def get_apis_in_service(cls, service):
158
+ version = cls.get_service_version(service)
151
159
  data = cls.get_response_from_pop_api(cls.GET_API_OVERVIEW, service=service, version=version)
152
160
  apis = list(data[APIS].keys())
153
161
  return apis
@@ -0,0 +1,134 @@
1
+ ## Optimized Prompt
2
+
3
+ When a user submits a request, analyze their needs and check if matching tools exist. If yes, use them directly. If not, proceed to the retrieval phase.
4
+
5
+ ---
6
+
7
+ ## Request Flow
8
+
9
+ 1. **Analysis & Selection**
10
+ - Analyze user intent
11
+ - Choose between specific tools or common API flow
12
+ - Verify service support
13
+
14
+ 2. **API Flow** (if no specific tool)
15
+ - Identify service
16
+ - Select API via `ListAPIs`
17
+ - Get params via `GetAPIInfo`
18
+ - Execute via `CommonAPICaller`
19
+
20
+ 3. **Error Handling**
21
+ - Service not supported: "Unfortunately, we currently do not support this service"
22
+ - API failures: Check error code, params, permissions
23
+ - Param validation: Verify types and formats
24
+
25
+ ---
26
+
27
+ ### Retrieval Phase
28
+
29
+ 1. **Service Selection**
30
+
31
+ Supported Services:
32
+ - ecs: Elastic Compute Service (ECS)
33
+ - oos: Operations Orchestration Service (OOS)
34
+ - rds: Relational Database Service (RDS)
35
+ - vpc: Virtual Private Cloud (VPC)
36
+ - slb: Server Load Balancer (SLB)
37
+ - ess: Elastic Scaling (ESS)
38
+ - ros: Resource Orchestration Service (ROS)
39
+ - cbn: Cloud Enterprise Network (CBN)
40
+ - dds: MongoDB Database Service (DDS)
41
+ - r-kvstore: Cloud database Tair (compatible with Redis) (R-KVStore)
42
+
43
+ 2. **API Process**
44
+ - Use `ListAPIs` for available APIs
45
+ - Use `GetAPIInfo` for API details
46
+ - Use `CommonAPICaller` to execute
47
+
48
+ ---
49
+
50
+ ### Notes
51
+ - Filter for most appropriate result
52
+ - Choose based on user context and common usage
53
+ - Validate parameters before calls
54
+ - Handle errors gracefully
55
+
56
+ ---
57
+
58
+ ### Common Scenarios
59
+
60
+ 1. **Instance Management**
61
+ ```
62
+ User: "Start ECS instance i-1234567890abcdef0"
63
+ Action: Use OOS_StartInstances
64
+ ```
65
+
66
+ 2. **Monitoring**
67
+ ```
68
+ User: "Check ECS CPU usage"
69
+ Action: Use CMS_GetCpuUsageData
70
+ ```
71
+
72
+ 3. **Custom API**
73
+ ```
74
+ User: "Create VPC in cn-hangzhou"
75
+ Action: ListAPIs → GetAPIInfo → CommonAPICaller
76
+ ```
77
+
78
+ ---
79
+
80
+ ## Available Tools
81
+
82
+ ### ECS (OOS/API)
83
+ - RunCommand: Execute commands on instances
84
+ - StartInstances: Start ECS instances
85
+ - StopInstances: Stop ECS instances
86
+ - RebootInstances: Reboot ECS instances
87
+ - DescribeInstances: List instance details
88
+ - DescribeRegions: List available regions
89
+ - DescribeZones: List available zones
90
+ - DescribeAvailableResource: Check resource inventory
91
+ - DescribeImages: List available images
92
+ - DescribeSecurityGroups: List security groups
93
+ - RunInstances: Create new instances
94
+ - DeleteInstances: Delete instances
95
+ - ResetPassword: Change instance password
96
+ - ReplaceSystemDisk: Change instance OS
97
+
98
+ ### VPC (API)
99
+ - DescribeVpcs: List VPCs
100
+ - DescribeVSwitches: List VSwitches
101
+
102
+ ### RDS (OOS/API)
103
+ - DescribeDBInstances: List database instances
104
+ - StartDBInstances: Start RDS instances
105
+ - StopDBInstances: Stop RDS instances
106
+ - RestartDBInstances: Restart RDS instances
107
+
108
+ ### OSS (API)
109
+ - ListBuckets: List OSS buckets
110
+ - PutBucket: Create bucket
111
+ - DeleteBucket: Delete bucket
112
+ - ListObjects: List bucket contents
113
+
114
+ ### CloudMonitor (API)
115
+ - GetCpuUsageData: Get instance CPU usage
116
+ - GetCpuLoadavgData: Get 1m CPU load
117
+ - GetCpuloadavg5mData: Get 5m CPU load
118
+ - GetCpuloadavg15mData: Get 15m CPU load
119
+ - GetMemUsedData: Get memory usage
120
+ - GetMemUsageData: Get memory utilization
121
+ - GetDiskUsageData: Get disk utilization
122
+ - GetDiskTotalData: Get total disk space
123
+ - GetDiskUsedData: Get used disk space
124
+
125
+ Note: (OOS) = Operations Orchestration Service, (API) = Direct API call
126
+
127
+ ---
128
+
129
+ ### Best Practices
130
+ - Use pre-defined tools when possible
131
+ - Follow API rate limits
132
+ - Implement proper error handling
133
+ - Validate all parameters
134
+ - Use appropriate endpoints
@@ -0,0 +1,8 @@
1
+ from importlib import resources
2
+
3
+ with (
4
+ resources.files('alibaba_cloud_ops_mcp_server.alibabacloud.static')
5
+ .joinpath('PROMPT_UNDERSTANDING.md')
6
+ .open('r', encoding='utf-8') as f
7
+ ):
8
+ PROMPT_UNDERSTANDING = f.read()
@@ -1,9 +1,46 @@
1
+ import logging
2
+
1
3
  from alibabacloud_credentials.client import Client as CredClient
2
4
  from alibabacloud_tea_openapi.models import Config
5
+ from fastmcp.server.dependencies import get_http_request
6
+
7
+ logger = logging.getLogger(__name__)
8
+
9
+
10
+ def get_credentials_from_header():
11
+ credentials = None
12
+ try:
13
+ request = get_http_request()
14
+ headers = request.headers
15
+ access_key_id = headers.get('x-acs-accesskey-id', None)
16
+ access_key_secret = headers.get('x-acs-accesskey-secret', None)
17
+ token = headers.get('x-acs-security-token', None)
18
+
19
+ if access_key_id:
20
+ credentials = {
21
+ 'AccessKeyId': access_key_id,
22
+ 'AccessKeySecret': access_key_secret,
23
+ 'SecurityToken': token
24
+ }
25
+
26
+ except Exception as e:
27
+ logger.info(f'get_credentials_from_header error: {e}')
28
+ return credentials
3
29
 
4
30
 
5
31
  def create_config():
6
- credentialsClient = CredClient()
7
- config = Config(credential=credentialsClient)
32
+ credentials = get_credentials_from_header()
33
+ if credentials:
34
+ access_key_id = credentials.get('AccessKeyId', None)
35
+ access_key_secret = credentials.get('AccessKeySecret', None)
36
+ token = credentials.get('SecurityToken', None)
37
+ config = Config(
38
+ access_key_id=access_key_id,
39
+ access_key_secret=access_key_secret,
40
+ security_token=token
41
+ )
42
+ else:
43
+ credentialsClient = CredClient()
44
+ config = Config(credential=credentialsClient)
8
45
  config.user_agent = 'alibaba-cloud-ops-mcp-server'
9
46
  return config
@@ -21,7 +21,7 @@ config = {
21
21
  ],
22
22
  'rds': [
23
23
  'DescribeDBInstances'
24
- ],
24
+ ]
25
25
  }
26
26
 
27
27
 
@@ -1,12 +1,26 @@
1
- from mcp.server.fastmcp import FastMCP
1
+ from fastmcp import FastMCP
2
2
  import click
3
3
  import logging
4
4
 
5
+ from alibaba_cloud_ops_mcp_server.tools.common_api_tools import set_custom_service_list
5
6
  from alibaba_cloud_ops_mcp_server.config import config
6
- from alibaba_cloud_ops_mcp_server.tools import cms_tools, oos_tools, oss_tools, api_tools
7
+ from alibaba_cloud_ops_mcp_server.tools import cms_tools, oos_tools, oss_tools, api_tools, common_api_tools
7
8
 
8
9
  logger = logging.getLogger(__name__)
9
10
 
11
+ SUPPORTED_SERVICES_MAP = {
12
+ "ecs": "Elastic Compute Service (ECS)",
13
+ "oos": "Operations Orchestration Service (OOS)",
14
+ "rds": "Relational Database Service (RDS)",
15
+ "vpc": "Virtual Private Cloud (VPC)",
16
+ "slb": "Server Load Balancer (SLB)",
17
+ "ess": "Elastic Scaling (ESS)",
18
+ "ros": "Resource Orchestration Service (ROS)",
19
+ "cbn": "Cloud Enterprise Network (CBN)",
20
+ "dds": "MongoDB Database Service (DDS)",
21
+ "r-kvstore": "Cloud database Tair (compatible with Redis) (R-KVStore)"
22
+ }
23
+
10
24
 
11
25
  @click.command()
12
26
  @click.option(
@@ -27,19 +41,32 @@ logger = logging.getLogger(__name__)
27
41
  default="127.0.0.1",
28
42
  help="Host",
29
43
  )
30
- def main(transport: str, port: int, host: str):
44
+ @click.option(
45
+ "--services",
46
+ type=str,
47
+ default=None,
48
+ help="Comma-separated list of supported services, e.g., 'ecs,vpc,rds'",
49
+ )
50
+ def main(transport: str, port: int, host: str, services: str):
31
51
  # Create an MCP server
32
52
  mcp = FastMCP(
33
53
  name="alibaba-cloud-ops-mcp-server",
34
54
  port=port,
35
55
  host=host
36
56
  )
57
+
58
+ if services:
59
+ service_keys = [s.strip().lower() for s in services.split(",")]
60
+ service_list = [(key, SUPPORTED_SERVICES_MAP.get(key, key)) for key in service_keys]
61
+ set_custom_service_list(service_list)
62
+ for tool in common_api_tools.tools:
63
+ mcp.tool(tool)
37
64
  for tool in oos_tools.tools:
38
- mcp.add_tool(tool)
65
+ mcp.tool(tool)
39
66
  for tool in cms_tools.tools:
40
- mcp.add_tool(tool)
67
+ mcp.tool(tool)
41
68
  for tool in oss_tools.tools:
42
- mcp.add_tool(tool)
69
+ mcp.tool(tool)
43
70
  api_tools.create_api_tools(mcp, config)
44
71
 
45
72
  # Initialize and run the server
@@ -24,12 +24,38 @@ type_map = {
24
24
  'number': float
25
25
  }
26
26
 
27
+ REGION_ENDPOINT_SERVICE = ['ecs', 'oos', 'vpc', 'slb']
28
+
29
+ DOUBLE_ENDPOINT_SERVICE = {
30
+ 'rds': ['cn-qingdao', 'cn-beijing', 'cn-hangzhou', 'cn-shanghai', 'cn-shenzhen', 'cn-heyuan', 'cn-guangzhou', 'cn-hongkong'],
31
+ 'ess': ['cn-qingdao', 'cn-beijing', 'cn-hangzhou', 'cn-shanghai', 'cn-nanjing', 'cn-shenzhen'],
32
+ 'ros': ['cn-qingdao'],
33
+ 'dds': ['cn-qingdao', 'cn-beijing', 'cn-wulanchabu', 'cn-hangzhou', 'cn-shanghai', 'cn-shenzhen', 'cn-heyuan', 'cn-guangzhou'],
34
+ 'r-kvstore': ['cn-qingdao', 'cn-beijing', 'cn-wulanchabu', 'cn-hangzhou', 'cn-shanghai', 'cn-shenzhen', 'cn-heyuan']
35
+ }
36
+
37
+ CENTRAL_ENDPOINTS_SERVICE = ['cbn']
38
+
39
+
40
+ def _get_service_endpoint(service: str, region_id: str):
41
+ region_id = region_id.lower()
42
+ use_region_endpoint = service in REGION_ENDPOINT_SERVICE or (
43
+ service in DOUBLE_ENDPOINT_SERVICE and region_id in DOUBLE_ENDPOINT_SERVICE[service]
44
+ )
45
+
46
+ if use_region_endpoint:
47
+ return f'{service}.{region_id}.aliyuncs.com'
48
+ elif service in CENTRAL_ENDPOINTS_SERVICE or service in DOUBLE_ENDPOINT_SERVICE:
49
+ return f'{service}.aliyuncs.com'
50
+ else:
51
+ return f'{service}.{region_id}.aliyuncs.com'
52
+
27
53
 
28
54
  def create_client(service: str, region_id: str) -> OpenApiClient:
29
55
  config = create_config()
30
56
  if isinstance(service, str):
31
57
  service = service.lower()
32
- config.endpoint = f'{service}.{region_id}.aliyuncs.com'
58
+ config.endpoint = _get_service_endpoint(service, region_id.lower())
33
59
  return OpenApiClient(config)
34
60
 
35
61
 
@@ -84,24 +110,37 @@ def _create_function_schemas(service, api, api_meta):
84
110
  schemas = {}
85
111
  schemas[api] = {}
86
112
  parameters = api_meta.get('parameters', [])
113
+
114
+ required_params = []
115
+ optional_params = []
116
+
87
117
  for parameter in parameters:
88
118
  name = parameter.get('name')
89
119
  # TODO 目前忽略了带'.'的参数
90
120
  if '.' in name:
91
121
  continue
92
122
  schema = parameter.get('schema', '')
123
+ required = schema.get('required', False)
124
+
125
+ if required:
126
+ required_params.append(parameter)
127
+ else:
128
+ optional_params.append(parameter)
129
+
130
+ def process_parameter(parameter):
131
+ name = parameter.get('name')
132
+ schema = parameter.get('schema', '')
93
133
  description = schema.get('description', '')
94
134
  example = schema.get('example', '')
95
135
  type_ = schema.get('type', '')
96
136
  description = f'{description} 参数类型: {type_},参数示例:{example}'
97
137
  required = schema.get('required', False)
98
-
99
- # 只有在service为ecs时,才对特定参数进行特殊处理
138
+
100
139
  if service.lower() == 'ecs' and name in ECS_LIST_PARAMETERS and type_ == 'string':
101
140
  python_type = list
102
141
  else:
103
142
  python_type = type_map.get(type_, str)
104
-
143
+
105
144
  field_info = (
106
145
  python_type,
107
146
  field(
@@ -109,7 +148,16 @@ def _create_function_schemas(service, api, api_meta):
109
148
  metadata={'description': description, 'required': required}
110
149
  )
111
150
  )
151
+ return name, field_info
152
+
153
+ for parameter in required_params:
154
+ name, field_info = process_parameter(parameter)
112
155
  schemas[api][name] = field_info
156
+
157
+ for parameter in optional_params:
158
+ name, field_info = process_parameter(parameter)
159
+ schemas[api][name] = field_info
160
+
113
161
  if 'RegionId' not in schemas[api]:
114
162
  schemas[api]['RegionId'] = (
115
163
  str,
@@ -37,8 +37,8 @@ def _get_cms_metric_data(region_id: str, instance_ids: List[str], metric_name: s
37
37
 
38
38
  @tools.append
39
39
  def CMS_GetCpuUsageData(
40
- RegionId: str = Field(description='AlibabaCloud region ID', default='cn-hangzhou'),
41
40
  InstanceIds: List[str] = Field(description='AlibabaCloud ECS instance ID List'),
41
+ RegionId: str = Field(description='AlibabaCloud region ID', default='cn-hangzhou')
42
42
  ):
43
43
  """获取ECS实例的CPU使用率数据"""
44
44
  return _get_cms_metric_data(RegionId, InstanceIds, 'cpu_total')
@@ -46,8 +46,8 @@ def CMS_GetCpuUsageData(
46
46
 
47
47
  @tools.append
48
48
  def CMS_GetCpuLoadavgData(
49
- RegionId: str = Field(description='AlibabaCloud region ID', default='cn-hangzhou'),
50
49
  InstanceIds: List[str] = Field(description='AlibabaCloud ECS instance ID List'),
50
+ RegionId: str = Field(description='AlibabaCloud region ID', default='cn-hangzhou')
51
51
  ):
52
52
  """获取CPU一分钟平均负载指标数据"""
53
53
  return _get_cms_metric_data(RegionId, InstanceIds, 'load_1m')
@@ -55,8 +55,8 @@ def CMS_GetCpuLoadavgData(
55
55
 
56
56
  @tools.append
57
57
  def CMS_GetCpuloadavg5mData(
58
- RegionId: str = Field(description='AlibabaCloud region ID', default='cn-hangzhou'),
59
58
  InstanceIds: List[str] = Field(description='AlibabaCloud ECS instance ID List'),
59
+ RegionId: str = Field(description='AlibabaCloud region ID', default='cn-hangzhou')
60
60
  ):
61
61
  """获取CPU五分钟平均负载指标数据"""
62
62
  return _get_cms_metric_data(RegionId, InstanceIds, 'load_5m')
@@ -64,16 +64,16 @@ def CMS_GetCpuloadavg5mData(
64
64
 
65
65
  @tools.append
66
66
  def CMS_GetCpuloadavg15mData(
67
- RegionId: str = Field(description='AlibabaCloud region ID', default='cn-hangzhou'),
68
67
  InstanceIds: List[str] = Field(description='AlibabaCloud ECS instance ID List'),
68
+ RegionId: str = Field(description='AlibabaCloud region ID', default='cn-hangzhou')
69
69
  ):
70
70
  """获取CPU十五分钟平均负载指标数据"""
71
71
  return _get_cms_metric_data(RegionId, InstanceIds, 'load_15m')
72
72
 
73
73
  @tools.append
74
74
  def CMS_GetMemUsedData(
75
- RegionId: str = Field(description='AlibabaCloud region ID', default='cn-hangzhou'),
76
75
  InstanceIds: List[str] = Field(description='AlibabaCloud ECS instance ID List'),
76
+ RegionId: str = Field(description='AlibabaCloud region ID', default='cn-hangzhou')
77
77
  ):
78
78
  """获取内存使用量指标数据"""
79
79
  return _get_cms_metric_data(RegionId, InstanceIds, 'memory_usedspace')
@@ -81,8 +81,8 @@ def CMS_GetMemUsedData(
81
81
 
82
82
  @tools.append
83
83
  def CMS_GetMemUsageData(
84
- RegionId: str = Field(description='AlibabaCloud region ID', default='cn-hangzhou'),
85
84
  InstanceIds: List[str] = Field(description='AlibabaCloud ECS instance ID List'),
85
+ RegionId: str = Field(description='AlibabaCloud region ID', default='cn-hangzhou')
86
86
  ):
87
87
  """获取内存利用率指标数据"""
88
88
  return _get_cms_metric_data(RegionId, InstanceIds, 'memory_usedutilization')
@@ -90,8 +90,8 @@ def CMS_GetMemUsageData(
90
90
 
91
91
  @tools.append
92
92
  def CMS_GetDiskUsageData(
93
- RegionId: str = Field(description='AlibabaCloud region ID', default='cn-hangzhou'),
94
93
  InstanceIds: List[str] = Field(description='AlibabaCloud ECS instance ID List'),
94
+ RegionId: str = Field(description='AlibabaCloud region ID', default='cn-hangzhou')
95
95
  ):
96
96
  """获取磁盘利用率指标数据"""
97
97
  return _get_cms_metric_data(RegionId, InstanceIds, 'diskusage_utilization')
@@ -99,8 +99,8 @@ def CMS_GetDiskUsageData(
99
99
 
100
100
  @tools.append
101
101
  def CMS_GetDiskTotalData(
102
- RegionId: str = Field(description='AlibabaCloud region ID', default='cn-hangzhou'),
103
102
  InstanceIds: List[str] = Field(description='AlibabaCloud ECS instance ID List'),
103
+ RegionId: str = Field(description='AlibabaCloud region ID', default='cn-hangzhou')
104
104
  ):
105
105
  """获取磁盘分区总容量指标数据"""
106
106
  return _get_cms_metric_data(RegionId, InstanceIds, 'diskusage_total')
@@ -108,8 +108,8 @@ def CMS_GetDiskTotalData(
108
108
 
109
109
  @tools.append
110
110
  def CMS_GetDiskUsedData(
111
- RegionId: str = Field(description='AlibabaCloud region ID', default='cn-hangzhou'),
112
111
  InstanceIds: List[str] = Field(description='AlibabaCloud ECS instance ID List'),
112
+ RegionId: str = Field(description='AlibabaCloud region ID', default='cn-hangzhou')
113
113
  ):
114
114
  """获取磁盘分区使用量指标数据"""
115
115
  return _get_cms_metric_data(RegionId, InstanceIds, 'diskusage_used')
@@ -0,0 +1,74 @@
1
+ import logging
2
+ import os
3
+ from pydantic import Field
4
+ from alibabacloud_tea_openapi import models as open_api_models
5
+ from alibabacloud_tea_util import models as util_models
6
+ from alibabacloud_tea_openapi.client import Client as OpenApiClient
7
+ from alibabacloud_openapi_util.client import Client as OpenApiUtilClient
8
+ from alibaba_cloud_ops_mcp_server.alibabacloud.api_meta_client import ApiMetaClient
9
+ from alibaba_cloud_ops_mcp_server.alibabacloud.static import PROMPT_UNDERSTANDING
10
+ from alibaba_cloud_ops_mcp_server.tools.api_tools import create_client, _tools_api_call
11
+
12
+ END_STATUSES = ['Success', 'Failed', 'Cancelled']
13
+
14
+ tools = []
15
+
16
+ _CUSTOM_SERVICE_LIST = None
17
+
18
+ logger = logging.getLogger(__name__)
19
+
20
+
21
+ def set_custom_service_list(service_list):
22
+ global _CUSTOM_SERVICE_LIST
23
+ _CUSTOM_SERVICE_LIST = service_list
24
+
25
+
26
+ @tools.append
27
+ def PromptUnderstanding() -> str:
28
+ """
29
+ Always use this tool first to understand the user's query and convert it into suggestions from Alibaba Cloud experts.
30
+ """
31
+ global _CUSTOM_SERVICE_LIST
32
+
33
+ content = PROMPT_UNDERSTANDING
34
+ if _CUSTOM_SERVICE_LIST:
35
+ import re
36
+ pattern = r'Supported Services\s*:\s*\n(?:\s{3}- .+?\n)+'
37
+ replacement = f"Supported Services:\n - " + "\n - ".join([f"{k}: {v}" for k, v in _CUSTOM_SERVICE_LIST])
38
+ content = re.sub(pattern, replacement, content, flags=re.DOTALL)
39
+
40
+ return content
41
+
42
+
43
+ @tools.append
44
+ def ListAPIs(
45
+ service: str = Field(description='AlibabaCloud service code')
46
+ ):
47
+ """
48
+ Use PromptUnderstanding tool first to understand the user's query, Get the corresponding API list information through the service name to prepare for the subsequent selection of the appropriate API to call
49
+ """
50
+ return ApiMetaClient.get_apis_in_service(service)
51
+
52
+
53
+ @tools.append
54
+ def GetAPIInfo(
55
+ service: str = Field(description='AlibabaCloud service code'),
56
+ api: str = Field(description='AlibabaCloud api name'),
57
+ ):
58
+ """
59
+ Use PromptUnderstanding tool first to understand the user's query, After specifying the service name and API name, get the detailed API META of the corresponding API
60
+ """
61
+ data, version = ApiMetaClient.get_api_meta(service, api)
62
+ return data.get('parameters')
63
+
64
+
65
+ @tools.append
66
+ def CommonAPICaller(
67
+ service: str = Field(description='AlibabaCloud service code'),
68
+ api: str = Field(description='AlibabaCloud api name'),
69
+ parameters: dict = Field(description='AlibabaCloud ECS instance ID List', default={}),
70
+ ):
71
+ """
72
+ Use PromptUnderstanding tool first to understand the user's query, Perform the actual call by specifying the Service, API, and Parameters
73
+ """
74
+ return _tools_api_call(service, api, parameters, None)
@@ -47,10 +47,10 @@ def _start_execution_sync(region_id: str, template_name: str, parameters: dict):
47
47
  time.sleep(1)
48
48
  @tools.append
49
49
  def OOS_RunCommand(
50
- RegionId: str = Field(description='AlibabaCloud region ID', default='cn-hangzhou'),
51
- InstanceIds: List[str] = Field(description='AlibabaCloud ECS instance ID List'),
52
- CommandType: str = Field(description='The type of command executed on the ECS instance, optional value:RunShellScript,RunPythonScript,RunPerlScript,RunBatScript,RunPowerShellScript', default='RunShellScript'),
53
- Command: str = Field(description='Content of the command executed on the ECS instance'),
50
+ Command: str = Field(description='Content of the command executed on the ECS instance'),
51
+ InstanceIds: List[str] = Field(description='AlibabaCloud ECS instance ID List'),
52
+ RegionId: str = Field(description='AlibabaCloud region ID', default='cn-hangzhou'),
53
+ CommandType: str = Field(description='The type of command executed on the ECS instance, optional value:RunShellScript,RunPythonScript,RunPerlScript,RunBatScript,RunPowerShellScript', default='RunShellScript')
54
54
  ):
55
55
  """批量在多台ECS实例上运行云助手命令,适用于需要同时管理多台ECS实例的场景,如应用程序管理和资源标记操作等。"""
56
56
 
@@ -74,8 +74,8 @@ def OOS_RunCommand(
74
74
 
75
75
  @tools.append
76
76
  def OOS_StartInstances(
77
- RegionId: str = Field(description='AlibabaCloud region ID', default='cn-hangzhou'),
78
- InstanceIds: List[str] = Field(description='AlibabaCloud ECS instance ID List'),
77
+ InstanceIds: List[str] = Field(description='AlibabaCloud ECS instance ID List'),
78
+ RegionId: str = Field(description='AlibabaCloud region ID', default='cn-hangzhou'),
79
79
  ):
80
80
  """批量启动ECS实例,适用于需要同时管理和启动多台ECS实例的场景,例如应用部署和高可用性场景。"""
81
81
 
@@ -93,9 +93,9 @@ def OOS_StartInstances(
93
93
 
94
94
  @tools.append
95
95
  def OOS_StopInstances(
96
- RegionId: str = Field(description='AlibabaCloud region ID', default='cn-hangzhou'),
97
- InstanceIds: List[str] = Field(description='AlibabaCloud ECS instance ID List'),
98
- ForeceStop: bool = Field(description='Is forced shutdown required', default=False),
96
+ InstanceIds: List[str] = Field(description='AlibabaCloud ECS instance ID List'),
97
+ RegionId: str = Field(description='AlibabaCloud region ID', default='cn-hangzhou'),
98
+ ForeceStop: bool = Field(description='Is forced shutdown required', default=False)
99
99
  ):
100
100
  """批量停止ECS实例,适用于需要同时管理和停止多台ECS实例的场景。"""
101
101
 
@@ -114,9 +114,9 @@ def OOS_StopInstances(
114
114
 
115
115
  @tools.append
116
116
  def OOS_RebootInstances(
117
- RegionId: str = Field(description='AlibabaCloud region ID', default='cn-hangzhou'),
118
- InstanceIds: List[str] = Field(description='AlibabaCloud ECS instance ID List'),
119
- ForeceStop: bool = Field(description='Is forced shutdown required', default=False),
117
+ InstanceIds: List[str] = Field(description='AlibabaCloud ECS instance ID List'),
118
+ RegionId: str = Field(description='AlibabaCloud region ID', default='cn-hangzhou'),
119
+ ForeceStop: bool = Field(description='Is forced shutdown required', default=False)
120
120
  ):
121
121
  """批量重启ECS实例,适用于需要同时管理和重启多台ECS实例的场景。"""
122
122
 
@@ -135,13 +135,13 @@ def OOS_RebootInstances(
135
135
 
136
136
  @tools.append
137
137
  def OOS_RunInstances(
138
- RegionId: str = Field(description='AlibabaCloud region ID', default='cn-hangzhou'),
139
138
  ImageId: str = Field(description='Image ID'),
140
139
  InstanceType: str = Field(description='Instance Type'),
141
140
  SecurityGroupId: str = Field(description='SecurityGroup ID'),
142
141
  VSwitchId: str = Field(description='VSwitch ID'),
142
+ RegionId: str = Field(description='AlibabaCloud region ID', default='cn-hangzhou'),
143
143
  Amount: int = Field(description='Number of ECS instances', default=1),
144
- InstanceName: str = Field(description='Instance Name', default=''),
144
+ InstanceName: str = Field(description='Instance Name', default='')
145
145
  ):
146
146
  """批量创建ECS实例,适用于需要同时创建多台ECS实例的场景,例如应用部署和高可用性场景。"""
147
147
 
@@ -158,9 +158,9 @@ def OOS_RunInstances(
158
158
 
159
159
  @tools.append
160
160
  def OOS_ResetPassword(
161
- RegionId: str = Field(description='AlibabaCloud region ID', default='cn-hangzhou'),
162
161
  InstanceIds: List[str] = Field(description='AlibabaCloud ECS instance ID List'),
163
162
  Password: str = Field(description='The password of the ECS instance must be 8-30 characters and must contain only the following characters: lowercase letters, uppercase letters, numbers, and special characters only.()~!@#$%^&*-_+=(40:<>,?/'),
163
+ RegionId: str = Field(description='AlibabaCloud region ID', default='cn-hangzhou'),
164
164
  ):
165
165
  """批量修改ECS实例的密码,请注意,本操作将会重启ECS实例"""
166
166
  parameters = {
@@ -177,9 +177,9 @@ def OOS_ResetPassword(
177
177
 
178
178
  @tools.append
179
179
  def OOS_ReplaceSystemDisk(
180
- RegionId: str = Field(description='AlibabaCloud region ID', default='cn-hangzhou'),
181
- InstanceIds: List[str] = Field(description='AlibabaCloud ECS instance ID List'),
182
- ImageId: str = Field(description='Image ID')
180
+ InstanceIds: List[str] = Field(description='AlibabaCloud ECS instance ID List'),
181
+ ImageId: str = Field(description='Image ID'),
182
+ RegionId: str = Field(description='AlibabaCloud region ID', default='cn-hangzhou')
183
183
  ):
184
184
  """批量替换ECS实例的系统盘,更换操作系统"""
185
185
  parameters = {
@@ -197,8 +197,8 @@ def OOS_ReplaceSystemDisk(
197
197
 
198
198
  @tools.append
199
199
  def OOS_StartRDSInstances(
200
- RegionId: str = Field(description='AlibabaCloud region ID', default='cn-hangzhou'),
201
- InstanceIds: List[str] = Field(description='AlibabaCloud ECS instance ID List'),
200
+ InstanceIds: List[str] = Field(description='AlibabaCloud ECS instance ID List'),
201
+ RegionId: str = Field(description='AlibabaCloud region ID', default='cn-hangzhou')
202
202
  ):
203
203
  """批量启动RDS实例,适用于需要同时管理和启动多台RDS实例的场景,例如应用部署和高可用性场景。"""
204
204
 
@@ -216,8 +216,8 @@ def OOS_StartRDSInstances(
216
216
 
217
217
  @tools.append
218
218
  def OOS_StopRDSInstances(
219
- RegionId: str = Field(description='AlibabaCloud region ID', default='cn-hangzhou'),
220
- InstanceIds: List[str] = Field(description='AlibabaCloud RDS instance ID List')
219
+ InstanceIds: List[str] = Field(description='AlibabaCloud RDS instance ID List'),
220
+ RegionId: str = Field(description='AlibabaCloud region ID', default='cn-hangzhou')
221
221
  ):
222
222
  """批量停止RDS实例,适用于需要同时管理和停止多台RDS实例的场景。"""
223
223
 
@@ -235,8 +235,8 @@ def OOS_StopRDSInstances(
235
235
 
236
236
  @tools.append
237
237
  def OOS_RebootRDSInstances(
238
- RegionId: str = Field(description='AlibabaCloud region ID', default='cn-hangzhou'),
239
- InstanceIds: List[str] = Field(description='AlibabaCloud RDS instance ID List')
238
+ InstanceIds: List[str] = Field(description='AlibabaCloud RDS instance ID List'),
239
+ RegionId: str = Field(description='AlibabaCloud region ID', default='cn-hangzhou')
240
240
  ):
241
241
  """批量重启RDS实例,适用于需要同时管理和重启多台RDS实例的场景。"""
242
242
 
@@ -1,6 +1,7 @@
1
1
  # oss_tools.py
2
2
  import os
3
3
  import alibabacloud_oss_v2 as oss
4
+ from alibaba_cloud_ops_mcp_server.alibabacloud.utils import get_credentials_from_header
4
5
 
5
6
  from pydantic import Field
6
7
  from alibabacloud_oss_v2 import Credentials
@@ -13,10 +14,16 @@ tools = []
13
14
 
14
15
  class CredentialsProvider(EnvironmentVariableCredentialsProvider):
15
16
  def __init__(self) -> None:
16
- credentialsClient = CredClient()
17
- access_key_id = credentialsClient.get_credential().access_key_id
18
- access_key_secret = credentialsClient.get_credential().access_key_secret
19
- session_token = credentialsClient.get_credential().security_token
17
+ credentials = get_credentials_from_header()
18
+ if credentials:
19
+ access_key_id = credentials.get('AccessKeyId', None)
20
+ access_key_secret = credentials.get('AccessKeySecret', None)
21
+ session_token = credentials.get('SecurityToken', None)
22
+ else:
23
+ credentialsClient = CredClient()
24
+ access_key_id = credentialsClient.get_credential().access_key_id
25
+ access_key_secret = credentialsClient.get_credential().access_key_secret
26
+ session_token = credentialsClient.get_credential().security_token
20
27
 
21
28
  self._credentials = Credentials(
22
29
  access_key_id, access_key_secret, session_token)
@@ -51,8 +58,8 @@ def OSS_ListBuckets(
51
58
 
52
59
  @tools.append
53
60
  def OSS_ListObjects(
54
- RegionId: str = Field(description='AlibabaCloud region ID', default='cn-hangzhou'),
55
61
  BucketName: str = Field(description='AlibabaCloud OSS Bucket Name'),
62
+ RegionId: str = Field(description='AlibabaCloud region ID', default='cn-hangzhou'),
56
63
  Prefix: str = Field(description='AlibabaCloud OSS Bucket Name prefix', default=None)
57
64
  ):
58
65
  """获取指定OSS存储空间中的所有文件信息。"""
@@ -72,8 +79,8 @@ def OSS_ListObjects(
72
79
 
73
80
  @tools.append
74
81
  def OSS_PutBucket(
75
- RegionId: str = Field(description='AlibabaCloud region ID', default='cn-hangzhou'),
76
82
  BucketName: str = Field(description='AlibabaCloud OSS Bucket Name'),
83
+ RegionId: str = Field(description='AlibabaCloud region ID', default='cn-hangzhou'),
77
84
  StorageClass: str = Field(description='The Storage Type of AlibabaCloud OSS Bucket, The value range is as follows: '
78
85
  'Standard (default): standard storage, '
79
86
  'IA: infrequent access, Archive: archive storage, '
@@ -100,8 +107,8 @@ def OSS_PutBucket(
100
107
 
101
108
  @tools.append
102
109
  def OSS_DeleteBucket(
103
- RegionId: str = Field(description='AlibabaCloud region ID', default='cn-hangzhou'),
104
- BucketName: str = Field(description='AlibabaCloud OSS Bucket Name')
110
+ BucketName: str = Field(description='AlibabaCloud OSS Bucket Name'),
111
+ RegionId: str = Field(description='AlibabaCloud region ID', default='cn-hangzhou')
105
112
  ):
106
113
  """删除指定的OSS存储空间。"""
107
114
  client = create_client(region_id=RegionId)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: alibaba-cloud-ops-mcp-server
3
- Version: 0.8.9
3
+ Version: 0.9.1
4
4
  Summary: A MCP server for Alibaba Cloud
5
5
  Author-email: Zheng Dayu <dayu.zdy@alibaba-inc.com>
6
6
  License-File: LICENSE
@@ -11,7 +11,7 @@ Requires-Dist: alibabacloud-ecs20140526>=6.1.0
11
11
  Requires-Dist: alibabacloud-oos20190601>=3.4.1
12
12
  Requires-Dist: alibabacloud-oss-v2>=1.1.0
13
13
  Requires-Dist: click>=8.1.8
14
- Requires-Dist: mcp[cli]>=1.9.0
14
+ Requires-Dist: fastmcp>=2.8.0
15
15
  Description-Content-Type: text/markdown
16
16
 
17
17
  # Alibaba Cloud Ops MCP Server
@@ -55,6 +55,8 @@ To use `alibaba-cloud-ops-mcp-server` MCP Server with any other MCP Client, you
55
55
  }
56
56
  ```
57
57
 
58
+ [For detailed parameter description, see MCP startup parameter document](./README_mcp_args.md)
59
+
58
60
  ## MCP Maketplace Integration
59
61
 
60
62
  * [Cline](https://cline.bot/mcp-marketplace)
@@ -0,0 +1,20 @@
1
+ alibaba_cloud_ops_mcp_server/__init__.py,sha256=BaluUNyRz8Qw-X7Y0ywDezwbkqiSvWlSYn2452XeGcA,213
2
+ alibaba_cloud_ops_mcp_server/config.py,sha256=PizctjXsQUWoMWBY1dFjNffVlZr9K6hNvqA4DpayR_o,513
3
+ alibaba_cloud_ops_mcp_server/server.py,sha256=1TRZMsgicsnaK_YFktL8JPglIc7Z-EQgDmSd0Ww_wdI,2219
4
+ alibaba_cloud_ops_mcp_server/alibabacloud/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
+ alibaba_cloud_ops_mcp_server/alibabacloud/api_meta_client.py,sha256=t2TSc0Gzcy_uEcaCgiHHuLoMiEGu3-NCtYmwYjyPWsY,7973
6
+ alibaba_cloud_ops_mcp_server/alibabacloud/exception.py,sha256=7PdhgqgXEGrTPL1cj98h9EH-RrM6-2TT89PDtcmlpmU,1230
7
+ alibaba_cloud_ops_mcp_server/alibabacloud/utils.py,sha256=7PldufvFOb9GcXLHbUxKV6m9XqJpoNe4FVdQcg7Zeuk,1495
8
+ alibaba_cloud_ops_mcp_server/alibabacloud/static/PROMPT_UNDERSTANDING.md,sha256=494HcCQQCc_iqDrRKhk7eWXB4I0dMtqCseT78KphDHg,3553
9
+ alibaba_cloud_ops_mcp_server/alibabacloud/static/__init__.py,sha256=wJrYamaIb7e_kA4ILZpdP1f1TUUTXMGqEhA4IbSZ2Ts,230
10
+ alibaba_cloud_ops_mcp_server/tools/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
11
+ alibaba_cloud_ops_mcp_server/tools/api_tools.py,sha256=T5Zat31yjEBEmILKbb2uDUkgDHSqOIlPAjpi47hsCz8,8220
12
+ alibaba_cloud_ops_mcp_server/tools/cms_tools.py,sha256=_M13s87WxxiHp3Phu5AmXKkHOj0KDvUlodJ6z5Ndi7E,4182
13
+ alibaba_cloud_ops_mcp_server/tools/common_api_tools.py,sha256=ccQAWqS1I9F-fdOdjLcXN-dIhNqSbZV8T5ODuGXlfXM,2711
14
+ alibaba_cloud_ops_mcp_server/tools/oos_tools.py,sha256=8CLidg8Vrzpxv4lEOokPdScv31xlg_gX7glifiSqa8g,10063
15
+ alibaba_cloud_ops_mcp_server/tools/oss_tools.py,sha256=MUAiYL4VlsYQPoR_JtHOLcF1i4VYK9KE6ff9BTqJr9E,5014
16
+ alibaba_cloud_ops_mcp_server-0.9.1.dist-info/METADATA,sha256=fhRqAb0Wk1fzC76dFuW45ETIHgIMTIyARtiPu5EjZ34,5965
17
+ alibaba_cloud_ops_mcp_server-0.9.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
18
+ alibaba_cloud_ops_mcp_server-0.9.1.dist-info/entry_points.txt,sha256=ESGAWXKEp184forhs7VzTD4P1AUdZz6vCW6hRUKITGw,83
19
+ alibaba_cloud_ops_mcp_server-0.9.1.dist-info/licenses/LICENSE,sha256=gQgVkp2ttRCjodiPpXZZR-d7JnrYIYNiHk1YDUYgpa4,11331
20
+ alibaba_cloud_ops_mcp_server-0.9.1.dist-info/RECORD,,
@@ -1,17 +0,0 @@
1
- alibaba_cloud_ops_mcp_server/__init__.py,sha256=BaluUNyRz8Qw-X7Y0ywDezwbkqiSvWlSYn2452XeGcA,213
2
- alibaba_cloud_ops_mcp_server/config.py,sha256=Nq6AT8bqSVa6zu9xjInaSjFcxA-GC7MLlCsV1q53yO0,514
3
- alibaba_cloud_ops_mcp_server/server.py,sha256=NrUFnF4bVBYzrZs186iq77R9C08Vcy1jCAftm4vpGEA,1168
4
- alibaba_cloud_ops_mcp_server/alibabacloud/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
- alibaba_cloud_ops_mcp_server/alibabacloud/api_meta_client.py,sha256=VOyOLuo_WC8uaJSlh5pLxaMb2z90HWHVtCMhb2hddRE,7685
6
- alibaba_cloud_ops_mcp_server/alibabacloud/exception.py,sha256=7PdhgqgXEGrTPL1cj98h9EH-RrM6-2TT89PDtcmlpmU,1230
7
- alibaba_cloud_ops_mcp_server/alibabacloud/utils.py,sha256=jWQtP59P4ejh7N6xiYSDq1WgCd3Les0aSZr2pLGzkls,299
8
- alibaba_cloud_ops_mcp_server/tools/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
- alibaba_cloud_ops_mcp_server/tools/api_tools.py,sha256=gXIZnQrCeS8SHWxFl4DlaKfHAaQAcA8K4s_G2YmOgQM,6523
10
- alibaba_cloud_ops_mcp_server/tools/cms_tools.py,sha256=GFSBDTddvQ7M9fDGm69jvH6Yt4nui5uOVjwD61CZKT4,4191
11
- alibaba_cloud_ops_mcp_server/tools/oos_tools.py,sha256=l228yl_SGg_rNdrBSDeqWYI8ZE1XUAHhsPLArvfE4A8,10116
12
- alibaba_cloud_ops_mcp_server/tools/oss_tools.py,sha256=c7D1fAjFBqHl0oMy0O6i7onoXeAN9cpdBdLtXKrxVQE,4615
13
- alibaba_cloud_ops_mcp_server-0.8.9.dist-info/METADATA,sha256=Pu2lZ17UiEzw4xGtYzgAFY0nJSHjgYlUMrwtFW0n-cs,5870
14
- alibaba_cloud_ops_mcp_server-0.8.9.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
15
- alibaba_cloud_ops_mcp_server-0.8.9.dist-info/entry_points.txt,sha256=ESGAWXKEp184forhs7VzTD4P1AUdZz6vCW6hRUKITGw,83
16
- alibaba_cloud_ops_mcp_server-0.8.9.dist-info/licenses/LICENSE,sha256=gQgVkp2ttRCjodiPpXZZR-d7JnrYIYNiHk1YDUYgpa4,11331
17
- alibaba_cloud_ops_mcp_server-0.8.9.dist-info/RECORD,,