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