mirror of
https://github.com/jmagar/unraid-mcp.git
synced 2026-03-23 04:29:17 -07:00
feat(elicitation): add ctx + credential elicitation to unraid_vm
This commit is contained in:
@@ -6,11 +6,21 @@ including start, stop, pause, resume, force stop, reboot, and reset.
|
|||||||
|
|
||||||
from typing import Any, Literal, get_args
|
from typing import Any, Literal, get_args
|
||||||
|
|
||||||
|
from fastmcp import Context as _Context
|
||||||
from fastmcp import FastMCP
|
from fastmcp import FastMCP
|
||||||
|
|
||||||
from ..config.logging import logger
|
from ..config.logging import logger
|
||||||
from ..core.client import make_graphql_request
|
from ..core.client import make_graphql_request
|
||||||
|
from ..core.exceptions import CredentialsNotConfiguredError as _CredErr
|
||||||
from ..core.exceptions import ToolError, tool_error_handler
|
from ..core.exceptions import ToolError, tool_error_handler
|
||||||
|
from ..core.setup import elicit_and_configure as _elicit
|
||||||
|
|
||||||
|
|
||||||
|
# Re-export at module scope so tests can patch "unraid_mcp.tools.virtualization.elicit_and_configure"
|
||||||
|
# and "unraid_mcp.tools.virtualization.CredentialsNotConfiguredError"
|
||||||
|
elicit_and_configure = _elicit
|
||||||
|
CredentialsNotConfiguredError = _CredErr
|
||||||
|
Context = _Context
|
||||||
|
|
||||||
|
|
||||||
QUERIES: dict[str, str] = {
|
QUERIES: dict[str, str] = {
|
||||||
@@ -90,6 +100,7 @@ def register_vm_tool(mcp: FastMCP) -> None:
|
|||||||
action: VM_ACTIONS,
|
action: VM_ACTIONS,
|
||||||
vm_id: str | None = None,
|
vm_id: str | None = None,
|
||||||
confirm: bool = False,
|
confirm: bool = False,
|
||||||
|
ctx: Context | None = None,
|
||||||
) -> dict[str, Any]:
|
) -> dict[str, Any]:
|
||||||
"""Manage Unraid virtual machines.
|
"""Manage Unraid virtual machines.
|
||||||
|
|
||||||
@@ -117,7 +128,15 @@ def register_vm_tool(mcp: FastMCP) -> None:
|
|||||||
logger.info(f"Executing unraid_vm action={action}")
|
logger.info(f"Executing unraid_vm action={action}")
|
||||||
|
|
||||||
if action == "list":
|
if action == "list":
|
||||||
data = await make_graphql_request(QUERIES["list"])
|
try:
|
||||||
|
data = await make_graphql_request(QUERIES["list"])
|
||||||
|
except CredentialsNotConfiguredError:
|
||||||
|
configured = await elicit_and_configure(ctx)
|
||||||
|
if not configured:
|
||||||
|
raise ToolError(
|
||||||
|
"Credentials required. Run `unraid_health action=setup` to configure."
|
||||||
|
)
|
||||||
|
data = await make_graphql_request(QUERIES["list"])
|
||||||
if data.get("vms"):
|
if data.get("vms"):
|
||||||
vms = data["vms"].get("domains") or data["vms"].get("domain") or []
|
vms = data["vms"].get("domains") or data["vms"].get("domain") or []
|
||||||
if isinstance(vms, dict):
|
if isinstance(vms, dict):
|
||||||
|
|||||||
Reference in New Issue
Block a user