e-Gov Law MCP Server

e-Gov Law MCP Server

Enables intelligent search and retrieval of Japanese legal statutes through the e-Gov API. Supports smart lookup of laws and articles with abbreviation recognition, batch processing, and multi-tier caching for high-performance legal research.

Category
Visit Server

README

e-Gov Law MCP Server v2 🏛️⚖️

FastMCP Python Test Coverage Windows License

Ultra Smart & Efficient - 日本政府e-Gov法令APIのための高性能Model Context Protocol (MCP) サーバー

🚀 v2の特徴: FastMCP準拠、Windows完全対応、58%コード削減、3層キャッシュ最適化、エンタープライズセキュリティ

✨ 主な特徴

🎯 インテリジェント法律検索

  • 16基本法直接マッピング: 六法 + 現代重要法への瞬時アクセス
  • 20略称自動変換: 道交法→道路交通法、労基法→労働基準法
  • 複雑パターン対応: 「第325条の3」「第9条第2項第1号」等
  • 4段階条文抽出: コンテンツスコアリングによる高精度抽出

ハイパフォーマンス

  • 3層LRUキャッシュ: 法律検索(2h)、法律内容(1h)、条文(30m)
  • 並行処理最適化: 50リクエスト/5.27秒の高速レスポンス
  • メモリ監視: psutil統合、自動クリーンアップ(512MB制限)
  • バッチ処理: 最大200件の一括検索対応

🛡️ エンタープライズセキュリティ

  • インジェクション防止: SQL、XSS、JNDI、コード実行を完全ブロック
  • 入力検証: 長さ制限、特殊文字フィルタリング
  • API保護: レート制限、403 Forbidden応答
  • エラーマスキング: 内部情報漏洩防止

🌐 クロスプラットフォーム

  • Windows完全対応: psutilオプション、パス互換性
  • FastMCP準拠: Context logging、ToolError例外、自動シリアライゼーション
  • 柔軟設定: YAML設定ファイル、プロンプト外部化

🛠️ 8つの高機能MCPツール

ツール 機能 特徴
find_law_article 条文検索 AI駆動パターンマッチング、漢数字対応
search_laws 法律検索 フィルタリング、ページネーション
search_laws_by_keyword キーワード検索 フルテキスト検索、ハイライト
get_law_content 法律全文取得 サイズ制限対応(800KB)、XML/JSON
batch_find_articles バッチ検索 最大200件、パフォーマンス統計
prefetch_common_laws キャッシュ最適化 頻出法律の事前読み込み
get_cache_stats 監視 リアルタイムパフォーマンス監視
clear_cache メンテナンス 粒度別キャッシュ管理

📊 対応法令

🚀 高速アクセス対応(直接マッピング済み)

六法

  • 憲法(昭和二十一年憲法)
  • 民法(明治二十九年法律第八十九号)
  • 刑法(明治四十年法律第四十五号)
  • 商法(昭和二十三年法律第二十五号)
  • 民事訴訟法(平成八年法律第百九号)
  • 刑事訴訟法(昭和二十三年法律第百三十一号)

現代重要法

  • 会社法、労働基準法、所得税法、法人税法
  • 著作権法、特許法、道路交通法、建築基準法
  • 独占禁止法、消費者契約法、特定受託事業者取引適正化法

🔍 略称検索対応

道交法 → 道路交通法    労基法 → 労働基準法
独禁法 → 独占禁止法    消契法 → 消費者契約法
著作権 → 著作権法      特許 → 特許法
税法 → 所得税法        労働法 → 労働基準法

📈 実証された性能

🏆 テスト結果(40+テスト、65%カバレッジ)

  • 機能テスト: 全ツール、エッジケース、境界値
  • セキュリティテスト: インジェクション攻撃、不正ペイロード
  • パフォーマンステスト: 並行性50/50成功、5.27秒
  • 統合テスト: FastMCP機能、Windows互換性

📊 パフォーマンス指標

  • 並行処理: 50リクエスト同時処理 → 100%成功
  • キャッシュヒット率: 主要法律で90%以上
  • レスポンス時間: 直接マッピング法律 < 1秒
  • メモリ効率: 512MB制限内で安定動作

🚀 クイックスタート

前提条件

uvをインストール:

# macOS/Linux
curl -LsSf https://astral.sh/uv/install.sh | sh

# Windows
powershell -c "irm https://astral.sh/uv/install.ps1 | iex"

インストール

# リポジトリをクローン
git clone https://github.com/ryoooo/e-gov-law-mcp.git
cd e-gov-law-mcp

# 依存関係をインストール
uv sync

# パフォーマンス監視を有効にする場合(オプション)
uv add psutil

Claude Desktop設定

設定ファイルの場所:

  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Linux: ~/.config/claude/claude_desktop_config.json

設定例:

{
  "mcpServers": {
    "e-gov-law": {
      "command": "uv",
      "args": [
        "run",
        "--directory",
        "/path/to/e-gov-law-mcp",
        "python",
        "run_server.py"
      ]
    }
  }
}

💡 使用例

Claude Desktopでの基本使用

民法192条について詳しく教えて
憲法第9条第2項の条文と解釈を知りたい
会社法325条の3の株主総会決議について
労基法の有給休暇の規定を調べて
道交法の飲酒運転の罰則は?

プログラム使用例

import asyncio
from fastmcp import Client

async def search_example():
    async with Client(["uv", "run", "python", "src/mcp_server.py"]) as client:
        # 民法192条を検索
        result = await client.call_tool("find_law_article", {
            "law_name": "民法",
            "article_number": "192"
        })
        print(result[0].text)

        # バッチ検索
        batch_data = json.dumps([
            {"law": "民法", "article": "192"},
            {"law": "憲法", "article": "9"}
        ])
        batch_result = await client.call_tool("batch_find_articles", {
            "law_article_pairs": batch_data
        })

asyncio.run(search_example())

🔧 開発とテスト

開発環境セットアップ

git clone https://github.com/ryoooo/e-gov-law-mcp.git
cd e-gov-law-mcp
uv sync --dev

テスト実行

# 全テスト実行(40+テスト)
uv run pytest

# カバレッジ付きテスト
uv run pytest --cov=src

# セキュリティテスト
uv run pytest test_comprehensive_ultra.py::TestSecurityAndRobustness -v

# パフォーマンステスト
uv run pytest test_comprehensive_ultra.py::TestPerformanceAndScalability -v

# FastMCP統合テスト
uv run pytest test_fastmcp_integration.py -v

コード品質

# フォーマット
uv run black src/ tests/

# リント
uv run ruff check src/ tests/

# 型チェック
uv run mypy src/

⚙️ 設定

環境変数

# e-Gov API設定
export EGOV_API_URL="https://laws.e-gov.go.jp/api/2"
export EGOV_API_TOKEN=""  # 通常は不要

# サーバー設定
export MCP_SERVER_NAME="e-Gov Law Server v2"
export LAW_CONFIG_PATH="config/laws.yaml"

設定ファイル

  • config/laws.yaml: 法律マッピング、略称定義
  • prompts/legal_analysis.md: 法的分析指導プロンプト

🏗️ アーキテクチャ

e-Gov Law MCP Server v2
├── 🎯 FastMCP Core (Context logging, ToolError, Auto-serialization)
├── 🔍 Smart Law Lookup (16 basic laws + 20 aliases)
├── ⚡ 3-Tier Cache System (LRU + TTL + Memory monitoring)
├── 🛡️ Security Layer (Injection prevention, Input validation)
├── 🌐 Cross-Platform Support (Windows/Linux/macOS)
└── 📊 Performance Monitoring (Real-time stats, Batch optimization)

📝 API詳細

find_law_article

最も重要なツール - 高精度条文検索

await client.call_tool("find_law_article", {
    "law_name": "民法",           # 法律名(略称可)
    "article_number": "325条の3"  # 条文番号(複雑パターン対応)
})

対応パターン例:

  • "192" → 第192条
  • "第192条" → 第192条
  • "325条の3" → 第325条の3
  • "第9条第2項" → 第9条第2項
  • "第9条第2項第1号" → 第9条第2項第1号

batch_find_articles

高速バッチ処理 - 最大200件の一括検索

batch_data = json.dumps([
    {"law": "民法", "article": "192"},
    {"law": "憲法", "article": "9"},
    {"law": "会社法", "article": "423"}
])

await client.call_tool("batch_find_articles", {
    "law_article_pairs": batch_data
})

🔧 トラブルシューティング

Windows環境トラブルシューティング

問題: "No module named 'yaml'" エラー

# 解決方法1: uv syncで依存関係をインストール
cd C:\path\to\e-gov-law-mcp
uv sync

# 解決方法2: 手動インストール
pip install PyYAML httpx fastmcp

問題: "No module named 'psutil'" 警告

# psutilはオプションのパフォーマンス監視ライブラリ
# インストールしなくても動作します

# パフォーマンス監視を有効にしたい場合
uv add psutil
# または
pip install psutil

問題: FastMCPコマンドエラー

# Claude Desktop設定でrun_server.pyを使用
# 依存関係チェック機能付き
"command": "uv",
"args": [
  "run",
  "--directory",
  "C:\\path\\to\\e-gov-law-mcp",
  "python",
  "run_server.py"
]

その他のWindows問題

# パス区切り文字 → pathlibで自動解決
# UTF-8エンコーディング → 明示的指定済み
# メモリ監視 → psutilなしでも動作

パフォーマンス最適化

# キャッシュ統計確認
await client.call_tool("get_cache_stats", {})

# 頻出法律をプリフェッチ
await client.call_tool("prefetch_common_laws", {})

# キャッシュクリア(メモリ不足時)
await client.call_tool("clear_cache", {"cache_type": "all"})

📚 参考リンク

🤝 貢献

  1. リポジトリをフォーク
  2. 機能ブランチを作成: git checkout -b feature/amazing-feature
  3. 変更をコミット: git commit -m 'feat: Add amazing feature'
  4. ブランチにプッシュ: git push origin feature/amazing-feature
  5. プルリクエストを作成

貢献ガイドライン

  • テストカバレッジを維持(65%以上)
  • セキュリティテストを必須追加
  • FastMCP仕様準拠を確認
  • Windows互換性をテスト

📄 ライセンス

MIT License - 詳細は LICENSE ファイルを参照

🙏 謝辞


🚀 Ultra Smart & Efficient e-Gov Law MCP Server v2
日本法令検索の新しいスタンダード

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured