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_array
This commit is contained in:
@@ -5,21 +5,11 @@ Provides the `unraid_array` tool with 5 actions for parity check management.
|
|||||||
|
|
||||||
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.array.elicit_and_configure"
|
|
||||||
# and "unraid_mcp.tools.array.CredentialsNotConfiguredError"
|
|
||||||
elicit_and_configure = _elicit
|
|
||||||
CredentialsNotConfiguredError = _CredErr
|
|
||||||
Context = _Context
|
|
||||||
|
|
||||||
|
|
||||||
QUERIES: dict[str, str] = {
|
QUERIES: dict[str, str] = {
|
||||||
@@ -79,7 +69,6 @@ def register_array_tool(mcp: FastMCP) -> None:
|
|||||||
async def unraid_array(
|
async def unraid_array(
|
||||||
action: ARRAY_ACTIONS,
|
action: ARRAY_ACTIONS,
|
||||||
correct: bool | None = None,
|
correct: bool | None = None,
|
||||||
ctx: Context | None = None,
|
|
||||||
) -> dict[str, Any]:
|
) -> dict[str, Any]:
|
||||||
"""Manage Unraid array parity checks.
|
"""Manage Unraid array parity checks.
|
||||||
|
|
||||||
@@ -97,15 +86,7 @@ def register_array_tool(mcp: FastMCP) -> None:
|
|||||||
logger.info(f"Executing unraid_array action={action}")
|
logger.info(f"Executing unraid_array action={action}")
|
||||||
|
|
||||||
if action in QUERIES:
|
if action in QUERIES:
|
||||||
try:
|
data = await make_graphql_request(QUERIES[action])
|
||||||
data = await make_graphql_request(QUERIES[action])
|
|
||||||
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[action])
|
|
||||||
return {"success": True, "action": action, "data": data}
|
return {"success": True, "action": action, "data": data}
|
||||||
|
|
||||||
query = MUTATIONS[action]
|
query = MUTATIONS[action]
|
||||||
@@ -116,15 +97,7 @@ def register_array_tool(mcp: FastMCP) -> None:
|
|||||||
raise ToolError("correct is required for 'parity_start' action")
|
raise ToolError("correct is required for 'parity_start' action")
|
||||||
variables = {"correct": correct}
|
variables = {"correct": correct}
|
||||||
|
|
||||||
try:
|
data = await make_graphql_request(query, variables)
|
||||||
data = await make_graphql_request(query, variables)
|
|
||||||
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(query, variables)
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"success": True,
|
"success": True,
|
||||||
|
|||||||
Reference in New Issue
Block a user