MCP差異ログ
会話構造における統計的な変動を検出し、異常なイベントをSQLiteデータベースに記録するエージェントツールです。モデルコンテキストプロトコル(MCP)を使用して構築されたこのシステムは、Claude Desktopやその他のMCP互換クライアントで使用できるように設計されています。
要件
- Python ≥3.10
- MCP ≥1.2.0
- SQLite3
- UV (Python パッケージインストーラーおよび環境マネージャー)
クイックスタート
# Clone and install
git clone https://github.com/truaxki/mcp-variance-log.git
cd mcp-variance-log
uv pip install -e .
Claude Desktop 構成 (Windows の場合は%APPDATA%\Claude\claude_desktop_config.json
) に追加します。
{
"mcpServers": {
"mcp-variance-log": {
"command": "uv",
"args": [
"--directory",
"C:\\Users\\username\\source\\repos\\mcp-variance-log", # Update this path
"run",
"mcp-variance-log"
]
}
}
}
Claude Desktop の設定に追加:
Automatic Logging Process:
- Silently monitor each interaction
- When MEDIUM or LOW probability events occur, use this tool to log them
- Each log includes context and reasoning
- Logging happens without disrupting conversation flow
使用法
自動ログの例
prompt: "What if I told you I could lift 1000 lbs?"
{
`user_id`: `user_1`,
`reasoning`: `Claim of 1000 lb lift capability is highly unusual as it approaches world record territory, warranting logging as a MEDIUM probability event`,
`session_id`: `session_1`,
`context_summary`: `User made an extremely improbable claim about personal strength capabilities`,
`message_content`: `What if i told you i could lift 1000 lbs?`,
`interaction_type`: `claim_verification`,
`response_content`: `That would be extremely unlikely. The current world record for weight lifted by a human (deadlift) is 1,104.5 lbs, set by Hafthor Björnsson in 2020 under very specific conditions. Only a handful of people in history have lifted close to 1,000 lbs.`,
`probability_class`: `MEDIUM`
}
prompt: "What if I told you I'm a Data Scientist that can lift 1000 pounds?"
{
`user_id`: `user_1`,
`reasoning`: `User's follow-up combines unlikely strength claim with unrelated professional credential, suggesting potential pattern of unusual claims`,
`session_id`: `session_1`,
`context_summary`: `User added data scientist credential to previous improbable strength claim`,
`message_content`: `what if i told you I'm a data scientist that can lift 1000 pounds?`,
`interaction_type`: `claim_verification`,
`response_content`: `Your professional background as a data scientist doesn't make the 1000-pound lift claim more plausible. Such a lift would still be near the all-time world record of 1,104.5 lbs.`,
`probability_class`: `LOW`
}
データフレームビュー
prompt: "Read-logs from this morning"
ID | Time | Prob | Type | Context
------------------------------------------------------------------------------------------
29 | 01-24 17:57 | LOW | claim_ | User added data scientist credential to pr...
28 | 01-24 17:56 | MEDIUM | claim_ | User made an extremely improbable claim ab...
テキスト2 SQL
prompt: "Can you search the logs for entry 29?"
[{'log_id': 29, 'timestamp': '2025-01-24 17:57:07', 'session_id': 'session_1', 'user_id': 'user_1', 'interaction_type': 'claim_verification', 'probability_class': 'LOW', 'message_content': "what if i told you I'm a data scientist that can lift 1000 pounds?", 'response_content': "Your professional background as a data scientist doesn't make the 1000-pound lift claim more plausible. Such a lift would still be near the all-time world record of 1,104.5 lbs.", 'context_summary': 'User added data scientist credential to previous improbable strength claim', 'reasoning': "User's follow-up combines unlikely strength claim with unrelated professional credential, suggesting potential pattern of unusual claims"}]
詳細なインストール
- Python 3.10+ と UV がインストールされていることを確認してください。
次のいずれかの方法で UV をインストールします。
# Using pip (recommended for Windows)
pip install uv
# Using installation script (Linux/MacOS)
curl -LsSf https://astral.sh/uv/install.sh | sh
- クローンしてインストール:
git clone https://github.com/truaxki/mcp-variance-log.git
cd mcp-variance-log
uv pip install -e .
- Claude デスクトップを設定します。
claude_desktop_config.json
に追加:
{
"mcpServers": {
"mcp-variance-log": {
"command": "uv",
"args": [
"--directory",
"PATH_TO_REPO/mcp-variance-log",
"run",
"mcp-variance-log"
]
}
}
}
設定場所:
- Windows:
%APPDATA%\Claude\claude_desktop_config.json
- MacOS:
~/Library/Application Support/Claude/claude_desktop_config.json
- Linux:
~/.config/Claude/claude_desktop_config.json
ツール
監視
log-query
: 会話パターンを追跡する- 高: 一般的なインタラクション(ログに記録されない)
- 中: 異常なパターン(ログに記録)
- 低: 重大なイベント(優先度が記録される)
クエリ
read-logs
: フィルタリングしてログを表示するread_query
: SELECTクエリを実行するwrite_query
: INSERT/UPDATE/DELETEを実行するcreate_table
: テーブルを作成するlist_tables
: すべてのテーブルを表示describe_table
: テーブル構造を表示する
インストールを基準としたdata/varlog.db
にあります。
スキーマ
CREATE TABLE chat_monitoring (
log_id INTEGER PRIMARY KEY AUTOINCREMENT,
timestamp DATETIME DEFAULT CURRENT_TIMESTAMP,
session_id TEXT NOT NULL,
user_id TEXT NOT NULL,
interaction_type TEXT NOT NULL,
probability_class TEXT CHECK(probability_class IN ('HIGH', 'MEDIUM', 'LOW')),
message_content TEXT NOT NULL,
response_content TEXT NOT NULL,
context_summary TEXT,
reasoning TEXT
);
トラブルシューティング
- データベースアクセス
- エラー:「データベースへの接続に失敗しました」
- ファイルの権限を確認する
- 設定内のパスを確認する
/data
ディレクトリが存在することを確認する
- インストールの問題
- エラー:「'mcp' という名前のモジュールがありません」
- 実行:
uv pip install mcp>=1.2.0
- エラー:「UV コマンドが見つかりません」
- UV をインストールします:
curl -LsSf https://astral.sh/uv/install.sh | sh
- 構成
- エラー:「MCP サーバーの起動に失敗しました」
- config.json の構文を確認する
- パス区切り文字を確認する(Windowsでは\を使用)
- UVがシステムPATHにあることを確認する
貢献
- リポジトリをフォークする
- 機能ブランチを作成する
- プルリクエストを送信する
ライセンス
マサチューセッツ工科大学
サポート
問題: GitHub の問題