Skip to content

Commit 0e31637

Browse files
author
Pedro Rodrigues
committed
enable virtual workspace actions
1 parent 937f300 commit 0e31637

File tree

5 files changed

+89
-7
lines changed

5 files changed

+89
-7
lines changed

changelog/0.5.0.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
## Added
44

55
- Enabled `terminate_virtual_workspace` and `create_starter_workspace` tools with safety confirmation ellicitation
6+
- New `list_sharedtier_regions` tool to list regions available for shared tier workspaces
67
- New `database_onboarding` prompt to guide users through the process of setting up a new database
78
- New `help` prompt to provide an overview of the SingleStore MCP server capabilities, available tools, resources, and prompts

src/api/tools/regions/regions.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from mcp.server.fastmcp import Context
88

99
from src.api.common import build_request
10+
from src.api.tools.regions.utils import fetch_shared_tier_regions
1011
from src.logger import get_logger
1112

1213
# Set up logger for this module
@@ -79,7 +80,7 @@ async def list_sharedtier_regions(ctx: Context) -> Dict[str, Any]:
7980
await ctx.info("Listing available shared tier regions...")
8081

8182
try:
82-
regions_data = build_request("GET", "regions/sharedtier")
83+
regions_data = fetch_shared_tier_regions()
8384

8485
return {
8586
"status": "success",
@@ -93,8 +94,8 @@ async def list_sharedtier_regions(ctx: Context) -> Dict[str, Any]:
9394
}
9495

9596
except Exception as e:
96-
error_msg = f"Failed to list shared tier regions: {str(e)}"
97-
ctx.error(error_msg)
97+
error_msg = str(e)
98+
await ctx.error(error_msg)
9899

99100
return {
100101
"status": "error",

src/api/tools/regions/utils.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"""Utility functions for regions operations."""
2+
3+
from typing import List, Dict, Any
4+
from src.api.common import build_request
5+
6+
7+
def fetch_shared_tier_regions() -> List[Dict[str, Any]]:
8+
"""
9+
Fetch shared tier regions data from the API.
10+
11+
Returns:
12+
List of region dictionaries containing region information
13+
14+
Raises:
15+
Exception: If the API request fails or returns an error
16+
"""
17+
try:
18+
regions_data = build_request("GET", "regions/sharedtier")
19+
return regions_data
20+
except Exception as e:
21+
raise Exception(f"Failed to list shared tier regions: {str(e)}")

src/api/tools/starter_workspaces/starter_workspaces.py

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
"""Starter workspaces tools for SingleStore MCP server."""
22

33
from datetime import datetime
4-
from typing import Dict, Any
4+
from typing import Dict, Any, Optional
55
from pydantic import BaseModel, Field
66

77
from mcp.server.fastmcp import Context
88

99
from src.config import config
1010
from src.api.common import build_request
11+
from src.api.tools.regions.utils import fetch_shared_tier_regions
1112
from src.utils.uuid_validation import validate_workspace_id
1213
from src.utils.elicitation import try_elicitation, ElicitationError
1314
from src.logger import get_logger
@@ -49,7 +50,11 @@ def list_virtual_workspaces() -> Dict[str, Any]:
4950

5051

5152
async def create_starter_workspace(
52-
ctx: Context, name: str, database_name: str, provider: str, region_name: str
53+
ctx: Context,
54+
name: str,
55+
database_name: str,
56+
provider: Optional[str] = None,
57+
region_name: Optional[str] = None,
5358
) -> Dict[str, Any]:
5459
"""
5560
Create a new starter workspace using the SingleStore SDK.
@@ -100,6 +105,60 @@ async def create_starter_workspace(
100105
)
101106

102107
try:
108+
# If provider or region_name are not provided, fetch available regions and ask user to pick
109+
if provider is None or region_name is None:
110+
await ctx.info("Fetching available shared tier regions...")
111+
regions_data = fetch_shared_tier_regions()
112+
113+
# Group regions by provider
114+
provider_regions = {}
115+
for region in regions_data:
116+
prov = region.get("provider")
117+
if prov not in provider_regions:
118+
provider_regions[prov] = []
119+
provider_regions[prov].append(region.get("regionName"))
120+
121+
# Create region selection schema
122+
class RegionSelection(BaseModel):
123+
provider: str = Field(
124+
description=f"Choose a cloud provider from: {', '.join(provider_regions.keys())}"
125+
)
126+
region_name: str = Field(
127+
description="Choose a region name from the available regions for the selected provider"
128+
)
129+
130+
# Format region information for user
131+
region_info = "\n".join(
132+
[
133+
f"**{prov}**: {', '.join([r for r in regions])}"
134+
for prov, regions in provider_regions.items()
135+
]
136+
)
137+
138+
elicit_result, error = await try_elicitation(
139+
ctx=ctx,
140+
message=f"Please select a provider and region for your starter workspace:\n\n{region_info}",
141+
schema=RegionSelection,
142+
)
143+
144+
if error == ElicitationError.NOT_SUPPORTED:
145+
# Use first available region if elicitation not supported
146+
first_region = regions_data[0]
147+
provider = first_region.get("provider")
148+
region_name = first_region.get("regionName")
149+
await ctx.info(f"Using default region: {provider} - {region_name}")
150+
elif elicit_result.status == "success" and elicit_result.data:
151+
provider = elicit_result.data.provider
152+
region_name = elicit_result.data.region_name
153+
await ctx.info(f"Selected region: {provider} - {region_name}")
154+
else:
155+
return {
156+
"status": "cancelled",
157+
"message": "Workspace creation cancelled - no region selected",
158+
"workspace_name": name,
159+
"database_name": database_name,
160+
}
161+
103162
# Create the starter workspace using the API
104163
payload = {
105164
"name": name,
@@ -127,7 +186,7 @@ async def create_starter_workspace(
127186

128187
except Exception as e:
129188
error_msg = f"Failed to create starter workspace '{name}': {str(e)}"
130-
ctx.error(error_msg)
189+
await ctx.error(error_msg)
131190

132191
return {
133192
"status": "error",

src/api/tools/tools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
{"func": workspace_groups_info},
3434
{"func": workspaces_info},
3535
{"func": list_virtual_workspaces},
36-
{"func": create_starter_workspace, "internal": True},
36+
{"func": create_starter_workspace},
3737
{"func": terminate_virtual_workspace},
3838
{"func": list_regions},
3939
{"func": list_sharedtier_regions},

0 commit comments

Comments
 (0)