Skip to main content
The OCI API MCP server provides tools to run Oracle Cloud Infrastructure CLI commands, offering a flexible way to interact with any OCI service through the command-line interface.

Installation

uvx oracle.oci-api-mcp-server

Running the Server

STDIO Transport Mode

uvx oracle.oci-api-mcp-server

HTTP Streaming Transport Mode

ORACLE_MCP_HOST=<hostname/IP address> ORACLE_MCP_PORT=<port number> uvx oracle.oci-api-mcp-server

Available Tools

The server provides the following tools for OCI CLI interaction:
Tool NameDescription
get_oci_command_helpGet help and instructions for running an OCI CLI command
run_oci_commandExecute an OCI CLI command
get_oci_commands (Resource)Get helpful information on various OCI services and related commands
Important: When using these tools, only provide the command after ‘oci’, do not include the string ‘oci’ in your command.For example:
  • Correct: compute instance list
  • Incorrect: oci compute instance list

Usage Examples

Get Command Help

How do I list compute instances?
Returns helpful instructions for the oci compute instance list command including required parameters and examples.
Show me help for creating a VCN
Retrieves documentation for VCN creation commands.

Run OCI Commands

List all compute instances in compartment ocid1.compartment.oc1..example
Executes: oci compute instance list --compartment-id ocid1.compartment.oc1..example
Get details for instance ocid1.instance.oc1.phx.example
Executes: oci compute instance get --instance-id ocid1.instance.oc1.phx.example
List all VCNs in my compartment
The AI will construct and execute the appropriate CLI command.

Get Service Information

What OCI commands are available for networking?
Retrieves information about networking-related OCI CLI commands and services.

Understanding the OCI CLI

What is OCI CLI?

The Oracle Cloud Infrastructure Command Line Interface (CLI) is a unified tool for managing OCI resources:
  • Comprehensive - Covers all OCI services
  • Scriptable - Automate cloud operations
  • Cross-Platform - Windows, macOS, Linux
  • JSON Output - Easy to parse programmatically

Command Structure

oci <service> <resource-type> <action> [options]
Examples:
oci compute instance list --compartment-id <id>
oci network vcn create --cidr-block 10.0.0.0/16 --compartment-id <id>
oci os bucket create --name mybucket --compartment-id <id>

Common Services

Compute
  • oci compute instance - Manage instances
  • oci compute image - Manage images
  • oci compute shape - List available shapes
Networking
  • oci network vcn - Manage VCNs
  • oci network subnet - Manage subnets
  • oci network security-list - Manage security lists
Identity
  • oci iam compartment - Manage compartments
  • oci iam user - Manage users
  • oci iam group - Manage groups
Storage
  • oci os bucket - Manage object storage buckets
  • oci os object - Manage objects
  • oci bv volume - Manage block volumes
Database
  • oci db autonomous-database - Manage Autonomous Databases
  • oci db system - Manage DB systems
  • oci db database - Manage databases

Authentication

The server uses OCI CLI configuration from ~/.oci/config:
oci setup config
Ensure you have:
  1. OCI CLI installed
  2. Valid API credentials configured
  3. Appropriate IAM permissions

Required Permissions

Permissions depend on the specific commands being executed. For example: Compute Operations:
Allow group ComputeAdmins to manage instances in compartment MyCompartment
Network Operations:
Allow group NetworkAdmins to manage virtual-network-family in compartment MyCompartment
Read-Only Access:
Allow group Viewers to inspect all-resources in compartment MyCompartment
Security NoticeAll actions are performed with the permissions of the configured OCI CLI profile. We advise:
  • Least-privilege IAM setup
  • Secure credential management
  • Safe network practices
  • Secure logging
  • Never expose secrets in command outputs
  • Review commands before execution
  • Be cautious with destructive operations (delete, terminate)

Common Use Cases

Ad-Hoc Queries

  • Quick resource lookups
  • Verify configurations
  • Check resource states
  • Gather information for troubleshooting

