Qoder long-term memory integration via MCP

更新时间:
复制 MD 格式

Overview

The AnalyticDB for PostgreSQL Long-Term Memory MCP Server is a service based on the Model Context Protocol (MCP). It provides the Qoder AI coding assistant with persistent memory across multiple sessions. MCP is a standard protocol defined by Anthropic, and Qoder supports it natively. After you register the adbpgmem MCP Server, Qoder AI can proactively call memory tools during conversations to create, read, update, and delete knowledge.

How it works

The AnalyticDB for PostgreSQL Long-Term Memory MCP Server communicates with Qoder through stdio. The workflow is as follows:

  1. Register the service: Configure the adbpgmem MCP Server on the Qoder MCP settings page or in the settings.json file.

  2. On-demand startup: Qoder starts the MCP Server subprocess on demand via uvx, an on-demand runner from the uv package manager. No pre-installation is required.

  3. Tool invocation: The Qoder AI coding assistant proactively calls MCP tools, such as add_memory and search_memories, based on the conversational context.

  4. API forwarding: The MCP Server converts tool calls into REST API requests to perform memory operations.

Qoder AI makes all MCP tool calls autonomously; you do not need to trigger them manually.

MCP tools

Tool

Function

Description

add_memory

Save a memory

With infer=true, the server automatically extracts atomic facts.

search_memories

Semantic search for memories

Matches by meaning, not keywords, to find relevant memories.

list_memories

List all memories with pagination

Browse all memories in the memory store.

update_memory

Update a specific memory

Modifies an existing memory based on its memory_id.

delete_memory

Delete a single memory

Removes an expired or useless memory based on its memory_id.

delete_all_memories

Deletes all memories for a user

Requires confirm=true as a safety measure.

Use cases

  • Manual control over memory content: Precisely control what information is recorded, rather than relying on automatic background saving.

  • On-demand queries for past experience: Let the Qoder AI proactively search the memory store for relevant knowledge when needed.

  • CRUD operations on memories: Gain fine-grained control to update, delete, and manage memories.

  • Shared team configuration: Share a memory service configuration across your team by using a project-level .qoder/settings.json file.

Install the MCP Server

Prerequisites

  • Qoder IDE or Qoder CLI is installed and running correctly.

  • Python 3.10 or later.

  • The uv package manager is installed (recommended for on-demand startup with uvx).

  • You have the API endpoint and authentication token for the AnalyticDB for PostgreSQL Context service.

  • You have the adbpgmem_mcp_selfhosted project source code: adbpgmem-mcp-server-0.2.0.tar.gz.

    Extract the archive to a directory named adbpgmem_mcp_selfhosted. The paths in the following steps refer to this directory.

Installation

You do not need to install the MCP Server globally. uvx creates a temporary virtual environment on demand from the local project path and starts the service. You only need to ensure the source code path is accessible.

# Verify that the source code path is accessible
ls /path/to/adbpgmem_mcp_selfhosted/pyproject.toml
# This command should output the file information, confirming the path is correct

Configure the MCP Server

The MCP Server retrieves the connection parameters for the AnalyticDB for PostgreSQL Long-Term Memory service from environment variables or a configuration file.

Parameters

Parameter

Type

Required

Description

ADBPGMEM_API_URL

string

Yes

The API endpoint for the AnalyticDB for PostgreSQL Long-Term Memory service.

ADBPGMEM_API_TOKEN

string

Yes

The authentication token for the service. This is sensitive information.

ADBPGMEM_USER_ID

string

No

The user identifier. If not specified, it defaults to the system username.

Configuration source priority

Priority

Source

Description

1

Environment variables

Injected through the env field during MCP registration. This method has the highest priority.

2

$ADBPGMEM_CONFIG_DIR

An environment variable that points to the directory containing the configuration file.

3

./.qoder/adbpgmem.conf

Project-level configuration file.

4

~/.qoder/adbpgmem.conf

