memory-mesh-mcp

Public

MemoryMesh MCP server for LM Studio

22 Downloads

README

memory-mesh-mcp

TypeScript
LM Studio Plugin
License: MIT

memory-mesh-mcp is an LM Studio Plugin that wraps the upstream MemoryMesh MCP server behind a lightweight @lmstudio/sdk adapter, exposing MemoryMesh's knowledge‑graph tools to models running inside LM Studio.

It lets an LM Studio model call MemoryMesh's knowledge‑graph tools (add_ / update_ / delete_ …) while never modifying or copying the upstream source — the original code stays in the MemoryMesh/ subdirectory and can still be updated with git pull.


Contents


What is memory-mesh-mcp

LM Studio Plugins and MCP servers are two different integration styles:

  • A Plugin runs inside LM Studio and, via @lmstudio/sdk, exposes tools the model can call, provides a custom settings UI, and so on.
  • An MCP server is a separate process that exposes tools to any MCP client (Claude Desktop, Cursor, VS Code…) over the Model Context Protocol.

memory-mesh-mcp is the former — an LM Studio Plugin. Because its core is a full set of MCP tools, it's named -mcp. Internally it launches and connects to the upstream MemoryMesh MCP server using StdioClientTransport, then dynamically registers those tools as LM Studio tools (each prefixed with mm_).


Project description

Upstream MemoryMesh (CheMiguel23/MemoryMesh) is a knowledge‑graph server for AI models, focused on text‑based RPGs and interactive storytelling. It keeps an AI's memory consistent and structured across conversations, enabling richer, more coherent interactions. It builds on the Knowledge Graph Memory Server from the MCP servers repo and keeps its core functionality. The latest release is v0.3.0 (compliant with MCP specification 2025‑11‑25).

This project, memory-mesh-mcp, acts as a thin adapter so that MemoryMesh's MCP tools can be used directly inside LM Studio, without changing or copying the upstream source.

Core concepts (from MemoryMesh)

  • Nodes: entities or concepts in the graph. Each node has name, nodeType, metadata (a string array), and an optional weight (0–1 relationship strength).
  • Edges: relationships between nodes. Each edge has from, to, and edgeType (e.g. owns, located_in).
  • Schemas: the heart of MemoryMesh. A .schema.json file defines a data structure and drives automatic tool generation. The filename is [name].schema.json, and name must start with add_ (e.g. add_npc).
  • Dynamic tools: MemoryMesh auto‑generates add_<entity>, update_<entity}, and delete_<entity> tools for each entity type. It ships 11 prebuilt schemas for RPGs.

Data defaults to dist/data/memory.json; schemas live in dist/data/schemas/.


Features

  • ✅ Zero upstream copying: the @lmstudio/sdk adapter calls the original MemoryMesh; it does not modify or copy MemoryMesh/, preserving git pull updates.
  • ✅ Dynamic tool registration: on launch it reads all tools from MemoryMesh's listTools() and converts each into an LM Studio tool (with the mm_ prefix).
  • ✅ Schema‑to‑Zod mapping: MemoryMesh's JSON Schema is mapped into zod parameter schemas that LM Studio can read and validate.
  • ✅ Connection caching: the MemoryMesh MCP client and transport are created on the first call and reused, avoiding a child process per tool call.
  • ✅ Automated install: installing from the Hub runs postinstall, which clones and builds upstream MemoryMesh automatically — no manual path setup.
  • ✅ Configurable: memory file path, schema directory, and an enable/disable toggle in the LM Studio Plugin settings.

