Skip to content

Commit 3f77935

Browse files
committed
MCP Tools 파일 분할 및 간소화 - mcp_main.py 파일에 포함된 tool 함수들을 다수의 tools/*.py 개별 파일로 이동 및 정리
1 parent cd8b6a5 commit 3f77935

File tree

94 files changed

+7167
-6376
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+7167
-6376
lines changed

src/mcp_openstack_ops/mcp_main.py

Lines changed: 371 additions & 6376 deletions
Large diffs are not rendered by default.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
"""Tool registration utilities for OpenStack MCP."""
2+
3+
import importlib
4+
import pkgutil
5+
from typing import Iterable
6+
7+
def _iter_tool_modules() -> Iterable[str]:
8+
"""Yield importable tool module names within this package."""
9+
for module_info in pkgutil.iter_modules(__path__): # type: ignore[name-defined]
10+
name = module_info.name
11+
if name.startswith('_'):
12+
continue
13+
yield name
14+
15+
def register_all_tools() -> None:
16+
"""Import every tool module so decorators register with FastMCP."""
17+
for module_name in sorted(_iter_tool_modules()):
18+
importlib.import_module(f"{__name__}.{module_name}")
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
"""Tool implementation for get_availability_zones."""
2+
3+
import json
4+
from datetime import datetime
5+
from ..functions import get_availability_zones as _get_availability_zones
6+
from ..mcp_main import (
7+
logger,
8+
mcp,
9+
)
10+
11+
@mcp.tool()
12+
async def get_availability_zones() -> str:
13+
"""
14+
List availability zones and their status
15+
16+
Returns:
17+
JSON string with availability zones information
18+
"""
19+
try:
20+
logger.info("Getting availability zones")
21+
22+
zones_result = _get_availability_zones()
23+
24+
response = {
25+
"timestamp": datetime.now().isoformat(),
26+
"operation": "get_availability_zones",
27+
"result": zones_result
28+
}
29+
30+
return json.dumps(response, indent=2, ensure_ascii=False)
31+
32+
except Exception as e:
33+
error_msg = f"Error: Failed to get availability zones - {str(e)}"
34+
logger.error(error_msg)
35+
return error_msg
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
"""Tool implementation for get_floating_ip_pools."""
2+
3+
import json
4+
from datetime import datetime
5+
from ..functions import get_floating_ip_pools as _get_floating_ip_pools
6+
from ..mcp_main import (
7+
logger,
8+
mcp,
9+
)
10+
11+
@mcp.tool()
12+
async def get_floating_ip_pools() -> str:
13+
"""
14+
Get list of floating IP pools (external networks).
15+
16+
Functions:
17+
- List all external networks that can provide floating IPs
18+
- Show available and used IP counts for each pool
19+
- Display network configuration for floating IP allocation
20+
- Provide pool capacity and utilization information
21+
22+
Use when user requests:
23+
- "Show floating IP pools"
24+
- "List available floating IP networks"
25+
- "Check floating IP capacity"
26+
- "What external networks are available?"
27+
28+
Returns:
29+
List of floating IP pools with capacity information in JSON format.
30+
"""
31+
try:
32+
result_data = _get_floating_ip_pools()
33+
34+
result = {
35+
"timestamp": datetime.now().isoformat(),
36+
"pools": result_data,
37+
"total_pools": len(result_data)
38+
}
39+
40+
return json.dumps(result, indent=2)
41+
42+
except Exception as e:
43+
error_msg = f"Error: Failed to get floating IP pools - {str(e)}"
44+
logger.error(error_msg)
45+
return error_msg
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
"""Tool implementation for get_floating_ips."""
2+
3+
import json
4+
from datetime import datetime
5+
from ..functions import get_floating_ips as _get_floating_ips
6+
from ..mcp_main import (
7+
logger,
8+
mcp,
9+
)
10+
11+
@mcp.tool()
12+
async def get_floating_ips() -> str:
13+
"""
14+
Get list of floating IPs with their associations.
15+
16+
Functions:
17+
- Query floating IPs and their current status
18+
- Display associated fixed IPs and ports
19+
- Show floating IP pool and router associations
20+
- Provide floating IP allocation and usage information
21+
22+
Use when user requests floating IP information, external connectivity queries, or IP management tasks.
23+
24+
Returns:
25+
List of floating IPs with detailed association information in JSON format.
26+
"""
27+
try:
28+
logger.info("Fetching floating IPs")
29+
floating_ips = _get_floating_ips()
30+
31+
result = {
32+
"timestamp": datetime.now().isoformat(),
33+
"total_floating_ips": len(floating_ips),
34+
"floating_ips": floating_ips
35+
}
36+
37+
return json.dumps(result, indent=2, ensure_ascii=False)
38+
39+
except Exception as e:
40+
error_msg = f"Error: Failed to fetch floating IPs - {str(e)}"
41+
logger.error(error_msg)
42+
return error_msg
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
"""Tool implementation for get_heat_stacks."""
2+
3+
import json
4+
from datetime import datetime
5+
from ..functions import get_heat_stacks as _get_heat_stacks
6+
from ..mcp_main import (
7+
logger,
8+
mcp,
9+
)
10+
11+
@mcp.tool()
12+
async def get_heat_stacks() -> str:
13+
"""
14+
Get list of Heat orchestration stacks.
15+
16+
Functions:
17+
- Query Heat stacks and their current status
18+
- Display stack creation and update timestamps
19+
- Show stack templates and resource information
20+
- Provide orchestration deployment information
21+
22+
Use when user requests stack information, orchestration queries, or infrastructure-as-code status.
23+
24+
Returns:
25+
List of Heat stacks with detailed information in JSON format.
26+
"""
27+
try:
28+
logger.info("Fetching Heat stacks")
29+
stacks = _get_heat_stacks()
30+
31+
result = {
32+
"timestamp": datetime.now().isoformat(),
33+
"total_stacks": len(stacks),
34+
"stacks": stacks
35+
}
36+
37+
return json.dumps(result, indent=2, ensure_ascii=False)
38+
39+
except Exception as e:
40+
error_msg = f"Error: Failed to fetch Heat stacks - {str(e)}"
41+
logger.error(error_msg)
42+
return error_msg
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
"""Tool implementation for get_hypervisor_details."""
2+
3+
import json
4+
from datetime import datetime
5+
from ..functions import get_hypervisor_details as _get_hypervisor_details
6+
from ..mcp_main import (
7+
logger,
8+
mcp,
9+
)
10+
11+
@mcp.tool()
12+
async def get_hypervisor_details(
13+
hypervisor_name: str = "all"
14+
) -> str:
15+
"""
16+
Get detailed information about hypervisors
17+
18+
Args:
19+
hypervisor_name: Name/ID of specific hypervisor or "all" for all hypervisors
20+
21+
Returns:
22+
JSON string with hypervisor details and statistics
23+
"""
24+
try:
25+
logger.info(f"Getting hypervisor details for: {hypervisor_name}")
26+
27+
hypervisor_result = _get_hypervisor_details(hypervisor_name=hypervisor_name)
28+
29+
response = {
30+
"timestamp": datetime.now().isoformat(),
31+
"operation": "get_hypervisor_details",
32+
"parameters": {
33+
"hypervisor_name": hypervisor_name
34+
},
35+
"result": hypervisor_result
36+
}
37+
38+
return json.dumps(response, indent=2, ensure_ascii=False)
39+
40+
except Exception as e:
41+
error_msg = f"Error: Failed to get hypervisor details - {str(e)}"
42+
logger.error(error_msg)
43+
return error_msg
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
"""Tool implementation for get_image_detail_list."""
2+
3+
import json
4+
from datetime import datetime
5+
from ..functions import get_image_detail_list as _get_image_detail_list
6+
from ..mcp_main import (
7+
logger,
8+
mcp,
9+
)
10+
11+
@mcp.tool()
12+
async def get_image_detail_list() -> str:
13+
"""
14+
Get detailed list of all images with comprehensive metadata.
15+
16+
Functions:
17+
- List all images available in the project
18+
- Show image status, size, and format information
19+
- Display image properties and metadata
20+
- Provide ownership and visibility details
21+
22+
Use when user requests image listing, image information, or image metadata details.
23+
24+
Returns:
25+
Comprehensive image list in JSON format with detailed metadata, properties, and status information.
26+
"""
27+
try:
28+
logger.info("Fetching detailed image list")
29+
images = _get_image_detail_list()
30+
31+
response = {
32+
"timestamp": datetime.now().isoformat(),
33+
"images": images,
34+
"count": len(images),
35+
"operation": "list_images_detailed"
36+
}
37+
38+
return json.dumps(response, indent=2, ensure_ascii=False)
39+
40+
except Exception as e:
41+
error_msg = f"Error: Failed to fetch detailed image list - {str(e)}"
42+
logger.error(error_msg)
43+
return error_msg

0 commit comments

Comments
 (0)