Add user-bound external MCP server and OAuth access

This commit is contained in:
anor
2026-11-27 17:12:15 +10:00
parent 9a8c2de750
commit 70ad8743d2
25 changed files with 1520 additions and 20 deletions
+10
View File
@@ -22,6 +22,10 @@ PROTOCOL_VERSION = "2025-06-18"
def _user_tab() -> tuple[str, str]:
from mcp_context import current_tool_context
bound = current_tool_context()
if bound is not None:
return bound.username, bound.tab_id
return (
os.environ.get("SMETA_USER", "").strip(),
os.environ.get("SMETA_TAB", "default").strip() or "default",
@@ -37,6 +41,12 @@ def _work_dir(user: str, tab: str) -> Path:
Иначе — DATA_DIR/user/tab (как на хосте main-приложения).
"""
from mcp_context import current_tool_context
bound = current_tool_context()
if bound is not None:
if (user, tab) != (bound.username, bound.tab_id):
raise PermissionError("MCP context does not own this work directory")
return bound.work_dir
direct = os.environ.get("SMETA_WORK_DIR")
if direct:
return Path(direct)