Automation Scripts

  • Build deployment scripts
  • Automate resource provisioning
  • Implement CI/CD pipelines
  • Schedule maintenance tasks

Troubleshooting

  • Debug connectivity issues
  • Verify resource configurations
  • Check service status
  • Investigate errors

Resource Management

  • Bulk operations
  • Cross-service operations
  • Complex workflows
  • Custom integrations

Reporting

  • Generate resource inventories
  • Export configurations
  • Collect metrics
  • Create audit reports

Best Practices

Command Construction

  • Use clear, specific commands
  • Include all required parameters
  • Use --help to verify syntax
  • Test commands in non-production first

Error Handling

  • Check command exit codes
  • Parse error messages
  • Implement retries for transient failures
  • Log command execution

Security

  • Never hardcode credentials
  • Use IAM policies for access control
  • Audit command execution
  • Sanitize sensitive output
  • Use —profile for different credentials

Output Processing

  • Use --query to filter JSON output
  • Pipe to jq for advanced JSON processing
  • Format output for readability
  • Save outputs for audit trail

Performance

  • Use pagination for large result sets
  • Parallel execution for independent operations
  • Cache frequently accessed data
  • Minimize API calls

Advanced Usage

JSON Querying

oci compute instance list --compartment-id <id> --query 'data[?"lifecycle-state"==`RUNNING`]'
Filters results using JMESPath query syntax.

Output Formatting

oci compute instance list --compartment-id <id> --output table
Format output as table instead of JSON.

Using Profiles

oci compute instance list --compartment-id <id> --profile production
Use specific OCI config profile.

Pagination

oci compute instance list --compartment-id <id> --all
Automatically fetch all pages of results.

Troubleshooting

Command Not Found

Check:
  • OCI CLI is installed
  • CLI is in system PATH
  • Command syntax is correct
  • Service name is valid
Solution:
which oci
oci --version

Authentication Errors

Error: NotAuthenticated
  • Verify OCI config file exists (~/.oci/config)
  • Check API key is valid
  • Ensure private key file exists and is readable
  • Verify correct profile is being used

Permission Denied

Error: NotAuthorizedOrNotFound
  • Check IAM policies grant required permissions
  • Verify you’re in correct compartment
  • Ensure resource exists
  • Confirm region is correct

Invalid Parameters

Error: Missing option / Invalid value
  • Use --help to check required parameters
  • Verify parameter format (especially OCIDs)
  • Check for required vs optional parameters
  • Ensure values meet constraints

Timeout Issues

  • Check network connectivity
  • Verify OCI service status
  • Increase timeout if needed
  • Retry the operation

Integration Patterns

Scripting

#!/bin/bash
# List all running instances
INSTANCES=$(oci compute instance list \
  --compartment-id $COMPARTMENT_ID \
  --lifecycle-state RUNNING \
  --query 'data[].id' \
  --raw-output)

for instance in $INSTANCES; do
  echo "Processing $instance"
  # Perform operations
done

CI/CD Integration

# GitHub Actions example
- name: Deploy to OCI
  run: |
    oci compute instance launch \
      --compartment-id ${{ secrets.COMPARTMENT_ID }} \
      --shape VM.Standard.E4.Flex \
      --image-id ${{ env.IMAGE_ID }}

Monitoring Scripts

# Check instance health
oci compute instance list \
  --compartment-id $COMPARTMENT_ID \
  --lifecycle-state RUNNING | \
  jq -r '.data[] | select(."freeform-tags".monitoring=="true") | .id'

CLI vs SDK

Use CLI when:
  • Quick ad-hoc operations
  • Shell scripting
  • Interactive exploration
  • Simple automation
Use SDK when:
  • Complex application logic
  • Need programmatic control
  • Error handling is critical
  • Building production applications
  • OCI Cloud - SDK-based API access
  • All other OCI servers - Service-specific tools

Additional Resources

Build docs developers (and LLMs) love