$ show supermemoryai/supermemory
Supermemory is a commercial-grade AI memory and context engine that provides persistent long-term memory for AI agents. The repository implements the client-side integration SDKs, an MCP (Model Context Protocol) server, a memory graph visualization component, and supporting infrastructure. In production, it connects to an external cloud API (api.supermemory.ai) that handles document ingestion, semantic search, user profiles, and knowledge graph construction. The codebase is organized as a monorepo with distinct packages for TypeScript/Python SDKs covering multiple AI frameworks (Vercel AI SDK, OpenAI, Mastra, Claude, etc.), a Cloudflare Workers-based MCP server with OAuth and widget UI, a ship-grade memory-graph React component with force-directed canvas rendering, and a comprehensive validation schema package. The architecture demonstrates strong engineering practices: strict Zod validation, middleware injection patterns, caching and deduplication logic, and thorough testing across languages. Notable skill is evident in the memory-graph canvas engine (viewport, simulation, spatial indexing, version chain visualization) and the shared memory-context injection utilities. The main downside is significant logic duplication across four Python SDK packages and their TypeScript counterparts, which increases maintenance risk. The repo is actively developed with CI/CD pipelines publishing to npm and PyPI.
The LLM identified 5 files worth highlighting for reuse:
Implements a force-directed simulation engine for a knowledge graph canvas. Uses Verlet integration with custom forces (repulsion, attraction, centering) and supports progressive LOD (level-of-detail) rendering: nodes appear as point dots, hexagon dots, or full circles based on zoom and screen area. Handles dense graphs with edge sampling and opacity reduction. The simulation can append new nodes using golden-angle spiral placement with spatial-grid collision avoidance. Demonstrates advanced understanding of physics simulation and performance optimization for real-time graph rendering.
A camera/viewport abstraction for a 2D canvas, supporting zoom (with midpoint preservation), pan, pinch-to-zoom, and coordinate transformation between screen and world space. Configurable with min/max zoom, initial scale, and position. Used as the foundation for interactive graph navigation. Extracting this component allows any canvas-based visualization to gain professional-grade camera controls with minimal effort.
Provides robust functions for injecting memory context into LLM system prompts using HTML-like tags (`<supermemory context="user-memories" readonly>`). Includes `wrapMemoryContext` (escapes untrusted memory content), `stripMemoryContext` (removes previous blocks), and `replaceMemoryContext` (single-block replacement per turn). The escaping logic prevents prompt injection from stored memories. This is a clean, self-contained pattern reusable in any agent middleware that needs to inject dynamic context while maintaining security.
A centralized, well-documented Zod schema file defining the entire Supermemory v3/v4 API surface – search parameters, profile responses, document ingest, analytics, billing, container tags, and settings. Each schema is annotated with descriptions and constraints (min/max, defaults). Demonstrates schema-first API design with Zod, making it reusable as a single source of truth for client validation and documentation generation. Clean organization with no internal coupling to the rest of the codebase.
Assembles the MCP server by registering tools, resources, and prompts with an analytics wrapper and authentication. Uses a builder pattern (`McpServer` from `@modelcontextprotocol/sdk`) with custom extensions for upload sessions and space state via Durable Objects. The `createTrackedToolServer` pattern wraps each tool call with PostHog analytics (sanitizing sensitive data) and error handling. This module shows how to structure a production MCP server with observability, auth, and state management – a reusable pattern for anyone building MCP servers.