Cross-Application AI Memory: Tablestore OpenMemory MCP

Updated at:

Mem0 is a memory layer for AI agents that enables self-improving, personalized AI experiences across applications. Table Store Openmemory MCP builds on Mem0, using Table Store as a stable, scalable memory center to create a persistent memory system for AI applications.

Features

Tablestore Openmemory MCP includes four MCP tools:

  • add_memories: Adds, modifies, and deletes user memories.

  • search_memories: Searches user memories.

  • list_memories: Lists all user memories.

  • delete_all_memories: Deletes all user memories.

Prerequisites

Deploy and connect MCP service

Tablestore Openmemory MCP supports two modes: Server-Side Encryption (SSE) and Standard Input/Output (stdio).

SSE mode

To deploy the Tablestore Openmemory MCP service in SSE mode, you need to prepare a server to run MCP. You can use an Alibaba Cloud ECS instance. To ensure Python dependencies download successfully, we recommend selecting the China (Hong Kong) region.

Note

The ECS instance used in this topic runs the Alibaba Cloud Linux 3.2104 LTS 64-bit operating system. The default Python 3 version is 3.6.8, which must be upgraded.

How to upgrade the Python version on an ECS instance

The following steps use Python 3.12.11 as an example.

  1. Download and extract Python.

    wget https://www.python.org/ftp/python/3.12.11/Python-3.12.11.tgz && tar -zxvf Python-3.12.11.tgz
  2. Install the required Python dependencies.

    sudo yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel xz-devel libffi-devel libuuid-devel libtirpc-devel libnsl2-devel
  3. Configure, build, and install Python.

    cd Python-3.12.11 && ./configure && make && sudo make install && source ~/.bashrc
  4. After the installation, run the following command to check the Python version.

    python3 --version

1. Deploy the MCP service

You can use the uv tool to run the service directly without installing MCP.

  1. Install the uv package manager.

    pip3 install uv
  2. Configure the environment variables required to run the service.

    echo "export OPENAI_API_KEY='sk-7*******************************'" >> ~/.bashrc
    echo "export OPENAI_BASE_URL='https://dashscope.aliyuncs.com/compatible-mode/v1'" >> ~/.bashrc
    echo "export TABLESTORE_ENDPOINT='https://k01r********.cn-hangzhou.ots.aliyuncs.com'" >> ~/.bashrc
    echo "export TABLESTORE_INSTANCE_NAME='k01r********'" >> ~/.bashrc
    echo "export TABLESTORE_ACCESS_KEY_ID='LTAI********************'" >> ~/.bashrc
    echo "export TABLESTORE_ACCESS_KEY_SECRET='Jy3H**************************'" >> ~/.bashrc

    After the configuration is complete, run the source ~/.bashrc command to apply the environment variables. The following table describes how to get the values for these variables.

    Parameter

    Description

    OPENAI_API_KEY

    Go to API Key Management to view and copy your API key. If you do not have an API key, click Create API Key to create one.

    OPENAI_BASE_URL

    https://dashscope.aliyuncs.com/compatible-mode/v1

    TABLESTORE_ENDPOINT

    Go to the Tablestore console. In the instance list, click an instance alias to go to the Instance Management page. Then, find and copy the instance name and instance endpoint. If you use an ECS instance, select an endpoint based on the region:

    • If your ECS instance and Tablestore instance are in the same region, select a public endpoint or a VPC endpoint.

    • If your ECS instance and Tablestore instance are in different regions, select a public endpoint.

    Important

    By default, new Tablestore instances do not allow public access. To use a public endpoint, go to the Network Management tab on the Instance Management page in the Tablestore console. Select Public for Allowed Network Types and click Set to save your changes.

    TABLESTORE_INSTANCE_NAME

    TABLESTORE_ACCESS_KEY_ID

    The AccessKey ID of your Alibaba Cloud account or RAM user.

    TABLESTORE_ACCESS_KEY_SECRET

    The AccessKey Secret of your Alibaba Cloud account or RAM user.

    Optional environment variables

    Parameter

    Description

    Default

    SERVER_HOST

    The host where the MCP service runs.

    0.0.0.0

    SERVER_PORT

    The port where the MCP service runs.

    8765

    TABLESTORE_STS_TOKEN

    An Alibaba Cloud STS temporary access credential.

    None

    TABLESTORE_VECTOR_DIMENSION

    The vector dimension.

    1536

    LLM_MODEL

    The large language model name.

    qwen-plus

    EMBEDDER_MODEL

    The embedding model name.

    text-embedding-v4

    TOOL_ADD_MEMORIES_DESCRIPTION

    Description for the tool that adds memories.

    Add a new memory. This method is called every time the user shares information about themselves, their preferences, or other relevant information for future conversations. This can also be called when the user asks you to remember something.

    TOOL_SEARCH_MEMORIES_DESCRIPTION

    Description for the tool that searches memories.

    Search through stored memories. This method is called every time the user asks anything.

    TOOL_LIST_MEMORIES_DESCRIPTION

    Description for the tool that lists memories.

    Lists all memories stored for the user.

    TOOL_DELETE_ALL_MEMORIES_DESCRIPTION

    Description for the tool that deletes memories.

    Deletes all memories stored for the user.

  3. Start the MCP service.

    uvx tablestore-openmemory-mcp --transport=sse

    When you run the service for the first time, it downloads its dependencies. This process may take some time. If the download fails due to network issues, run the command again. After the service starts, the MCP service automatically creates the required data tables and Search Indexes in your Tablestore instance. The following log output indicates that the service has started successfully.

    INFO:     Started server process [43283]
    INFO:     Waiting for application startup.
    INFO:     Application startup complete.
    INFO:     Uvicorn running on http://0.0.0.0:8765 (Press CTRL+C to quit)

