Integrate Long-Term Memory with Qoder via MCP

更新时间:
复制 MD 格式

Overview

AnalyticDB for PostgreSQLLong-Term Memory MCP Server is an MCP (Model Context Protocol)-based service that gives the Qoder AI coding assistant persistent memory across sessions. MCP is a standard protocol defined by Anthropic, and Qoder natively supports it. 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

AnalyticDB for PostgreSQLLong-Term Memory MCP Server communicates with Qoder through stdio (standard input/output). The workflow is as follows:

  1. Register: 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 (uv package manager) without pre-installation.

  3. Tool invocation: Qoder AI proactively calls MCP tools such as add_memory, search_memories based on the conversation context.

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

All MCP tool calls are autonomously decided by Qoder AI. No manual triggering is required.

Six MCP Tools

Tool

Function

Description

add_memory

Save memory

Supports infer=true to let the server automatically extract atomic facts

search_memories

Semantic memory search

Matches by meaning rather than keywords to find relevant past experiences

list_memories

List all memories with pagination

Browse all memories in the memory store with pagination

update_memory

Update specified memory

Update a specified memory by memory_id

delete_memory

Delete a single memory

Remove expired or unused memories by memory_id

delete_all_memories

Bulk delete all memories

Requires confirm=true as a safety measure

Use Cases

  • Manual memory control: You want precise control over what knowledge is recorded, rather than fully automatic background saving.

  • On-demand history query: Qoder AI proactively searches the memory store for relevant knowledge when needed.

  • Memory CRUD operations: You need fine-grained management of memories such as updating and deleting.

  • Team-shared configuration: Share the same memory service configuration across team members through the project-level .qoder/settings.json file.

Install MCP Server

Prerequisites

  • Qoder IDE or Qoder CLI is installed and functional.

  • Python >= 3.10.

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

  • Obtained the AnalyticDB for PostgreSQLContext service API URL and token.

  • Obtained 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. All paths in the following steps refer to this extracted directory.

Installation

MCP Server does not require pre-installation. uvx creates a temporary virtual environment from the local project path on demand and starts the service. You only need to ensure that the source path is accessible.

# Verify the source path is accessible
ls /path/to/adbpgmem_mcp_selfhosted/pyproject.toml
# The file info should be displayed, confirming the path is correct

Configure MCP Server

Configure the connection parameters for the AnalyticDB for PostgreSQLLong-Term Memory service.

Parameters

Parameter

Type

Required

Description

ADBPGMEM_API_URL

string

Yes

AnalyticDB for PostgreSQLAPI URL of the long-term memory service

ADBPGMEM_API_TOKEN

string

Yes

Service authentication token (sensitive)

ADBPGMEM_USER_ID

string

No

User identifier. Defaults to the system username

Configuration Source Priority

Priority

Source

Description

1

Environment variable

Injected through the env field during MCP registration. Takes the highest priority

2

$ADBPGMEM_CONFIG_DIR

Environment variable pointing to the configuration file directory

3

./.qoder/adbpgmem.conf

Project-level configuration file

4

~/.qoder/adbpgmem.conf

Global-level configuration file

Method 1: Inject via the env Field During MCP Registration (Recommended)

Inject environment variables directly in the settings.json env field when registering the MCP Server. No additional configuration files are needed. See Register MCP Server.

Method 2: Manually Create a Configuration File

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

# 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 to the current project only)
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

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

Configuration File Description

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

Register MCP Server

Qoder uses the settings.json file to register the MCP Server. You can register it globally or at the project level.

Global Registration (Recommended)

Edit ~/.qoder/settings.json to apply the configuration to all 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

Startup command. Uses uvx to create a temporary virtual environment on demand and run the MCP Server

args

Command arguments. --from specifies the local source path, followed by the entry function name

env

Environment variables injected through the env field take higher priority than configuration files

Project-Level Registration

Create .qoder/settings.json in the project root directory. This configuration 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 the Git repository so team members share the configuration after cloning. Do not include real API tokens.

