Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:24kchengYe MemoMind serve py

From Leeroopedia
Knowledge Sources
Domains DevOps, Deployment
Last Updated 2026-10-28 00:00 GMT

Overview

Concrete tool for starting the MemoMind production API server with MemoryEngine, tenant extension, and uvicorn ASGI, configured via environment variables.

Description

The serve.py script is the production entry point for the MemoMind API server. It:

  1. Reads environment variables: SUB2API_MEMOMIND_KEY (LLM API key, required), MEMOMIND_LLM_BASE_URL, MEMOMIND_LLM_MODEL, MEMOMIND_PG_URL, MEMOMIND_PORT
  2. Configures environment: disables proxy, sets HF_HOME for model cache, forces CPU reranker, sets embeddings model to BAAI/bge-m3
  3. Loads tenant extension: via load_extension("TENANT", TenantExtension) - configured as MultiApiKeyTenantExtension in Docker
  4. Creates MemoryEngine: with separate LLM configs for memory, retain, reflect, and consolidation (all using the same OpenAI-compatible provider)
  5. Creates ASGI app: via create_app(memory, mcp_api_enabled=True, initialize_memory=True)
  6. Runs uvicorn: on 0.0.0.0:PORT (default 19999) with log_level="info"

The server exposes both HTTP REST API and MCP endpoints. The MCP endpoint is at /mcp/ (multi-bank) or /mcp/{bank_id}/ (single-bank).

Usage

Run this script as the Docker container command. It requires a .env file with PG_PASSWORD, SUB2API_MEMOMIND_KEY, and MEMOMIND_MCP_TOKEN.

Code Reference

Source Location

  • Repository: MemoMind
  • File: deploy/server/serve.py
  • Lines: L1-73

Signature

# Environment variables (read at startup):
# SUB2API_MEMOMIND_KEY - LLM API key (required)
# MEMOMIND_LLM_BASE_URL - LLM base URL (default: http://sub2api:8080/v1)
# MEMOMIND_LLM_MODEL - LLM model (default: gpt-5.6)
# MEMOMIND_PG_URL - PostgreSQL URL (default: postgresql://hindsight@pg:5432/hindsight)
# MEMOMIND_PORT - port (default: 19999)

memory = MemoryEngine(db_url=PG_URL, memory_llm_*, retain_llm_*, reflect_llm_*, consolidation_llm_*, tenant_extension)
app = create_app(memory=memory, mcp_api_enabled=True, initialize_memory=True)
uvicorn.run(app, host="0.0.0.0", port=PORT)

Import

# Run as a script: python serve.py
# Or as Docker command: ["python", "/app/serve.py"]

I/O Contract

Inputs

Name Type Required Description
SUB2API_MEMOMIND_KEY str (env) Yes LLM API key
MEMOMIND_LLM_BASE_URL str (env) No LLM base URL (default http://sub2api:8080/v1)
MEMOMIND_LLM_MODEL str (env) No LLM model (default gpt-5.6)
MEMOMIND_PG_URL str (env) No PostgreSQL URL (default postgresql://hindsight@pg:5432/hindsight)
MEMOMIND_PORT int (env) No Port (default 19999)
HINDSIGHT_API_TENANT_EXTENSION str (env) No Tenant extension class path

Outputs

Name Type Description
server uvicorn ASGI Running HTTP + MCP server on 0.0.0.0:PORT

Usage Examples

Docker Compose Configuration

# docker-compose.yml (simplified)
services:
  memomind-api:
    build: .
    env_file: .env
    environment:
      MEMOMIND_PG_URL: postgresql://hindsight:${PG_PASSWORD}@pg:5432/hindsight
      HINDSIGHT_API_TENANT_EXTENSION: tenant:MultiApiKeyTenantExtension
      HINDSIGHT_API_TENANT_API_KEY: ${MEMOMIND_MCP_TOKEN}
    command: ["python", "/app/serve.py"]
    ports:
      - "${BIND_IP:-127.0.0.1}:19999:19999"
    depends_on:
      pg:
        condition: service_healthy

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment