Memory Server
Provides persistent memory management with SQLite, enabling storage and retrieval of conversational context with metadata via MCP tools and REST API.
README
Memory Server - MCP Server for Persistent Memory Management
A TypeScript-based Model Context Protocol (MCP) server that provides persistent memory management using SQLite database. This server exposes both MCP tools and RESTful API endpoints for storing and retrieving conversational context with metadata.
Features
- SQLite Database Integration: Persistent storage with automatic schema creation and indexing
- MCP Protocol Compliance: Full support for MCP tool registration and execution
- RESTful API: HTTP endpoints for programmatic access
- TypeScript: Full type safety and modern async/await patterns
- Logging: Comprehensive logging with configurable levels
- Error Handling: Robust error handling and input validation
- Database Connection Pooling: Optimized database performance
- Modular Architecture: Clean separation of concerns
Database Schema
The server automatically creates a SQLite database with the following schema:
CREATE TABLE memory (
id INTEGER PRIMARY KEY AUTOINCREMENT,
content TEXT NOT NULL,
timestamp TEXT NOT NULL,
session_id TEXT NOT NULL,
content_hash TEXT NOT NULL UNIQUE,
metadata TEXT,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
);
-- Indexes for performance optimization
CREATE INDEX idx_session_id ON memory(session_id);
CREATE INDEX idx_timestamp ON memory(timestamp);
CREATE INDEX idx_content_hash ON memory(content_hash);
CREATE INDEX idx_created_at ON memory(created_at);
Installation
- Clone or create the project directory
- Install dependencies:
npm install
- Build the TypeScript code:
npm run build
Usage
MCP Mode (Stdio Transport)
To run as an MCP server using stdio transport:
npm start -- --mcp
# or
MCP_MODE=true npm start
HTTP Server Mode
To run as a standalone HTTP server:
npm start
The server will start on http://localhost:3000 by default.
Environment Variables
PORT: HTTP server port (default: 3000)HOST: HTTP server host (default: localhost)DB_PATH: SQLite database file path (default: ./data/memory.db)DB_MAX_CONNECTIONS: Maximum database connections (default: 10)LOG_LEVEL: Logging level (debug, info, warn, error) (default: info)CORS_ORIGIN: Comma-separated list of allowed CORS originsMCP_MODE: Set to 'true' to run in MCP modeNODE_ENV: Environment (development, production)
MCP Tools
The server provides the following MCP tools:
save_memory
Saves content to memory with metadata.
Parameters:
content(string, required): The content to savesession_id(string, required): Session identifier for groupingmetadata(object, optional): Additional metadata
Example:
{
"content": "User prefers dark mode and uses TypeScript",
"session_id": "user-123-session-1",
"metadata": {
"category": "preferences",
"importance": "high"
}
}
read_memory
Retrieves stored memories with optional filtering.
Parameters:
session_id(string, optional): Filter by session IDstart_date(string, optional): Filter from date (ISO format)end_date(string, optional): Filter until date (ISO format)limit(number, optional): Maximum records to return (1-1000)offset(number, optional): Records to skip for pagination
get_memory_count
Gets the total count of memory records.
Parameters:
session_id(string, optional): Count for specific session
delete_memory
Deletes a specific memory record.
Parameters:
id(number, required): ID of the memory record to delete
REST API Endpoints
POST /api/memory/save
Save a new memory record.
Request Body:
{
"content": "Content to save",
"session_id": "session-identifier",
"metadata": {
"key": "value"
}
}
GET /api/memory/read
Read memory records with optional query parameters:
session_id: Filter by sessionstart_date: Filter from dateend_date: Filter until datelimit: Maximum recordsoffset: Pagination offset
GET /api/memory/count
Get memory count with optional session_id query parameter.
DELETE /api/memory/:id
Delete a specific memory record by ID.
GET /api/memory/health
Health check endpoint.
MCP Server Configuration
To use this server with an MCP client, add it to your MCP settings:
{
"mcpServers": {
"memory-server": {
"command": "node",
"args": ["path/to/memory-server/build/index.js", "--mcp"],
"env": {
"DB_PATH": "path/to/memory.db",
"LOG_LEVEL": "info"
}
}
}
}
Development
Scripts
npm run build: Compile TypeScript to JavaScriptnpm run dev: Watch mode for developmentnpm start: Start the server
Project Structure
memory-server/
├── src/
│ ├── index.ts # Main server entry point
│ ├── database.ts # SQLite database operations
│ ├── api.ts # REST API routes
│ ├── mcp-tools.ts # MCP tool handlers
│ ├── logger.ts # Logging utility
│ └── types.ts # TypeScript interfaces
├── build/ # Compiled JavaScript (generated)
├── data/ # Database files (generated)
├── package.json
├── tsconfig.json
└── README.md
Error Handling
The server includes comprehensive error handling:
- Input validation for all endpoints and tools
- Database connection error handling
- Graceful shutdown on SIGTERM/SIGINT
- Detailed error logging
- Proper HTTP status codes
Performance Optimization
- Database indexes on frequently queried columns
- Connection pooling for database operations
- Efficient query patterns
- Content hashing to prevent duplicates
- Configurable limits and pagination
Security Considerations
- Input validation and sanitization
- CORS configuration
- Content hash verification
- SQL injection prevention through parameterized queries
- Error message sanitization in production
License
MIT License
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。