ShadowShield MCP
A local-first MCP server that reduces LLM token usage by intercepting, deduplicating, compressing, and optimizing MCP tool calls and responses.
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.
npx shadowshield-mcp install
No accounts. No hosted backend. No workflow changes.
</div>
π Table of Contents
- Why ShadowShield?
- Key Features
- Quick Start
- How It Works
- Local-First by Design
- Technology Stack
- Repository Structure
- Development
- Design Principles
- Roadmap
- Contributing
- Security
- License
π€ 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:
- Locate your supported MCP client configuration
- Register ShadowShield as an MCP server
- Preserve all existing MCP server entries
- Create the local
~/.shadowshield/data directory - 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:
- Check existing issues first
- Open a new issue describing the problem or idea
- 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
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
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.
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.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
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.
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.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
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.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.