2. Connect to the MCP service

Connection URL format: http://server_ip:port/mcp/client_name/sse/user_id

  • server_ip: The IP address of the server running the MCP service.

  • port: The port on which the MCP service runs. The default port is 8765.

    Important

    To access the MCP service on an ECS instance, you must add a security group rule to the inbound rules of the instance's security group. This rule must allow TCP traffic on the port used by the MCP service, which is 8765 by default.

  • client_name and user_id: Custom parameters that isolate memories for different users.

Cline

Fill in the Remote Servers information as shown in the following example, or click Edit Configuration and add the MCP service configuration to the cline_mcp_settings.json configuration file.

Example: Cline connection configuration

{
  "mcpServers": {
    "tablestore-openmemory": {
      "autoApprove": [
        "add_memories",
        "search_memories",
        "list_memories",
        "delete_all_memories"
      ],
      "disabled": false,
      "timeout": 60,
      "type": "sse",
      "url": "http://47.******.88:8765/mcp/mem0/sse/user0"
    }
  }
}

Configuring autoApprove automatically approves invocations of the MCP tool without requiring manual confirmation. If you do not want to automatically trigger tool invocations, delete the autoApprove field.

After the configuration is complete, enable the MCP service in the Cline conversation window.

After you enable the service, the switch next to the tablestore-openmemory-mcp entry in the MCP Servers panel turns green and a green status indicator appears, indicating that the MCP service is connected. You can also click the + button in the toolbar at the bottom of the conversation window to quickly add an MCP service.

Cherry Studio

In Cherry Studio, navigate to Settings > MCP Settings, click Add Server > Quick Create, and then fill in the following fields:

  • Name: A custom name for the MCP service.

  • Type: Select Server-Sent Events (sse).

  • URL: Enter the URL in the format described earlier.

After the MCP server is added, enable the MCP service in the conversation window.

Click the MCP icon in the toolbar at the bottom of the conversation window and select Tablestore OpenMemory Stdio from the server list.

Stdio mode

This section explains how to deploy the Tablestore Openmemory MCP service in Cline and Cherry Studio.

Cline

In Cline, configure the Tablestore Openmemory MCP service in the cline_mcp_settings.json configuration file. The following is an example configuration:

