{"slug": "mcp-server-for-reduce-use-of-token", "title": "MCP Server for reduce use of Token", "summary": "Nxm-memory, a local memory and search engine for AI assistants, indexes an entire workspace on the user's own machine and exposes its tools through the Model Context Protocol (MCP) to cut the number of tokens sent to a model. The tool compresses source code into structural maps plus shell output and chat history, and for prose documents retrieves only relevant chunks via search instead of loading whole files, with a dedicated semantic document-compression mode listed on the roadmap. It installs via a single curl command to ~/.local/bin, supports macOS arm64 (Apple Silicon) and Linux x86_64, and downloads a roughly 200 MB embedding model plus the ONNX Runtime library on first run.", "body_md": "**nxm-memory** is a local memory and search engine for AI assistants. Although it works great for coding projects, it is not limited to code — it can index and search any collection of files: documentation, notes, research, contracts, knowledge bases, and more. It indexes an entire workspace on your own machine and makes it queryable in natural language, without sending anything to the cloud. It reads the documents in your workspace and gives you fast, relevant answers about them. It also **cuts the number of tokens** sent to the model: it compresses **source code** into structural maps, plus shell output and chat history, and — crucially for documents — it retrieves only the **relevant chunks** via search instead of loading whole files. It exposes its tools through the **Model Context Protocol (MCP)**, so it plugs into agents like Claude Code, Opencode, Pi, and others.\n\nImportant\n\n**⭐ Token reduction to cut cost and fit more in context — one of the most important features.** nxm-memory compresses **source code** (into structural maps), shell output, and chat history before they reach the model. For **prose documents** (Markdown, text, PDF), it saves tokens by **searching and returning only the relevant chunks** rather than compressing whole files. A dedicated semantic document-compression mode is on the roadmap.\n\n**It is configured exactly like any other MCP server.** **Everything runs locally: fast, private, always available.**\n\nSee nxm-memory in action:\n\nOne command. It auto-detects your system (macOS Apple Silicon or Linux x86_64), downloads the binary, and installs it to `~/.local/bin`:\n\n```\ncurl -fsSL https://raw.githubusercontent.com/dangranaz/nxm-memory/main/install.sh | sh\n```\n\nOn **first run**, the program automatically downloads the embedding model (~200 MB) and the required ONNX Runtime library. There is nothing else to download by hand.\n\nIf `~/.local/bin` is not on your `PATH`, add it:\n\n```\nexport PATH=\"$HOME/.local/bin:$PATH\"\n```\n\nSupported platforms: **macOS arm64** (Apple Silicon) and **Linux x86_64**.\n\nnxm-memory is a standard MCP server, so you can configure it in your agents, your harnesses, and any tool that supports the MCP standard. Here is an example for **OpenCode** — add it to your `opencode.json` (global) or `opencode.jsonc` under the `mcp` key. Point `--w` at the project you want indexed:\n\n```\n{\n  \"$schema\": \"https://opencode.ai/config.json\",\n  \"mcp\": {\n    \"nxm-memory\": {\n      \"type\": \"local\",\n      \"command\": [\"nxm-mcp-server\", \"--w\", \"/path/to/your/project\", \"--transport\", \"stdio\"],\n      \"enabled\": true\n    }\n  }\n}\n```\n\nThe configuration follows the same pattern in other agents (Claude Code, Pi, Cursor, Kiro…): a local MCP server whose command is `nxm-mcp-server` with `--transport stdio`.\n\nStart the server pointing it at your project folder (the workspace). On startup it scans the folder and builds its index:\n\n```\nnxm-mcp-server --w /path/to/your/project --port 7169\n```\n\nThe server stays running and keeps the index up to date automatically as files change. To stop it:\n\n```\nnxm-mcp-server --stop\n```\n\nCreate a **`.nxmignore`** file at the root of your project to tell nxm-memory which folders and files **not** to index. The syntax is the same as `.gitignore`. This matters: without exclusions, huge and useless folders (dependencies, build output, artifacts) would end up in the index, slowing everything down and polluting search results.\n\nRecommended `.nxmignore` example:\n\n```\n# Dependencies and packages\nnode_modules/\nvendor/\n.venv/\nvenv/\n\n# Build output and artifacts\ntarget/\ndist/\nbuild/\nout/\n*.min.js\n*.min.css\n\n# Version control and caches\n.git/\n.cache/\n__pycache__/\n\n# Lock files and logs\n*.lock\n*.log\n```\n\nUseful rules:\n\n- one pattern per line; `#` starts a comment;\n- a trailing `/` (e.g.`build/` ) matches directories only;\n- `!pattern` re-includes something excluded earlier;\n- the data folder `.nxm/` is**always** excluded automatically (the index never ingests its own state).\n\nTo use it inside an agent (Claude Code, Cursor, Kiro…), use the `stdio` transport, with the agent managing the process lifecycle:\n\n```\nnxm-mcp-server --w /path/to/your/project --transport stdio\n```\n\nThink of nxm-memory as **long-term memory for your AI assistant**, dedicated to a project.\n\nWhen you give it a folder, it reads everything and breaks it into small pieces (\"chunks\"). For each piece it stores two things: the **exact words** it contains and its **meaning**. Meaning is captured with an embedding model (a neural network that turns text into numbers, so that texts meaning similar things end up \"close\" together). This way you can search either for a precise word or for a concept expressed with words different from those in the code.\n\nSearch combines three approaches — exact match, keyword search, and meaning-based search — and blends their results to surface the most relevant answers at the top.\n\nMemory is organized into **four types**, much like human memory:\n\n- **Semantic** — stable facts, rules, and preferences (e.g. \"this project uses Rust\", \"I prefer tests before code\").\n- **Episodic** — events and sessions: what happened and when.\n- **Procedural** — skills and procedures: how a given thing is done in this project.\n- **Prospective** — tasks to do and future reminders.\n\nIt has been tested on workspaces of **tens of gigabytes** mixing documents and code (hundreds of thousands of files). And it does not stop after the first scan: it stays running in the **background**, constantly keeping the **vector database** up to date — every file you add to or change in the workspace is picked up and re-indexed automatically.\n\nEverything lives on your computer, in a `.nxm/` folder inside the project. Nothing leaves your machine.\n\nnxm-memory gives an AI assistant **persistent memory and instant search** over a project: it retrieves the right function, the relevant document, or the decision made weeks ago, without having to re-read everything each time. It builds and maintains **the index** of the project and answers the agent's queries.\n\nImportant\n\n**Token reduction — one of the most valuable features.** nxm-memory includes a built-in **context-compression** engine (`context_compress`) that shrinks **source code** (into structural maps), shell output, and chat history before they reach the model. It reports how many tokens it saved (`tokens_before` / `tokens_after` / `reduction_pct`), keeping long agent sessions inside the context window and cutting cost — while preserving errors and the important parts. For **prose documents** (Markdown/text/PDF) it does not yet compress semantically; use `search_docs` / `index_search` to load only the relevant chunks. A semantic document-compression mode is planned (see roadmap).\n\n**Example** — compressing a real source file into its structural map:\n\n```\ncontext_compress (mode: file)\n  tokens_before: 3050\n  tokens_after :  416\n  reduction    :   87%  saved\n```\n\nThat is 2634 tokens saved on a single file — multiplied across every file, shell output, and chat turn an agent handles in a session.\n\nOn startup (and whenever files change) it **builds the index** of the workspace. Indexing is incremental: only files that actually changed are reprocessed.\n\n- **Code** : Rust, Python, JavaScript/TypeScript (`.rs` ,`.py` ,`.js` ,`.jsx` ,`.ts` ,`.tsx` ), plus`.sh` ,`.sql` ,`.proto` ,`.graphql` ,`.html` ,`.css` .\n- **Documents** : Markdown (`.md` ,`.mdx` ), PDF, plain text (`.txt` ,`.rst` ,`.adoc` ).\n- **Configuration** :`.toml` ,`.yaml` /`.yml` ,`.json` ,`.ini` ,`.cfg` .\n\nFolders listed in `.nxmignore` are skipped (see section 2).\n\nThe server exposes these tools to the AI agent:\n\n| Tool | What it does | \n|---|---|\n| `index_workspace` | Index or re-index a workspace (automatic full/incremental). | \n| `index_search` | Hybrid search (meaning + keywords + fusion) across everything indexed. | \n| `search_code` | Search code files only, with language and path filters. | \n| `search_docs` | Search documents only (PDF, Markdown, TXT). | \n| `search_exact` | Exact substring search, very fast, no embedding needed. | \n| `search_regex` | Search with regular expressions. | \n| `get_chunk` | Retrieve the full content of a chunk by ID (on-demand loading). | \n| `find_symbol` | Find the definition of a symbol (function, struct, class…). | \n| `outline` | List the top-level symbols of a file. | \n| `find_references` | Find all uses of a symbol across a project. | \n| `memory_remember` | Store a fact, event, skill, or task in memory. | \n| `memory_recall` | Search memory for relevant facts, events, and skills. | \n| `context_compress` | **Reduce token usage** : compress source code (into structural maps), shell output, or chat history — reports tokens saved. For prose documents, prefer`search_docs` /`index_search` . One of the most useful tools. | \n| `context_budget` | Compute the optimal context allocation for a given window. | \n| `workspace_list` /`workspace_create` | List / create configured workspaces. | \n| `stats` | Index statistics (files indexed, chunks, storage). | \n| `watcher_status` | Status of the automatic file watcher. | \n\nIf nxm-memory saves you tokens, time, or keeps your data private, please **give the repository a star** and share it — it is the simplest way to help the project grow and reach other developers. Feedback and suggestions are welcome via issues.\n\n*The source code is maintained privately. This repository distributes the binaries and the installer; the embedding model is distributed separately and downloaded automatically on first run.*", "url": "https://wpnews.pro/news/mcp-server-for-reduce-use-of-token", "canonical_source": "https://github.com/dangranaz/nxm-memory", "published_at": "2026-09-13 09:19:29+00:00", "updated_at": "2026-09-13 10:05:47.732624+00:00", "lang": "en", "topics": ["ai-tools", "ai-agents", "developer-tools", "ai-infrastructure"], "entities": ["nxm-memory", "Model Context Protocol", "Claude Code", "OpenCode", "Cursor", "Kiro", "ONNX Runtime", "GitHub"], "alternates": {"html": "https://wpnews.pro/news/mcp-server-for-reduce-use-of-token", "markdown": "https://wpnews.pro/news/mcp-server-for-reduce-use-of-token.md", "text": "https://wpnews.pro/news/mcp-server-for-reduce-use-of-token.txt", "jsonld": "https://wpnews.pro/news/mcp-server-for-reduce-use-of-token.jsonld"}}