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
访问服务器

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>

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选