Configure AGENTS.md Behavior Instructions (Optional)

Add the following content to AGENTS.md (Qoder's project-level AI behavior specification file, automatically loaded at each session start) in the project root directory. This guides Qoder AI to proactively use memory tools. Without this configuration, MCP tools still work, but Qoder AI will not proactively call them.

# MCP Servers

- **adbpgmem**: Persistent memory service. At the start of each session, use search_memories
  to search for relevant context. Use add_memory to save architectural decisions,
  debugging experience, and coding patterns. Use update_memory when memory content
  changes. Better to save too much than to miss something.

How to Use MCP Tools

Verify Registration

On the Qoder IDE MCP settings page, verify that adbpgmem shows a Connected status.

Invocation

Qoder AI autonomously calls MCP tools based on conversation context. You trigger them through natural language:

What You Say

Tool Called by Qoder AI

Remember: the project uses PostgreSQL 15

add_memory

Search for previous memories about database configuration

search_memories

List all memories

list_memories

Update the content of this memory

update_memory

Delete this memory

delete_memory

Detailed Tool Usage

add_memory (Save Memory)

Save development knowledge to the AnalyticDB for PostgreSQLLong-Term Memory store for cross-session retrieval.

Parameter

Type

Default

Description

content

string

-

Memory content to save (required)

user_id

string

Config value

User identifier. Defaults to the configured user_id

infer

bool

false

Whether to let the server extract atomic facts

Usage Example

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

Qoder AI calls add_memory → Server stores the memory

When infer=true is enabled, the server automatically extracts atomic facts from the content:

You: Remember these project decisions: we chose Kafka over RabbitMQ because we need
    message replay capability; chose PostgreSQL for JSONB support; frontend uses React + TypeScript

Qoder AI calls add_memory(infer=true) → Server extracts 3 independent atomic facts and stores them separately

search_memories (Semantic Memory Search)

Search the memory store for relevant historical memories by meaning rather than keywords.

Parameter

Type

Default

Description

query

string

-

Search query text (required)

user_id

string

Config value

User identifier

top_k

int

5

Number of results to return

Usage Example

You: Search for previous memories about database selection

Qoder AI calls search_memories → Returns semantically matched historical memories

list_memories (List Memories)

List all memories in the memory store with pagination.

Parameter

Type

Default

Description

user_id

string

Config value

User identifier

page

int

1

Page number

page_size

int

50

Items per page

update_memory (Update Memory)

Update the content of a specified memory by memory_id.

Parameter

Type

Description

memory_id

string

UUID of the memory (required)

text

string

New memory content (required)

delete_memory (Delete Single Memory)

Delete a specified memory by memory_id.

Parameter

Type

Description

memory_id

string

UUID of the memory (required)

delete_all_memories (Bulk Delete)

Delete all memories of the specified user. Memories are deleted one by one instead of clearing the entire collection.

Parameter

Type

Default

Description

user_id

string

Config value

User identifier

confirm

bool

false

Confirm deletion. Must be set to true to proceed

Important

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

Typical Usage Scenarios

Scenario 1: Save Project Tech Stack Information

When you start a new project, you can record the tech stack information for use in subsequent sessions.

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

Qoder AI calls add_memory → Saves tech stack info to the memory store

Qoder AI Behavior:

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

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

  3. Outputs: Memory saved.

Scenario 2: Cross-Session Knowledge Reuse

In a previous session, API design conventions were established. The current session requires developing new API endpoints.

Session 1:
You: Remember: our APIs uniformly use RESTful style, pagination uses page/page_size,
    sorting uses sort=field:asc|desc, error responses include type/title/status/detail fields
Session 2 (days later, a new session):
You: Help me design a new user management API endpoint

Qoder AI: Based on the API design conventions saved earlier, I'll design the user management endpoint...
         [Automatically outputs the design following team conventions without needing repeated instructions]

Qoder AI automatically retrieves the conventions established in the previous session from the memory store. New sessions can directly reuse team consensus without repeated communication.