MCP Spine
MCP Spine
コンテキスト最小化 & 状態ガード — トークンの無駄を削減し、ツールの消失を防ぎ、コンテキストの劣化を解消するローカルファーストのMCPミドルウェアプロキシ。
MCP Spineは、LLMクライアント(Claude Desktopなど)とMCPサーバーの間に位置し、セキュリティ強化、インテリジェントなツールルーティング、スキーマ圧縮、ファイル状態追跡を単一のプロキシ経由で提供します。
なぜ必要なのか
MCPツールを使用するLLMエージェントは、以下の3つの問題に直面しています。
トークンの無駄 — ツールスキーマはリクエストごとに数千トークンを消費します。40以上のツールを読み込むと、会話が始まる前にJSONスキーマでコンテキストを浪費してしまいます。
コンテキストの劣化 — 長時間のセッションでは、LLMが以前に記憶した古いバージョンのファイルを編集しようとし、最新の変更を上書きしてしまうことがあります。
セキュリティ境界の欠如 — MCPサーバーはフルアクセス権限で実行されます。LLMとツールの間に監査証跡、レート制限、シークレットのスクラブ(削除)機能がありません。
MCP Spineはこれら3つの問題をすべて解決します。
インストール
pip install mcp-spine
# With semantic routing (optional)
pip install mcp-spine[ml]クイックスタート
# 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.tomlClaude Desktopとの統合
個別のMCPサーバーエントリをすべて削除し、単一のSpineエントリに置き換えます:
{
"mcpServers": {
"spine": {
"command": "python",
"args": ["-u", "-m", "spine.cli", "serve", "--config", "/path/to/spine.toml"],
"cwd": "/path/to/mcp-spine"
}
}
}-uフラグはstdoutをバッファリングしないようにし、Windowsでのパイプのハングを防ぎます。
機能
ステージ1:セキュリティプロキシ
JSON-RPCメッセージの検証とサニタイズ
シークレットのスクラブ(AWSキー、GitHubトークン、ベアラートークン、秘密鍵、接続文字列)
スライディングウィンドウによるツール単位およびグローバルなレート制限
シンボリックリンクを考慮したJailによるパス・トラバーサル防止
サーバー起動時のコマンドインジェクションガード
HMACフィンガープリント付きSQLite監査証跡
障害サーバーに対するサーキットブレーカー
設定による宣言的なセキュリティポリシー
ステージ2:セマンティックルーター
all-MiniLM-L6-v2を使用したローカルベクトル埋め込み(API呼び出しなし、データはマシン外に出ません)ChromaDBによるツールインデックス作成
クエリ時のルーティング:最も関連性の高いツールのみがLLMに送信されます
明示的なコンテキスト切り替えのためのメタツール
spine_set_contextキーワードの重複 + 最近の利用状況に基づくリランキング
バックグラウンドでのモデル読み込み — ツールは即座に使用可能で、ルーティングは準備ができ次第有効になります
ステージ3:スキーマの最小化
4段階の圧縮レベル(0=オフ、1=軽量、2=標準、3=アグレッシブ)
レベル2ではツールスキーマのトークンを61%削減可能
$schema、タイトル、additionalProperties、パラメータの説明、デフォルト値を削除必須フィールドと型情報はすべて保持
ステージ4:状態ガード
watchfilesによるプロジェクトファイルの監視単調増加するバージョン管理を備えたSHA-256マニフェストの維持
ツール応答へのコンパクトな状態ピンの挿入
LLMによる古いファイルバージョンの編集を防止
ヒューマン・イン・ザ・ループ (HITL)
破壊的なツールに対する
require_confirmationポリシーフラグSpineが呼び出しをインターセプトし、引数を表示してユーザーの承認を待機
LLMが決定を中継するためのメタツール
spine_confirm/spine_denyグロブパターンによるツール単位の粒度設定
ツール出力メモリ
直近50件のツール結果を保持するリングバッファキャッシュ
ツール名 + 引数ハッシュによる重複排除
TTL有効期限(デフォルト1時間)
キャッシュされた結果をクエリするためのメタツール
spine_recallセマンティックルーターがターン間でツールを切り替える際のコンテキスト喪失を防止
SSEトランスポート
ローカルのstdioサーバーに加え、HTTP/SSE経由でリモートのMCPサーバーに接続
外部依存関係なし(標準ライブラリのurllibを使用)
認証用のカスタムヘッダーをサポート
診断
# 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設定例
[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"]セキュリティモデル
多層防御 — 各レイヤーは他のレイヤーが失敗する可能性があることを前提としています。
脅威 | 緩和策 |
ツール引数経由のプロンプトインジェクション | 入力検証、ツール名の許可リスト |
パス・トラバーサル |
|
シークレットの漏洩 | AWSキー、トークン、秘密鍵の自動スクラブ |
エージェントの暴走ループ | ツール単位およびグローバルなレート制限 |
コマンドインジェクション | コマンド許可リスト、シェルメタ文字のブロック |
サービス拒否 (DoS) | メッセージサイズ制限、サーキットブレーカー |
機密ファイルへのアクセス |
|
ツールの悪用 | ポリシーベースのブロック、監査ログ、HITL承認 |
ログの改ざん | すべての監査エントリへのHMACフィンガープリント |
破壊的な操作 |
|
アーキテクチャ
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
└───────┘起動シーケンス
即時ハンドシェイク (~2ms) —
initializeに即座に応答並列サーバー起動 — すべてのサーバーが
asyncio.gatherで並列接続段階的な準備完了 — サーバーが接続され次第、ツールが利用可能に
遅延サーバー通知 — 低速なサーバーの準備が完了した時点で
tools/listChangedを送信バックグラウンドML読み込み — モデルの読み込み完了時にセマンティックルーターが静かに有効化
Windowsサポート
以下の点について強化を行い、Windowsで実戦テスト済みです:
Claude Desktopの設定およびログ用のMSIXサンドボックスパス
shutil.which()によるnpx.cmdの解決スペース (
C:\Users\John Doe\) や括弧 (C:\Program Files (x86)\) を含むパスクロスプラットフォームでのベース名抽出のための
PureWindowsPath環境変数のマージ(設定環境変数はシステム環境変数を置き換えるのではなく拡張)
BOMなしのUTF-8エンコーディング
パイプのハングを防ぐためのバッファなしstdout (
-uフラグ)
プロジェクト構造
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テスト
pytest tests/ -vセキュリティ、設定検証、スキーマ最小化、状態ガード、HITLポリシー、ダッシュボードクエリ、分析、ツールメモリ、Windowsパスの境界ケースを網羅する135以上のテスト。
CIはプッシュごとに実行:Windows + Linux, Python 3.11/3.12/3.13。
ライセンス
MIT
Latest Blog Posts
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/Donnyb369/mcp-spine'
If you have feedback or need assistance with the MCP directory API, please join our Discord server