Skip to content

feat: add MCP integration for MemoryService#376

Open
De13ruyne wants to merge 14 commits intoNevaMind-AI:mainfrom
De13ruyne:feat/add_mcp
Open

feat: add MCP integration for MemoryService#376
De13ruyne wants to merge 14 commits intoNevaMind-AI:mainfrom
De13ruyne:feat/add_mcp

Conversation

@De13ruyne
Copy link
Copy Markdown
Collaborator

@De13ruyne De13ruyne commented Mar 9, 2026

📝 Pull Request Summary

Add MCP (Model Context Protocol) integration to expose memU's MemoryService as a set of MCP tools, enabling MCP-compatible clients (memUBot, Cursor, Claude Desktop, etc.) to interact with memU's memory capabilities directly.
image


✅ What does this PR do?

  • New MCP integration module (src/memu/integrations/mcp.py, 387 lines): Implements an MCP Server using FastMCP, exposing 8 memory operation tools — memorize, retrieve, list_memories, list_categories, create_memory, update_memory, delete_memory, and clear_memory.
  • New CLI entry point (memu-mcp): Supports configuration via command-line arguments or environment variables for LLM settings (API key, base URL, model, separate embedding provider) and storage backends (inmemory / sqlite / postgres), with both stdio and SSE MCP transports.
  • Cursor MCP manifest (manifest.json): Provides a standard MCP server descriptor so that Cursor and other MCP clients can discover and install memU with one click.
  • Extended user scope model (MCPUserModel): Adds agent_id and session_id fields on top of the standard user_id, enabling memory isolation across multiple agents and sessions.
  • Updated pyproject.toml: Adds the mcp optional dependency group (mcp>=1.0, python-dotenv>=1.0), registers the memu-mcp script entry point, and adds mypy/deptry configuration for the new dependencies.
  • Lazy import for integrations (src/memu/integrations/__init__.py): Replaced eager from .langgraph import ... with __getattr__-based lazy import, preventing ModuleNotFoundError when langgraph is not installed (e.g. in MCP-only environments).
  • Bug fix in CRUD layer (src/memu/app/crud.py): Added the missing resource_id argument to create_memory_item call, which was causing failures when creating memory items via the MCP create_memory tool.

🤔 Why is this change needed?

  • MCP is becoming the standard protocol for the AI tool ecosystem. Major clients such as Cursor and Claude Desktop already support it. By adding MCP integration, memU can be consumed by any MCP-compatible client, significantly lowering the barrier to adoption.
  • Users can give AI agents persistent memory capabilities without writing any code — simply configure and run memu-mcp as an MCP server.
  • The agent_id + session_id scoping design makes memory isolation in multi-agent scenarios work out of the box.

🔍 Type of Change

  • Bug fix
  • New feature
  • Documentation update
  • Refactor / cleanup
  • Other (please explain)

✅ PR Quality Checklist

  • PR title follows the conventional format
  • Changes are limited in scope and easy to review
  • Documentation updated where applicable (manifest.json serves as MCP client configuration documentation)
  • No breaking changes (or clearly documented) — purely additive, no breaking changes
  • Related issues or discussions linked

📌 Optional

  • Screenshots or examples added (if applicable)
  • Edge cases considered — tests are not yet included in this PR (see follow-up)
  • Follow-up tasks mentioned

Follow-up suggestions:

  • Add comprehensive unit tests for MCP tools (scope isolation, temp file cleanup, error handling, etc.).
  • Add MCP integration usage instructions and configuration examples to README.md and docs/.
  • Add a dedicated MCP usage example under examples/.
  • The git URL in manifest.json currently points to a fork's feature branch (De13ruyne/memU@feat/add_mcp). After merging, update it to reference the main repository or switch to a PyPI package install.

@De13ruyne De13ruyne changed the title Feat/add mcp feat: add MCP integration for MemoryService Mar 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant