settings
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
from functools import cache
|
||||
from importlib.resources import files
|
||||
from pathlib import Path
|
||||
from typing import Literal
|
||||
|
||||
from pydantic import BaseModel
|
||||
from pydantic import DirectoryPath
|
||||
@@ -11,9 +13,17 @@ DEFAULT_ENV_FILE = Path(".env").resolve()
|
||||
_REPO_ROOT = Path(__file__).resolve().parents[2]
|
||||
|
||||
|
||||
@cache
|
||||
def _package_docs_dir() -> Path:
|
||||
docs_dir = files("personal_mcp").joinpath("docs")
|
||||
if not isinstance(docs_dir, Path):
|
||||
raise TypeError("personal_mcp docs must be installed as a filesystem directory")
|
||||
return docs_dir
|
||||
|
||||
|
||||
class Mounts(BaseModel):
|
||||
docs: str = "/docs"
|
||||
docs_dir: DirectoryPath = Field(default=_REPO_ROOT / "docs")
|
||||
docs_dir: DirectoryPath = Field(default_factory=_package_docs_dir)
|
||||
mcp: str = "/mcp"
|
||||
|
||||
|
||||
@@ -29,6 +39,7 @@ class Settings(BaseSettings):
|
||||
debug: bool = False
|
||||
log_level: str = "info"
|
||||
mounts: Mounts = Field(default_factory=Mounts)
|
||||
mcp_transport: Literal["http", "sse"] = "http"
|
||||
site_dir: DirectoryPath = Field(default=_REPO_ROOT / "site")
|
||||
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ def create_app(settings: Settings | None = None) -> FastAPI:
|
||||
path=runtime_settings.mounts.mcp,
|
||||
json_response=True,
|
||||
stateless_http=True,
|
||||
transport="http",
|
||||
transport=runtime_settings.mcp_transport,
|
||||
)
|
||||
app = FastAPI(
|
||||
debug=runtime_settings.debug,
|
||||
|
||||
Reference in New Issue
Block a user