Repository navigation
Expand file tree
/
Copy pathasgi.py
More file actions
50 lines (37 loc) · 1.62 KB
/
Copy pathasgi.py
File metadata and controls
50 lines (37 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
"""
ASGI application factory for production multi-worker deployment.
This module exposes the MCP server as an ASGI app that Uvicorn can import
directly with multiple workers:
uvicorn mcp_server.asgi:app --host 0.0.0.0 --port 8000 --workers 4
For local development, use `python -m mcp_server.main` instead (single worker).
"""
import asyncio
import os
import threading
from mcp_server.server import mcp
from mcp_server.tools.image_query_tool import image_query # noqa: F401 — registers tool
from mcp_server.tools.video_query_tool import video_query # noqa: F401 — registers tool
if os.environ.get("ENABLE_DATA_APIS", "").lower() == "true":
from mcp_server.tools.data_routes import get_transcript, get_frames, get_video_ids # noqa: F401 — registers routes
from fastmcp_docs import FastMCPDocs
from loguru import logger
# Set up tool documentation.
# Use a separate thread with its own event loop because uvicorn workers
# import this module inside a running event loop, which blocks asyncio.run().
docs = FastMCPDocs(
mcp,
title="MMCT Agent MCP Tools",
description="Interactive documentation for MMCT Agent MCP server tools. "
"Browse available tools, view input/output schemas, and test calls.",
base_url=os.environ.get("BASE_URL", ""),
)
def _setup_docs():
loop = asyncio.new_event_loop()
loop.run_until_complete(docs.setup())
loop.close()
_thread = threading.Thread(target=_setup_docs)
_thread.start()
_thread.join()
logger.info("Tool documentation registered at /docs")
# Create the ASGI application for Uvicorn
app = mcp.http_app(transport="streamable-http", stateless_http=True)