From 0b096ee500466045b118ee211ffe292e7e158045 Mon Sep 17 00:00:00 2001 From: RightL Date: Tue, 18 Aug 2026 14:34:12 +0800 Subject: [PATCH 1/2] feat: migrate MCP adapter to SDK v2 --- docs/MCP.md | 2 +- pyproject.toml | 4 ++-- rightmemory/mcp.py | 6 +++--- tests/test_mcp.py | 15 +++++++++++++-- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/docs/MCP.md b/docs/MCP.md index dbe3431..8e9d372 100644 --- a/docs/MCP.md +++ b/docs/MCP.md @@ -1,6 +1,6 @@ # RightMemory MCP -RightMemory exposes a local MCP stdio server for ordinary agent work: +RightMemory exposes a local MCP stdio server for ordinary agent work using the current stable v2 line of the official MCP Python SDK: ```bash rightmemory mcp diff --git a/pyproject.toml b/pyproject.toml index dbc1aea..05976b5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -29,8 +29,8 @@ classifiers = [ ] dependencies = [ "fastapi>=0.115.0", - "mcp>=1.28,<2", - "pydantic-ai>=1.0.0", + "mcp>=2,<3", + "pydantic-ai-slim[anthropic,openai]>=1.0.0", "uvicorn>=0.30.0", ] diff --git a/rightmemory/mcp.py b/rightmemory/mcp.py index 952c403..23be36e 100644 --- a/rightmemory/mcp.py +++ b/rightmemory/mcp.py @@ -6,7 +6,7 @@ from pathlib import Path from typing import Annotated, Protocol -from mcp.server.fastmcp import FastMCP +from mcp.server import MCPServer from mcp.types import CallToolResult, TextContent from pydantic import Field @@ -176,11 +176,11 @@ def create_mcp_server( memory_root: Path, *, backend: McpBackend | None = None, -) -> FastMCP: +) -> MCPServer: selected_backend = backend or DefaultMcpBackend( Path(memory_root).expanduser().resolve() ) - server = FastMCP(name="RightMemory", log_level="WARNING") + server = MCPServer("RightMemory", log_level="WARNING") @server.tool( name="rightmemory_retrieve", diff --git a/tests/test_mcp.py b/tests/test_mcp.py index 0144f3d..0026ba7 100644 --- a/tests/test_mcp.py +++ b/tests/test_mcp.py @@ -9,6 +9,7 @@ from types import SimpleNamespace from unittest.mock import patch +from mcp import Client from mcp.types import CallToolResult from rightmemory import entrypoint @@ -48,20 +49,30 @@ def actionable_warning(self) -> str | None: return self.warning +async def _call_tool(server, name: str, arguments: dict[str, str]) -> CallToolResult: + async with Client(server, raise_exceptions=True) as client: + return await client.call_tool(name, arguments) + + def call_tool(server, name: str, arguments: dict[str, str]) -> CallToolResult: - result = asyncio.run(server.call_tool(name, arguments)) + result = asyncio.run(_call_tool(server, name, arguments)) if not isinstance(result, CallToolResult): raise AssertionError(f"expected CallToolResult, got {type(result).__name__}") return result +async def _list_tools(server): + async with Client(server, raise_exceptions=True) as client: + return (await client.list_tools()).tools + + class McpToolTests(unittest.TestCase): def setUp(self) -> None: self.backend = FakeBackend() self.server = create_mcp_server(Path("/unused"), backend=self.backend) def test_server_exposes_only_the_three_ordinary_agent_tools(self): - tools = asyncio.run(self.server.list_tools()) + tools = asyncio.run(_list_tools(self.server)) self.assertEqual( {tool.name for tool in tools}, { From 83a978d3a3953649be0fc700111a50e06d566f42 Mon Sep 17 00:00:00 2001 From: RightL Date: Tue, 18 Aug 2026 14:36:56 +0800 Subject: [PATCH 2/2] docs: make MCP version wording durable --- docs/MCP.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/MCP.md b/docs/MCP.md index 8e9d372..deddac8 100644 --- a/docs/MCP.md +++ b/docs/MCP.md @@ -1,6 +1,6 @@ # RightMemory MCP -RightMemory exposes a local MCP stdio server for ordinary agent work using the current stable v2 line of the official MCP Python SDK: +RightMemory exposes a local MCP stdio server for ordinary agent work using the official MCP Python SDK v2: ```bash rightmemory mcp