feat(auth): elicit Astrolabe URL on missing app password

When a tool requiring Nextcloud access is called without a stored app
password (Login Flow v2 mode), the @require_scopes decorator now invokes
MCP elicitation with a clickable Astrolabe settings URL — reconstructed
from NEXTCLOUD_PUBLIC_ISSUER_URL / NEXTCLOUD_HOST — before raising
ProvisioningRequiredError. Clients without elicitation support fall back
to the existing text error.

Surfaced by cbcoutinho/nextcloud-mcp-server#752, where users hit a 401
after OAuth and had no clickable URL to start Login Flow v2 from.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Chris Coutinho
2026-05-02 12:02:18 +02:00
co-authored by Claude Opus 4.7
parent cb2b2e82d6
commit 2da8b38aeb
4 changed files with 352 additions and 2 deletions
@@ -151,7 +151,16 @@ def require_scopes(*required_scopes: str):
stored_scopes = await _get_stored_scopes(user_id)
if stored_scopes is None:
# No stored app password → require provisioning
# No stored app password → require provisioning. Try to
# elicit a clickable Astrolabe / Login-Flow-v2 link so
# the user has somewhere to click; the elicit helper
# silently falls back when the client lacks support.
from nextcloud_mcp_server.auth.elicitation import ( # noqa: PLC0415
present_provisioning_required,
)
await present_provisioning_required(ctx)
error_msg = (
f"Access denied to {func_name}: "
f"Nextcloud access not provisioned. "