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:
co-authored by
Claude Opus 4.6
parent
1af85bc05e
commit
f340380898
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user