feat: add api and mcp
This commit is contained in:
1 parent
6a5cde6ae4
commit
c40e720163
30 files changed
+2354
-31
No files matched your search
+41
-3
@@ -4,18 +4,44 @@ from contextlib import asynccontextmanager
|
||||
import asyncpg
|
||||
from dishka.integrations.fastapi import DishkaRoute, FromDishka, setup_dishka
|
||||
from fastapi import FastAPI
|
||||
from fastmcp.utilities.lifespan import combine_lifespans
|
||||
from starlette.applications import Starlette
|
||||
|
||||
from api.routers import backfill, folders, policy
|
||||
from api.auth import BearerAuthMiddleware
|
||||
from api.mcp.server import mcp
|
||||
from api.routers import (
|
||||
annotations,
|
||||
backfill,
|
||||
chats,
|
||||
folders,
|
||||
media,
|
||||
peers,
|
||||
policy,
|
||||
presence,
|
||||
search,
|
||||
social,
|
||||
watches,
|
||||
)
|
||||
from dependencies.container import container
|
||||
from utils.env import env
|
||||
|
||||
if env.auth.token is None:
|
||||
msg = "AUTH__TOKEN is required for the api process"
|
||||
raise RuntimeError(msg)
|
||||
_token = env.auth.token.get_secret_value()
|
||||
|
||||
mcp_app = mcp.http_app(path="/")
|
||||
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifespan(app_: FastAPI) -> AsyncGenerator[None]:
|
||||
async def lifespan(app_: Starlette) -> AsyncGenerator[None]:
|
||||
yield
|
||||
await app_.state.dishka_container.close()
|
||||
|
||||
|
||||
app = FastAPI(title="beavergram API", lifespan=lifespan)
|
||||
app = FastAPI(
|
||||
title="beavergram API", lifespan=combine_lifespans(lifespan, mcp_app.lifespan)
|
||||
)
|
||||
app.router.route_class = DishkaRoute
|
||||
|
||||
|
||||
@@ -31,5 +57,17 @@ async def health(pool: FromDishka[asyncpg.Pool]) -> dict[str, bool]:
|
||||
app.include_router(policy.router)
|
||||
app.include_router(folders.router)
|
||||
app.include_router(backfill.router)
|
||||
app.include_router(search.router)
|
||||
app.include_router(chats.router)
|
||||
app.include_router(media.router)
|
||||
app.include_router(social.router)
|
||||
app.include_router(presence.router)
|
||||
app.include_router(peers.router)
|
||||
app.include_router(annotations.router)
|
||||
app.include_router(watches.router)
|
||||
|
||||
app.mount("/mcp", mcp_app)
|
||||
|
||||
app.add_middleware(BearerAuthMiddleware, token=_token)
|
||||
|
||||
setup_dishka(container, app)
|
||||
Reference in new issue
Block a user