Global configuration file.

Method 1: Inject via env (Recommended)

When registering the MCP Server, inject the environment variables directly into the env field of your settings.json file. This avoids the need to create a separate configuration file. For details, see "Register the MCP Server".

Method 2: Create a configuration file

Create a global configuration file at ~/.qoder/adbpgmem.conf or a project-level one at .qoder/adbpgmem.conf:

# Global configuration (applies to all projects)
mkdir -p ~/.qoder
cat > ~/.qoder/adbpgmem.conf << 'EOF'
ADBPGMEM_API_URL="https://api-longmemory-cn-chengdu.opentrust.net"
ADBPGMEM_API_TOKEN="sk-your-token-here"
ADBPGMEM_USER_ID="your.username"
EOF

# Project-level configuration (applies only to the current project)
mkdir -p .qoder
cat > .qoder/adbpgmem.conf << 'EOF'
ADBPGMEM_API_URL="https://api-longmemory-cn-chengdu.opentrust.net"
ADBPGMEM_API_TOKEN="sk-your-token-here"
ADBPGMEM_USER_ID="your.username"
EOF
Important

The adbpgmem.conf file contains your authentication token. Do not commit it to Git. Add .qoder/adbpgmem.conf to your .gitignore file.

Configuration file

The configuration file uses a KEY="VALUE" format, with one entry per line. If a configuration is missing, the MCP Server logs a warning and still starts, but subsequent API calls will fail.

Register the MCP Server

You register the MCP Server in the settings.json file. Both global and project-level registration methods are supported.

Global registration (Recommended)

Edit the ~/.qoder/settings.json file. This registration applies to all your projects:

{
  "mcpServers": {
    "adbpgmem": {
      "command": "uvx",
      "args": ["--from", "/path/to/adbpgmem_mcp_selfhosted", "adbpgmem-mcp-server"],
      "env": {
        "ADBPGMEM_API_URL": "https://api-longmemory-cn-chengdu.opentrust.net",
        "ADBPGMEM_API_TOKEN": "sk-your-token-here",
        "ADBPGMEM_USER_ID": "your.username"
      }
    }
  }
}

Field description

Field

Description

command

The startup command. It uses uvx to create a temporary virtual environment on demand and run the MCP Server.

args

Command arguments. --from specifies the local source code path, and the last argument is the entry function name.

env

Environment variables for injecting connection parameters. These have a higher priority than parameters set in a configuration file.

Project-level registration

Create a .qoder/settings.json file in your project's root directory. This registration applies only to the current project and can be committed to version control for team sharing:

{
  "mcpServers": {
    "adbpgmem": {
      "command": "uvx",
      "args": ["--from", "/path/to/adbpgmem_mcp_selfhosted", "adbpgmem-mcp-server"],
      "env": {
        "ADBPGMEM_API_URL": "https://api-longmemory-cn-chengdu.opentrust.net",
        "ADBPGMEM_API_TOKEN": "sk-your-token-here",
        "ADBPGMEM_USER_ID": "your.username"
      }
    }
  }
}
Note

You can commit the project-level .qoder/settings.json to your Git repository. This allows team members to share the configuration after cloning the repository. Be careful not to include real authentication tokens.

Configure AGENTS.md instructions (Optional)

You can add instructions to the AGENTS.md file in your project's root directory. This file defines project-level behavioral guidelines for the Qoder AI and is loaded automatically at the start of each session. These instructions guide the AI to use memory tools proactively. The MCP tools will work without this configuration, but the AI will not use them proactively.

# MCP Servers

- **adbpgmem**: A persistent memory service. At the start of each session, use `search_memories` to look for relevant context. 
  When you find architectural decisions, debugging experiences, or coding patterns, save them using `add_memory`. 
  If memory content changes, update it with `update_memory`. It is better to record too much than to miss something.

Use the MCP tools

Verify the registration

In the Qoder IDE, go to the MCP settings page and check the status of adbpgmem. It should show as Connected.