Installation (from the LM Studio Hub)

  • Open LM Studio, go to the Hub (or use the CLI), and search for **`memory-mesh-mcp``.

  • Click Install / Add. Via CLI:

    lms add memory-mesh-mcp
    
  • Automated install flow: installation triggers the postinstall script in package.json:

    "scripts": {
      "postinstall": "node scripts/setup.cjs"
    }
    

    scripts/setup.cjs performs (see Porting & development log) the following:

    • If MemoryMesh/ does not exist yet: git clone https://github.com/CheMiguel23/MemoryMesh.
    • If it does exist: git pull to update instead.
    • Then build the upstream MemoryMesh (npm install --ignore-scripts, tsc, tsc-alias, copy schema and data files), placing MemoryMesh/dist/ and MemoryMesh/dist/data/schemas/.
  • After install, confirm the settings in LM Studio's Plugin Settings (below).

  • Open a new chat; if the model's callable tool list shows mm_‑prefixed tools, it worked.

Environment: Plugins run on LM Studio's built‑in Node.js v22.21.1; no separate Node.js install is needed.


Configuration

The plugin exposes two setting groups — configSchematics (per‑chat) and globalConfigSchematics (global) — adjustable from the LM Studio Plugin settings UI.

Per‑chat config (configSchematics)

FieldTypeDefaultDescription
memoryFilestring./MemoryMesh/dist/data/memory.jsonPath to the memory (JSON) file
schemasDirstring./MemoryMesh/dist/data/schemasDirectory holding .schema.json files
enabledbooleantrueEnable/disable all MemoryMesh tools

Global config (globalConfigSchematics)

FieldTypeDefaultDescription
mcpServerPathstring`` (empty)Absolute path to the MemoryMesh dist/index.js (optional; uses the default location when empty)

These are adapter‑level parameters. MemoryMesh's internal settings remain in its own /config/config.ts (MEMORY_FILE, SCHEMAS_DIR).


Using the MCP tools

After install and enable, every callable tool is exposed with an mm_ prefix (e.g. mm_add_npc, mm_update_npc, mm_delete_location) — a namespace to keep them distinct from other tools in LM Studio. Tool parameters are generated dynamically from the matching schema. Common operations:

Add a node (add)

Call mm_add_npc, supplying fields per add_npc.schema.json:

{
  "name": "Aragorn",
  "nodeType": "player_character",
  "race": "Human",
  "currentLocation": "Rivendell"
}

(If a field is an enum, pick one of the options; required fields are mandatory; a required field with a relationship creates both the node and its edge.)

Update a node (update)

Call mm_update_npc to modify an existing node's attributes or relationships.

Delete a node (delete)

Call mm_delete_npc to remove a node.

Inspect & debugging

  • On failure, a clear error is returned (formatted as Error during tool execution [<name>]: <message>).
  • The adapter joins MemoryMesh's text content into a string for the model; if the result isn't a text array, it's returned as serialized JSON.

Best practices (from upstream MemoryMesh)

  • Use metadata to record provenance and reliability (e.g. "Source: Tavern gossip", `"Reliability: Low") to handle conflicting information (MemoryMesh uses "last write wins").
  • For subjective or disputed facts, create separate nodes for each viewpoint (e.g. rumor vs. confirmed truth about a villain).
  • The AI may hesitate to delete nodes; prompt it to do so when needed.

As a standalone MCP server

memory-mesh-mcp itself is an LM Studio Plugin, not a standalone MCP server — it connects to upstream MemoryMesh over the MCP protocol inside LM Studio. If you want to use upstream MemoryMesh as a standalone MCP server (e.g. for Claude Desktop, Cursor, or VS Code), use the upstream project directly:

git clone https://github.com/CheMiguel23/MemoryMesh
cd MemoryMesh
npm install
npm run build

Then point your MCP client at MemoryMesh/dist/index.js. See MemoryMesh/README.md for the full upstream docs.


Porting & development log

Background & motivation

Upstream MemoryMesh is a TypeScript MCP server whose architecture is not compatible with the LM Studio Plugin SDK (@lmstudio/sdk). To make MemoryMesh's tools usable in LM Studio while keeping the source updatable via git pull, this project uses a "lightweight adapter" strategy: it does not modify or copy the upstream code. Instead, a thin wrapper built on @lmstudio/sdk calls the upstream MemoryMesh MCP tools.

Architecture

┌───────────────────────────────────────────────────────────┐
│                    LM Studio (Node.js v22.21.1)              │
│                                                                │
│   .lmstudio/entry.ts ──► src/index.ts                         │
│                            │  withToolsProvider                │
│                            ▼                                   │
│                     src/toolsProvider.ts                       │
│                            │  dynamic registration (mm_ prefix)│
│                            ▼                                   │
│          @lmstudio/sdk  (Tool / zod / settings UI)            │
└───────────────────────────────────────────────────────────┘
                          │  StdioClientTransport (spawn node)
                          ▼
