{
  "markdown": "# ng-token-saver\n\n[![npm version](https://img.shields.io/npm/v/%40alex-apps%2Fng-token-saver)](https://www.npmjs.com/package/@alex-apps/ng-token-saver)\n[![weekly downloads](https://img.shields.io/npm/dw/%40alex-apps%2Fng-token-saver)](https://www.npmjs.com/package/@alex-apps/ng-token-saver)\n[![node](https://img.shields.io/node/v/%40alex-apps%2Fng-token-saver)](#requirements-and-setup)\n[![license](https://img.shields.io/npm/l/%40alex-apps%2Fng-token-saver)](LICENSE)\n\nAn MCP server that lets an AI agent understand Angular **templates** by asking the same\ncompiler that builds the project, instead of guessing from file text. The token saving is\nmeasured, not promised.\n\nAngular ships a first-class language server, but no official AI integration exposes it — the\nAngular CLI MCP (`ng mcp`) works at the docs-and-build level and does not touch templates.\nThis server is that missing layer, and it answers **for the Angular version the project\nactually runs**.\n\nEverything below marked as measured was produced by running code against six real Angular\nworkspaces (17.3.12, 18.2.14, 19.2.25, 20.3.26, 21.2.18, 22.0.8) and two production projects.\nEvery number can be reproduced with the commands in\n[Reproducing the measurements](#reproducing-the-measurements).\n\n## Quick start\n\nThe language server ships as a regular dependency — nothing to install besides the package:\n\n```\nnpm install -g @alex-apps/ng-token-saver\n```\n\nClaude Code:\n\n```\nclaude mcp add ng-token-saver -- ng-token-saver\n```\n\nCodex CLI:\n\n```\ncodex mcp add ng-token-saver -- ng-token-saver\n```\n\nAny other MCP client:\n\n```json\n{ \"mcpServers\": { \"ng-token-saver\": { \"command\": \"ng-token-saver\" } } }\n```\n\nOr skip the install and let the client fetch it through npx:\n\n```json\n{ \"mcpServers\": { \"ng-token-saver\": { \"command\": \"npx\", \"args\": [\"-y\", \"@alex-apps/ng-token-saver\"] } } }\n```\n\nIn Cursor that npx form is one click:\n\n[![Add to Cursor](https://cursor.com/deeplink/mcp-install-dark.svg)](https://cursor.com/install-mcp?name=ng-token-saver&config=eyJjb21tYW5kIjoibnB4IiwiYXJncyI6WyIteSIsIkBhbGV4LWFwcHMvbmctdG9rZW4tc2F2ZXIiXX0%3D)\n\nThe npm and npx paths are verified by running: the packed tarball (79 kB, dist only) was\ninstalled into a clean prefix and all four tool kinds answered through a real MCP client,\nand the npx form connects in 1.2–2.0 s from a warm npm cache (the very first run on a\nmachine also downloads the dependency tree — the language server alone unpacks to 13.6 MB).\n\nA first question to ask it — the contract of a component whose members are scattered across\nan extends chain. Asked for `fixtures/v17/src/app/derived-card.component.ts` (a fixture in\nthis repository), `ng_component_info` answers, verbatim:\n\n```json\n{\"found\":true,\"angularVersion\":\"17.3.12\",\"className\":\"DerivedCardComponent\",\"kind\":\"component\",\"selector\":\"app-derived-card\",\"standalone\":true,\"inlineTemplate\":true,\"styleUrls\":[],\"imports\":[],\"hostDirectives\":[],\"extends\":\"BasePanel\",\"ancestors\":[\"BasePanel\",\"BaseWidget\"],\"inputs\":[{\"name\":\"accent\",\"type\":\"boolean\"},{\"name\":\"heading\",\"type\":\"string\"},{\"name\":\"disabled\",\"type\":\"boolean\"}],\"outputs\":[{\"name\":\"blurred\",\"type\":\"void\"}],\"publicMembers\":[{\"name\":\"focus\",\"kind\":\"method\",\"signature\":\"focus(): void\",\"noop\":true},{\"name\":\"collapse\",\"kind\":\"method\",\"signature\":\"collapse(animated: boolean): void\",\"noop\":true}]}\n```\n\n624 characters, 305 ms on the session's first call (it loads the project's own TypeScript),\nsingle-digit milliseconds after. The asked file declares one input and an `extends` clause;\n`heading`, `disabled`, the output and both methods live in `BasePanel` and `BaseWidget` and\nare resolved statically, and `\"noop\": true` on `focus()` is the subclass shadowing it with\nan empty body — the kind of fact that otherwise costs a whole file read per ancestor.\n\nConfigs for Cursor, VS Code, Windsurf, Codex CLI and JetBrains, the Node floor, and running\nfrom source are in [Requirements and setup](#requirements-and-setup).\n\n## The two problems it solves\n\n**1. No template awareness.** `grep` over an `.html` file cannot tell you where\n`{{ user().fullName }}` is declared, and no amount of reading gives you `NG2339 Property\n'emailAddress' does not exist on type 'UserVm'`. That is compiler output, not text.\n\n**2. Version drift.** The AI context files on angular.dev (`llms.txt`) describe only the\nnewest major and carry no version markers; the versioned archive sites serve none at all.\nOn v17–v21 they hand the agent instructions that produce APIs which do not exist. Measured\nexamples are in [Version facts](#version-facts).\n\n## Tools\n\nSix tools, 1001 characters of descriptions in total. Answers are dense JSON with no markdown.\n\n| Tool | What it answers | Needs the language server |\n|---|---|---|\n| `ng_template_definition` | where a symbol under this template position is declared | yes |\n| `ng_template_diagnostics` | Angular compiler errors for a template, or for a `files` batch; an entry anchored in the companion `.ts` carries `file` | yes |\n| `ng_component_info` | the public contract of a component or directive | no |\n| `ng_workspace_map` | projects, versions, `strictTemplates` and zone.js per project | no |\n| `ng_version_rules` | what exists and what does not in this project's Angular version | no |\n| `ng_find_usages` | where a component, directive, pipe or service is used; with `input` — where that input is bound | no |\n\nFour of the six never start the language server, so they answer in milliseconds and keep\nworking on workspaces where the server refuses to load.\n\n## Measured: contract instead of the whole file\n\n`ng_component_info` returns the public contract of a component rather than its source.\nMeasured across two production codebases through a real MCP client:\n\n| | Nx monorepo | CLI workspace\\* |\n|---|---|---|\n| Angular / TypeScript | 19.2.18 / 5.8.3 | 17.3.8 / 5.3.3 |\n| Components in the tally | 1298 | 407 |\n| Parse errors | 0 | 0 |\n| Sources | 5 404 708 chars | 1 735 223 chars |\n| Contracts (base-class members included) | 1 759 331 chars | 463 563 chars |\n| **Saved** | **67%** | **73%** |\n| **Saved in tokens** (o200k_base proxy) | **67%** | **71%** |\n| Contract shorter than source | 1201 of 1298 (93%) | 386 of 407 (95%) |\n| Flagged as partial | 1 of 1298 | 3 of 407 |\n| First call (loads the project's TypeScript) | 306 ms | 564 ms |\n\n\\* measured with the pre-0.1.2 wire format; the current format is leaner, so this saving\nis a floor.\n\nThe largest component in the monorepo shrinks from **177 863 to 10 770 characters** while\nlisting 117 contract members. Contracts include members inherited from base classes — the\nextends chain is resolved through relative imports, tsconfig path aliases and barrels.\nBefore that resolver, 91 of 1298 monorepo contracts were flagged as partial; now 1 is.\n\nThree caveats that travel with these numbers:\n\n- **Tokens are counted through a proxy** — OpenAI's `o200k_base`, since Claude's tokenizer\n  is not public; `cl100k_base` agrees within one point on this data. Characters are exact.\n- **The baseline is reading the whole file**, which is what an agent does by default.\n- **JSON tokenizes slightly worse than TypeScript**, so token savings sit a point or two\n  below character savings. The table carries both.\n\nOn small components there is no saving at all: a 17-line component produces a 578-character\ncontract against a 315-character source. The contract grows with the number of members, the\nsource with method bodies — and on production code the second wins almost always.\n\n## Measured: rename and diagnose\n\n**Renaming an input across usages.** The grep path an agent actually takes — read the\ncomponent file to learn the selector, then grep the selector and the binding spellings\nrepo-wide — against `ng_component_info` plus `ng_find_usages` with its `input` filter,\nwhich returns only the tags that bind the name, each entry pointing at the binding itself.\nOn the production monorepo, 6243 files scanned:\n\n| Component | grep path | bridge | saved (o200k) |\n|---|---|---|---|\n| 577 usages, `mask` bound on 5 tags | 50 527 tokens | 1 035 tokens | **98%** |\n| 466 usages, `icon` bound on 463 tags | 41 698 tokens | 22 566 tokens | **46%** |\n| 1211 usages, `name` bound on 1134 tags | 129 227 tokens | 30 650 tokens | 76%\\* |\n\n\\* the tool returns at most 500 entries per answer, and the answer says so.\n\nThe saving is decided by how many of the usages actually bind the input: `mask` is bound on\n5 of 568 tags, and grep still prints every selector line plus 67 binding-shaped lines from\nacross the repo — 62 of them somebody else's `mask` — while the bridge answers with exactly\nthose five sites.\n\n**Diagnosing a template that will not compile.** A whole-project compiler listing costs\n**395 tokens and 1321 ms**; one `ng_template_diagnostics` call answers with the asked\nfile's diagnostics in **81 tokens, 1 ms warm**. The gap only widens with project size: the\nlisting grows with the project, the answer does not. After an edit, fresh diagnostics\narrive as a 340–400 ms push — against a rebuild.\n\n## Version facts\n\n`ng_version_rules` contains no rule taken from documentation: the data comes from importing\nthe packages actually installed in each fixture and from running the compiler.\n\n**The zoneless provider is renamed between v19 and v20.**\n\n| API | v17 | v18 | v19 | v20 | v21 | v22 |\n|---|---|---|---|---|---|---|\n| `provideExperimentalZonelessChangeDetection` | – | yes | yes | – | – | – |\n| `provideZonelessChangeDetection` | – | – | – | yes | yes | yes |\n\nAdvice to \"enable zoneless\" without a version breaks on three majors out of six.\n\n**Existing is not the same as ready.** The `@experimental` and `@developerPreview` tags live\nonly in declaration JSDoc and are invisible at runtime:\n\n| API | v17 | v18 | v19 | v20 | v21 | v22 |\n|---|---|---|---|---|---|---|\n| `input`, `output`, `model`, `viewChild`, `contentChild` | preview | preview | stable | stable | stable | stable |\n| `effect`, `toObservable` | preview | preview | preview | stable | stable | stable |\n| `linkedSignal`, `afterRenderEffect` | – | – | preview | stable | stable | stable |\n| `resource`, `rxResource`, `httpResource` | – | – | **experimental** | **experimental** | **experimental** | stable |\n\nSo \"rewrite `@Input()` as `input()`\" on a v17 or v18 project means moving to a non-public\nAPI, and `resource()` was experimental all the way through v21. A batch of signal APIs\nappears exactly at v19: `linkedSignal`, `resource`, `rxResource`, `httpResource`,\n`afterRenderEffect`, `provideAppInitializer`.\n\n**Two documentation claims that measurement contradicted:** `standalone` becomes the default\nat **v19**, not v20; and `*ngIf` is not removed in 22.0.8 — it reports hint `NG6385` and\nkeeps working, with `NgIf` still exported from `@angular/common`.\n\n**Compiler gates**, read in the 22.0.8 bundle and confirmed by running it — all keyed on\n`--angularCoreVersion`, and with no version passed the newest semantics are assumed:\n\n| Feature | Gate |\n|---|---|\n| `@if` / `@for` / `@switch` blocks | ≥ 17.0.0 |\n| signals in two-way bindings | ≥ 17.2.0-0 |\n| `@let` | ≥ 18.1.0 |\n| implicit `standalone` | ≥ 19.0.0 |\n| DOM event type assertion | ≥ 20.2.0 |\n\nAlso measured: Signal Forms (`@angular/forms/signals`) exist only from v21 and are stable on\n22.0.8; `AbstractControl.events` from v18; `TestBed.tick` from v20.\n\nOutside the measured v17–v22 range `ng_version_rules` returns nothing and says so —\nextrapolating \"it was in v22, so it is in v23\" is exactly the failure it exists to prevent.\n\n## Honesty as a feature\n\nAn incomplete answer says so, in words, inside the answer:\n\n- A contract merges base-class members and host-directive exposures, resolved statically\n  through relative imports, tsconfig aliases and barrels. Where the walk cannot continue —\n  a base class from a package, a mixin call — the answer carries `incomplete`, naming the\n  class and the file to ask about next.\n- `ng_version_rules` reports `notMeasured` topics, and a `caveat` when your minor differs\n  from the measured one.\n- `ng_find_usages` labels declarations as `declaration`, admits when class-name matches were\n  found without resolving imports, and names selector twins — a second declaration of the\n  same selector elsewhere in the workspace — instead of silently mixing their usages.\n- `ng_template_diagnostics` separates three states that all look like an empty list: the\n  template is clean; the server is silently down (caught by a canary probe); or template\n  checking is off for this project — then the answer carries `checksDisabled` naming the\n  tsconfig responsible. In the measured monorepo `strictTemplates` is off in two of seven\n  applications, so the distinction is not theoretical.\n\n## What this is not\n\n- **Not better than a careful `grep` at finding usages.** `grep -rn \"<app-widget\"` finds the\n  same 62 usages. What `ng_find_usages` adds: the selector and class name are derived from\n  the file for you, usage kinds are labelled, all four attribute-binding spellings are\n  covered, and `path` scopes the scan — 33 selectors in the measured monorepo are declared\n  in two applications at once, and an unscoped search would mix them.\n- **Not a replacement for the Angular CLI MCP** — a different layer. `ng mcp` covers docs,\n  best practices and build orchestration; none of its nine tools touches templates or the\n  language server. The two complement each other.\n- **Not a type checker of its own.** The LSP-backed tools deliver the project's own compiler\n  output, undistorted.\n\nKnown gaps are recorded, not hidden: a base class from a package or behind a mixin call\nstops the ancestor walk (1 of 1298 components in the measured monorepo), Nx projects with\ninferred targets come without `tsConfig`, and pipe twins are not detected.\n\n## Requirements and setup\n\n- **Node ≥ 18.20.8** — the measured floor: the published package answered on clean Node\n  18.20.8, 20.20.2 and 22.x. This is about the MCP server process only — **your project\n  keeps building on its own Node**. To give just the server a newer runtime, point the\n  client config at that binary: `\"command\": \"C:\\\\node22\\\\node.exe\"`.\n\n**From source** (instead of npm):\n\n- The project's own dependencies: `npm install`, then `npm run build`.\n- The shipped language-server branch lives in `tools/servers/ls22` and needs `npm ci` there once.\n- In every client config, replace the `ng-token-saver` command with `node <path>/dist/index.js`;\n  for Claude Code: `claude mcp add ng-token-saver -- node <path>/dist/index.js`.\n\n`node_modules` folders are not committed, including the twelve inside the stand. To restore\nthe full measurement environment:\n\n```\nnpm install && npm run build\ncd tools/servers/ls22 && npm ci        # the branch actually shipped\ncd fixtures/v22 && npm ci              # repeat per fixture you want to run\n```\n\n### Clients\n\nThe server is a plain stdio MCP server with no client-specific features, so any MCP client\ncan launch it; installation and Claude Code registration are in [Quick start](#quick-start).\n\n**Cursor** — the one-click button in Quick start, or the same `mcpServers` JSON as in\nQuick start, in `~/.cursor/mcp.json` (all projects) or `.cursor/mcp.json` (one project).\n\n**Windsurf** — the same JSON, in `~/.codeium/windsurf/mcp_config.json`.\n\n**VS Code (Copilot agent mode)** — `.vscode/mcp.json`; the key is `servers` and the entry\ntakes a `type`:\n\n```json\n{ \"servers\": { \"ng-token-saver\": { \"type\": \"stdio\", \"command\": \"ng-token-saver\" } } }\n```\n\n**Codex CLI** — `codex mcp add ng-token-saver -- ng-token-saver`, or `~/.codex/config.toml`:\n\n```toml\n[mcp_servers.ng-token-saver]\ncommand = \"ng-token-saver\"\n```\n\n**JetBrains AI Assistant / Junie** — Settings → Tools → AI Assistant → Model Context\nProtocol accepts the same JSON as Quick start's; for Junie, additionally enable \"Pass\ncustom MCP servers\".\n\nConfiguration, both variables optional:\n\n- `NG_TOKEN_SAVER_IDLE_MS` — a language-server session unused this long shuts its ngserver\n  down; the next call pays the cold start again. Default 900000 (15 minutes); `0` keeps\n  sessions alive until the server exits. A session with a call in flight is never shut down.\n- `NG_TOKEN_SAVER_SERVERS_DIR` — where the language-server branch lives, if not in\n  `tools/servers` next to the build.\n\n## Reproducing the measurements\n\n```\nnpm test                                  build plus 164 unit tests (node:test, no dependencies)\nnpm run smoke                             end-to-end check with a real MCP client over stdio\nnpm run bench:settle                      whether a pause after didOpen is needed (it is not)\nnpm run bench:standalone                  where standalone becomes the default (v17..v22)\nnpm run bench:api                         which Angular APIs exist in which majors, and their stability\nnpm run bench:contract <project root>     contract size against reading whole files (--tokens adds token counts)\nnpm run bench:rename <component> <input>  the grep path against the bridge for an input rename\nnpm run bench:diagnose                    a compiler listing against one diagnostics call\nnpm run bench:matrix                      resolution probes across a fixture\nnpm run bench:negative                    what the server returns when things break\nnpm run bench:didchange                   diagnostics timing after an edit\n```\n\nThe stand is `fixtures/v17..v22` — six real Angular workspaces, each with its own\n`node_modules` and its own pinned TypeScript, plus `fixtures/negative/*` for failure cases.\n\n## Status\n\nAll six tools verified on the six fixtures and on two production codebases — 1298 and 407\ncomponents, zero parse errors — plus one Angular 16 project to check that out-of-range\nrefusals are structured rather than silent. 164 unit tests, all green.\n\nMeasured latency: the two LSP-backed tools pay 8–28 s of cold start on the first call and\nanswer in 2–9 ms after it; the four static tools answer in 250–600 ms on the first call and\nin milliseconds once the project's TypeScript is cached. A session idle for 15 minutes shuts\nits language server down, and the next call pays the cold start again — see\n`NG_TOKEN_SAVER_IDLE_MS` above.\n\n## License\n\nGPL-3.0-or-later — see [LICENSE](LICENSE). Copyright (C) 2026 Alex Ryabov.\nUse and modify freely; derivative works must stay open under the same license.\n",
  "bytes": 18270,
  "sha": "03e9bbad43e0757d12fefe899787a67ccb5eb36247b5f536f67b99a12c3bcd57",
  "repo_slug": "alex88ryabov/alex-apps-ng-token-saver",
  "fonte": "repo",
  "truncated": false,
  "api": "https://agentalog.com/api/listings/mcp_io_github_alex88ryabov_ng_token_saver_31301f61/readme"
}