mirror of
https://github.com/jmagar/unraid-mcp.git
synced 2026-03-23 12:39:24 -07:00
refactor(creds): remove per-tool elicitation from unraid_settings
This commit is contained in:
@@ -6,21 +6,11 @@ configuration, time settings, UPS, API settings, and Unraid Connect.
|
|||||||
|
|
||||||
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.settings.elicit_and_configure"
|
|
||||||
# and "unraid_mcp.tools.settings.CredentialsNotConfiguredError"
|
|
||||||
elicit_and_configure = _elicit
|
|
||||||
CredentialsNotConfiguredError = _CredErr
|
|
||||||
Context = _Context
|
|
||||||
|
|
||||||
|
|
||||||
MUTATIONS: dict[str, str] = {
|
MUTATIONS: dict[str, str] = {
|
||||||
@@ -121,7 +111,6 @@ def register_settings_tool(mcp: FastMCP) -> None:
|
|||||||
access_url_ipv4: str | None = None,
|
access_url_ipv4: str | None = None,
|
||||||
access_url_ipv6: str | None = None,
|
access_url_ipv6: str | None = None,
|
||||||
dynamic_enabled: bool | None = None,
|
dynamic_enabled: bool | None = None,
|
||||||
ctx: Context | None = None,
|
|
||||||
) -> dict[str, Any]:
|
) -> dict[str, Any]:
|
||||||
"""Update Unraid system settings, time, UPS, and remote access configuration.
|
"""Update Unraid system settings, time, UPS, and remote access configuration.
|
||||||
|
|
||||||
@@ -148,19 +137,7 @@ def register_settings_tool(mcp: FastMCP) -> None:
|
|||||||
if action == "update":
|
if action == "update":
|
||||||
if settings_input is None:
|
if settings_input is None:
|
||||||
raise ToolError("settings_input is required for 'update' action")
|
raise ToolError("settings_input is required for 'update' action")
|
||||||
try:
|
data = await make_graphql_request(MUTATIONS["update"], {"input": settings_input})
|
||||||
data = await make_graphql_request(
|
|
||||||
MUTATIONS["update"], {"input": settings_input}
|
|
||||||
)
|
|
||||||
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(
|
|
||||||
MUTATIONS["update"], {"input": settings_input}
|
|
||||||
)
|
|
||||||
return {"success": True, "action": "update", "data": data.get("updateSettings")}
|
return {"success": True, "action": "update", "data": data.get("updateSettings")}
|
||||||
|
|
||||||
if action == "update_temperature":
|
if action == "update_temperature":
|
||||||
@@ -168,19 +145,9 @@ def register_settings_tool(mcp: FastMCP) -> None:
|
|||||||
raise ToolError(
|
raise ToolError(
|
||||||
"temperature_config is required for 'update_temperature' action"
|
"temperature_config is required for 'update_temperature' action"
|
||||||
)
|
)
|
||||||
try:
|
data = await make_graphql_request(
|
||||||
data = await make_graphql_request(
|
MUTATIONS["update_temperature"], {"input": temperature_config}
|
||||||
MUTATIONS["update_temperature"], {"input": temperature_config}
|
)
|
||||||
)
|
|
||||||
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(
|
|
||||||
MUTATIONS["update_temperature"], {"input": temperature_config}
|
|
||||||
)
|
|
||||||
return {
|
return {
|
||||||
"success": True,
|
"success": True,
|
||||||
"action": "update_temperature",
|
"action": "update_temperature",
|
||||||
@@ -201,19 +168,7 @@ def register_settings_tool(mcp: FastMCP) -> None:
|
|||||||
raise ToolError(
|
raise ToolError(
|
||||||
"update_time requires at least one of: time_zone, use_ntp, ntp_servers, manual_datetime"
|
"update_time requires at least one of: time_zone, use_ntp, ntp_servers, manual_datetime"
|
||||||
)
|
)
|
||||||
try:
|
data = await make_graphql_request(MUTATIONS["update_time"], {"input": time_input})
|
||||||
data = await make_graphql_request(
|
|
||||||
MUTATIONS["update_time"], {"input": time_input}
|
|
||||||
)
|
|
||||||
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(
|
|
||||||
MUTATIONS["update_time"], {"input": time_input}
|
|
||||||
)
|
|
||||||
return {
|
return {
|
||||||
"success": True,
|
"success": True,
|
||||||
"action": "update_time",
|
"action": "update_time",
|
||||||
@@ -223,19 +178,9 @@ def register_settings_tool(mcp: FastMCP) -> None:
|
|||||||
if action == "configure_ups":
|
if action == "configure_ups":
|
||||||
if ups_config is None:
|
if ups_config is None:
|
||||||
raise ToolError("ups_config is required for 'configure_ups' action")
|
raise ToolError("ups_config is required for 'configure_ups' action")
|
||||||
try:
|
data = await make_graphql_request(
|
||||||
data = await make_graphql_request(
|
MUTATIONS["configure_ups"], {"config": ups_config}
|
||||||
MUTATIONS["configure_ups"], {"config": ups_config}
|
)
|
||||||
)
|
|
||||||
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(
|
|
||||||
MUTATIONS["configure_ups"], {"config": ups_config}
|
|
||||||
)
|
|
||||||
return {
|
return {
|
||||||
"success": True,
|
"success": True,
|
||||||
"action": "configure_ups",
|
"action": "configure_ups",
|
||||||
@@ -254,15 +199,7 @@ def register_settings_tool(mcp: FastMCP) -> None:
|
|||||||
raise ToolError(
|
raise ToolError(
|
||||||
"update_api requires at least one of: access_type, forward_type, port"
|
"update_api requires at least one of: access_type, forward_type, port"
|
||||||
)
|
)
|
||||||
try:
|
data = await make_graphql_request(MUTATIONS["update_api"], {"input": api_input})
|
||||||
data = await make_graphql_request(MUTATIONS["update_api"], {"input": api_input})
|
|
||||||
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(MUTATIONS["update_api"], {"input": api_input})
|
|
||||||
return {
|
return {
|
||||||
"success": True,
|
"success": True,
|
||||||
"action": "update_api",
|
"action": "update_api",
|
||||||
@@ -282,19 +219,9 @@ def register_settings_tool(mcp: FastMCP) -> None:
|
|||||||
user_info["avatar"] = avatar
|
user_info["avatar"] = avatar
|
||||||
if user_info:
|
if user_info:
|
||||||
sign_in_input["userInfo"] = user_info
|
sign_in_input["userInfo"] = user_info
|
||||||
try:
|
data = await make_graphql_request(
|
||||||
data = await make_graphql_request(
|
MUTATIONS["connect_sign_in"], {"input": sign_in_input}
|
||||||
MUTATIONS["connect_sign_in"], {"input": sign_in_input}
|
)
|
||||||
)
|
|
||||||
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(
|
|
||||||
MUTATIONS["connect_sign_in"], {"input": sign_in_input}
|
|
||||||
)
|
|
||||||
return {
|
return {
|
||||||
"success": True,
|
"success": True,
|
||||||
"action": "connect_sign_in",
|
"action": "connect_sign_in",
|
||||||
@@ -302,15 +229,7 @@ def register_settings_tool(mcp: FastMCP) -> None:
|
|||||||
}
|
}
|
||||||
|
|
||||||
if action == "connect_sign_out":
|
if action == "connect_sign_out":
|
||||||
try:
|
data = await make_graphql_request(MUTATIONS["connect_sign_out"])
|
||||||
data = await make_graphql_request(MUTATIONS["connect_sign_out"])
|
|
||||||
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(MUTATIONS["connect_sign_out"])
|
|
||||||
return {
|
return {
|
||||||
"success": True,
|
"success": True,
|
||||||
"action": "connect_sign_out",
|
"action": "connect_sign_out",
|
||||||
@@ -325,19 +244,9 @@ def register_settings_tool(mcp: FastMCP) -> None:
|
|||||||
remote_input["forwardType"] = forward_type
|
remote_input["forwardType"] = forward_type
|
||||||
if port is not None:
|
if port is not None:
|
||||||
remote_input["port"] = port
|
remote_input["port"] = port
|
||||||
try:
|
data = await make_graphql_request(
|
||||||
data = await make_graphql_request(
|
MUTATIONS["setup_remote_access"], {"input": remote_input}
|
||||||
MUTATIONS["setup_remote_access"], {"input": remote_input}
|
)
|
||||||
)
|
|
||||||
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(
|
|
||||||
MUTATIONS["setup_remote_access"], {"input": remote_input}
|
|
||||||
)
|
|
||||||
return {
|
return {
|
||||||
"success": True,
|
"success": True,
|
||||||
"action": "setup_remote_access",
|
"action": "setup_remote_access",
|
||||||
@@ -361,21 +270,10 @@ def register_settings_tool(mcp: FastMCP) -> None:
|
|||||||
if access_url_ipv6 is not None:
|
if access_url_ipv6 is not None:
|
||||||
url_input["ipv6"] = access_url_ipv6
|
url_input["ipv6"] = access_url_ipv6
|
||||||
dra_vars = {"input": {"url": url_input, "enabled": dynamic_enabled}}
|
dra_vars = {"input": {"url": url_input, "enabled": dynamic_enabled}}
|
||||||
try:
|
data = await make_graphql_request(
|
||||||
data = await make_graphql_request(
|
MUTATIONS["enable_dynamic_remote_access"],
|
||||||
MUTATIONS["enable_dynamic_remote_access"],
|
dra_vars,
|
||||||
dra_vars,
|
)
|
||||||
)
|
|
||||||
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(
|
|
||||||
MUTATIONS["enable_dynamic_remote_access"],
|
|
||||||
dra_vars,
|
|
||||||
)
|
|
||||||
return {
|
return {
|
||||||
"success": True,
|
"success": True,
|
||||||
"action": "enable_dynamic_remote_access",
|
"action": "enable_dynamic_remote_access",
|
||||||
|
|||||||
Reference in New Issue
Block a user