vs_toggle
Enable or disable a Virtual Service to control traffic flow. Disabling stops all traffic and requires confirmation for safety.
Instructions
[WRITE] Enable or disable a Virtual Service. Disabling stops all traffic to this VS.
Use vs_status first to check current state.
SAFETY: When enable=False, requires confirmed=True to execute. Default False returns a preview message describing the intended action. Enabling a VS is always safe and does not require confirmation.
Args: name: Exact Virtual Service name. enable: true to enable, false to disable. confirmed: Must be True when enable=False to actually disable the VS. Default False returns a preview-only message. Ignored when enable=True.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | ||
| enable | Yes | ||
| confirmed | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- mcp_server/server.py:83-106 (handler)MCP tool 'vs_toggle' — the primary handler that implements the tool logic. Decorated with @mcp.tool (destructiveHint=True) and @vmware_tool(risk_level='high'). Accepts name, enable, and confirmed params. Returns a preview message if confirmed=False when disabling; otherwise delegates to toggle_vs via _capture_output.
@mcp.tool(annotations={"readOnlyHint": False, "destructiveHint": True, "idempotentHint": False, "openWorldHint": True}) @vmware_tool(risk_level="high") def vs_toggle(name: str, enable: bool, confirmed: bool = False) -> str: """[WRITE] Enable or disable a Virtual Service. Disabling stops all traffic to this VS. Use vs_status first to check current state. SAFETY: When enable=False, requires confirmed=True to execute. Default False returns a preview message describing the intended action. Enabling a VS is always safe and does not require confirmation. Args: name: Exact Virtual Service name. enable: true to enable, false to disable. confirmed: Must be True when enable=False to actually disable the VS. Default False returns a preview-only message. Ignored when enable=True. """ from vmware_avi.ops.vs_mgmt import toggle_vs if not enable and not confirmed: return ( f"[preview] Would disable Virtual Service '{name}', stopping all traffic to this VS. " "Re-invoke with confirmed=True to execute." ) return _capture_output(toggle_vs, name, enable=enable, skip_prompt=True) - vmware_avi/ops/vs_mgmt.py:131-162 (helper)toggle_vs — the low-level AVI API operation that actually enables/disables a VS. Loads config, connects via AviConnectionManager, finds the VS by name, sets enabled flag, and PUTs the update. Handles the double_confirm safety check when skip_prompt=False.
def toggle_vs(name: str, *, enable: bool, skip_prompt: bool = False) -> None: """Enable or disable a Virtual Service. Args: name: Virtual Service name. enable: True to enable, False to disable. skip_prompt: When True, bypass the interactive double-confirm prompt. Used by MCP callers that enforce confirmation via the ``confirmed`` parameter before reaching this function. """ action = "enable" if enable else "disable" if not enable and not skip_prompt: from vmware_avi._safety import double_confirm if not double_confirm(f"Disable Virtual Service '{name}'"): console.print("[yellow]Cancelled.[/yellow]") return cfg = load_config() mgr = AviConnectionManager(cfg) session = mgr.connect() vs = session.get_object_by_name("virtualservice", name) if not vs: console.print(f"[red]Virtual Service '{name}' not found.[/red]") raise SystemExit(1) vs["enabled"] = enable session.put(f"virtualservice/{vs['uuid']}", data=vs) console.print(f"[green]Virtual Service '{name}' {action}d.[/green]") - mcp_server/server.py:83-85 (registration)Registration of 'vs_toggle' as an MCP tool via the @mcp.tool decorator on FastMCP instance. The function name vs_toggle becomes the tool name automatically.
@mcp.tool(annotations={"readOnlyHint": False, "destructiveHint": True, "idempotentHint": False, "openWorldHint": True}) @vmware_tool(risk_level="high") def vs_toggle(name: str, enable: bool, confirmed: bool = False) -> str: - mcp_server/server.py:24-48 (helper)_capture_output helper — captures Rich console output from the underlying operation function and returns it as a plain-text string. Used by vs_toggle to capture toggle_vs output.
def _capture_output(func, *args, **kwargs) -> str: """Run a function and capture its Rich console output as plain text.""" import importlib # noqa: F401 — used via sys.modules lookup import sys buf = StringIO() from rich.console import Console capture_console = Console(file=buf, force_terminal=False, width=120) mod_name = func.__module__ mod = sys.modules.get(mod_name) original_console = getattr(mod, "console", None) if mod else None if mod and original_console is not None: mod.console = capture_console try: func(*args, **kwargs) except SystemExit: pass finally: if mod and original_console is not None: mod.console = original_console return buf.getvalue() - mcp_server/server.py:94-99 (schema)Input schema for vs_toggle defined via type hints and docstring: name (str), enable (bool), confirmed (bool, default False). The @mcp.tool decorator auto-generates JSON Schema from the function signature.
Args: name: Exact Virtual Service name. enable: true to enable, false to disable. confirmed: Must be True when enable=False to actually disable the VS. Default False returns a preview-only message. Ignored when enable=True. """