Skip to main content
Glama
brevdev

Brev

Official
by brevdev

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
NameRequiredDescriptionDefault
cloud_providerYesThe cloud provider for the workspace
instance_typeNoThe instance type of the workspace
nameNoThe name of the workspace

Implementation Reference

  • 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
            )
        ]
  • 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
    )
  • 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
  • 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)
  • 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)}")
Install Server

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/brevdev/brev-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server