DEV Community

Dinesh Marimuthu
Dinesh Marimuthu

Posted on

OCI-MCP Integration: Connecting Oracle Cloud with AI

OCI-MCP Integration: Connecting Oracle Cloud with AI

Oracle Cloud Infrastructure (OCI) integration with Model Context Protocol (MCP) enables natural language interaction with cloud resources through AI assistants. This guide covers the essentials of implementing OCI-MCP integration.

What is OCI-MCP Integration?

OCI-MCP integration allows you to manage Oracle Cloud resources using conversational interfaces. By wrapping OCI SDK commands in an MCP server, you can execute cloud operations through natural language prompts.

Architecture

AI Assistant ↔ MCP Server ↔ OCI SDK ↔ Oracle Cloud
Enter fullscreen mode Exit fullscreen mode

Quick Setup

Prerequisites

  • Oracle Cloud Infrastructure account
  • Python 3.8+ for MCP server
  • OCI CLI and SDK installed
  • Claude Desktop or MCP client

Step 1: Create MCP Server

from mcp import Server
from oci import config, compute

class OCIMCPServer:
    def __init__(self):
        self.config = config.from_file()
        self.compute_client = compute.ComputeClient(self.config)

    def list_instances(self, compartment_id):
        return self.compute_client.list_instances(compartment_id)
Enter fullscreen mode Exit fullscreen mode

Step 2: Configure Authentication

# Configure ~/.oci/config
[DEFAULT]
user=ocid1.user.oc1..your_user_ocid
fingerprint=your_key_fingerprint
key_file=~/.oci/oci_api_key.pem
tenancy=ocid1.tenancy.oc1..your_tenancy_ocid
region=us-ashburn-1
Enter fullscreen mode Exit fullscreen mode

Step 3: Define Tools

@server.tool("list_compute_instances")
def list_compute_instances(compartment_id: str):
    try:
        response = compute_client.list_instances(compartment_id=compartment_id)
        return [{"name": instance.display_name, 
                "state": instance.lifecycle_state} 
               for instance in response.data]
    except Exception as e:
        return {"error": str(e)}
Enter fullscreen mode Exit fullscreen mode

Step 4: Register with Claude

{
  "mcpServers": {
    "oci-integration": {
      "command": "python",
      "args": ["oci-mcp-server.py"]
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

Key Use Cases

Compute Management

  • List, start, stop instances
  • Resize compute shapes
  • Fetch performance metrics

Example: "Show me all stopped instances"

Database Operations

  • Start/stop Autonomous Databases
  • Scale resources
  • Manage backups

Example: "Scale production database to 4 OCPUs"

Storage Management

  • List buckets and objects
  • Upload/download files
  • Generate access URLs

Additional Services

  • Networking (VCNs, load balancers)
  • Monitoring (metrics, alarms)
  • IAM (users, policies)
  • Cost management

Benefits

  1. Natural Language Control: Use simple English instead of complex CLI commands
  2. Operational Efficiency: Faster execution and reduced learning curve
  3. Cross-Platform Integration: Combine with other systems
  4. Enhanced Security: Leverage OCI native authentication

Security Best Practices

  • Use principle of least privilege
  • Implement regular key rotation
  • Separate credentials by environment
  • Enable audit logging
# Secure configuration
class SecureOCIConfig:
    def __init__(self):
        if os.getenv('OCI_RESOURCE_PRINCIPAL_VERSION'):
            self.signer = InstancePrincipalsSecurityTokenSigner()
        else:
            self.config = config.from_file()
Enter fullscreen mode Exit fullscreen mode

Troubleshooting

Authentication Issues

  • Verify API key configuration
  • Check key file permissions
  • Validate IAM permissions

Permission Errors

  • Review IAM policies
  • Check compartment access
  • Verify resource visibility

Real-World Example

@server.tool("auto_scale_web_tier")
def auto_scale_web_tier(compartment_id: str):
    instances = list_compute_instances(compartment_id)
    # Check metrics and scale if needed
    if high_cpu_detected(instances):
        return scale_instances(compartment_id, 'up')
    return {"status": "No scaling needed"}
Enter fullscreen mode Exit fullscreen mode

Usage: "Check if web tier needs scaling"

Getting Started

  1. Set up OCI environment
  2. Install dependencies
  3. Create first MCP tool
  4. Test with simple prompts
  5. Expand functionality
  6. Add monitoring

Conclusion

OCI-MCP integration transforms cloud operations by enabling natural language interaction with Oracle Cloud Infrastructure. This reduces complexity and makes cloud management more accessible.

Start with basic operations and gradually expand to complex workflows as your team adopts the technology.

Resources

Top comments (0)