restart_llm_server
Restart the LLM server running on a given port, optionally switching to a different model.
Instructions
指定されたポートで稼働しているサーバーを一度停止し、再起動します。モデルの切り替えなどにも使用できます。
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| port | Yes | 再起動するサーバーのポート番号 | |
| model_name | No | (オプション)新しく起動するモデル名。省略した場合は現在そのポートで稼働しているモデルをそのまま再起動します。 | |
| memory_requirement_gb | No | (オプション)起動に必要な空きメモリの目安(GB)。未指定時はデフォルトで 4.0GB。 |
Implementation Reference
- src/mcp_mlx_launcher/server.py:219-238 (handler)Handler for restart_llm_server tool. Validates arguments (port integer, optional model_name string, optional memory_requirement_gb number) then calls process_manager.restart_server() via asyncio.to_thread.
elif name == "restart_llm_server": port = arguments.get("port") model_name = arguments.get("model_name") memory_requirement_gb = arguments.get("memory_requirement_gb", 4.0) if not isinstance(port, int): raise ValueError("Port must be an integer") if model_name is not None and not isinstance(model_name, str): raise ValueError("model_name must be a string") 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.restart_server, port, model_name, 10, float(memory_requirement_gb) ) return [types.TextContent(type="text", text=result_msg)] - MlxProcessManager.restart_server() method. Loads state, checks if port exists, optionally switches model name, calls shutdown_server(), waits 1s for OS port release, then calls launch_server() with the target model.
def restart_server(self, port: int, model_name: str = None, timeout: int = 10, memory_requirement_gb: float = 4.0) -> str: """指定されたポートのサーバーを再起動する""" state = self._load_state() port_str = str(port) if port_str not in state: return f"Error: No running server found on port {port} to restart." # モデル名が指定されていない場合は、現在のモデルを引き継ぐ current_model = state[port_str].get("model", "unknown") target_model = model_name if model_name else current_model if target_model == "unknown": return "Error: Cannot determine the current model to restart. Please specify model_name explicitly." shutdown_msg = self.shutdown_server(port) if "Error" in shutdown_msg: return f"Failed to shutdown existing server: {shutdown_msg}" # OSがポートを完全に解放するまで少し待機 time.sleep(1) launch_msg = self.launch_server(target_model, port, timeout, memory_requirement_gb) return f"{shutdown_msg}\nRestart Result: {launch_msg}" - Tool registration with inputSchema. Defines 'restart_llm_server' with required 'port' (integer), optional 'model_name' (string), optional 'memory_requirement_gb' (number).
types.Tool( name="restart_llm_server", description="指定されたポートで稼働しているサーバーを一度停止し、再起動します。モデルの切り替えなどにも使用できます。", inputSchema={ "type": "object", "properties": { "port": {"type": "integer", "description": "再起動するサーバーのポート番号"}, "model_name": { "type": "string", "description": "(オプション)新しく起動するモデル名。省略した場合は現在そのポートで稼働しているモデルをそのまま再起動します。" }, "memory_requirement_gb": { "type": "number", "description": "(オプション)起動に必要な空きメモリの目安(GB)。未指定時はデフォルトで 4.0GB。" } }, "required": ["port"], }, ), - src/mcp_mlx_launcher/server.py:17-128 (registration)Tool registration via @server.list_tools() decorator. The list includes 'restart_llm_server' at lines 98-116 within the handle_list_tools function.
@server.list_tools() async def handle_list_tools() -> list[types.Tool]: """AIエージェントに提供するツールの一覧とスキーマを定義します""" return [ types.Tool( name="check_system_environment", description="現在のシステム環境(Apple Siliconか、空きメモリが何GBあるかなど)を診断します。", inputSchema={ "type": "object", "properties": {}, }, ), types.Tool( name="check_llm_status", description="指定されたポートでサーバーがリッスンしているか(稼働中か)を確認します。", inputSchema={ "type": "object", "properties": { "port": {"type": "integer", "description": "確認するポート番号"} }, "required": ["port"], }, ), types.Tool( name="list_running_servers", description="現在バックグラウンドで稼働しているすべてのローカルLLMサーバー(ポート番号とモデル名)の一覧を取得します。", inputSchema={ "type": "object", "properties": {}, }, ), types.Tool( name="search_mlx_models", description="Hugging Faceからダウンロード可能なMLXフォーマットのLLMモデルを検索・リストアップします。", inputSchema={ "type": "object", "properties": { "search_query": { "type": "string", "description": "検索キーワード(例: 'llama', 'qwen')。未指定の場合は人気のMLXモデルを返します。" }, "limit": { "type": "integer", "description": "取得する最大件数。デフォルトは10。" } }, }, ), types.Tool( name="download_model", description="Hugging Faceから指定されたMLXモデルを事前にダウンロードし、ローカルにキャッシュします。大きなモデルの起動前の準備に利用します。", inputSchema={ "type": "object", "properties": { "model_name": { "type": "string", "description": "ダウンロードするモデル名 (例: mlx-community/Llama-3-8B-Instruct-4bit)" } }, "required": ["model_name"], }, ), 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"], }, ), types.Tool( name="restart_llm_server", description="指定されたポートで稼働しているサーバーを一度停止し、再起動します。モデルの切り替えなどにも使用できます。", inputSchema={ "type": "object", "properties": { "port": {"type": "integer", "description": "再起動するサーバーのポート番号"}, "model_name": { "type": "string", "description": "(オプション)新しく起動するモデル名。省略した場合は現在そのポートで稼働しているモデルをそのまま再起動します。" }, "memory_requirement_gb": { "type": "number", "description": "(オプション)起動に必要な空きメモリの目安(GB)。未指定時はデフォルトで 4.0GB。" } }, "required": ["port"], }, ), types.Tool( name="shutdown_llm_server", description="指定されたポートで稼働しているローカル LLM サーバープロセスを安全に終了させます。", inputSchema={ "type": "object", "properties": { "port": {"type": "integer", "description": "終了させるサーバーのポート番号"} }, "required": ["port"], }, ), ]