Qwen Memory MCP
The Qwen Memory MCP server provides long-term, cross-session memory management for AI agents, powered by Qwen, and exposed via the Model Context Protocol (MCP).
Write Memories (
memory_write): Persist durable information about a user (preferences, facts, commitments, or events). Qwen automatically derives a summary, tags, importance score, and memory kind. You can optionally override the salience score or attach a source session ID.Search Memories (
memory_search): Perform semantic search over stored memories, ranked by similarity, importance, recency, and recall frequency. Returns up to 50 matches (default 5) and reinforces recalled memories.Recall Context Within a Token Budget (
memory_recall_context): Retrieve the most critical memories relevant to a query, packed to fit within a specified token budget (up to 32,000 tokens) — ideal for injecting long-term memory into a limited context window.Consolidate and Forget (
memory_forget): Run a maintenance pass that merges related memories, flags contradicted or outdated items, and decays stale low-importance memories. Returns a report of what was consolidated, archived, forgotten, and retained.
Key properties:
All memories are namespaced by
userId, enabling one server to serve many users/agents simultaneously.Works offline without an API key (falls back to local deterministic intelligence).
Supports both
stdioand Streamable HTTP transports for local and cloud deployment.
Integrates with Alibaba Cloud's Qwen (via DashScope) for embeddings and intelligence, and uses Alibaba Cloud RDS/PolarDB for MySQL as a production storage backend for persistent memory.
Allows using MySQL (specifically Alibaba Cloud RDS/PolarDB) as a persistent storage backend for memory data, enabling durable storage of memories.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@Qwen Memory MCPRemember that I prefer dark mode in all apps."
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
Qwen Memory MCP
Long-term memory for AI agents, powered by Qwen on Alibaba Cloud and exposed over the Model Context Protocol (MCP). Any MCP-capable agent gains durable, cross-session memory that accumulates experience, retrieves what matters within a limited context window, and forgets what is outdated.
Hackathon track: Track 1 - MemoryAgent. License: MIT. Copyright (c) 2026 JHELY GLOBAL SL.
Repository: https://github.com/John-CEO-HQ/qwen-memory-mcp
Demo video: https://youtu.be/ZxXKvVY6iMQ
This project is a learning experiment for the Qwen Cloud Hackathon: a standalone MCP server for agent memory on Alibaba Cloud.
Documentation
Guide | Purpose |
Master index: testing phases and pass criteria | |
Accounts, API keys, regions, cost guardrails | |
Live Qwen / DashScope tests from your machine | |
Alibaba deploy + verify deployed URL | |
Full install, local run, Alibaba production deploy, troubleshooting | |
Instructions for hackathon judges | |
Alibaba ECS / Function Compute quick reference | |
Agent conventions and isolation contract |
Related MCP server: mindcore-memory-mcp
Why
Agents feel sharp inside a single conversation and amnesiac across sessions. This server gives an agent a managed memory layer that does four things well:
Write - extract a durable memory (preference, fact, commitment, event), with a Qwen-derived summary, tags, importance (salience), and kind.
Search - semantic retrieval ranked by similarity + salience + recency + reinforcement.
Recall context - pack the most critical memories into a fixed token budget, ready to inject into a small context window.
Forget - a maintenance pass that consolidates related memories with Qwen and lets stale, low-value memories decay away.
Architecture
flowchart LR
agent["Any MCP client / agent"] -->|"MCP: write / search / recall / forget"| server["Qwen Memory MCP server (stdio or HTTP)"]
server --> service["MemoryService"]
service -->|"embeddings + reasoning"| qwen["Qwen on Alibaba Cloud Model Studio (DashScope)"]
service -->|"persist + retrieve"| store["MemoryStore"]
store --> file["File / in-memory (local + demo)"]
store --> mysql["Alibaba Cloud RDS / PolarDB for MySQL (production)"]Memory lifecycle:
flowchart TD
w["memory_write"] --> analyze["Qwen analyze: summary, tags, salience, kind"]
analyze --> embed1["Qwen embed (text-embedding-v3)"]
embed1 --> active["active memory"]
active --> s["memory_search / memory_recall_context"]
s --> rank["rank: similarity + salience + recency + reinforcement"]
rank --> pack["pack into token budget"]
s -.reinforce.-> active
active --> f["memory_forget"]
f --> cluster["cluster by embedding similarity"]
cluster --> consolidate["Qwen consolidate cluster -> canonical memory"]
consolidate --> outdated["flag contradicted items -> forgotten"]
active --> decay["decay score below threshold -> forgotten"]Quick start
npm install
# Offline demo (no API key needed - deterministic local intelligence):
npm run demo
# Run the test suite:
npm test
# Run as an MCP server over stdio (for MCP Inspector / desktop clients):
npm run build && npm startTo use the real Qwen models, copy .env.example to .env and set
QWEN_API_KEY (and optionally QWEN_BASE_URL for your region). Without a key,
the server automatically falls back to the offline deterministic intelligence
so it always runs.
MCP tools
Tool | Purpose | Key inputs |
| Persist a durable memory |
|
| Top-k semantic recall |
|
| Critical memories packed to a token budget |
|
| Consolidate + decay maintenance |
|
All memories are namespaced by userId, so one server can serve many agents.
Transports
stdio (
MCP_TRANSPORT=stdio, default) - launched as a child process by a local MCP client.Streamable HTTP (
MCP_TRANSPORT=http) - stateless JSON-RPC atPOST /mcpwith optionalAuthorization: Bearer <MCP_AUTH_TOKEN>, plusGET /health. This is the shape used for cloud deployment and remote per-user MCP URLs.
Storage
MEMORY_STORE=memory- in-process, ephemeral (tests/demo).MEMORY_STORE=file- single JSON file atMEMORY_FILE_PATH(local default).MEMORY_STORE=mysql- Alibaba Cloud RDS / PolarDB for MySQL (production); schema is created automatically. Vectors are stored as JSON and scored in the app; seesrc/memory/mysql-store.tsfor the AnalyticDB-PG (pgvector) upgrade path.
Alibaba Cloud / Qwen
The only integration points with Alibaba Cloud are
src/qwen.ts (DashScope embeddings + chat) and
src/memory/mysql-store.ts (RDS/PolarDB). See
docs/INSTALL.md for full production setup and
deploy/README.md for a short Alibaba quick reference.
Configuration
See .env.example for all variables (Qwen models, store
selection, transport, auth token, and forgetting/decay tuning).
Layout
qwen-memory-mcp/
src/
qwen.ts # Alibaba Cloud / Qwen (DashScope) intelligence [PROOF]
fake-intelligence.ts # offline deterministic intelligence (tests/demo)
intelligence.ts # picks Qwen vs fake
config.ts # env-driven config
types.ts # domain types
memory/
store.ts # MemoryStore interface
file-store.ts # file / in-memory store
mysql-store.ts # Alibaba RDS / PolarDB store [PROOF]
create-store.ts # store factory
ranking.ts # retrieval ranking + token-budget packing
forgetting.ts # clustering + consolidation + decay
service.ts # MemoryService (orchestration)
server.ts # MCP server + 4 tools
transports/
stdio.ts # stdio transport
http.ts # streamable HTTP transport (stateless)
index.ts # entry point
demo/cli.ts # multi-session offline demo
test/ # vitest suite
deploy/ # Alibaba Cloud deployment docs
DockerfileLicense
MIT License. Copyright (c) 2026 JHELY GLOBAL SL. See LICENSE.
Available Tools
4 toolsmemory_forgetConsolidate and forgetA
Runs the maintenance pass: clusters of related memories are merged by Qwen into one canonical memory, contradicted/outdated items are forgotten, and stale low-importance memories decay away. Returns a report of what was consolidated, archived, forgotten, and retained.
| Name | Required | Description | Default |
|---|---|---|---|
| userId | Yes |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
With no annotations, the description carries the full burden of behavioral disclosure. It explains the process: merging clusters, forgetting contradicted/outdated items, decaying stale low-importance memories, and returning a report. It could mention idempotency or data loss details, but it is fairly transparent.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is two sentences, front-loaded with the core action, and the second sentence explains the output. No extraneous information.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
Given the simplicity of the tool (1 param, no output schema, no annotations), the description explains the process but lacks parameter semantics and usage guidance. Without an output schema, describing the report structure would improve completeness.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Schema coverage is 0% (no description for the userId parameter). The description does not explain the parameter's meaning or how it affects the operation. With only one required parameter, the description should compensate, but it fails to provide any additional semantics.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description clearly states the tool runs a maintenance pass that consolidates, forgets, and decays memories. It uses specific verbs and resources, and distinguishes from siblings (memory_recall_context, memory_search, memory_write) which are for recall, search, and writing, not maintenance.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
The description implies usage context (maintenance pass) but provides no explicit guidance on when to use this tool versus alternatives or when not to use it. No exclusions or prerequisites are mentioned.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
memory_recall_contextRecall context within a token budgetB
Returns the most critical memories for a query, greedily packed to fit a token budget, as a ready-to-inject context block. Use this to load long-term memory into a limited context window before answering.
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | ||
| userId | Yes | ||
| tokenBudget | Yes | Approximate max tokens the returned context may use. |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
No annotations are present, so the description carries full burden. Discloses greedy packing and criticality ranking, but does not cover idempotency, state mutations, rate limits, or other behavioral traits. Adds some value beyond the name but lacks comprehensiveness.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
Two sentences efficiently convey the core function and usage. While concise and front-loaded, the description could benefit from a structured breakdown, but overall it avoids unnecessary words.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
Given the absence of annotations and output schema, the description partially covers purpose and usage but lacks details on parameter semantics, return format, and side effects. Adequate but not fully comprehensive for an agent to use without additional information.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Schema description coverage is only 33% (only tokenBudget has a description). The tool description does not explain query or userId parameters, leaving them undefined. Fails to compensate for the low schema coverage, so minimal meaning is added beyond the schema.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
Describes returning the most critical memories for a query, greedily packed within a token budget. Clearly states verb and resource, distinguishing from sibling tools by emphasizing the token budget and context-block output, though not explicitly differentiating from memory_search.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
Explicitly states to use this tool to load long-term memory into a limited context window before answering. Provides clear context for when to use, but does not explicitly exclude alternatives like memory_search or mention when not to use.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
memory_searchSearch memoriesA
Semantic search over a user's memories, ranked by similarity, importance, recency, and how often each memory has been recalled. Returns the top matches. Recalled memories are reinforced.
| Name | Required | Description | Default |
|---|---|---|---|
| k | No | Max results (default 5). | |
| query | Yes | What you want to recall. | |
| userId | Yes |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
With no annotations, the description discloses the key behavioral trait that recalled memories are reinforced (state modification), and explains ranking factors. However, it does not mention any potential side effects or truncation behavior beyond 'top matches'.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
Three concise sentences front-load the purpose and ranking details, with no redundant or extraneous information.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
Given no output schema and 3 parameters, the description explains the ranking, reinforcement, and top match behavior. It lacks details on return format but is sufficient for a search tool with k parameter limiting.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Schema coverage is 67% (userId missing description). The description adds minimal additional meaning beyond the schema for 'query' and 'k', and nothing for userId, resulting in marginal value added.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description clearly states 'semantic search over a user's memories' with specific ranking criteria (similarity, importance, recency, recall count), distinguishing it from sibling tools like memory_write and memory_forget.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
The description implies usage for retrieving memories but does not explicitly state when to use versus alternatives, nor does it provide when-not conditions.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
memory_writeWrite memoryA
Persist something worth remembering about a user (a preference, fact, commitment, or event). Qwen derives a short summary, tags, importance (salience), and kind. Call this whenever the user reveals durable information you should recall in future sessions.
| Name | Required | Description | Default |
|---|---|---|---|
| userId | Yes | Stable id namespacing this user's memories. | |
| content | Yes | The information to remember, in plain language. | |
| salience | No | Optional importance override in [0,1]; otherwise Qwen decides. | |
| sourceSession | No | Optional originating session/conversation id. |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
The description reveals that Qwen derives summary, tags, importance, and kind, which is beyond the schema. However, with no annotations, it doesn't cover side effects, idempotency, or limits. Adequate but not thorough.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
Two efficient sentences: first defines purpose with examples, second provides usage guidance. No wasted words, front-loaded with key information.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
For a 4-parameter write tool with no output schema or annotations, the description covers purpose, usage, and key behavioral nuances (derived fields). Lacks some details like return value or error handling, but sufficient for typical use.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Schema coverage is 100%, so baseline is 3. The description adds no parameter-specific details beyond the schema, only tying the concept of 'content' to the tool's purpose.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description clearly states the tool persists user memories, with specific examples (preference, fact, commitment, event). It implicitly distinguishes from siblings (forget, recall_context, search) by focusing on writing new information.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
The second sentence explicitly says when to call: 'whenever the user reveals durable information you should recall in future sessions.' No explicit when-not-to-use or alternative tools mentioned, but the context is clear.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
4 tool updates
v0.1.0- First observed
memory_forget - First observed
memory_recall_context - First observed
memory_search - First observed
memory_write
TDQS
Scored across 4 tools
Each tool has a clearly distinct purpose: writing new memories, searching them, recalling context for a query, and running maintenance. No overlap in functionality.
All tool names follow a consistent 'memory_<verb>' pattern, making the action clear and predictable.
Four tools cover the core memory operations (write, search, recall, maintenance) without unnecessary bloat. The scope is appropriate for a memory management server.
Missing explicit update and list operations; however, the automatic maintenance and selective retrieval cover common use cases. Gaps exist for direct manipulation of individual memories.
Maintenance
Related MCP Connectors
An MCP memory server. One memory your agents share — across models, devices and apps.
Persistent memory for AI agents — log and recall conversation context over MCP.
- memnodeOAuthdev.memnode
Persistent, inspectable memory for AI agents with lineage, correction, and a hosted MCP endpoint.
Shared, governed long-term memory for AI agents across tools and sessions via MCP and REST.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceA Model Context Protocol server that provides AI agents with persistent memory capabilities through Mem0, allowing them to store, retrieve, and semantically search memories.684MIT
- AlicenseAqualityCmaintenanceA production-grade long-term memory MCP server that enables AI agents to persist and recall memories across sessions with importance weighting, confidence calibration, and efficient context window management.91MIT
- AlicenseNot gradedqualityCmaintenancePersistent, searchable memory for AI agents over the Model Context Protocol, enabling memory storage, full-text search with BM25 ranking, and retrieval across sessions.6 npmMIT
- FlicenseNot gradedqualityBmaintenanceA persistent memory server for AI agents using MCP protocol, enabling semantic storage and retrieval of dialogues, documents, and agent states.-