-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathserver.py
More file actions
35 lines (27 loc) · 907 Bytes
/
server.py
File metadata and controls
35 lines (27 loc) · 907 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
import os
from mcp.server.fastmcp import FastMCP
from memvid import MemvidEncoder, MemvidChat, MemvidRetriever
PORT = os.getenv("PORT", "3000")
# Create an MCP server
mcp = FastMCP("memvid", port=PORT, debug=True, log_level="DEBUG")
video = "memory.mp4"
index = "memory_index.json"
# Add an addition tool
@mcp.tool()
def add_chunks(chunks: list[str]) -> str:
encoder = MemvidEncoder(video, index)
encoder.add_chunks(chunks)
encoder.build_video(video, index)
return "added chunks to memory.mp4"
@mcp.tool()
def search(query: str, top_k: int = 5) -> str:
retriever = MemvidRetriever(video, index)
# Semantic search
results = retriever.search(query, top_k=top_k)
res_strs = []
for chunk in results:
res_strs.append(chunk)
return "\n".join(res_strs)
if __name__ == "__main__":
print(f"Running on port {PORT}")
mcp.run(transport="streamable-http")