MCP OCI OPSI服务器
版本3.0 | FastMCP 2.0 | 13 DBA技能 | OAuth+neneneba API密钥验证 | 多租户
用于Oracle云基础架构(OCI)运营洞察的MCP(模型上下文协议)服务器。此服务器通过Claude Desktop、Claude Code、ChatGPT或任何兼容MCP的客户端(stdio或HTTP传输)提供全面的Oracle数据库监控和分析功能。
快速链接: 安装 | 快速开始 | 启动和运输 | 提示和播放手册 | OCI VM部署 | API 参考 指南: 技能指南 | FastMCP v3指南 | OCI部署指南
______________________________________________________________________
标准
docs/OCI_MCP_SERVER_STANDARD.md
______________________________________________________________________
截图
车队摘要-即时概述
使用零API调用获取数据库车队的完整概览:
*显示数据库计数、类型和隔间分布的车队概述-来自本地缓存的即时响应*
数据库搜索结果
立即搜索和发现整个租约中的数据库:
*包含OCID、类型和隔间的全面数据库列表-缓存以供即时查询*
数据库详细信息
获取有关任何特定数据库的详细信息:
*详细的数据库信息,包括OCID、类型、隔间和状态-从缓存中即时查找*
______________________________________________________________________
v3.0中的新增功能
| 特性 | 描述 |
|---|---|
| OCI IAM OAuth | 使用OCI身份域进行企业身份验证 |
| API密钥回退 | 无缝回退到~/.oci/config进行开发 |
| MCP资源 | 10个只读数据端点,实现高效访问 |
| MCP提示 | 15个DBA工作流程指导模板 |
| 服务器组成 | 4个带有工具前缀的模块化子服务器 |
| DBA技能 | 13项专门技能,实现代币高效工作流程 |
| Di\[链接到安全变量:OPENAI_API_KEY\]存储 | 无需Redis-加密文件存储 |
| OCI VM就绪 | 用于自动部署的Terraform脚本 |
| 异步任务 | 后台缓存构建(cache_start_cache_build_task)通过投票 |
| 预构建的播放手册 | admin_get_troubleshooting_playbook 和 admin_list_prompts 快速LLM指导 |
______________________________________________________________________
启动和运输
- stdio(默认):
python -m mcp_oci_opsi(最适合克劳德桌面/代码,ChatGPT MCP)。 - 超文本传输协议:
MCP_TRANSPORT=http MCP_PORT=8000 python -m mcp_oci_opsi(适用于远程客户端)。 - SSE/流式HTTP:
MCP_TRANSPORT=sse|streamable-http MCP_PORT=8000 python -m mcp_oci_opsi(如果您的FastMCP运行时支持)。 - 版本切换:
MCP_VERSION=v2(FastMCP服务器)。MCP_VERSION=v3运行本地引导/CLI(不是MCP服务器)。 - 日志记录:设置
LOG_LEVEL=DEBUG用于冗长的启动;OCI SDK日志默认为警告。 - 超时:
OCI_CLIENT_TIMEOUT,OPSI_CLIENT_TIMEOUT,DBM_CLIENT_TIMEOUT(秒)绑定每个呼叫延迟;MCP_CLIENT_TIMEOUT_MScaps工具调用。
______________________________________________________________________
架构概述
高级体系结构
┌─────────────────────────────────────┐
│ MCP Clients │
│ (Claude Desktop/Code, ChatGPT) │
└──────────────┬──────────────────────┘
│
MCP Protocol (stdio/HTTP)
│
┌──────────────────────────────────────────────────┴──────────────────────────────────────────────────┐
│ │
│ MCP OCI OPSI SERVER v3.0 │
│ │
│ ┌────────────────────────────────────────────────────────────────────────────────────────────────┐ │
│ │ FastMCP 2.0 Core │ │
│ │ │ │
│ │ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ┌─────────────────────┐ │ │
│ │ │ cache_* │ │ opsi_* │ │ dbm_* │ │ admin_* │ │ Skills Engine │ │ │
│ │ │ 8 tools │ │ 9 tools │ │ 8 tools │ │ 10 tools │ │ 13 DBA skills │ │ │
│ │ │ 4 resources│ │ 1 resource │ │ 2 resources│ │ 3 resources│ │ │ │ │
│ │ │ │ │ │ │ │ │ │ │ • Fleet Overview │ │ │
│ │ │ Zero API │ │ Operations │ │ Database │ │ Profile │ │ • SQL Performance │ │ │
│ │ │ calls │ │ Insights │ │ Management │ │ Config │ │ • Capacity Plan │ │ │
│ │ └─────────────┘ └─────────────┘ └─────────────┘ └─────────────┘ └─────────────────────┘ │ │
│ │ │ │
│ │ ┌─────────────────────────────────────────────────────────────────────────────────────────┐ │ │
│ │ │ 15 MCP Prompts (Workflow Templates) │ │ │
│ │ │ Analysis: analyze_database_performance, investigate_slow_query, analyze_wait_events │ │ │
│ │ │ Operations: enable_monitoring, security_audit, tablespace_maintenance │ │ │
│ │ │ Reporting: capacity_planning_report, fleet_inventory_report, compliance_report │ │ │
│ │ └─────────────────────────────────────────────────────────────────────────────────────────┘ │ │
│ └────────────────────────────────────────────────────────────────────────────────────────────────┘ │
│ │
│ ┌────────────────────────────────────────────────────────────────────────────────────────────────┐ │
│ │ Authentication Layer │ │
│ │ │ │
│ │ ┌─────────────────────┐ ┌─────────────────────┐ ┌─────────────────────────────────────┐ │ │
│ │ │ OCI IAM OAuth │ │ API Key Auth │ │ Resource Principal (Future) │ │ │
│ │ │ (Production/HTTP) │ │ (Development/stdio)│ │ (OCI Functions/Containers) │ │ │
│ │ │ │ │ │ │ │ │ │
│ │ │ • OIDC Proxy │ │ • ~/.oci/config │ │ • Instance metadata auth │ │ │
│ │ │ • Token Exchange │ │ • Profile support │ │ • Dynamic credentials │ │ │
│ │ │ • Disk storage │ │ • Multi-tenancy │ │ • Auto-rotation │ │ │
│ │ └─────────────────────┘ └─────────────────────┘ └─────────────────────────────────────┘ │ │
│ └────────────────────────────────────────────────────────────────────────────────────────────────┘ │
│ │
│ ┌────────────────────────────────────────────────────────────────────────────────────────────────┐ │
│ │ OCI SDK Client Layer │ │
│ │ • Operations Insights Client • Database Management Client • Identity Client │ │
│ │ • Client caching (16 clients) • Multi-region support • Automatic pagination │ │
│ └────────────────────────────────────────────────────────────────────────────────────────────────┘ │
│ │
└──────────────────────────────────────────────────────────────────────────────────────────────────────┘
│
HTTPS REST API Calls
(Regional endpoints)
│
┌──────────────────────────────────────────────────┴──────────────────────────────────────────────────┐
│ │
│ ORACLE CLOUD INFRASTRUCTURE │
│ │
│ ┌──────────────────────────┐ ┌──────────────────────────┐ ┌──────────────────────────┐ │
│ │ Operations Insights │ │ Database Management │ │ Identity │ │
│ │ │ │ │ │ │ │
│ │ • Host Insights │ │ • Managed Databases │ │ • Users & Groups │ │
│ │ • Database Insights │ │ • SQL Plan Baselines │ │ • Compartments │ │
│ │ • SQL Statistics │ │ • Performance Hub │ │ • Policies │ │
│ │ • Capacity Planning │ │ • ADDM / AWR │ │ • Identity Domains │ │
│ │ • ML Forecasting │ │ • Tablespaces │ │ │ │
│ └──────────────────────────┘ └──────────────────────────┘ └──────────────────────────┘ │
│ │
│ Regional Endpoints: operationsinsights.{region}.oci.oraclecloud.com │
│ database.{region}.oraclecloud.com │
│ identity.{region}.oci.oraclecloud.com │
└──────────────────────────────────────────────────────────────────────────────────────────────────────┘工具组织(v3.0)
| 前缀 | 服务器 | 描述 |
|---|---|---|
cache_ | cache-tools | 即时操作(零API调用)和异步缓存构建任务 |
opsi_ | opsi工具 | 带有分页和速率限制提示的Operations Insights分析 |
dbm_ | dbm工具 | 带分页的数据库管理操作 |
admin_ | 管理工具 | 配置文件/配置、运行状况、提示、故障排除手册 |
| *(提示)* | 管理工具 | admin_list_prompts, admin_get_troubleshooting_playbook |
身份验证流程
┌────────────────────────────────────────────────────────────────────────────────┐
│ Authentication Decision Tree │
└────────────────────────────────────────────────────────────────────────────────┘
│
┌──────────────────┴──────────────────┐
▼ ▼
┌─────────────────────┐ ┌─────────────────────┐
│ HTTP Transport? │ │ stdio Transport │
│ (Production) │ │ (Development) │
└──────────┬──────────┘ └──────────┬──────────┘
│ │
┌──────────┴──────────┐ │
▼ ▼ ▼
┌───────────────┐ ┌───────────────┐ ┌───────────────────┐
│ OAuth Enabled │ │ OAuth Not │ │ API Key Auth │
│ (FASTMCP_ │ │ Configured │ │ ~/.oci/config │
│ OAUTH=1) │ │ │ │ │
└───────┬───────┘ └───────┬───────┘ └─────────┬─────────┘
│ │ │
▼ ▼ ▼
┌───────────────────────────────────────────────────────────────────┐
│ OCI API Calls │
│ • Signed requests with user/tenancy context │
│ • Regional endpoint routing │
│ • Automatic retry and error handling │
└───────────────────────────────────────────────────────────────────┘______________________________________________________________________
先决条件
- Python 3.10+
- OCI CLI已配置 在
~/.oci/config - 所需IAM策略:
Allow group YourGroup to read operations-insights-family in tenancy
Allow group YourGroup to read database-management-family in tenancy
Allow group YourGroup to read compartments in tenancy______________________________________________________________________
提示和播放手册
- 提示模板:
admin_list_prompts返回CPU热点、存储风险、慢速SQL和机群概述的预构建指令。用作任何LLM的罐装系统提示。 - 故障排除手册:
admin_get_troubleshooting_playbook(issue?)建议缓存优先的工具流及其原因。 - 健康检查:
admin_ping,opsi_health,dbm_health是零成本准备探头。 - 异步任务:启动缓存构建
cache_start_cache_build_task(compartment_ids=[...])并投票给cache_get_task_status(task_id=...).
______________________________________________________________________
安装
快速安装(开发)
# Clone repository
git clone https://github.com/adibirzu/mcp_oci_opsi.git
cd mcp_oci_opsi
# Create virtual environment
python3 -m venv .venv
source .venv/bin/activate
# Install dependencies
pip install -e .
# Verify installation
python -c "from mcp_oci_opsi.main_v3 import app; print('OK')"生产安装(Docker)
# Build image
docker build -t mcp-oci-opsi .
# Run with stdio transport
docker run -it --rm \
-v ~/.oci:/home/mcp/.oci:ro \
mcp-oci-opsi
# Run with HTTP transport
docker run -d \
-p 8000:8000 \
-v ~/.oci:/home/mcp/.oci:ro \
-e MCP_TRANSPORT=http \
mcp-oci-opsi______________________________________________________________________
快速开始
1.构建缓存(推荐)
# One-time setup - builds local cache for instant queries
./scripts/setup_and_build.sh
# Or with specific profile
./scripts/setup_and_build.sh --profile PRODUCTION2.配置MCP客户端(stdio)
克劳德桌面版 (~/Library/Application Support/Claude/claude_desktop_config.json)或ChatGPT MCP:
{
"mcpServers": {
"oci-opsi": {
"command": "/path/to/mcp_oci_opsi/.venv/bin/python",
"args": ["-m", "mcp_oci_opsi"],
"env": {
"MCP_VERSION": "v3",
"OCI_CLI_PROFILE": "DEFAULT"
}
}
}
}3.HTTP传输(远程)
export MCP_TRANSPORT=http
export MCP_HTTP_PORT=8000
python -m mcp_oci_opsiChatGPT MCP(HTTP)
{
"mcpServers": {
"oci-opsi": {
"url": "http://127.0.0.1:8000"
}
}
}4.开始使用
# Instant queries (from cache)
"How many databases do I have?"
"Find database PRODDB01"
"Show fleet summary"
# Real-time analytics (API calls)
"Analyze SQL performance for the last 24 hours"
"Show CPU forecast for next 30 days"
"Generate ADDM report for database X"
# Guided workflows (skills)
"Use the sql-performance skill to analyze slow queries"
"Run daily health check"
### 5. Run tests
cd mcp_oci_opsi python -m pytest
Example: Fleet Summary Response
Ask "Show me a summary of my database fleet" and get instant results:
OCI VM Deployment
Deploy to OCI Compute with automated provisioning using Terraform.
Quick Deploy
cd terraform/oci-vm
# Configure variables
cp terraform.tfvars.example terraform.tfvars
# Edit terraform.tfvars with your values
# Deploy
terraform init
terraform plan
terraform apply
# Get connection info
terraform output什么被配置
- OCI计算实例 (VM.标准E.4.Flex,2个OCPU,16GB RAM)
- 带子网的VCN (公共或私人)
- 安全列表 (SSH+可选HTTP)
- 云初始化配置:
- Python 3.11+pip - Docker+Docker组合 - MCP OCI OPSI服务器 - OCI-CLI - 自动启动系统服务
详细指南
看 docs/OCI_VM_DEPLOYMENT.md 用于:
- 分步说明
- 网络配置选项
- 安全强化
- 用于生产的OAuth设置
- 监测和维护
______________________________________________________________________
可用工具
缓存工具(即时-零API调用)
| 工具 | 说明 |
|---|---|
cache_get_fleet_summary | 车队概述,包括数量和类型 |
cache_search_databases | 按名称、类型、隔间搜索 |
cache_get_databases_by_compartment | 列出隔间中的数据库 |
cache_get_cached_statistics | 缓存元数据和统计数据 |
cache_list_cached_compartments | 缓存中的所有隔间 |
cache_build_database_cache | 构建/重建缓存 |
cache_refresh_cache_if_needed | 检查并刷新缓存 |
cache_get_database_by_id | 通过OCID获取数据库 |
Cache Tools Examples (click to expand)
数据库搜索: Database Search
数据库详细信息: Database Details
OPSI工具(运营洞察)
| 工具 | 说明 |
|---|---|
opsi_list_database_insights | 列出数据库见解 |
opsi_summarize_sql_statistics | SQL性能指标 |
opsi_summarize_sql_insights | SQL异常检测 |
opsi_get_database_capacity_trend | 历史容量 |
opsi_get_database_resource_forecast | ML预测 |
opsi_list_host_insights | 主机监控 |
opsi_list_exadata_insights | Exadata监控 |
opsi_query_warehouse | OPSI仓库SQL |
opsi_summarize_addm_findings | ADDM分析 |
DBM工具(数据库管理)
| 工具 | 说明 |
|---|---|
dbm_list_managed_databases | 列出托管数据库 |
dbm_get_managed_database | 数据库详细信息 |
dbm_get_tablespace_usage | 存储指标 |
dbm_list_awr_snapshots | AWR快照 |
dbm_get_awr_report | 生成AWR报告 |
dbm_get_addm_report | ADDM建议 |
dbm_list_sql_plan_baselines | SPM基线 |
dbm_get_database_parameters | 数据库参数 |
管理工具
| 工具 | 说明 |
|---|---|
admin_ping | 健康检查 |
admin_whoami | 当前背景 |
admin_list_profiles | OCI配置文件 |
admin_validate_profile | 验证配置 |
admin_switch_profile | 更改配置文件 |
admin_get_auth_status | 身份验证模式信息 |
admin_diagnose_permissions | 权限检查 |
admin_generate_oauth_keys | 生成密钥 |
admin_list_compartments | 隔间树 |
admin_get_tenancy_info | 租赁详情 |
技能工具
| 工具 | 说明 |
|---|---|
list_available_skills | 列出13个DBA技能 |
get_skill_context | 获取技能指导 |
get_skill_for_query | 自动匹配技能 |
get_quick_reference | Ta\[安全变量链接:OPENAI_API_KEY\]映射 |
get_token_optimization_tips | 最佳做法 |
______________________________________________________________________
MCP资源
通过URI模式访问只读数据:
| 资源URI | 描述 |
|---|---|
resource://fleet/summary | 车队概述 |
resource://fleet/statistics | 详细统计数据 |
resource://fleet/compartments | 隔间列表 |
resource://database/{id} | 数据库信息 |
resource://database/{id}/tablespaces | 表空间使用情况 |
resource://config/profiles | OCI配置文件 |
resource://config/current | 当前配置 |
resource://auth/status | 身份验证状态 |
resource://welcome | 开始使用 |
______________________________________________________________________
MCP提示
可重复使用的工作流模板:
分析提示
analyze_database_performance(database_name, time_range)investigate_slow_query(sql_id)analyze_wait_events(database_name, wait_class)analyze_resource_contention(compartment_name)daily_health_check()
操作提示
enable_monitoring(compartment_name)security_audit(compartment_name)tablespace_maintenance(database_name)plan_baseline_management(database_name)profile_setup(profile_name)
报告提示
capacity_planning_report(compartment_name, forecast_days)performance_summary_report(database_name, days)fleet_inventory_report()awr_comparison_report(database_name, baseline, compare)compliance_report(compartment_name)
______________________________________________________________________
DBA技能
常见DBA任务的13项专业技能:
| 技能 | 描述 | 关键工具 |
|---|---|---|
fleet-overview | 车队库存和健康状况 | cache_get_flete_summary |
sql-performance | SQL分析和调优 | opsi_gsummarize_SQL_statistics |
capacity-planning | 预测和趋势 | opsi_get_tabase_resource_forecast |
database-diagnostics | ADDM和故障排除 | dbm_get_ADDM_report |
awr-analysis | AWR报告和快照 | dbm_get_AWR_report |
host-monitoring | 主机资源监控 | opsi_list_Host_insights |
storage-management | 表空间监视 | dbm_get_tables_usage |
security-audit | 用户和权限审核 | admin_dignose_permissions |
sql-watch-management | SQL Watch配置 | opsi工具 |
sql-plan-baselines | SPM管理 | dbm_list_sql_plan_baselines |
multi-tenancy | 配置文件管理 | admin_list_profiles |
exadata-monitoring | Exadata见解 | opsi_list_Exadata_insights |
dba-assistant | 一般DBA帮助 | 所有工具 |
______________________________________________________________________
配置
环境变量
| 变量 | 默认值 | 描述 |
|---|---|---|
MCP_VERSION | v2 | 进入模式(v2=MCP服务器,v3=引导/CLI) |
MCP_TRANSPORT | stdio | 传输(stdio、http、sse、可流式传输http) |
MCP_HOST | 0.0.0.0 | 为网络传输绑定地址 |
MCP_PORT | 8000 | 网络传输端口 |
MCP_HTTP_HOST | 0.0.0.0 | 传统HTTP绑定地址(回退) |
MCP_HTTP_PORT | 8000 | 传统HTTP端口(回退) |
OCI_CLI_PROFILE | DEFAULT | OCI配置文件名称 |
OCI_REGION | 从配置 | 区域覆盖 |
FASTMCP_OAUTH_ENABLED | 0 | 启用OAuth |
JWT_SIGNING_KEY | - | JWT签名密钥(OAuth) |
STORAGE_ENCRYPTION_KEY | - | 令牌加密密钥 |
OTEL_TRACING_ENABLED | true | 启用OpenTetry跟踪 |
OCI_APM_ENDPOINT | - | OCI APM OTLP端点(\[链接到安全变量:OCI_APM_endpoint\]) |
OCI_APM_PRIVATE_DATA_KEY | - | OCI APM私有数据密钥(\[链接到安全变量:OCI_APM_private_data_key\]) |
OTEL_EXPORTER_OTLP_ENDPOINT | - | 通用OTLP端点(HTTP或gRPC) |
OTEL_DISABLE_LOCAL | false | 禁用本地收集器回退 |
OAuth配置(生产)
看 FASTCMP_V3_GUIDE.md 用于使用OCI身份域进行OAuth设置。
______________________________________________________________________
文档
| 文档 | 描述 |
|---|---|
| FASTCMP_V3_GUIDE.md | 完整的v3.0指南 |
| 技能_指南.md | DBA技能参考 |
| docs/OCI_VM_DEPLOYMENT.md | OCI VM部署 |
| docs/ARCHITECTURE.md | 详细架构 |
| CACHE_SYSTEM.md | 缓存系统文档 |
| 安全.md | 安全指南 |
______________________________________________________________________
许可证
麻省理工学院
贡献
欢迎投稿!请看 贡献.md.
