alibaba-cloud-ops-mcp-server 0.8.9__tar.gz → 0.9.1__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.
- {alibaba_cloud_ops_mcp_server-0.8.9 → alibaba_cloud_ops_mcp_server-0.9.1}/PKG-INFO +4 -2
- {alibaba_cloud_ops_mcp_server-0.8.9 → alibaba_cloud_ops_mcp_server-0.9.1}/README.md +2 -0
- alibaba_cloud_ops_mcp_server-0.9.1/README_mcp_args.md +22 -0
- {alibaba_cloud_ops_mcp_server-0.8.9 → alibaba_cloud_ops_mcp_server-0.9.1}/README_zh.md +2 -0
- {alibaba_cloud_ops_mcp_server-0.8.9 → alibaba_cloud_ops_mcp_server-0.9.1}/pyproject.toml +3 -3
- {alibaba_cloud_ops_mcp_server-0.8.9 → alibaba_cloud_ops_mcp_server-0.9.1}/src/alibaba_cloud_ops_mcp_server/alibabacloud/api_meta_client.py +10 -2
- alibaba_cloud_ops_mcp_server-0.9.1/src/alibaba_cloud_ops_mcp_server/alibabacloud/static/PROMPT_UNDERSTANDING.md +134 -0
- alibaba_cloud_ops_mcp_server-0.9.1/src/alibaba_cloud_ops_mcp_server/alibabacloud/static/__init__.py +8 -0
- alibaba_cloud_ops_mcp_server-0.9.1/src/alibaba_cloud_ops_mcp_server/alibabacloud/utils.py +46 -0
- {alibaba_cloud_ops_mcp_server-0.8.9 → alibaba_cloud_ops_mcp_server-0.9.1}/src/alibaba_cloud_ops_mcp_server/config.py +1 -1
- alibaba_cloud_ops_mcp_server-0.9.1/src/alibaba_cloud_ops_mcp_server/server.py +78 -0
- {alibaba_cloud_ops_mcp_server-0.8.9 → alibaba_cloud_ops_mcp_server-0.9.1}/src/alibaba_cloud_ops_mcp_server/tools/api_tools.py +52 -4
- {alibaba_cloud_ops_mcp_server-0.8.9 → alibaba_cloud_ops_mcp_server-0.9.1}/src/alibaba_cloud_ops_mcp_server/tools/cms_tools.py +9 -9
- alibaba_cloud_ops_mcp_server-0.9.1/src/alibaba_cloud_ops_mcp_server/tools/common_api_tools.py +74 -0
- {alibaba_cloud_ops_mcp_server-0.8.9 → alibaba_cloud_ops_mcp_server-0.9.1}/src/alibaba_cloud_ops_mcp_server/tools/oos_tools.py +24 -24
- {alibaba_cloud_ops_mcp_server-0.8.9 → alibaba_cloud_ops_mcp_server-0.9.1}/src/alibaba_cloud_ops_mcp_server/tools/oss_tools.py +15 -8
- {alibaba_cloud_ops_mcp_server-0.8.9 → alibaba_cloud_ops_mcp_server-0.9.1}/tests/alibabacloud/test_api_meta_client.py +70 -7
- alibaba_cloud_ops_mcp_server-0.9.1/tests/alibabacloud/test_utils.py +75 -0
- alibaba_cloud_ops_mcp_server-0.9.1/tests/test_server.py +102 -0
- {alibaba_cloud_ops_mcp_server-0.8.9 → alibaba_cloud_ops_mcp_server-0.9.1}/tests/tools/test_api_tools.py +65 -0
- {alibaba_cloud_ops_mcp_server-0.8.9 → alibaba_cloud_ops_mcp_server-0.9.1}/tests/tools/test_oss_tools.py +14 -0
- {alibaba_cloud_ops_mcp_server-0.8.9 → alibaba_cloud_ops_mcp_server-0.9.1}/uv.lock +114 -76
- alibaba_cloud_ops_mcp_server-0.8.9/src/alibaba_cloud_ops_mcp_server/alibabacloud/utils.py +0 -9
- alibaba_cloud_ops_mcp_server-0.8.9/src/alibaba_cloud_ops_mcp_server/server.py +0 -51
- alibaba_cloud_ops_mcp_server-0.8.9/tests/alibabacloud/test_utils.py +0 -15
- alibaba_cloud_ops_mcp_server-0.8.9/tests/test_server.py +0 -30
- {alibaba_cloud_ops_mcp_server-0.8.9 → alibaba_cloud_ops_mcp_server-0.9.1}/.github/workflows/python-ci.yml +0 -0
- {alibaba_cloud_ops_mcp_server-0.8.9 → alibaba_cloud_ops_mcp_server-0.9.1}/.gitignore +0 -0
- {alibaba_cloud_ops_mcp_server-0.8.9 → alibaba_cloud_ops_mcp_server-0.9.1}/LICENSE +0 -0
- {alibaba_cloud_ops_mcp_server-0.8.9 → alibaba_cloud_ops_mcp_server-0.9.1}/examples/openapi_mcp_quickstart/server.py +0 -0
- {alibaba_cloud_ops_mcp_server-0.8.9 → alibaba_cloud_ops_mcp_server-0.9.1}/image/Alibaba-Cloud-Ops-MCP-User-Group-en.png +0 -0
- {alibaba_cloud_ops_mcp_server-0.8.9 → alibaba_cloud_ops_mcp_server-0.9.1}/image/Alibaba-Cloud-Ops-MCP-User-Group-zh.png +0 -0
- {alibaba_cloud_ops_mcp_server-0.8.9 → alibaba_cloud_ops_mcp_server-0.9.1}/image/alibaba-cloud.png +0 -0
- {alibaba_cloud_ops_mcp_server-0.8.9 → alibaba_cloud_ops_mcp_server-0.9.1}/src/__init__.py +0 -0
- {alibaba_cloud_ops_mcp_server-0.8.9 → alibaba_cloud_ops_mcp_server-0.9.1}/src/alibaba_cloud_ops_mcp_server/__init__.py +0 -0
- {alibaba_cloud_ops_mcp_server-0.8.9 → alibaba_cloud_ops_mcp_server-0.9.1}/src/alibaba_cloud_ops_mcp_server/alibabacloud/__init__.py +0 -0
- {alibaba_cloud_ops_mcp_server-0.8.9 → alibaba_cloud_ops_mcp_server-0.9.1}/src/alibaba_cloud_ops_mcp_server/alibabacloud/exception.py +0 -0
- {alibaba_cloud_ops_mcp_server-0.8.9 → alibaba_cloud_ops_mcp_server-0.9.1}/src/alibaba_cloud_ops_mcp_server/tools/__init__.py +0 -0
- {alibaba_cloud_ops_mcp_server-0.8.9 → alibaba_cloud_ops_mcp_server-0.9.1}/tests/alibabacloud/test_exception.py +0 -0
- {alibaba_cloud_ops_mcp_server-0.8.9 → alibaba_cloud_ops_mcp_server-0.9.1}/tests/test_init.py +0 -0
- {alibaba_cloud_ops_mcp_server-0.8.9 → alibaba_cloud_ops_mcp_server-0.9.1}/tests/tools/test_cms_tools.py +0 -0
- {alibaba_cloud_ops_mcp_server-0.8.9 → alibaba_cloud_ops_mcp_server-0.9.1}/tests/tools/test_oos_tools.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: alibaba-cloud-ops-mcp-server
|
|
3
|
-
Version: 0.
|
|
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:
|
|
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)
|
|
@@ -39,6 +39,8 @@ To use `alibaba-cloud-ops-mcp-server` MCP Server with any other MCP Client, you
|
|
|
39
39
|
}
|
|
40
40
|
```
|
|
41
41
|
|
|
42
|
+
[For detailed parameter description, see MCP startup parameter document](./README_mcp_args.md)
|
|
43
|
+
|
|
42
44
|
## MCP Maketplace Integration
|
|
43
45
|
|
|
44
46
|
* [Cline](https://cline.bot/mcp-marketplace)
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# MCP Startup Parameters Guide
|
|
2
|
+
|
|
3
|
+
This document provides a detailed introduction to the available parameters for starting the Alibaba Cloud MCP Server, helping users configure the server according to their needs.
|
|
4
|
+
|
|
5
|
+
## Parameter Table
|
|
6
|
+
|
|
7
|
+
| Parameter | Required | Type | Default | Description |
|
|
8
|
+
|:--------------:|:--------:|:------:|:----------:|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|
9
|
+
| `--transport` | No | string | `stdio` | Transport protocol for MCP Server communication.<br>Options:<br> • `stdio` <br> • `sse` <br> • `streamable-http` |
|
|
10
|
+
| `--port` | No | int | `8000` | Specifies the port number MCP Server listens on. Make sure the port is not occupied. |
|
|
11
|
+
| `--host` | No | string | `127.0.0.1`| Specifies the host address MCP Server listens on. `0.0.0.0` means listening on all network interfaces. |
|
|
12
|
+
| `--services` | No | string | None | Comma-separated services, e.g., `ecs,vpc`.<br>Supported services:<br> • `ecs`<br> • `oos`<br> • `rds`<br> • `vpc`<br> • `slb`<br> • `ess`<br> • `ros`<br> • `cbn`<br> • `dds`<br> • `r-kvstore` |
|
|
13
|
+
|
|
14
|
+
## Usage Example
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
uv run src/alibaba_cloud_ops_mcp_server/server.py --transport sse --port 8080 --host 0.0.0.0 --services ecs,vpc
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
For more help, please refer to the main project documentation or contact the maintainer.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "alibaba-cloud-ops-mcp-server"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.9.1"
|
|
4
4
|
description = "A MCP server for Alibaba Cloud"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
authors = [
|
|
@@ -14,7 +14,7 @@ dependencies = [
|
|
|
14
14
|
"alibabacloud_oss_v2>=1.1.0",
|
|
15
15
|
"alibabacloud-credentials>=1.0.0",
|
|
16
16
|
"click>=8.1.8",
|
|
17
|
-
"
|
|
17
|
+
"fastmcp>=2.8.0"
|
|
18
18
|
]
|
|
19
19
|
|
|
20
20
|
[build-system]
|
|
@@ -34,4 +34,4 @@ dev = [
|
|
|
34
34
|
]
|
|
35
35
|
|
|
36
36
|
[project.scripts]
|
|
37
|
-
alibaba-cloud-ops-mcp-server = "alibaba_cloud_ops_mcp_server:main"
|
|
37
|
+
alibaba-cloud-ops-mcp-server = "alibaba_cloud_ops_mcp_server:main"
|
|
@@ -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
|
|
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,46 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
|
|
3
|
+
from alibabacloud_credentials.client import Client as CredClient
|
|
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
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def create_config():
|
|
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)
|
|
45
|
+
config.user_agent = 'alibaba-cloud-ops-mcp-server'
|
|
46
|
+
return config
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
from fastmcp import FastMCP
|
|
2
|
+
import click
|
|
3
|
+
import logging
|
|
4
|
+
|
|
5
|
+
from alibaba_cloud_ops_mcp_server.tools.common_api_tools import set_custom_service_list
|
|
6
|
+
from alibaba_cloud_ops_mcp_server.config import config
|
|
7
|
+
from alibaba_cloud_ops_mcp_server.tools import cms_tools, oos_tools, oss_tools, api_tools, common_api_tools
|
|
8
|
+
|
|
9
|
+
logger = logging.getLogger(__name__)
|
|
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
|
+
|
|
24
|
+
|
|
25
|
+
@click.command()
|
|
26
|
+
@click.option(
|
|
27
|
+
"--transport",
|
|
28
|
+
type=click.Choice(["stdio", "sse", "streamable-http"]),
|
|
29
|
+
default="stdio",
|
|
30
|
+
help="Transport type",
|
|
31
|
+
)
|
|
32
|
+
@click.option(
|
|
33
|
+
"--port",
|
|
34
|
+
type=int,
|
|
35
|
+
default=8000,
|
|
36
|
+
help="Port number",
|
|
37
|
+
)
|
|
38
|
+
@click.option(
|
|
39
|
+
"--host",
|
|
40
|
+
type=str,
|
|
41
|
+
default="127.0.0.1",
|
|
42
|
+
help="Host",
|
|
43
|
+
)
|
|
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):
|
|
51
|
+
# Create an MCP server
|
|
52
|
+
mcp = FastMCP(
|
|
53
|
+
name="alibaba-cloud-ops-mcp-server",
|
|
54
|
+
port=port,
|
|
55
|
+
host=host
|
|
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)
|
|
64
|
+
for tool in oos_tools.tools:
|
|
65
|
+
mcp.tool(tool)
|
|
66
|
+
for tool in cms_tools.tools:
|
|
67
|
+
mcp.tool(tool)
|
|
68
|
+
for tool in oss_tools.tools:
|
|
69
|
+
mcp.tool(tool)
|
|
70
|
+
api_tools.create_api_tools(mcp, config)
|
|
71
|
+
|
|
72
|
+
# Initialize and run the server
|
|
73
|
+
logger.debug(f'mcp server is running on {transport} mode.')
|
|
74
|
+
mcp.run(transport=transport)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
if __name__ == "__main__":
|
|
78
|
+
main()
|
|
@@ -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 =
|
|
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)
|