{
  "mcpServers": {
    "tablestore-openmemory-mcp": {
      "autoApprove": [
        "add_memories",
        "list_memories",
        "delete_all_memories",
        "search_memories"
      ],
      "disabled": false,
      "timeout": 60,
      "type": "stdio",
      "command": "uvx",
      "args": [
        "tablestore-openmemory-mcp",
        "--transport",
        "stdio"
      ],
      "env": {
        "OPENAI_API_KEY": "sk-7*******************************",
        "OPENAI_BASE_URL": "https://dashscope.aliyuncs.com/compatible-mode/v1",
        "TABLESTORE_ENDPOINT": "https://k01r********.cn-hangzhou.ots.aliyuncs.com",
        "TABLESTORE_INSTANCE_NAME": "k01r********",
        "TABLESTORE_ACCESS_KEY_ID": "LTAI********************",
        "TABLESTORE_ACCESS_KEY_SECRET": "Jy3H**************************"
      }
    }
  }
}

env environment variable configuration:

Parameter

Description

OPENAI_API_KEY

On the API Key Management page, view and copy your API key. If you do not have an API key, click Create API Key to create one.

OPENAI_BASE_URL

https://dashscope.aliyuncs.com/compatible-mode/v1

TABLESTORE_ENDPOINT

In the Tablestore console, go to the instance list and click an instance name to open the instance management page. From there, view and copy the instance name and instance endpoint. If you use an ECS instance, select an endpoint based on the region:

  • If your ECS instance and Tablestore instance are in the same region, select a public endpoint or a VPC endpoint.

  • If your ECS instance and Tablestore instance are in different regions, select a public endpoint.

Important

By default, new Tablestore instances do not allow public network access. To use a public endpoint, go to the network management tab on the instance management page in the Tablestore console. For Allowed Network Types, select Public and then click Set.

TABLESTORE_INSTANCE_NAME

TABLESTORE_ACCESS_KEY_ID

The AccessKey ID of your Alibaba Cloud account or RAM user.

TABLESTORE_ACCESS_KEY_SECRET

The AccessKey Secret of your Alibaba Cloud account or RAM user.

Other optional environment variables

Parameter

Description

Default

SERVER_HOST

The host on which the MCP service runs.

0.0.0.0

SERVER_PORT

The port on which the MCP service runs.

8765

TABLESTORE_STS_TOKEN

An Alibaba Cloud STS temporary access credential.

None

TABLESTORE_VECTOR_DIMENSION

The vector dimension.

1536

LLM_MODEL

The name of the large language model.

qwen-plus

EMBEDDER_MODEL

The name of the embedding model.

text-embedding-v4

TOOL_ADD_MEMORIES_DESCRIPTION

The description for the add memories tool.

Add a new memory. This method is called every time the user provides information about themselves, their preferences, or other details that might be useful in future conversations. This can also be called when the user asks you to remember something.

TOOL_SEARCH_MEMORIES_DESCRIPTION

The description for the search memories tool.

Search through stored memories. This method is called every time the user asks a question.

TOOL_LIST_MEMORIES_DESCRIPTION

The description for the list memories tool.

Lists all memories stored for the user.

TOOL_DELETE_ALL_MEMORIES_DESCRIPTION

The description for the delete memories tool.

Deletes all memories stored for the user.

MCP_STDIO_USER_ID

The user ID and client name. You can specify custom values to isolate memories for different users.

stdio_default_user

MCP_STDIO_CLIENT_NAME

stdio_default_client

After the configuration is complete, enable the MCP service in the Cline conversation window.

Click the + button in the toolbar at the bottom of the conversation window to open the MCP Servers panel. Ensure the switch for the tablestore-openmemory-mcp entry is enabled. A green status indicator confirms a successful connection.

Cherry Studio

