MCP Spine

MCP Spine

A local-first middleware proxy that proxies multiple MCP servers through a single entry with schema minification, semantic routing, security hardening, and state guard.

Category
访问服务器

README

MCP Spine

Context Minifier & State Guard — A local-first MCP middleware proxy that reduces token waste, prevents tool attrition, and eliminates context rot.

MCP Spine sits between your LLM client (Claude Desktop, etc.) and your MCP servers, providing security hardening, intelligent tool routing, schema compression, and file state tracking — all through a single proxy.

Why

LLM agents using MCP tools face three problems:

  1. Token waste — Tool schemas consume thousands of tokens per request. With 40+ tools loaded, you're burning context on JSON schemas before the conversation even starts.
  2. Context rot — In long sessions, LLMs revert to editing old file versions they memorized earlier, silently overwriting your latest changes.
  3. No security boundary — MCP servers run with full access. There's no audit trail, no rate limiting, no secret scrubbing between the LLM and your tools.

MCP Spine solves all three.

Install

pip install mcp-spine

# With semantic routing (optional)
pip install mcp-spine[ml]

Quick Start

# Generate config
mcp-spine init

# Diagnose your setup
mcp-spine doctor --config spine.toml

# Validate config
mcp-spine verify --config spine.toml

# Start the proxy
mcp-spine serve --config spine.toml

Claude Desktop Integration

Replace all your individual MCP server entries with a single Spine entry:

{
  "mcpServers": {
    "spine": {
      "command": "python",
      "args": ["-u", "-m", "spine.cli", "serve", "--config", "/path/to/spine.toml"],
      "cwd": "/path/to/mcp-spine"
    }
  }
}

The -u flag ensures unbuffered stdout, preventing pipe hangs on Windows.

Features

Stage 1: Security Proxy

  • JSON-RPC message validation and sanitization
  • Secret scrubbing (AWS keys, GitHub tokens, bearer tokens, private keys, connection strings)
  • Per-tool and global rate limiting with sliding windows
  • Path traversal prevention with symlink-aware jail
  • Command injection guards for server spawning
  • HMAC-fingerprinted SQLite audit trail
  • Circuit breakers on failing servers
  • Declarative security policies from config

Stage 2: Semantic Router

  • Local vector embeddings using all-MiniLM-L6-v2 (no API calls, no data leaves your machine)
  • ChromaDB-backed tool indexing
  • Query-time routing: only the most relevant tools are sent to the LLM
  • spine_set_context meta-tool for explicit context switching
  • Keyword overlap + recency boost reranking
  • Background model loading — tools work immediately, routing activates when ready

Stage 3: Schema Minification

  • 4 aggression levels (0=off, 1=light, 2=standard, 3=aggressive)
  • Level 2 achieves 61% token savings on tool schemas
  • Strips $schema, titles, additionalProperties, parameter descriptions, defaults
  • Preserves all required fields and type information

Stage 4: State Guard

  • Watches project files via watchfiles
  • Maintains SHA-256 manifest with monotonic versioning
  • Injects compact state pins into tool responses
  • Prevents LLMs from editing stale file versions

Human-in-the-Loop

  • require_confirmation policy flag for destructive tools
  • Spine intercepts the call, shows the arguments, and waits for user approval
  • spine_confirm / spine_deny meta-tools for the LLM to relay the decision
  • Per-tool granularity via glob patterns

Tool Output Memory

  • Ring buffer caching last 50 tool results
  • Deduplication by tool name + argument hash
  • TTL expiration (1 hour default)
  • spine_recall meta-tool to query cached results
  • Prevents context loss when semantic router swaps tools between turns

SSE Transport

  • Connect to remote MCP servers over HTTP/SSE alongside local stdio servers
  • No external dependencies (uses stdlib urllib)
  • Supports custom headers for authentication

Diagnostics

# Check your setup
mcp-spine doctor --config spine.toml

# Live monitoring dashboard
mcp-spine dashboard

# Usage analytics
mcp-spine analytics --hours 24

# Query audit log
mcp-spine audit --last 50
mcp-spine audit --security-only
mcp-spine audit --tool write_file

Example Config

[spine]
log_level = "info"
audit_db = "spine_audit.db"

# Add as many servers as you need — they start concurrently
[[servers]]
name = "filesystem"
command = "npx"
args = ["-y", "@modelcontextprotocol/server-filesystem", "/path/to/project"]
timeout_seconds = 120

[[servers]]
name = "github"
command = "npx"
args = ["-y", "@modelcontextprotocol/server-github"]
env = { GITHUB_TOKEN = "ghp_..." }
timeout_seconds = 180

[[servers]]
name = "sqlite"
command = "uvx"
args = ["mcp-server-sqlite", "--db-path", "/path/to/database.db"]
timeout_seconds = 60

[[servers]]
name = "memory"
command = "npx"
args = ["-y", "@modelcontextprotocol/server-memory"]
timeout_seconds = 60

[[servers]]
name = "brave-search"
command = "node"
args = ["/path/to/node_modules/@modelcontextprotocol/server-brave-search/dist/index.js"]
env = { BRAVE_API_KEY = "your_key" }
timeout_seconds = 60

# Remote server via SSE
# [[servers]]
# name = "remote-tools"
# transport = "sse"
# url = "https://your-server.com/sse"
# headers = { Authorization = "Bearer token" }
# timeout_seconds = 30

