ShadowShield MCP

ShadowShield MCP

A local-first MCP server that reduces LLM token usage by intercepting, deduplicating, compressing, and optimizing MCP tool calls and responses.

Category
Visit Server

README

<div align="center">

πŸ›‘οΈ ShadowShield MCP

Cut wasted LLM tokens before they ever reach your context window.

A local-first Model Context Protocol (MCP) server that reduces LLM token usage for developers using Claude Desktop, Cursor, or Claude Code.

npm version npm downloads License: MIT Node

npx shadowshield-mcp install

No accounts. No hosted backend. No workflow changes.

</div>


πŸ“– Table of Contents


πŸ€” Why ShadowShield?

Modern AI agents don't just consume tokens from what you type β€” they burn through context silently, in the background, during every tool call.

During long agentic sessions, they routinely:

  • πŸ” Re-read files they've already seen
  • πŸ” Execute the exact same tool call twice
  • πŸ“¦ Receive oversized API responses full of noise
  • πŸ—‚οΈ Carry bloated prompts and outputs through the context window
  • 🧹 Waste tokens on null values, dead metadata, and duplicate information
AI Agent
   β”‚
   β”œβ”€β”€ list_issues() ───────► 3,000 tokens
   β”‚
   β”œβ”€β”€ read(config.py) ─────► 1,200 tokens
   β”‚
   β”œβ”€β”€ read(config.py) ─────► 1,200 tokens  (again πŸ™ƒ)
   β”‚
   └── large tool response ─► 4,000 tokens

Nothing here is broken β€” but your context window fills up faster, requests get bigger, and you pay for tokens you never needed.

ShadowShield MCP sits transparently between your AI client and other MCP tools (GitHub, filesystem, web search, and more), intercepting, deduplicating, compressing, and optimizing context traffic β€” without requiring any change to your normal workflow.


⚑ Key Features

🧠 Smart Dedup Cache

Computes deterministic fingerprints for every MCP tool call. When the same tool is invoked again with identical arguments inside a rolling session window, ShadowShield serves the cached response instead of re-running the operation.

First request                          Repeated request

Agent β†’ Tool Call β†’ MCP Server         Agent β†’ Tool Call β†’ ShadowShield Cache
             β”‚                                        β”‚
             β–Ό                                        β–Ό
           Cache                                   Response ⚑
  • Avoids repeated tool execution
  • Cuts duplicate context
  • Lowers unnecessary token usage
  • Improves response latency on cache hits

βœ‚οΈ Intelligent Output Compressor

A rule-based trimmer that cleans up tool responses before they ever enter the model's context.

  • Strips null and empty properties
  • Truncates oversized text fields
  • Removes redundant metadata
  • Applies whitelisted key filtering
  • Reduces unnecessarily verbose structured responses
// Before
{
  "id": 4812,
  "title": "Authentication bug",
  "body": "...very large response...",
  "metadata": null,
  "unused_field": "",
  "internal_data": "..."
}

// After
{
  "id": 4812,
  "title": "Authentication bug",
  "body": "...trimmed, relevant content..."
}

Send useful information to the model β€” not structural noise.

πŸ”§ Code & Prompt Optimizer

Automatically rewrites oversized prompts or files to minimize their token footprint β€” backed by local embedding cosine similarity validation (all-MiniLM-L6-v2) to help ensure semantic meaning is preserved before any change is accepted.

Original Content
      β”‚
      β–Ό
  Optimization
      β”‚
      β–Ό
 Candidate Output
      β”‚
      β–Ό
Local Embedding Verification
      β”‚
      β”œβ”€β”€ Similar enough ──► βœ… Accept
      β”‚
      └── Unsafe change ───► ❌ Reject

Safety principles:

  • Original files are never silently overwritten
  • Optimized versions can be written separately for review
  • Low-confidence transformations are rejected automatically
  • Optimization stays focused on redundancy β€” not rewriting your code's intent

πŸ“Š Single-File Local Savings Dashboard

A lightweight, static dashboard.html β€” no account, no backend, no analytics service β€” showing:

  • πŸ’° Total tokens saved
  • πŸ” Deduplication savings
  • βœ‚οΈ Compression savings
  • πŸ”§ Optimization savings
  • πŸ“ˆ Daily savings trends
  • πŸ•’ Recent optimization events
~/.shadowshield/dashboard.html

🧰 Zero-Config Installer

One command locates your MCP client config, registers ShadowShield, and preserves every existing server entry β€” no manual JSON editing required.


πŸš€ Quick Start

Requirements

  • Node.js (v18+)
  • npm
  • A supported MCP-compatible client (Claude Desktop, Cursor, Claude Code)

1. Install

npx shadowshield-mcp install

Or build from source:

git clone <your-repository-url>
cd shadowshield-mcp
npm install
npm run build
node bin/install.js

The installer will:

  1. Locate your supported MCP client configuration
  2. Register ShadowShield as an MCP server
  3. Preserve all existing MCP server entries
  4. Create the local ~/.shadowshield/ data directory
  5. Configure the required runtime paths

2. Restart Your AI Client

Restart Claude Desktop, Cursor, or your Claude Code environment. ShadowShield connects automatically and exposes:

shadowshield_dedup_cache
shadowshield_compress_output
shadowshield_optimize

3. Just Use Your AI β€” As Normal

There's no separate ShadowShield workflow to learn.

You
 β”‚
 β–Ό