In Cherry Studio, navigate to Settings > MCP Settings, click Add Server > Quick Create, and then fill in the following fields:

  • Name: The name of the MCP service. You can enter a custom name.

  • Type: Select standard input/output (stdio).

  • Command: The startup command. Enter uvx.

  • Arguments: Enter the following startup arguments.

    tablestore-openmemory-mcp
    --transport
    stdio
  • Environment Variables: Enter the environment variables required for startup, as shown in the following example.

    OPENAI_API_KEY=sk-7*******************************
    OPENAI_BASE_URL=https://dashscope.aliyuncs.com/compatible-mode/v1
    TABLESTORE_ENDPOINT=https://k01r********.cn-hangzhou.ots.aliyuncs.com
    TABLESTORE_INSTANCE_NAME=k01r********
    TABLESTORE_ACCESS_KEY_ID=LTAI********************
    TABLESTORE_ACCESS_KEY_SECRET=Jy3H**************************

    The following table explains how to get the values for these environment variables.

    Parameter

    Description

    OPENAI_API_KEY

    On the API Key Management page, view and copy your API key. If you do not have an API key, click Create API Key to create one.

    OPENAI_BASE_URL

    https://dashscope.aliyuncs.com/compatible-mode/v1

    TABLESTORE_ENDPOINT

    In the Tablestore console, go to the instance list and click an instance name to open the instance management page. From there, view and copy the instance name and instance endpoint. If you use an ECS instance, select an endpoint based on the region:

    • If your ECS instance and Tablestore instance are in the same region, select a public endpoint or a VPC endpoint.

    • If your ECS instance and Tablestore instance are in different regions, select a public endpoint.

    Important

    By default, new Tablestore instances do not allow public network access. To use a public endpoint, go to the network management tab on the instance management page in the Tablestore console. For Allowed Network Types, select Public and then click Set.

    TABLESTORE_INSTANCE_NAME

    TABLESTORE_ACCESS_KEY_ID

    The AccessKey ID of your Alibaba Cloud account or RAM user.

    TABLESTORE_ACCESS_KEY_SECRET

    The AccessKey Secret of your Alibaba Cloud account or RAM user.

Other optional environment variables

Parameter

Description

Default

SERVER_HOST

The host on which the MCP service runs.

0.0.0.0

SERVER_PORT

The port on which the MCP service runs.

8765

TABLESTORE_STS_TOKEN

An Alibaba Cloud STS temporary access credential.

None

TABLESTORE_VECTOR_DIMENSION

The vector dimension.

1536

LLM_MODEL

The name of the large language model.

qwen-plus

EMBEDDER_MODEL

The name of the embedding model.

text-embedding-v4

TOOL_ADD_MEMORIES_DESCRIPTION

The description for the add memories tool.

Add a new memory. This method is called every time the user provides information about themselves, their preferences, or other details that might be useful in future conversations. This can also be called when the user asks you to remember something.

TOOL_SEARCH_MEMORIES_DESCRIPTION

The description for the search memories tool.

Search through stored memories. This method is called every time the user asks a question.

TOOL_LIST_MEMORIES_DESCRIPTION

The description for the list memories tool.

Lists all memories stored for the user.

TOOL_DELETE_ALL_MEMORIES_DESCRIPTION

The description for the delete memories tool.

Deletes all memories stored for the user.

MCP_STDIO_USER_ID

The user ID and client name. You can specify custom values to isolate memories for different users.

stdio_default_user

MCP_STDIO_CLIENT_NAME

stdio_default_client

After you add the MCP server, enable the MCP service in the conversation window.

Click the MCP tool button (green square bracket icon) in the toolbar at the bottom of the conversation window and select Tablestore OpenMemory Stdio from the server selection panel.

Verify persistent memory

