fix: address third round of review feedback

Add BasicAuthLifespanContext Protocol to make the contract between
StdioContext and get_client() explicit and type-safe. Document why
mcp.get_context() is required for non-template resources. Add News
and Collectives to README Supported Apps table, fix transport default.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Chris Coutinho
2026-04-07 23:59:39 +02:00
co-authored by Claude Opus 4.6
parent 1af85bc05e
commit f340380898
3 changed files with 25 additions and 7 deletions
+13 -1
View File
@@ -1,6 +1,7 @@
"""Helper functions for accessing context in MCP tools."""
import logging
from typing import Protocol, runtime_checkable
from httpx import BasicAuth
from mcp.server.fastmcp import Context
@@ -14,6 +15,17 @@ from nextcloud_mcp_server.config import get_settings
logger = logging.getLogger(__name__)
@runtime_checkable
class BasicAuthLifespanContext(Protocol):
"""Protocol for lifespan contexts that carry a shared NextcloudClient.
Implemented by :class:`~nextcloud_mcp_server.stdio.StdioContext` and
the single-user lifespan context in ``app.py``.
"""
client: NextcloudClient
async def get_client(ctx: Context) -> NextcloudClient:
"""
Get the appropriate Nextcloud client based on authentication mode.
@@ -59,7 +71,7 @@ async def get_client(ctx: Context) -> NextcloudClient:
return await _get_client_from_login_flow(ctx, lifespan_ctx.nextcloud_host)
# BasicAuth mode - use shared client (no token exchange)
if hasattr(lifespan_ctx, "client"):
if isinstance(lifespan_ctx, BasicAuthLifespanContext):
return lifespan_ctx.client
# OAuth multi-audience mode (has 'nextcloud_host' attribute)