-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathmcp_server.py
More file actions
43 lines (37 loc) · 998 Bytes
/
mcp_server.py
File metadata and controls
43 lines (37 loc) · 998 Bytes
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
# mcp_server.py
import asyncio
from typing import Optional
from fastmcp import FastMCP
from orchestrator import initialize_rag, handle_insert, handle_query
mcp = FastMCP("memverse")
_initialized = False
_lock = asyncio.Lock()
async def ensure_init():
global _initialized
if _initialized:
return
async with _lock:
if not _initialized:
await initialize_rag()
_initialized = True
print("MCP ready")
@mcp.tool()
async def insert_memory(
query: str,
image: Optional[str] = None,
audio: Optional[str] = None,
video: Optional[str] = None,
):
await ensure_init()
entry = await handle_insert(query, image, audio, video)
return {"entry": entry}
@mcp.tool()
async def query_memory(
query: str,
mode: str = "hybrid",
use_pm: bool = True,
):
await ensure_init()
return await handle_query(query, mode, use_pm)
if __name__ == "__main__":
mcp.run(host="0.0.0.0", port=5250, transport="http")