Tablestore Openmemory MCP provides persistent memory by storing it in Tablestore. During interactions with your AI application, you can add, retrieve, update, and delete this memory. This section demonstrates these operations using coding preferences as an example.

  1. Add memory: Start a conversation in Cline and instruct the model to use a tool to remember your coding preferences.

    Use a tool to remember the following: I am a programmer and I need your help with coding. I am proficient in Java and Python. I prefer to use PascalCase for function and class names, camelCase for variables, and all uppercase letters with underscores for constants.

    The large model calls the add_memories tool to store the memory in the mem0 table in Tablestore.

    You can view the memory data in the Tablestore console.

    On the data management tab of the mem0 table, the memory data is stored as rows. These rows include columns such as document_id (primary key), tenant_id (primary key), embedding, payload, payload_source, and text. The default value of the tenant_id column is __default, and the text column stores your coding preferences.

  2. Retrieve memory: To ensure the model retrieves information from its persistent memory instead of the current conversation context, start a new session before asking the following question in Cline.

    What is my preferred variable naming convention?

    The large model calls the search_memories tool to retrieve the relevant memory from Tablestore and returns an accurate answer.

    The model returns the result and summarizes your preferred naming conventions: use camelCase for variables, such as myVariableName; all uppercase with underscores for constants, such as MY_CONSTANT_VALUE; and PascalCase for functions and class names, such as MyClassName.

  3. Update memory: Start a conversation in Cline and instruct the model to use a tool to update your coding preferences.

    Please remember that I now prefer to use lowercase letters with underscores for variable names.

    The large model calls the add_memories tool to update the relevant memory stored in Tablestore.

    You can view the updated memory data in the Tablestore console.

    On the data management tab of the mem0 table, the text column now contains "The user now prefers to use lowercase letters with underscores for variable names," indicating the memory was successfully updated.

Cross-platform memory verification

Storing memory in Tablestore decouples it from applications and models, allowing you to access the same memory from different applications or models. This section uses Cline and Cherry Studio as an example. You will add personal information in Cline, and then generate a personalized travel plan in a different AI client, Cherry Studio.

  1. Add personal information: Start a conversation in Cline and instruct the large language model to use a tool to save your personal information, such as your address and hobbies.

    Remember the following information: I live in China (Hangzhou), I like spicy food, and I enjoy mystery novels and movies. I always like to try new things, even though they often disappoint me.

    The large language model calls the add_memories tool to store the memory in the mem0 data table in Tablestore.

    You can view the memory data in the Tablestore console.

    In the Tablestore console, on the data management tab for the mem0 data table, you can see the stored memory. The table includes the primary key columns document_id and tenant_id, and the attribute columns embedding, payload, payload_source, and text. The default value of tenant_id is __default.

  2. Access memory across platforms: Start a conversation in Cherry Studio and instruct the model to create a personalized weekend plan based on your stored memory.

    Based on my memory, help me create a weekend outing plan.

    The large language model calls the search_memories tool to retrieve the relevant memory from Tablestore and generates a plan based on that memory.

    In Cherry Studio, the qwen-max model processes your request. The status of the search_memories tool call is completed, and the resulting plan provides a detailed schedule for the morning, noon, afternoon, and evening.

Deploy to production

When using Tablestore Openmemory MCP in a production environment, consider the following factors to ensure service stability, security, and scalability.

Deployment architecture optimization

Deploy the MCP service across multiple ECS instances and use Server Load Balancer (SLB) to balance the load between them. Alternatively, you can replace a single-ECS deployment with Container Service for Kubernetes (ACK) or Compute Nest. This approach provides auto-scaling and dynamic resource adjustment based on load, enabling you to handle traffic spikes and reduce costs during idle periods.

Security hardening

To secure production data, use RAM users and apply the principle of least privilege, granting them access only to specific Tablestore instances. In addition, restrict access by configuring IP whitelists in security groups, or deploy an API Gateway for centralized authentication, throttling, and logging.

Operations and monitoring

To ensure service health, use Cloud Monitor to set up monitoring and alerts for key metrics, such as CPU and memory, on your ECS instances or containers. Centralize your runtime logs in Log Service (SLS) for quick troubleshooting, performance analysis, and business insight.

Resource cleanup

To avoid unnecessary charges, clean up the resources you created in this tutorial:

  1. Release the ECS instance: Go to the ECS console, find the target instance, and click All Operations > Release.

  2. Delete the Tablestore data table: In the Tablestore console, click the target instance alias on the Instance List page. On the Instance Management page, locate the target data table. First, click Index Management to the right of the data table to delete its search index. Then, click ... > Delete.

  3. Release the Tablestore instance: Go to the Tablestore console and find the target instance in the Instance List. In the Actions column, click Release or ... > Release.