# Semantic routing
[routing]
max_tools = 15
rerank = true

# Schema minification — 61% token savings at level 2
[minifier]
level = 2

# State guard — prevent context rot
[state_guard]
enabled = true
watch_paths = ["/path/to/project"]

# Human-in-the-loop for destructive tools
[[security.tools]]
pattern = "write_file"
action = "allow"
require_confirmation = true

[[security.tools]]
pattern = "write_query"
action = "allow"
require_confirmation = true

# Security
[security]
scrub_secrets_in_logs = true
audit_all_tool_calls = true
global_rate_limit = 120
per_tool_rate_limit = 60

[security.path]
allowed_roots = ["/path/to/project"]
denied_patterns = ["**/.env", "**/*.key", "**/*.pem"]

Security Model

Defense-in-depth — every layer assumes the others might fail.

Threat Mitigation
Prompt injection via tool args Input validation, tool name allowlists
Path traversal Symlink-aware jail to allowed_roots
Secret leakage Automatic scrubbing of AWS keys, tokens, private keys
Runaway agent loops Per-tool + global rate limiting
Command injection Command allowlist, shell metacharacter blocking
Denial of service Message size limits, circuit breakers
Sensitive file access Deny-list patterns for .env, .key, .pem, .ssh/
Tool abuse Policy-based blocking, audit logging, HITL confirmation
Log tampering HMAC fingerprints on every audit entry
Destructive operations require_confirmation pauses for user approval

Architecture

Client ◄──stdio──► MCP Spine ◄──stdio──► Filesystem Server
                       │      ◄──stdio──► GitHub Server
                       │      ◄──stdio──► SQLite Server
                       │      ◄──stdio──► Memory Server
                       │      ◄──stdio──► Brave Search
                       │      ◄──SSE────► Remote Server
                   ┌───┴───┐
                   │SecPol │  ← Rate limits, path jail, secret scrub
                   │Router │  ← Semantic routing (local embeddings)
                   │Minify │  ← Schema compression (61% savings)
                   │Guard  │  ← File state pinning (SHA-256)
                   │HITL   │  ← Human-in-the-loop confirmation
                   │Memory │  ← Tool output cache
                   └───────┘

Startup Sequence

  1. Instant handshake (~2ms) — Responds to initialize immediately
  2. Concurrent server startup — All servers connect in parallel via asyncio.gather
  3. Progressive readiness — Tools available as soon as any server connects
  4. Late server notificationtools/listChanged sent when slow servers finish
  5. Background ML loading — Semantic router activates silently when model loads

Windows Support

Battle-tested on Windows with specific hardening for:

  • MSIX sandbox paths for Claude Desktop config and logs
  • npx.cmd resolution via shutil.which()
  • Paths with spaces (C:\Users\John Doe\) and parentheses (C:\Program Files (x86)\)
  • PureWindowsPath for cross-platform basename extraction
  • Environment variable merging (config env extends, not replaces, system env)
  • UTF-8 encoding without BOM
  • Unbuffered stdout (-u flag) to prevent pipe hangs

Project Structure

mcp-spine/
├── pyproject.toml
├── spine/
│   ├── cli.py              # Click CLI (init, serve, verify, audit, dashboard, analytics, doctor)
│   ├── config.py           # TOML config loader with validation
│   ├── proxy.py            # Core proxy event loop
│   ├── protocol.py         # JSON-RPC message handling
│   ├── transport.py        # Server pool, circuit breakers, concurrent startup
│   ├── audit.py            # Structured logging + SQLite audit trail
│   ├── router.py           # Semantic routing (ChromaDB + sentence-transformers)
│   ├── minifier.py         # Schema pruning (4 aggression levels)
│   ├── state_guard.py      # File watcher + SHA-256 manifest + pin injection
│   ├── memory.py           # Tool output cache (ring buffer + dedup + TTL)
│   ├── dashboard.py        # Live TUI dashboard (Rich)
│   ├── sse_client.py       # SSE transport client for remote servers
│   └── security/
│       ├── secrets.py      # Credential detection & scrubbing
│       ├── paths.py        # Path traversal jail
│       ├── validation.py   # JSON-RPC message validation
│       ├── commands.py     # Server spawn guards
│       ├── rate_limit.py   # Sliding window throttling
│       ├── integrity.py    # SHA-256 + HMAC fingerprints
│       ├── env.py          # Fail-closed env var resolution
│       └── policy.py       # Declarative security policies
├── tests/
│   ├── test_security.py    # Security tests
│   ├── test_config.py      # Config validation tests
│   ├── test_minifier.py    # Schema minification tests
│   ├── test_state_guard.py # State guard tests
│   ├── test_proxy_features.py  # HITL, dashboard, analytics tests
│   └── test_memory.py      # Tool output memory tests
├── configs/
│   └── example.spine.toml  # Complete reference config
└── .github/
    └── workflows/
        └── ci.yml          # GitHub Actions: test + lint + publish

Tests

pytest tests/ -v

135+ tests covering security, config validation, schema minification, state guard, HITL policies, dashboard queries, analytics, tool memory, and Windows path edge cases.

CI runs on every push: Windows + Linux, Python 3.11/3.12/3.13.

License

MIT

推荐服务器

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选