mirror of
https://github.com/jmagar/unraid-mcp.git
synced 2026-03-23 12:39:24 -07:00
feat(elicitation): add ctx + credential elicitation to unraid_docker
This commit is contained in:
@@ -7,14 +7,24 @@ logs, networks, update management, and Docker organizer operations.
|
|||||||
import re
|
import re
|
||||||
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
|
||||||
from ..core.utils import safe_get
|
from ..core.utils import safe_get
|
||||||
|
|
||||||
|
|
||||||
|
# Re-export at module scope so tests can patch "unraid_mcp.tools.docker.elicit_and_configure"
|
||||||
|
# and "unraid_mcp.tools.docker.CredentialsNotConfiguredError"
|
||||||
|
elicit_and_configure = _elicit
|
||||||
|
CredentialsNotConfiguredError = _CredErr
|
||||||
|
Context = _Context
|
||||||
|
|
||||||
|
|
||||||
QUERIES: dict[str, str] = {
|
QUERIES: dict[str, str] = {
|
||||||
"list": """
|
"list": """
|
||||||
query ListDockerContainers {
|
query ListDockerContainers {
|
||||||
@@ -376,6 +386,7 @@ def register_docker_tool(mcp: FastMCP) -> None:
|
|||||||
new_folder_name: str | None = None,
|
new_folder_name: str | None = None,
|
||||||
view_id: str = "default",
|
view_id: str = "default",
|
||||||
view_prefs: dict[str, Any] | None = None,
|
view_prefs: dict[str, Any] | None = None,
|
||||||
|
ctx: Context | None = None,
|
||||||
) -> dict[str, Any]:
|
) -> dict[str, Any]:
|
||||||
"""Manage Docker containers, networks, and updates.
|
"""Manage Docker containers, networks, and updates.
|
||||||
|
|
||||||
@@ -427,7 +438,15 @@ def register_docker_tool(mcp: FastMCP) -> None:
|
|||||||
|
|
||||||
# --- Read-only queries ---
|
# --- Read-only queries ---
|
||||||
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"])
|
||||||
containers = safe_get(data, "docker", "containers", default=[])
|
containers = safe_get(data, "docker", "containers", default=[])
|
||||||
return {"containers": containers}
|
return {"containers": containers}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user