update_server
Updates the server to the latest version by pulling changes from git and updating dependencies.
Instructions
サーバーを最新バージョンにアップデートする。git pull + 依存関係の更新を行います。
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/jvlink_mcp_server/updater.py:151-232 (handler)Core handler that performs the update: checks for updates, runs git pull, and installs dependencies (uv sync or pip install -e .). Returns a dict with success status and details.
def perform_update(confirmed: bool = False) -> dict: """Perform update: git pull + uv sync (or pip install -e .). Args: confirmed: Trueの場合のみ実際にアップデートを実行。 Falseの場合は確認メッセージを返す。 Returns dict with success, message, and details. """ results = {"success": False, "steps": []} # Step 1: Check for updates first info = check_for_updates() if info is None: results["message"] = "アップデートの確認に失敗しました" return results if not info["update_available"]: results["success"] = True results["message"] = f"最新バージョン {info['current_version']} です。アップデートは不要です。" return results results["from_version"] = info["current_version"] results["to_version"] = info["latest_version"] # 確認が未完了の場合は確認メッセージを返す if not confirmed: results["message"] = ( f"アップデートが利用可能です: {info['current_version']} → {info['latest_version']}\n" "実行するには confirmed=True を指定してください。\n" "注意: git pull と依存関係の更新が実行され、サーバーの再起動が必要になります。" ) results["requires_confirmation"] = True return results # Step 2: git pull try: result = subprocess.run( ["git", "pull", "--ff-only"], capture_output=True, text=True, cwd=str(PROJECT_ROOT), timeout=60, ) if result.returncode != 0: results["message"] = f"git pull 失敗: {result.stderr.strip()}" results["steps"].append({"git_pull": "failed", "error": result.stderr.strip()}) return results results["steps"].append({"git_pull": "success", "output": result.stdout.strip()}) except Exception as e: results["message"] = f"git pull エラー: {e}" return results # Step 3: uv sync or pip install -e . try: # Try uv first result = subprocess.run( ["uv", "sync"], capture_output=True, text=True, cwd=str(PROJECT_ROOT), timeout=120, ) if result.returncode == 0: results["steps"].append({"uv_sync": "success"}) else: raise FileNotFoundError("uv sync failed") except (FileNotFoundError, Exception): # Fallback to pip try: result = subprocess.run( [sys.executable, "-m", "pip", "install", "-e", "."], capture_output=True, text=True, cwd=str(PROJECT_ROOT), timeout=120, ) if result.returncode != 0: results["message"] = f"pip install 失敗: {result.stderr.strip()}" return results results["steps"].append({"pip_install": "success"}) except Exception as e: results["message"] = f"依存関係の更新に失敗: {e}" return results results["success"] = True results["message"] = ( f"アップデート完了: {info['current_version']} → {info['latest_version']}\n" "サーバーを再起動してください。" ) return results - src/jvlink_mcp_server/server.py:704-707 (registration)Registration of 'update_server' as an MCP tool via @mcp.tool() decorator. Delegates to perform_update() in updater.py.
@mcp.tool() def update_server() -> dict: """サーバーを最新バージョンにアップデートする。git pull + 依存関係の更新を行います。""" return perform_update() - Helper called within perform_update to check GitHub for available updates (releases/tags API).
def check_for_updates() -> Optional[dict]: """Check GitHub for latest release. Returns dict with latest_version, current_version, update_available, html_url or None on failure. """ import urllib.request import urllib.error current = get_current_version() # Try releases/latest first try: url = f"{GITHUB_API_URL}/releases/latest" req = urllib.request.Request( url, headers={"Accept": "application/vnd.github.v3+json", "User-Agent": GITHUB_REPO}, ) with urllib.request.urlopen(req, timeout=10) as resp: data = json.loads(resp.read().decode("utf-8")) latest = data.get("tag_name", "unknown") return { "latest_version": latest, "current_version": current, "update_available": _version_newer(latest, current), "html_url": data.get("html_url", ""), "release_name": data.get("name", ""), "body": data.get("body", ""), } except urllib.error.HTTPError as e: if e.code != 404: logger.debug("GitHub API error: %s", e.code) return None except Exception as e: logger.debug("Failed to check releases: %s", e) return None # Fallback: check tags try: url = f"{GITHUB_API_URL}/tags?per_page=1" req = urllib.request.Request( url, headers={"Accept": "application/vnd.github.v3+json", "User-Agent": GITHUB_REPO}, ) with urllib.request.urlopen(req, timeout=10) as resp: data = json.loads(resp.read().decode("utf-8")) if data: latest = data[0].get("name", "unknown") return { "latest_version": latest, "current_version": current, "update_available": _version_newer(latest, current), "html_url": f"https://github.com/{GITHUB_OWNER}/{GITHUB_REPO}/releases", "release_name": "", "body": "", } except Exception as e: logger.debug("Failed to check tags: %s", e) return None - src/jvlink_mcp_server/server.py:47-48 (registration)Import statement that brings perform_update into server.py so update_server can call it.
from .updater import check_for_updates, perform_update, startup_update_check