┌───────────────────────────────────────────────────────────┐
│              MemoryMesh (upstream MCP server, unchanged)     │
│   git clone → installed at /home/sensei/.../MemoryMesh      │
│   dist/index.js  ──► listTools / callTool                   │
│   dist/data/schemas/*.schema.json                            │
│   dist/data/memory.json                                      │
└───────────────────────────────────────────────────────────┘

Data flow: main() registers toolsProvider via withToolsProvider. On the first call, the provider launches node <MemoryMesh>/dist/index.js with StdioClientTransport, connects (Client.connect), calls listTools() to get every tool, then converts each into an LM Studio tool() with an mm_ prefix and a JSON‑Schema→zod parameter mapping. Each tool's implementation calls cachedClient.callTool(...) and formats the return value.

File structure (after porting)

PathRole
manifest.jsonDeclares the plugin (type: plugin, runner: node), name memory-mesh-mcp
package.jsonPackage info; main → dist/index.js; postinstall → node scripts/setup.cjs
.lmstudio/entry.tsCompiled entry point: import("../src/index.ts").then(m => m.main(pluginContext))
src/index.tsNamed exports toolsProvider, configSchematics, globalConfigSchematics; main() registers each via PluginContext
src/toolsProvider.tsAdapter core: connects to MemoryMesh, dynamic tool registration, JSON Schema → Zod mapping, error handling
src/config.tsSettings UI (memoryFile, schemasDir, enabled; global mcpServerPath)
scripts/setup.cjspostinstall entry: git clone/git pull + builds upstream MemoryMesh
dist/tsc output (index.js, toolsProvider.js, config.js, …)
MemoryMesh/Upstream source (unchanged), updateable via git pull

Key porting techniques

  • Avoiding ESM/CJS conflicts: toolsProvider.ts does not import @modelcontextprotocol/sdk at the top level; it uses dynamic import() inside the async function to load Client and StdioClientTransport, matching the CJS build output.
  • JSON Schema → Zod mapping: mapJsonSchemaToZod converts MemoryMesh's JSON Schema (enum, string, number/integer, boolean, array, object, …) into zod validators; fields not listed as required are marked optional().
  • Connection caching: cachedClient/cachedTransport are created on the first call and reused, avoiding a child process per tool call.
  • Error handling: both toolsProvider and each tool's implementation are wrapped in try/catch, returning a clear error instead of crashing; debug messages go to console (readable via lms dev / the Hub).
  • Automated install (postinstall): scripts/setup.cjs runs on plugin install, cloning and building upstream MemoryMesh so dist/ and schemas are in place.

Porting build/run flow

# 1. Create / enter the project (scaffolded with `lms create`)
cd /home/sensei/.../memory-mesh-mcp

# 2. Install (triggers postinstall: clone + build upstream MemoryMesh)
npm install

# 3. Typecheck / lint / build
npm run typecheck
npm run lint
npm run build

# 4. Run in LM Studio dev mode
lms dev

# 5. Confirm tools are readable and callable (mm_ prefix)

# 6. Publish to the Hub
lms push

Before publishing, confirm npm run typecheck, npm run lint, npm run build, and lms dev all pass.


For contributors (changing the wrapper)

For those editing the adapter (not upstream MemoryMesh):

npm install          # triggers postinstall: clone + build upstream MemoryMesh
npm run build        # tsc → dist/
npm run typecheck    # type check
npm run lint         # ESLint (eslint src --ext .ts)
lms dev              # LM Studio dev mode, live
lms push             # package and upload to the LM Studio Hub (use `lms push --private` for private publish)

Relationship to upstream MemoryMesh

  • This project does not modify or copy upstream MemoryMesh's code. The upstream source lives in the MemoryMesh/ subdirectory:

    git clone https://github.com/CheMiguel23/MemoryMesh   # run automatically by scripts/setup.cjs on install
    
  • To update upstream later, enter MemoryMesh/ and run git pull (back up dist/data first to keep your memory data).

  • The adapter only depends on the built dist/index.js and dist/data/schemas/ of upstream MemoryMesh, so upstream version upgrades won't break this adapter's interface.


Troubleshooting

Q: After install, I don't see mm_‑prefixed tools. A: Confirm MemoryMesh/dist/index.js exists and is compiled (scripts/setup.cjs runs automatically); reopen LM Studio and a new chat.

Q: MemoryMesh/ is missing or dist/ is absent. A: postinstall may have failed due to network/git issues. Check your connection and that git is available, or run manually:

cd MemoryMesh && npm install --ignore-scripts && npm run build

Q: I want to support LM Studio and other MCP clients. A: memory-mesh-mcp is built for the LM Studio Plugin. For other MCP clients, use upstream MemoryMesh directly (see As a standalone MCP server); both can share the same upstream source.

Q: Will updating upstream lose my memory data? A: Possibly. Back up MemoryMesh/dist/data before updating.


License

This adapter project is released under the MIT license (see LICENSE. Its upstream, MemoryMesh, is also MIT‑licensed (CheMiguel23/MemoryMesh).