这是一个适用于Oracle云基础设施(OCI)核心服务的生产级FastMCP服务器,采用以大语言模型(LLM)优先的设计方法,提供全面的计算实例管理、数据库操作和网络信息服务。它基于官方OCI Python SDK构建,以实现最佳性能和可靠性。
本服务器使用标准的OCI配置,你可以按照以下步骤进行安装和配置:
# 安装Python依赖项
pip install fastmcp>=0.9.0 oci>=2.157.0 python-dotenv
# 确保配置了OCI CLI
oci setup config
服务器使用标准的OCI配置:
~/.oci/config(默认)OCI_COMPARTMENT_ID 用于指定默认分区python3 oci_core_services_server.py
./run_core_services_server.sh
oci>=2.157.0),以实现最佳性能~/.oci/config 配置文件,支持API密钥或资源主体认证生产环境测试:所有工具均在管理13个以上运行实例的实时OCI租户中进行了验证
list_compute_instances列出指定分区中的所有计算实例,并提供基本详细信息。
参数:
compartment_id(可选):OCI分区IDlifecycle_state(可选):按状态过滤(运行中、已停止等)返回值:
{
"success": true,
"summary": "在eu-frankfurt-1区域找到13个运行中的计算实例",
"count": 13,
"method": "OCI Python SDK",
"instances": [
{
"id": "ocid1.instance.oc1...",
"name": "ArkimeGOAD",
"shape": "VM.Standard.E5.Flex",
"state": "RUNNING",
"availability_domain": "NoEK:EU-FRANKFURT-1-AD-1",
"region": "eu-frankfurt-1",
"created_time": "2025-02-25T17:22:25.782000+00:00"
}
],
"retrieved_at": "2025-07-30T09:42:30Z"
}
get_instance_details获取特定计算实例的详细信息。
参数:
instance_id(必需):OCI实例OCIDcompartment_id(可选):OCI分区IDinclude_network(可选):是否包含网络接口详细信息返回值:
{
"success": true,
"summary": "实例 'ArkimeGOAD'(VM.Standard.E5.Flex)正在运行,私有IP为192.168.56.132",
"method": "OCI Python SDK",
"instance": {
"id": "ocid1.instance.oc1...",
"name": "ArkimeGOAD",
"configuration": {
"launch_options": {},
"agent_config": {}
}
},
"network_interfaces": [],
"network_info_included": true
}
list_instances_with_network列出包含完整网络信息的计算实例。
参数:
compartment_id(可选):OCI分区IDlifecycle_state(可选):按状态过滤返回值:
{
"success": true,
"summary": "找到13个包含网络信息的运行中计算实例",
"count": 13,
"network_info_included": true,
"instances": [
{
"name": "ArkimeGOAD",
"primary_private_ip": "192.168.56.132",
"primary_public_ip": null,
"hostname": "arkimegoad",
"network_interfaces": [
{
"is_primary": true,
"private_ip": "192.168.56.132",
"public_ip": null,
"mac_address": "02:00:17:10:ED:9F"
}
]
}
]
}
get_compute_instance_state获取特定计算实例的当前生命周期状态。
参数:
instance_id(必需):OCI实例OCID返回值:
{
"success": true,
"summary": "实例 'ArkimeGOAD' 目前正在运行",
"method": "OCI Python SDK",
"state_info": {
"instance_id": "ocid1.instance.oc1...",
"instance_name": "ArkimeGOAD",
"lifecycle_state": "RUNNING",
"shape": "VM.Standard.E5.Flex",
"availability_domain": "NoEK:EU-FRANKFURT-1-AD-1",
"compartment_id": "ocid1.compartment.oc1...",
"time_created": "2025-02-25T17:22:25.782000+00:00"
},
"retrieved_at": "2025-07-30T09:42:30Z"
}
工作请求集成:所有生命周期操作都会返回OCI工作请求ID,用于跟踪长时间运行的操作
start_compute_instance启动一个已停止的计算实例。
参数:
instance_id(必需):OCI实例OCIDcompartment_id(可选):OCI分区ID返回值:
{
"success": true,
"summary": "已为实例 'WebServer'(之前处于停止状态)发起启动操作 - 工作请求:ocid1.workrequest.oc1...",
"method": "OCI Python SDK",
"action_details": {
"instance_id": "ocid1.instance.oc1...",
"instance_name": "WebServer",
"action": "START",
"previous_state": "STOPPED",
"work_request_id": "ocid1.workrequest.oc1...",
"request_id": "unique-request-id",
"initiated_at": "2025-07-30T09:42:30Z"
},
"initiated_at": "2025-07-30T09:42:30Z"
}
stop_compute_instance停止一个正在运行的计算实例,可以选择优雅关闭或强制关闭。
参数:
instance_id(必需):OCI实例OCIDcompartment_id(可选):OCI分区IDsoft_stop(可选):如果为True,则使用优雅关闭(SOFTSTOP);如果为False,则使用强制停止(STOP)。默认值为True返回值:
{
"success": true,
"summary": "已为实例 'WebServer'(之前正在运行)发起优雅停止操作",
"method": "OCI Python SDK",
"action_details": {
"instance_id": "ocid1.instance.oc1...",
"instance_name": "WebServer",
"action": "SOFTSTOP",
"previous_state": "RUNNING",
"work_request_id": "ocid1.workrequest.oc1...",
"initiated_at": "2025-07-30T09:42:30Z"
}
}
restart_compute_instance重启一个计算实例,可以选择优雅重启或强制重启。
参数:
instance_id(必需):OCI实例OCIDcompartment_id(可选):OCI分区IDsoft_restart(可选):如果为True,则使用优雅重启(SOFTRESET);如果为False,则使用强制重启(RESET)。默认值为True返回值:
{
"success": true,
"summary": "已为实例 'WebServer'(之前正在运行)发起优雅重启操作",
"method": "OCI Python SDK",
"action_details": {
"instance_id": "ocid1.instance.oc1...",
"instance_name": "WebServer",
"action": "SOFTRESET",
"previous_state": "RUNNING",
"work_request_id": "ocid1.workrequest.oc1...",
"initiated_at": "2025-07-30T09:42:30Z"
}
}
list_database_systems列出指定分区中的传统数据库系统。
参数:
compartment_id(可选):OCI分区IDlifecycle_state(可选):按状态过滤(可用、已停止等)返回值:
{
"success": true,
"summary": "在eu-frankfurt-1区域找到2个数据库系统",
"count": 2,
"method": "OCI Python SDK",
"database_systems": [
{
"id": "ocid1.dbsystem.oc1...",
"display_name": "MyDB",
"shape": "VM.Standard2.1",
"lifecycle_state": "AVAILABLE",
"database_edition": "ENTERPRISE_EDITION",
"version": "19.0.0.0",
"node_count": 1
}
]
}
start_database_system / stop_database_system管理数据库系统的生命周期操作。
完整的生命周期和扩展:支持完整的CRUD操作,以及动态计算/存储扩展
list_autonomous_databases列出指定分区中的自治数据库,并支持过滤选项。
参数:
compartment_id(可选):OCI分区IDlifecycle_state(可选):按状态过滤(可用、已停止等)db_workload(可选):按工作负载过滤(OLTP、DW、AJD、APEX)返回值:
{
"success": true,
"summary": "在eu-frankfurt-1区域找到3个自治数据库",
"count": 3,
"method": "OCI Python SDK",
"autonomous_databases": [
{
"id": "ocid1.autonomousdatabase.oc1...",
"display_name": "MyAutonomousDB",
"db_name": "MYATP",
"lifecycle_state": "AVAILABLE",
"db_workload": "OLTP",
"compute_model": "ECPU",
"compute_count": 2.0,
"data_storage_size_in_tbs": 1,
"is_auto_scaling_enabled": true,
"is_free_tier": false,
"connection_urls": {
"sql_dev_web_url": "https://...",
"apex_url": "https://..."
}
}
]
}
get_autonomous_database_details获取特定自治数据库的详细信息。
参数:
autonomous_database_id(必需):自治数据库OCID返回值:
{
"success": true,
"summary": "自治数据库 'MyAutonomousDB'(事务处理)可用,拥有2.0 ECPU和1TB存储",
"method": "OCI Python SDK",
"autonomous_database": {
"id": "ocid1.autonomousdatabase.oc1...",
"display_name": "MyAutonomousDB",
"db_workload": "OLTP",
"compute_model": "ECPU",
"compute_count": 2.0,
"data_storage_size_in_tbs": 1,
"connection_strings": {},
"connection_urls": {},
"backup_retention_period_in_days": 60,
"is_refreshable_clone": false,
"vault_id": null,
"kms_key_id": null
}
}
start_autonomous_database / stop_autonomous_database / restart_autonomous_database管理自治数据库的生命周期操作。
参数:
autonomous_database_id(必需):自治数据库OCID返回值:
{
"success": true,
"summary": "已为自治数据库 'MyAutonomousDB'(之前处于停止状态)发起启动操作 - 工作请求:ocid1.workrequest.oc1...",
"method": "OCI Python SDK",
"action_details": {
"autonomous_database_id": "ocid1.autonomousdatabase.oc1...",
"database_name": "MyAutonomousDB",
"db_name": "MYATP",
"action": "START",
"previous_state": "STOPPED",
"work_request_id": "ocid1.workrequest.oc1...",
"initiated_at": "2025-08-02T09:42:30Z"
}
}
scale_autonomous_database扩展自治数据库的计算和存储资源。
参数:
autonomous_database_id(必需):自治数据库OCIDcompute_count(可选):ECPU数量(对于ECPU模型,推荐使用)cpu_core_count(可选):CPU核心数量(对于OCPU模型,旧版)data_storage_size_in_tbs(可选):存储大小(TB)is_auto_scaling_enabled(可选):启用/禁用计算资源的自动扩展is_auto_scaling_for_storage_enabled(可选):启用/禁用存储资源的自动扩展返回值:
{
"success": true,
"summary": "已为自治数据库 'MyAutonomousDB' 发起扩展操作:ECPU:4.0,存储:2TB - 工作请求:ocid1.workrequest.oc1...",
"method": "OCI Python SDK",
"action_details": {
"autonomous_database_id": "ocid1.autonomousdatabase.oc1...",
"database_name": "MyAutonomousDB",
"action": "SCALE",
"changes": ["ECPU: 4.0", "Storage: 2TB"],
"work_request_id": "ocid1.workrequest.oc1...",
"initiated_at": "2025-08-02T09:42:30Z"
}
}
get_autonomous_database_state获取自治数据库的当前生命周期状态。
参数:
autonomous_database_id(必需):自治数据库OCID返回值:
{
"success": true,
"summary": "自治数据库 'MyAutonomousDB'(事务处理)目前可用",
"method": "OCI Python SDK",
"state_info": {
"autonomous_database_id": "ocid1.autonomousdatabase.oc1...",
"database_name": "MyAutonomousDB",
"lifecycle_state": "AVAILABLE",
"db_workload": "OLTP",
"compute_model": "ECPU",
"compute_count": 2.0,
"is_auto_scaling_enabled": true,
"is_free_tier": false
}
}
test_core_services_connection测试与OCI核心服务的连接,并验证配置。
返回以下服务的连接状态:
⚠️ 重要提示
- 实例操作:不支持实例创建/终止功能(仅支持读取/管理现有实例);仅支持单分区操作(不支持跨分区查询);不支持实例控制台连接访问;不支持实例池或配置管理。
- 存储和网络:不支持块存储卷管理;网络操作有限(仅支持只读VNIC信息);不支持虚拟云网络(VCN)/子网管理功能;不支持负载均衡器集成。
- 监控和成本:不支持实例指标或性能数据;不支持成本跟踪或计费信息;不提供资源优化建议。
✅ 已在生产环境的OCI租户中成功测试
summary 字段success 布尔值,便于解析{
"success": true|false,
"summary": "易于人类阅读的描述",
"count": 13,
"method": "OCI Python SDK|OCI CLI",
"data_field": [...],
"retrieved_at": "2025-07-30T09:42:30Z",
"error": "如果失败,显示错误消息"
}
from fastmcp import FastMCP
mcp = FastMCP("OCI Core Services Server")
@mcp.tool()
async def list_compute_instances(...) -> Dict[str, Any]:
# 工具实现
from oci.core import ComputeClient, VirtualNetworkClient
# 使用自动认证初始化客户端
self.compute_client = ComputeClient(self.config)
self.network_client = VirtualNetworkClient(self.config)
try:
instances = await self.list_instances_sdk(compartment_id)
method = "OCI Python SDK"
except Exception as sdk_error:
logger.warning(f"SDK失败,尝试使用CLI:{sdk_error}")
instances = await self.list_instances_cli_fallback(compartment_id)
method = "OCI CLI"
{
"name": "list_compute_instances",
"arguments": {
"lifecycle_state": "RUNNING"
}
}
{
"name": "get_instance_details",
"arguments": {
"instance_id": "ocid1.instance.oc1.eu-frankfurt-1...",
"include_network": true
}
}
{
"name": "list_instances_with_network",
"arguments": {
"compartment_id": "ocid1.compartment.oc1...",
"lifecycle_state": "RUNNING"
}
}
{
"name": "start_compute_instance",
"arguments": {
"instance_id": "ocid1.instance.oc1.eu-frankfurt-1..."
}
}
{
"name": "stop_compute_instance",
"arguments": {
"instance_id": "ocid1.instance.oc1.eu-frankfurt-1...",
"soft_stop": true
}
}
{
"name": "restart_compute_instance",
"arguments": {
"instance_id": "ocid1.instance.oc1.eu-frankfurt-1...",
"soft_restart": false
}
}
{
"name": "get_compute_instance_state",
"arguments": {
"instance_id": "ocid1.instance.oc1.eu-frankfurt-1..."
}
}
~/.oci/config 配置即可工作本项目采用MIT许可证 - 详情请参阅 LICENSE 文件。
MIT License
Copyright (c) 2025
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
这个生产级的OCI核心服务FastMCP服务器提供全面的OCI基础设施管理,拥有15个专业工具、LLM优化的响应和经过实战检验的可靠性。非常适合需要深入OCI计算、数据库和网络操作能力的AI助手。