|
| 1 | +from typing import Any |
| 2 | + |
| 3 | +import aiohttp |
| 4 | +from claude_agent_sdk import create_sdk_mcp_server, tool |
| 5 | + |
| 6 | +BASE_URL = "https://api.memu.so" |
| 7 | +API_KEY = "your memu api key" |
| 8 | +USER_ID = "claude_user" |
| 9 | +AGENT_ID = "claude_agent" |
| 10 | + |
| 11 | + |
| 12 | +@tool("memu_memory", "Retrieve memory based on a query", {"query": str}) |
| 13 | +async def get_memory(args: dict[str, Any]) -> dict[str, Any]: |
| 14 | + """Retrieve memory from the memory API based on the provided query.""" |
| 15 | + query = args["query"] |
| 16 | + url = f"{BASE_URL}/api/v3/memory/retrieve" |
| 17 | + headers = {"Authorization": f"Bearer {API_KEY}"} |
| 18 | + data = {"user_id": USER_ID, "agent_id": AGENT_ID, "query": query} |
| 19 | + |
| 20 | + async with aiohttp.ClientSession() as session, session.post(url, headers=headers, json=data) as response: |
| 21 | + result = await response.json() |
| 22 | + |
| 23 | + return {"content": [{"type": "text", "text": str(result)}]} |
| 24 | + |
| 25 | + |
| 26 | +async def _get_todos() -> str: |
| 27 | + url = f"{BASE_URL}/api/v3/memory/categories" |
| 28 | + headers = {"Authorization": f"Bearer {API_KEY}"} |
| 29 | + data = { |
| 30 | + "user_id": USER_ID, |
| 31 | + "agent_id": AGENT_ID, |
| 32 | + } |
| 33 | + async with aiohttp.ClientSession() as session, session.post(url, headers=headers, json=data) as response: |
| 34 | + result = await response.json() |
| 35 | + |
| 36 | + categories = result["categories"] |
| 37 | + todos = "" |
| 38 | + for category in categories: |
| 39 | + if category["name"] == "todo": |
| 40 | + todos = category["summary"] |
| 41 | + return todos |
| 42 | + |
| 43 | + |
| 44 | +@tool("memu_todos", "Retrieve todos for the user", {}) |
| 45 | +async def get_todos() -> dict[str, Any]: |
| 46 | + """Retrieve todos from the memory API.""" |
| 47 | + todos = await _get_todos() |
| 48 | + return {"content": [{"type": "text", "text": str(todos)}]} |
| 49 | + |
| 50 | + |
| 51 | +# Create the MCP server with the tool |
| 52 | +memu_server = create_sdk_mcp_server(name="memu", version="1.0.0", tools=[get_memory, get_todos]) |
0 commit comments