Skip to content

Commit ef258ab

Browse files
aaron-lafittegebhardtr
authored andcommitted
Adds initial OCI migration tool (oracle#24)
This tool includes functionality to: - Retrieve migration details by OCID. - List migrations within a compartment, optionally filtered by lifecycle state. Also adds .idea/ to .gitignore.
1 parent b5ac40d commit ef258ab

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-0
lines changed

mcphost.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,14 @@
7474
"run",
7575
"datetime_helper.py"
7676
]
77+
},
78+
"oci_migration": {
79+
"type": "local",
80+
"command": [
81+
"uv",
82+
"run",
83+
"oci_migration.py"
84+
]
7785
}
7886
}
7987
}

oci_migration.py

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import os
2+
from logging import Logger
3+
4+
import oci
5+
from fastmcp import FastMCP
6+
7+
logger = Logger("oci_migration_mcp", level="INFO")
8+
9+
mcp = FastMCP("oci_migration")
10+
11+
12+
def get_migration_client():
13+
logger.info("entering get_migration_client")
14+
config = oci.config.from_file(
15+
profile_name=os.getenv("OCI_CONFIG_PROFILE", oci.config.DEFAULT_PROFILE)
16+
)
17+
private_key = oci.signer.load_private_key_from_file(config["key_file"])
18+
token_file = config["security_token_file"]
19+
token = None
20+
with open(token_file, "r") as f:
21+
token = f.read()
22+
signer = oci.auth.signers.SecurityTokenSigner(token, private_key)
23+
return oci.cloud_migrations.MigrationClient(config, signer=signer)
24+
25+
26+
@mcp.tool
27+
def get_migration(migration_id: str):
28+
"""
29+
Get details for a specific Migration Project by OCID.
30+
Args:
31+
migration_id (str): OCID of the migration project.
32+
Returns:
33+
dict: Migration project details.
34+
"""
35+
client = get_migration_client()
36+
return client.get_migration(migration_id).data
37+
38+
39+
@mcp.tool
40+
def list_migrations(compartment_id: str, lifecycle_state: str = None):
41+
"""
42+
List Migration Projects for a compartment, optionally filtered by lifecycle state.
43+
Args:
44+
compartment_id (str): OCID of the compartment.
45+
lifecycle_state (str, optional): Filter by lifecycle state.
46+
Returns:
47+
list of dict: Each dict is a migration object.
48+
"""
49+
client = get_migration_client()
50+
list_args = {"compartment_id": compartment_id}
51+
52+
if lifecycle_state is not None:
53+
list_args["lifecycle_state"] = lifecycle_state
54+
55+
migrations = client.list_migrations(**list_args).data.items
56+
return [
57+
{
58+
"id": migration.id,
59+
"display_name": migration.display_name,
60+
"compartment_id": migration.compartment_id,
61+
"lifecycle_state": migration.lifecycle_state,
62+
"lifecycle_details": migration.lifecycle_details,
63+
"time_created": migration.time_created,
64+
"replication_schedule_id": migration.replication_schedule_id,
65+
"is_completed": migration.is_completed,
66+
}
67+
for migration in migrations
68+
]
69+
70+
71+
if __name__ == "__main__":
72+
# MCP spec: OpenAPI exposed at /openapi.json, native MCP at /mcp/v1
73+
# mcp.run(transport="http", host="127.0.0.1", port=8000, path="/mcp")
74+
# mcp.run(transport="sse", host="127.0.0.1", port=args.port)
75+
mcp.run()

0 commit comments

Comments
 (0)