AI Client
 β”‚
 β–Ό
ShadowShield
 β”‚
 β”œβ”€β”€ Deduplication
 β”œβ”€β”€ Compression
 └── Optimization
 β”‚
 β–Ό
MCP Tools / Context

4. Check Your Savings

Open the dashboard in any browser:

~/.shadowshield/dashboard.html

πŸ—οΈ How It Works

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚     Claude / Cursor      β”‚
β”‚       / MCP Client       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
             β”‚
             β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚     ShadowShield MCP     β”‚
β”‚                          β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚ Dedup Cache        β”‚  β”‚
β”‚  β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€  β”‚
β”‚  β”‚ Output Compressor  β”‚  β”‚
β”‚  β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€  β”‚
β”‚  β”‚ Prompt Optimizer   β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
             β”‚
             β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚       MCP Tools          β”‚
β”‚                          β”‚
β”‚ GitHub Β· Filesystem      β”‚
β”‚ Search Β· APIs Β· etc.     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Every optimization event is measured and logged locally, so you always know exactly where your savings come from.


πŸ”’ Local-First by Design

Your development context should remain under your control.

~/.shadowshield/
β”œβ”€β”€ cache.db
β”œβ”€β”€ savings-log.jsonl
└── dashboard.html

ShadowShield does not require:

  • ❌ A ShadowShield account
  • ❌ A hosted ShadowShield database
  • ❌ A separate analytics backend
  • ❌ Dashboard authentication
  • ❌ Uploading your savings history anywhere

Your cache, logs, token accounting, embedding verification, and dashboard data stay entirely on your machine.

Any external model interaction used by configured optimization functionality depends on your own model/provider setup.


🧰 Technology Stack

Component Technology
Language TypeScript
Runtime Node.js
MCP @modelcontextprotocol/sdk
Cache SQLite
Logging JSONL
Token counting tiktoken
Semantic verification all-MiniLM-L6-v2
Similarity metric Cosine similarity
Dashboard HTML + Chart.js
Distribution npm

πŸ“ Repository Structure

shadowshield-mcp/
β”‚
β”œβ”€β”€ bin/
β”‚   └── install.js              # npx installer entry point
β”‚
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ server.ts                # MCP server entry point
β”‚   β”‚
β”‚   β”œβ”€β”€ tools/
β”‚   β”‚   β”œβ”€β”€ dedupCache.ts        # Tool call deduplication cache logic
β”‚   β”‚   β”œβ”€β”€ outputCompressor.ts  # Rule-based tool output compressor
β”‚   β”‚   └── optimizer.ts         # Prompt & code optimizer with embedding verification
β”‚   β”‚
β”‚   β”œβ”€β”€ storage/
β”‚   β”‚   β”œβ”€β”€ sqlite.ts            # SQLite cache database (~/.shadowshield/cache.db)
β”‚   β”‚   └── logger.ts            # Append-only logger (~/.shadowshield/savings-log.jsonl)
β”‚   β”‚
β”‚   └── utils/
β”‚       β”œβ”€β”€ tokenCount.ts        # tiktoken token counter wrapper
β”‚       └── embeddings.ts        # Local feature extraction & cosine similarity wrapper
β”‚
β”œβ”€β”€ dashboard.html               # Static savings visualization dashboard
β”œβ”€β”€ downstream.example.json
β”œβ”€β”€ package.json
β”œβ”€β”€ tsconfig.json
β”œβ”€β”€ README.md
└── LICENSE

πŸ› οΈ Development

Clone the repository and install dependencies:

git clone <your-repository-url>
cd shadowshield-mcp
npm install

Build the project:

npm run build

Run the installer locally:

node bin/install.js

Sanity-check the package before publishing:

npm pack --dry-run

🎯 Design Principles

ShadowShield follows four core principles:

# Principle Description
1 Reduce waste, not capability Optimization only matters if the resulting context stays useful to the model.
2 Stay invisible You shouldn't have to change how you work with your AI tools to save tokens.
3 Prefer local infrastructure Caching, logs, measurement, verification, and visualization β€” all local, no hosted services.
4 Don't modify more than necessary Optimization is conservative and targeted, never an excuse to rewrite unrelated code.

πŸ—ΊοΈ Roadmap

  • [ ] VS Code extension for inline optimization suggestions
  • [ ] Per-project token savings analytics
  • [ ] Additional MCP client integrations
  • [ ] Improved tool-specific compression strategies
  • [ ] Configurable optimization thresholds
  • [ ] Weekly local savings summaries
  • [ ] Better savings attribution and reporting

🀝 Contributing

Contributions are welcome! πŸŽ‰

If you've found a bug, have an optimization idea, or want to improve support for another MCP client or tool:

  1. Check existing issues first
  2. Open a new issue describing the problem or idea
  3. For significant architectural changes, open an issue before submitting a PR so the approach can be discussed

πŸ” Security

If you discover a security vulnerability, please do not publish exploit details in a public issue.

Report it privately through the repository's configured security channel instead.


πŸ“„ License

Released under the MIT License. See LICENSE for full details.


<div align="center">

πŸ›‘οΈ ShadowShield MCP

Less redundant context. Fewer wasted tokens. Same workflow.

npx shadowshield-mcp install

Built for developers who want their AI tooling to use context more efficiently.

⭐ If ShadowShield saves you tokens, consider starring the repo!

</div>

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured