Skip to main content
Glama
HiroakiKatoh

legal-impact-mapper

by HiroakiKatoh
README.md
# Legal Impact Mapper (LIM)

**法律文書の変更影響シミュレーター** - 1行の変更がどこまで影響するかを即座に可視化するMCPサーバー

## 概要

Legal Impact Mapper は、弁護士・パラリーガル向けの MCP (Model Context Protocol) サーバーです。Claude Code、Cursor などの AI エディタから呼び出し、法律文書の1箇所を変更した際の影響範囲を構造的に分析します。

**このツールがやること:**
- 契約書・法律文書をノード(事実・義務・条件等)とエッジ(依存関係)のグラフに構造化
- ノードの変更を検出し、依存グラフを辿って影響範囲を自動伝播
- 各影響ノードへの影響理由とリスクレベルを提示

**このツールがやらないこと:**
- 文書生成
- 要約
- 法的助言

## インストール

```bash
npm install legal-impact-mapper
```

または、ローカルでビルド:

```bash
git clone https://github.com/HiroakiKatoh/legal-impact-mapper.git
cd legal-impact-mapper
npm install
npm run build
```

## 設定

### 環境変数

| 変数名 | 必須 | 説明 |
|--------|------|------|
| `ANTHROPIC_API_KEY` | Yes | Anthropic API キー |
| `LIM_MODEL` | No | 使用するモデル(デフォルト: `claude-sonnet-4-20250514`) |

### Claude Desktop での設定

`claude_desktop_config.json` に以下を追加:

```json
{
  "mcpServers": {
    "legal-impact-mapper": {
      "command": "node",
      "args": ["path/to/Legal_Impact_Mapper/dist/server.js"],
      "env": {
        "ANTHROPIC_API_KEY": "sk-ant-xxxxx"
      }
    }
  }
}
```

### Cursor での設定

`.cursor/mcp.json` に以下を追加:

```json
{
  "mcpServers": {
    "legal-impact-mapper": {
      "command": "node",
      "args": ["path/to/Legal_Impact_Mapper/dist/server.js"],
      "env": {
        "ANTHROPIC_API_KEY": "sk-ant-xxxxx"
      }
    }
  }
}
```

## 提供ツール

### 1. `extract_fact_graph`

テキストから事実分類ノードと依存関係グラフを抽出します。

**入力:**
```json
{
  "text": "第5条(支払条件)\n甲は乙に対し、本業務の対価として月額50万円を..."
}
```

**出力:**
```json
{
  "nodes": [
    {
      "id": "n1",
      "type": "obligation",
      "text": "甲は乙に月額50万円を支払う",
      "confidence": 0.95
    },
    {
      "id": "n2",
      "type": "timing",
      "text": "支払期限:翌月末",
      "confidence": 0.9
    }
  ],
  "edges": [
    { "from": "n2", "to": "n1", "type": "enables" }
  ]
}
```

### 2. `update_fact_classification`

ノードのテキストや分類を変更し、差分情報を返します。

**入力:**
```json
{
  "graph": { "nodes": [...], "edges": [...] },
  "node_id": "n2",
  "new_text": "支払期限:翌月10日",
  "mark_verified": true
}
```

**出力:**
```json
{
  "graph": { "nodes": [...], "edges": [...] },
  "changed_node_ids": ["n2"],
  "diff_summary": {
    "modified_nodes": 1,
    "details": [
      {
        "id": "n2",
        "old_text": "支払期限:翌月末",
        "new_text": "支払期限:翌月10日"
      }
    ]
  }
}
```

### 3. `analyze_impact`

変更ノードから影響範囲を分析し、理由とリスクレベルを返します。

**入力:**
```json
{
  "graph": { "nodes": [...], "edges": [...] },
  "changed_node_ids": ["n2"]
}
```

**出力:**
```json
{
  "changed_node_ids": ["n2"],
  "affected_node_ids": ["n1"],
  "directly_affected": ["n1"],
  "indirectly_affected": [],
  "explanations": [
    {
      "node_id": "n1",
      "node_text": "甲は乙に月額50万円を支払う",
      "reason": "支払タイミングが短縮されるため甲の資金負担に影響",
      "impact_level": "direct"
    }
  ],
  "risk_level": "medium",
  "warning": "この変更は支払条件だけでなく契約全体の資金設計に影響します"
}
```

## 使い方の流れ

```
Step 1: extract_fact_graph(text)     → テキストをグラフ化
Step 2: update_fact_classification() → ノードを変更
Step 3: analyze_impact()             → 影響範囲を分析
```

### 実践例:業務委託契約の支払期限変更

1. **グラフ化**: 契約書テキストを `extract_fact_graph` に渡す
2. **変更**: 「支払期限:翌月末」→「支払期限:翌月10日」に `update_fact_classification` で変更
3. **影響分析**: `analyze_impact` で影響範囲を確認
   - 直接影響:支払義務のキャッシュフロー変化
   - 間接影響:支払留保条項の運用負荷増加
   - 潜在影響:契約バランスの再交渉リスク

## 主要機能

### 世界線分岐(group_id)

同一事実に対する複数の解釈を `group_id` で管理し、法的評価の分岐を表現します。

```json
{
  "id": "n6a", "type": "interpretation",
  "text": "アルバイトとしての就労",
  "group_id": "employment_type"
},
{
  "id": "n6b", "type": "interpretation",
  "text": "正社員としての雇用",
  "group_id": "employment_type"
}
```

### 弁護士修正保護(user_verified)

弁護士が修正したノードは `user_verified: true` となり、以降のLLM再生成から保護されます。

## 開発

```bash
npm install          # 依存パッケージのインストール
npm run build        # TypeScriptのビルド
npm test             # テストの実行
npm run dev          # 開発モード(watchビルド)
```

## ライセンス

ISC

TDQS

A4.6/5.0

Scored across 3 tools

Disambiguation5/5

Each tool serves a distinct, non-overlapping purpose: extract_fact_graph creates the graph, update_fact_classification modifies a node, and analyze_impact computes the ripple effects. An agent can clearly distinguish when to use each tool.

Naming Consistency5/5

All tool names follow a consistent verb_noun pattern (analyze_impact, extract_fact_graph, update_fact_classification) using snake_case and clear action verbs, making them predictable and easy to understand.

Tool Count4/5

With 3 tools, the set is minimal but covers the essential workflow for the server's purpose. Each tool earns its place, though the count is slightly low for a broader legal document analysis platform.

Completeness3/5

The tools cover the core workflow (create, update, analyze), but lack features like reading the graph directly, deleting nodes, or managing multiple documents. Minor gaps exist that an agent may need to work around.

Maintenance

ActivityInactive
ResponsivenessNo issues