<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Vidyax</title>
    <description>The latest articles on DEV Community by Vidyax (@daffa2555).</description>
    <link>https://dev.to/daffa2555</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4125363%2F2f80f83a-db73-4345-a6ea-b98779317d43.png</url>
      <title>DEV Community: Vidyax</title>
      <link>https://dev.to/daffa2555</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/daffa2555"/>
    <language>en</language>
    <item>
      <title>How I Cut 45,000 Next.js Error Tokens to 118 in &lt;0.2ms Using a Rust MCP Server</title>
      <dc:creator>Vidyax</dc:creator>
      <pubDate>Tue, 15 Sep 2026 03:19:09 +0000</pubDate>
      <link>https://dev.to/daffa2555/how-i-cut-45000-nextjs-error-tokens-to-118-in-02msusing-a-rust-mcp-server-1c7j</link>
      <guid>https://dev.to/daffa2555/how-i-cut-45000-nextjs-error-tokens-to-118-in-02msusing-a-rust-mcp-server-1c7j</guid>
      <description>&lt;p&gt;If you use Cursor, Claude Desktop, or Cline daily,&lt;br&gt;
  you have probably watched your rate limits evaporate&lt;br&gt;
  because of a single runtime crash.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;A Next.js build fails or a Python script panics, and
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;your terminal vomits 500 lines of stack traces. The&lt;br&gt;
  LLM eagerly ingests all 45,000 tokens of internal&lt;br&gt;
  &lt;code&gt;node_modules&lt;/code&gt; machinery, webpack bundles, and event&lt;br&gt;
  loop frames.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;You just paid $0.15 for an AI model to read code it
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;can't edit, your prompt cache is wiped, and your agent&lt;br&gt;
  is now hallucinating because its context window is&lt;br&gt;
  full of garbage.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Worse, your terminal stderr probably just leaked
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;code&gt;DATABASE_URL=postgres://admin:password@...&lt;/code&gt; straight&lt;br&gt;
  to an external API.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;I got tired of paying for framework noise, so I
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;built an open-source Rust Model Context Protocol (MCP)&lt;br&gt;
  server called &lt;strong&gt;Tokenectomy Razor&lt;/strong&gt; to fix it locally&lt;br&gt;
  before logs ever touch the LLM.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;## What is eating your context window?

A typical Next.js error trace looks like this:
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
text
    TypeError: Cannot read properties of undefined
  (reading 'digest')
        at Object.&amp;lt;anon&amp;gt; (/node_modules/next/bundle5.
  js:142:31)
        at __webpack_require__
  (/node_modules/next/bundle5.js:198:12)
        at Object.execute (/node_modules/next/dev-
  server.js:412:19)
        at processTicksAndRejections (task_queues:95:5)
        Database connection failed:
  postgresql://admin:super_secret_password@db.prod.
  internal:5432/primary
        API key leaked: sk-ant-api03-
  abcdef1234567890abcdef1234567890
        [... 480 internal dependency frames flooding
  context ...]

  Notice three things:

  1. 98% of those frames are inside node_modules. Your
  AI agent is not going to edit webpack's internal
  bundle logic. It only cares about the one line in
  src/components/Header.tsx:42 where you missed a
  parenthesis.
  2. The database password and API key are sitting
  unmasked in plain text.
  3. The raw token count for this single error dump was
  45,820 tokens.

  ## What happens after Tokenectomy runs

  When the AI agent invokes get_error_context via MCP,
  Tokenectomy intercepts the log, strips framework
  internals, redacts all secrets locally using a
  deterministic DFA regex, and grabs bounded source code
  lines around the actual crash:

    [:TOKENECTOMY:M2M_CONTROL_PLANE:v1.3.0]
    [STATE=FRAMEWORK_NOISE_PURGED]
    [STRATEGY_APPLIED=AGGRESSIVE]
    [ORIGINAL_BYTES=45820 | CLEAN_BYTES=118 |
  REDUCTION=99%]
    [PRIMARY_CRASH_COORDINATES=src/components/Header.
  tsx:42]

  [COGNITIVE_DIRECTIVE=INSPECT_CALLER_AT_src/components/
  Header.tsx:42]
    [:END_CONTROL_PLANE]

    src/components/Header.tsx:42:15 - SyntaxError
      42 |   const user = useSession( ;
         |                           ^ Expected ')'
    🛡️ [CONNECTION_STRING_REDACTED]
    🛡️ [REDACTED]
  ANTHROPIC_API_KEY=[REDACTED_SECRET_KEY]

  Final token count: 118 tokens.
  Reduction: 99.7%.
  Zero credentials leaked to the cloud.

  ## Why Rust and why local-first?

  I did not want another slow node script or cloud proxy
  adding 300ms of network latency to an agent loop.

  1. Sub-millisecond latency: The core log surgery and
  secret redaction pipeline runs in &amp;lt;0.2 milliseconds on
  an Intel i5 CPU.
  2. Zero cloud leaks: It runs 100% locally over stdio.
  Your error logs, environment variables, and
  proprietary code never touch an external server.
  3. AST verification &amp;amp; rollback: The apply_code_patch
  tool parses modified code with Tree-sitter before
  saving to disk. If the agent generates invalid syntax,
  it immediately rolls back with zero dirty git diff.
  4. Lightweight footprint: Baseline process memory is
  3.45 MB VmRSS.

  Glama.ai audited the server definition under their
  Tool Definition Quality Score (TDQS) and awarded it
  Grade A (4.7 / 5.0) across all tools.

  ## How to set it up (Takes 30 seconds)

  You don't need to install Rust or compile anything. We
  distribute pre-built native binaries via npm for
  Linux, macOS (Apple Silicon &amp;amp; Intel), and Windows.

  Add this to your claude_desktop_config.json or Cursor
  MCP settings:

    {
      "mcpServers": {
        "tokenectomy": {
          "command": "npx",
          "args": ["-y", "tokenectomy-razor", "--mcp"]
        }
      }
    }

  Or if you prefer native cargo:

    cargo install tokenectomy

  Then configure:

    {
      "mcpServers": {
        "tokenectomy": {
          "command": "razor",
          "args": ["--mcp"]
        }
      }
    }

  ## Open Source &amp;amp; Repositories

  Everything is open source under the MIT license:

  1. GitHub: https://github.com/Tokenectomy-
  Labs/Tokenectomy
  2. Glama: https://glama.ai/mcp/servers/Tokenectomy-
  Labs/Tokenectomy
  3. npm: https://www.npmjs.com/package/tokenectomy-
  razor
  4. crates.io: https://crates.io/crates/tokenectomy

  Give it a run next time your agent is about to eat a
  40,000-token crash log. Your token bill will thank
  you.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
      <category>ai</category>
      <category>agents</category>
      <category>rust</category>
      <category>nextjs</category>
    </item>
  </channel>
</rss>
