mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-07-10 22:32:16 +02:00
feat(mcp): make api_key optional, add http host/port config
This commit is contained in:
parent
8a54e0293e
commit
3b4678ade4
2 changed files with 19 additions and 8 deletions
|
|
@ -12,6 +12,8 @@ from dataclasses import dataclass
|
|||
DEFAULT_BASE_URL = "http://localhost:8000"
|
||||
DEFAULT_API_PREFIX = "/api/v1"
|
||||
DEFAULT_TIMEOUT_SECONDS = 180.0
|
||||
DEFAULT_HTTP_HOST = "127.0.0.1"
|
||||
DEFAULT_HTTP_PORT = 8080
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
|
|
@ -19,10 +21,12 @@ class Settings:
|
|||
"""Resolved configuration for a server process."""
|
||||
|
||||
base_url: str
|
||||
api_key: str
|
||||
api_key: str | None
|
||||
api_prefix: str
|
||||
timeout: float
|
||||
default_workspace: str | None
|
||||
host: str
|
||||
port: int
|
||||
|
||||
@property
|
||||
def api_base(self) -> str:
|
||||
|
|
@ -30,13 +34,9 @@ class Settings:
|
|||
|
||||
@classmethod
|
||||
def from_env(cls) -> Settings:
|
||||
api_key = os.environ.get("SURFSENSE_API_KEY", "").strip()
|
||||
if not api_key:
|
||||
raise SystemExit(
|
||||
"SURFSENSE_API_KEY is required. Create an API key in SurfSense "
|
||||
"(Settings -> API) and pass it via the SURFSENSE_API_KEY "
|
||||
"environment variable."
|
||||
)
|
||||
# Optional here: remote (http) callers pass their own key per request in
|
||||
# a header. ``__main__`` enforces it for stdio, its only source of a key.
|
||||
api_key = os.environ.get("SURFSENSE_API_KEY", "").strip() or None
|
||||
|
||||
base_url = (
|
||||
os.environ.get("SURFSENSE_BASE_URL", DEFAULT_BASE_URL).strip().rstrip("/")
|
||||
|
|
@ -53,10 +53,19 @@ class Settings:
|
|||
|
||||
default_workspace = os.environ.get("SURFSENSE_WORKSPACE", "").strip() or None
|
||||
|
||||
host = os.environ.get("SURFSENSE_MCP_HOST", "").strip() or DEFAULT_HTTP_HOST
|
||||
raw_port = os.environ.get("SURFSENSE_MCP_PORT", "").strip()
|
||||
try:
|
||||
port = int(raw_port) if raw_port else DEFAULT_HTTP_PORT
|
||||
except ValueError:
|
||||
port = DEFAULT_HTTP_PORT
|
||||
|
||||
return cls(
|
||||
base_url=base_url,
|
||||
api_key=api_key,
|
||||
api_prefix=api_prefix,
|
||||
timeout=timeout,
|
||||
default_workspace=default_workspace,
|
||||
host=host,
|
||||
port=port,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -47,6 +47,8 @@ async def _collect_tools() -> dict[str, object]:
|
|||
api_prefix="/api/v1",
|
||||
timeout=5.0,
|
||||
default_workspace=None,
|
||||
host="127.0.0.1",
|
||||
port=8080,
|
||||
)
|
||||
mcp, _client = build_server(settings)
|
||||
tools = await mcp.list_tools()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue