Add user-bound external MCP server and OAuth access
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
"""Per-request identity for domain tools shared by stdio and remote MCP."""
|
||||
from __future__ import annotations
|
||||
|
||||
from contextlib import contextmanager
|
||||
from contextvars import ContextVar
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
from typing import Iterator
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class ToolContext:
|
||||
username: str
|
||||
tab_id: str
|
||||
work_dir: Path
|
||||
client_id: str
|
||||
scopes: frozenset[str]
|
||||
|
||||
|
||||
_current: ContextVar[ToolContext | None] = ContextVar("smeta_mcp_tool_context", default=None)
|
||||
|
||||
|
||||
def current_tool_context() -> ToolContext | None:
|
||||
return _current.get()
|
||||
|
||||
|
||||
@contextmanager
|
||||
def bind_tool_context(context: ToolContext) -> Iterator[None]:
|
||||
marker = _current.set(context)
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
_current.reset(marker)
|
||||
Reference in New Issue
Block a user