Skip to main content
Glama

launch_llm_server

Launches an mlx_lm server as a background subprocess with specified model and port, ensuring sufficient free memory before starting.

Instructions

mlx_lm.server をサブプロセスとしてバックグラウンドで起動します。空きメモリが少ない場合は起動が拒否されます。

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
model_nameYes起動するモデル名 (例: mlx-community/Llama-3-8B-Instruct-4bit)
portYesサーバーを起動するポート番号
memory_requirement_gbNo起動に必要な空きメモリの目安(GB)。未指定時はデフォルトで 4.0GB。

Implementation Reference

  • Tool registration for 'launch_llm_server' in handle_list_tools(). Defines the tool name, description, and inputSchema with model_name (string, required), port (integer, required), and memory_requirement_gb (number, optional, default 4.0).
    types.Tool(
        name="launch_llm_server",
        description="mlx_lm.server をサブプロセスとしてバックグラウンドで起動します。空きメモリが少ない場合は起動が拒否されます。",
        inputSchema={
            "type": "object",
            "properties": {
                "model_name": {
                    "type": "string",
                    "description": "起動するモデル名 (例: mlx-community/Llama-3-8B-Instruct-4bit)",
                },
                "port": {"type": "integer", "description": "サーバーを起動するポート番号"},
                "memory_requirement_gb": {
                    "type": "number",
                    "description": "起動に必要な空きメモリの目安(GB)。未指定時はデフォルトで 4.0GB。"
                }
            },
            "required": ["model_name", "port"],
        },
    ),
  • Handler for 'launch_llm_server' in handle_call_tool(). Extracts arguments (model_name, port, memory_requirement_gb), validates types, and calls process_manager.launch_server() with timeout=10.
    elif name == "launch_llm_server":
        model_name = arguments.get("model_name")
        port = arguments.get("port")
        memory_requirement_gb = arguments.get("memory_requirement_gb", 4.0)
        
        if not isinstance(model_name, str) or not isinstance(port, int):
            raise ValueError("Invalid arguments for launch_llm_server")
        if not isinstance(memory_requirement_gb, (int, float)):
            raise ValueError("memory_requirement_gb must be a number")
            
        result_msg = await asyncio.to_thread(
            process_manager.launch_server, 
            model_name, 
            port, 
            10, 
            float(memory_requirement_gb)
        )
        return [types.TextContent(type="text", text=result_msg)]
  • Core implementation of launch_server() in MlxProcessManager. Checks port availability, verifies sufficient memory, spawns mlx_lm.server as a subprocess, health-checks port availability within timeout, and saves state. Returns success/error message.
    def launch_server(self, model_name: str, port: int, timeout: int = 10, memory_requirement_gb: float = 4.0) -> str:
        """mlx_lm.server を起動し、生存とポートの開放を確認する"""
        
        if self.is_port_in_use(port):
            return f"Error: Port {port} is already in use."
    
        mem = psutil.virtual_memory()
        available_gb = mem.available / (1024 ** 3)
        if available_gb < memory_requirement_gb:
            return f"Error: Insufficient memory. Only {available_gb:.2f}GB available, but at least {memory_requirement_gb}GB is requested to launch this model safely."
    
        is_cached = self.is_model_cached(model_name)
    
        cmd = [
            sys.executable,
            "-m",
            "mlx_lm.server",
            "--model",
            model_name,
            "--port",
            str(port),
        ]
    
        try:
            process = subprocess.Popen(
                cmd,
                stdout=subprocess.DEVNULL,
                stderr=subprocess.DEVNULL,
                start_new_session=True,
            )
    
            start_time = time.time()
            is_verified = False
            
            while time.time() - start_time < timeout:
                poll_result = process.poll()
                if poll_result is not None:
                    return f"Error: Process exited immediately with code {poll_result}. Check if the model name is correct or if you have enough unified memory."
    
                if self.is_port_in_use(port):
                    is_verified = True
                    break
                
                time.sleep(0.5)
    
            if not is_verified:
                if not is_cached:
                    msg_suffix = " (Note: Model is currently being downloaded from Hugging Face in the background. It may take a while before the port becomes active.)"
                else:
                    msg_suffix = " (Warning: Port not yet listening, model might still be loading into memory)"
            else:
                msg_suffix = ""
    
            state = self._load_state()
            state[str(port)] = {"pid": process.pid, "model": model_name}
            self._save_state(state)
    
            return f"Successfully launched '{model_name}' on port {port} (PID: {process.pid}){msg_suffix}."
    
        except Exception as e:
            return f"Error launching process: {str(e)}"
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. It mentions background subprocess and memory rejection, but lacks details on return behavior, readiness confirmation, error handling, or side effects. This is insufficient for a launch tool.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Two short, front-loaded sentences with no unnecessary words. Each sentence provides essential information concisely.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

No output schema exists, so the description should explain return values or status. It only describes the action and a rejection condition, but not success behavior, how to check status, or how to interact with the launched server. Incomplete for a start operation.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, so the schema already documents all parameters. The description adds no extra parameter meaning beyond what is in the schema descriptions.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states it launches mlx_lm.server as a background subprocess, a specific verb+resource. It also mentions a condition for rejection (low memory). This distinguishes it from siblings like check_llm_status or list_running_servers.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage for initial server launch, but does not explicitly state when to use vs alternatives (e.g., restart_llm_server for restarting). No explicit exclusions or prerequisites beyond memory.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other 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/globalpocket/mcp-mlx-launcher'

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