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_users
This commit is contained in:
@@ -6,11 +6,21 @@ Note: Unraid GraphQL API does not support user management operations (list, add,
|
|||||||
|
|
||||||
from typing import Any, Literal
|
from typing import Any, Literal
|
||||||
|
|
||||||
|
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.users.elicit_and_configure"
|
||||||
|
# and "unraid_mcp.tools.users.CredentialsNotConfiguredError"
|
||||||
|
elicit_and_configure = _elicit
|
||||||
|
CredentialsNotConfiguredError = _CredErr
|
||||||
|
Context = _Context
|
||||||
|
|
||||||
|
|
||||||
QUERIES: dict[str, str] = {
|
QUERIES: dict[str, str] = {
|
||||||
@@ -30,7 +40,10 @@ def register_users_tool(mcp: FastMCP) -> None:
|
|||||||
"""Register the unraid_users tool with the FastMCP instance."""
|
"""Register the unraid_users tool with the FastMCP instance."""
|
||||||
|
|
||||||
@mcp.tool()
|
@mcp.tool()
|
||||||
async def unraid_users(action: USER_ACTIONS = "me") -> dict[str, Any]:
|
async def unraid_users(
|
||||||
|
action: USER_ACTIONS = "me",
|
||||||
|
ctx: Context | None = None,
|
||||||
|
) -> dict[str, Any]:
|
||||||
"""Query current authenticated user.
|
"""Query current authenticated user.
|
||||||
|
|
||||||
Actions:
|
Actions:
|
||||||
@@ -43,7 +56,15 @@ def register_users_tool(mcp: FastMCP) -> None:
|
|||||||
|
|
||||||
with tool_error_handler("users", action, logger):
|
with tool_error_handler("users", action, logger):
|
||||||
logger.info("Executing unraid_users action=me")
|
logger.info("Executing unraid_users action=me")
|
||||||
data = await make_graphql_request(QUERIES["me"])
|
try:
|
||||||
|
data = await make_graphql_request(QUERIES["me"])
|
||||||
|
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["me"])
|
||||||
return data.get("me") or {}
|
return data.get("me") or {}
|
||||||
|
|
||||||
logger.info("Users tool registered successfully")
|
logger.info("Users tool registered successfully")
|
||||||
|
|||||||
Reference in New Issue
Block a user