Tool invocation

The Qoder AI decides when to call MCP tools based on the conversational context. You can trigger these calls using natural language:

Your prompt

Tool called

Remember: the project uses PostgreSQL 15

add_memory

Search for memories about the database configuration

search_memories

List all memories

list_memories

Update the content of this memory

update_memory

Delete this memory

delete_memory

Tool reference

add_memory (Save a memory)

Saves development knowledge to the AnalyticDB for PostgreSQL Long-Term Memory store, making it retrievable across sessions.

Parameter

Type

Default

Description

content

string

-

The content of the memory to save. (Required)

user_id

string

Configured value

The user identifier. Defaults to the user_id from your configuration.

infer

bool

false

Specifies whether the server should extract atomic facts from the content.

Example

You: Remember: this project uses Go 1.22 + Gin framework, the ORM is GORM v2, and the database is PostgreSQL 15.

Qoder AI calls add_memory → The server stores the memory

With infer=true, the server automatically extracts atomic facts from the content:

You: Remember the following project decisions: We chose Kafka instead of RabbitMQ because we need the ability to replay messages.
    We selected PostgreSQL for its JSONB support. The front end uses React and TypeScript.

Qoder AI calls add_memory(infer=true) → The server extracts and stores three separate atomic facts.

search_memories (Semantic search for memories)

Performs a semantic search for relevant memories in the memory store. The search matches by meaning, not by keywords.

Parameter

Type

Default

Description

query

string

-

The text for the search query. (Required)

user_id

string

Configured value

The user identifier.

top_k

int

5

The number of results to return.

Example

You: Search for memories about the database selection.

Qoder AI calls search_memories → The server returns semantically matched historical memories.

list_memories (List memories)

Lists all memories in the memory store with pagination.

Parameter

Type

Default

Description

user_id

string

Configured value

The user identifier.

page

int

1

The page number.

page_size

int

50

The number of items per page.

update_memory (Update a memory)

Updates the content of a specific memory based on its memory_id.

Parameter

Type

Description

memory_id

string

The UUID of the memory. (Required)

text

string

The new content for the memory. (Required)

delete_memory (Delete a single memory)

Deletes a single, specific memory based on its memory_id.

Parameter

Type

Description

memory_id

string

The UUID of the memory. (Required)

delete_all_memories (Delete all memories)

Safely deletes all memories for a specified user. This operation deletes memories individually and does not clear the entire collection at once.

Parameter

Type

Default

Description

user_id

string

Configured value

The user identifier.

confirm

bool

false

A confirmation flag. It must be set to true to proceed.

Important

The confirm parameter must be explicitly set to true. Otherwise, the operation will be rejected.

Example use cases

Scenario 1: Save project tech stack information

You start a new project and want to record its tech stack for use in future sessions.

You: Remember: this project uses Python 3.11 + FastAPI, the database is PostgreSQL 15, 
    the cache is Redis 7, and the message queue is Kafka 3.5.

Qoder AI calls add_memory → The tech stack information is saved to the memory store.

Qoder AI behavior:

  1. Recognizes the user's request to save information.

  2. Calls add_memory to save the tech stack information to the memory store.

  3. Responds that the memory has been saved.

Scenario 2: Reuse knowledge across sessions

In a previous session, you defined the API design standards for your project. In the current session, you need to develop a new API endpoint.

Session 1:
You: Remember: our APIs use the RESTful style. For pagination, use page and page_size.
    For sorting, use sort=field:asc|desc. Error responses must include the type, title, status, and detail fields.
Session 2 (a few days later):
You: Help me design a new user management API endpoint.

Qoder AI: Based on the API design standards I have in my memory, here is a design for the user management endpoint... 
         [The AI automatically follows the team's standards without you having to repeat them.]

The Qoder AI automatically retrieves the established standards from the memory store. In a new session, you can directly reuse the team's consensus without having to restate them.