ShadowShield MCP
by Mahesh8214
README.md
<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.**
[](https://www.npmjs.com/package/shadowshield-mcp)
[](https://www.npmjs.com/package/shadowshield-mcp)
[](LICENSE)
[](https://nodejs.org)
```bash
npx shadowshield-mcp install
```
No accounts. No hosted backend. No workflow changes.
</div>
---
## π Table of Contents
- [Why ShadowShield?](#-why-shadowshield)
- [Key Features](#-key-features)
- [Quick Start](#-quick-start)
- [How It Works](#οΈ-how-it-works)
- [Local-First by Design](#-local-first-by-design)
- [Technology Stack](#-technology-stack)
- [Repository Structure](#-repository-structure)
- [Development](#οΈ-development)
- [Design Principles](#-design-principles)
- [Roadmap](#οΈ-roadmap)
- [Contributing](#-contributing)
- [Security](#-security)
- [License](#-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
```text
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.
```text
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
```json
// 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.
```text
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
```text
~/.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
```bash
npx shadowshield-mcp install
```
Or build from source:
```bash
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:
```text
shadowshield_dedup_cache
shadowshield_compress_output
shadowshield_optimize
```
### 3. Just Use Your AI β As Normal
There's no separate ShadowShield workflow to learn.
```text
You
β
βΌ
AI Client
β
βΌ
ShadowShield
β
βββ Deduplication
βββ Compression
βββ Optimization
β
βΌ
MCP Tools / Context
```
### 4. Check Your Savings
Open the dashboard in any browser:
```text
~/.shadowshield/dashboard.html
```
---
## ποΈ How It Works
```text
ββββββββββββββββββββββββββββ
β 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.**
```text
~/.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
```text
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:
```bash
git clone (https://github.com/Mahesh8214/ShadowShield-MCP)
cd shadowshield-mcp
npm install
```
Build the project:
```bash
npm run build
```
Run the installer locally:
```bash
node bin/install.js
```
Sanity-check the package before publishing:
```bash
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](../../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`](LICENSE) for full details.
---
<div align="center">
### π‘οΈ ShadowShield MCP
**Less redundant context. Fewer wasted tokens. Same workflow.**
```bash
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>
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo issues