create_workspace
Generate a workspace by specifying an instance type and cloud provider, enabling efficient deployment and management of ML models on Brev's MCP server.
Instructions
Create a workspace from an instance type and cloud provider
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| cloud_provider | Yes | The cloud provider for the workspace | |
| instance_type | No | The instance type of the workspace | |
| name | No | The name of the workspace |
Implementation Reference
- src/brev_mcp/tools.py:23-34 (handler)The primary MCP tool handler for 'create_workspace'. Validates input arguments (name, cloud_provider, instance_type), constructs CloudProvider, calls helper create_provider_workspace, and returns the workspace JSON as TextContent.async def create_workspace_tool(args: dict[str, str]) -> TextContent: if "name" not in args or "cloud_provider" not in args or "instance_type" not in args: raise ValueError("missing required arguments for create_workspace tool") cloud_provider = CloudProvider(args["cloud_provider"]) workspace = await create_provider_workspace(args["name"], cloud_provider, args["instance_type"]) return [ TextContent( type="text", text=workspace ) ]
- src/brev_mcp/tools.py:55-79 (registration)Registration of the 'create_workspace' tool in the tool_models dictionary, including Tool definition with name, description, input schema, and reference to the handler function."create_workspace": ToolModel( tool=Tool( name="create_workspace", description="Create a workspace from an instance type and cloud provider", inputSchema={ "type": "object", "properties": { "name": { "description": "The name of the workspace", "type": "string", }, "cloud_provider": { "description": "The cloud provider for the workspace", "enum": [provider.value for provider in CloudProvider] }, "instance_type": { "description": "The instance type of the workspace", "type": "string", } }, "required": ["cloud_provider"] } ), call_tool=create_workspace_tool )
- src/brev_mcp/models.py:204-246 (schema)Pydantic model defining the request schema for creating a workspace, used internally by the API client.class CreateWorkspaceRequest(BaseModel): # version: Optional[str] = None name: str # description: Optional[str] = None workspace_group_id: Optional[str] = Field(None, alias="workspaceGroupId") # workspace_template_id: Optional[str] = Field(None, alias="workspaceTemplateId") # workspace_class: Optional[WorkspaceClassID] = Field(None, alias="workspaceClassId") # git_repo: Optional[str] = Field(None, alias="gitRepo") # is_stoppable: Optional[bool] = Field(None, alias="isStoppable") # tunnel: Optional[WorkspaceTunnel] = None # primary_application_id: Optional[str] = Field(None, alias="primaryApplicationId") # startup_script: Optional[str] = Field(None, alias="startupScript") # startup_script_path: Optional[str] = Field(None, alias="startupScriptPath") # ide_config: Optional[ClientConfig] = Field(None, alias="ideConfig") # dont_check_ssh_keys: bool = Field(False, alias="dontCheckSSHKeys") # repos: ReposV0 # execs: ExecsV0 # init_branch: Optional[str] = Field(None, alias="initBranch") # dot_brev_path: Optional[str] = Field(None, alias="dotBrevPath") # repos_v1: Optional[ReposV1] = Field(None, alias="reposV1") # execs_v1: Optional[ExecsV1] = Field(None, alias="execsV1") instance_type: Optional[str] = Field(None, alias="instanceType") # disk_storage: Optional[str] = Field(None, alias="diskStorage") # region: Optional[str] = None # image: Optional[str] = None # architecture: Optional[Architecture] = None # spot: bool = False # on_container: bool = Field(False, alias="onContainer") # initial_container_image: Optional[str] = Field(None, alias="containerImage") verb_yaml: Optional[str] = Field(DEFAULT_VERB_CONFIG, alias="verbYaml") # base_image: Optional[str] = Field(None, alias="baseImage") # custom_container: Optional[CustomContainer] = Field(None, alias="customContainer") # port_mappings: Optional[Dict[str, str]] = Field(None, alias="portMappings") workspace_version: Optional[Literal["v1", "v0"]] = Field("v1", alias="workspaceVersion") # retry_for: Optional[str] = Field(None, alias="retryFor") # vm_only_mode: bool = Field(False, alias="vmOnlyMode") # files: Optional[List[FileRequest]] = None # labels: Optional[Dict[str, str]] = None # launch_jupyter_on_start: bool = Field(False, alias="launchJupyterOnStart") class Config: populate_by_name = True
- src/brev_mcp/workspace.py:8-15 (helper)Helper function that builds the CreateWorkspaceRequest using provider-specific workspace group ID and calls the API create_workspace function.async def create_provider_workspace(name: str, cloud_provider: CloudProvider, instance_type: str) -> str: req = CreateWorkspaceRequest( name=name, workspaceGroupId=cloud_provider.get_workspace_group_id(), instanceType=instance_type, ) workspace = await create_workspace(req) return json.dumps(workspace.model_dump(), indent=2)
- src/brev_mcp/api.py:34-55 (helper)Core API integration helper that sends HTTP POST request to Brev's API to create the workspace, using authentication and org ID.async def create_workspace(request: CreateWorkspaceRequest) -> Workspace: access_token = get_acess_token() org_id = get_active_org_id() try: async with httpx.AsyncClient(timeout=httpx.Timeout(25.0)) as client: json = request.model_dump(by_alias=True) response = await client.post( f"{BASE_API_URL}/organizations/{org_id}/workspaces", headers={ "Authorization": f"Bearer {access_token}", "Content-Type": "application/json" }, json=json ) response.raise_for_status() data = response.json() workspace = Workspace.model_validate(data) return workspace except ValidationError as e: raise RuntimeError(f"Failed to validate workspace: {str(e)}") except Exception as e: raise RuntimeError(f"Failed to create workspace: {str(e)}")