Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions local.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM python:3.11-slim-bookworm
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/

# Copy the project into the image
ADD . /app

# Sync the project into a new environment, asserting the lockfile is up to date
WORKDIR /app
RUN uv sync --locked

# Expose the port the MCP server runs on
EXPOSE 8000

CMD ["uv", "run", "src/main.py", "start", "--transport", "stdio"]
3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ dependencies = [
"nbformat>=5.10.4",
"pydantic-settings>=2.9.1",
"segment-analytics-python>=2.3.4",
"singlestoredb",
"singlestoredb>=1.14.2",
"starlette>=0.46.2",
]

Expand Down Expand Up @@ -91,7 +91,6 @@ dev-dependencies = [

[tool.uv.sources]
singlestore-mcp-server = { workspace = true }
singlestoredb = { git = "https://github.com/Rodriguespn/singlestoredb-python", rev = "feature/free-tier-endpoints" }

[tool.pytest.ini_options]
testpaths = ["tests"]
Expand Down
83 changes: 49 additions & 34 deletions src/api/tools/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -2048,21 +2048,43 @@ def __get_workspace_by_id(workspace_id: str) -> WorkspaceTarget:
Raises:
ValueError: If workspace cannot be found
"""
workspace_manager = s2.manage_workspaces(
access_token=get_access_token(), organization_id=get_org_id()
)

target = None
is_shared = False

try:
target = workspace_manager.get_workspace(workspace_id)
# Try as dedicated workspace first
workspace_data = build_request("GET", f"workspaces/{workspace_id}")

# Create a simple object to match the SDK interface
class SimpleWorkspace:
def __init__(self, data):
self.name = data.get("name", "")
self.id = data.get("workspaceID", workspace_id)
self.endpoint = data.get("endpoint")

target = SimpleWorkspace(workspace_data)
is_shared = False # Dedicated workspace
except Exception as e:
if "404" in str(e):
# Try as virtual workspace
target = workspace_manager.get_starter_workspace(workspace_id)
is_shared = True # Shared/virtual workspace
try:
virtual_workspace_data = build_request(
"GET", f"sharedtier/virtualWorkspaces/{workspace_id}"
)

# Create a simple object to match the SDK interface
class SimpleVirtualWorkspace:
def __init__(self, data):
self.name = data.get("name", "")
self.id = data.get("virtualWorkspaceID", workspace_id)
self.endpoint = data.get("endpoint")
self.database_name = data.get("databaseName", "")

target = SimpleVirtualWorkspace(virtual_workspace_data)
is_shared = True # Shared/virtual workspace
except Exception:
raise ValueError(f"Cannot find workspace {workspace_id}")
else:
raise e

Expand Down Expand Up @@ -2120,31 +2142,29 @@ def create_starter_workspace(
)

try:
# Initialize workspace manager using the SDK
workspace_manager = s2.manage_workspaces(
access_token=get_access_token(),
base_url=settings.s2_api_base_url,
organization_id=get_org_id(),
)

# Create the starter workspace
starter_workspace = workspace_manager.create_starter_workspace(
name=name,
database_name=database_name,
# Create the starter workspace using the API
payload = {
"name": name,
"databaseName": database_name,
# TODO: Dinamically set region_id if needed
workspace_group={"cell_id": "3482219c-a389-4079-b18b-d50662524e8a"},
"workspaceGroup": {"cellID": "3482219c-a389-4079-b18b-d50662524e8a"},
}

starter_workspace_data = build_request(
"POST", "sharedtier/virtualWorkspaces", data=payload
)

ctx.info(
f"Starter workspace '{name}' created successfully with ID: {starter_workspace.workspace_id}"
f"Starter workspace '{name}' created successfully with ID: {starter_workspace_data.get('virtualWorkspaceID')}"
)

return {
"status": "success",
"message": f"Starter workspace '{name}' created successfully",
"name": starter_workspace.name,
"endpoint": starter_workspace.endpoint,
"database_name": starter_workspace.database_name,
"workspace_id": starter_workspace_data.get("virtualWorkspaceID"),
"name": starter_workspace_data.get("name"),
"endpoint": starter_workspace_data.get("endpoint"),
"database_name": starter_workspace_data.get("databaseName"),
}

except Exception as e:
Expand Down Expand Up @@ -2221,20 +2241,13 @@ def terminate_virtual_workspace(
)

try:
# Initialize workspace manager using the SDK
workspace_manager = s2.manage_workspaces(
access_token=get_access_token(),
base_url=settings.s2_api_base_url,
organization_id=get_org_id(),
)

# First, try to get the workspace details before termination
workspace_name = None
try:
starter_workspace = workspace_manager.get_starter_workspace(
validated_workspace_id
starter_workspace_data = build_request(
"GET", f"sharedtier/virtualWorkspaces/{validated_workspace_id}"
)
workspace_name = starter_workspace.name
workspace_name = starter_workspace_data.get("name")
ctx.info(
f"Found virtual workspace '{workspace_name}' (ID: {validated_workspace_id})"
)
Expand All @@ -2246,7 +2259,9 @@ def terminate_virtual_workspace(
)

# Terminate the virtual workspace
workspace_manager.terminate_starter_workspace(validated_workspace_id)
build_request(
"DELETE", f"sharedtier/virtualWorkspaces/{validated_workspace_id}"
)

termination_time = datetime.now().isoformat()

Expand Down Expand Up @@ -2297,7 +2312,7 @@ def terminate_virtual_workspace(
{"func": complete_database_migration, "internal": True},
# This tool is under development and not yet available for public use
{"func": create_starter_workspace, "internal": True},
{"func": terminate_virtual_workspace},
{"func": terminate_virtual_workspace, "internal": True},
]

# Export the tools
Expand Down
13 changes: 11 additions & 2 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.