Skip to main content

MCP Server for MLIT (Ministry of Land, Infrastructure, Transport and Tourism) Real Estate Information

Project description

MLIT Real Estate MCP Server

日本の国土交通省「不動産情報ライブラリ」API を利用し、不動産取引価格・地価公示・都市計画などの情報を LLM (Large Language Model) エージェントに提供する MCP (Model Context Protocol) サーバーです。

特徴

  • MCP 対応: Cursor, Claude Desktop などの MCP クライアントから直接利用可能。
  • キャッシュ機能: API レスポンスをキャッシュし、API 制限や待機時間を緩和 (InMemory & File-based)。
  • GeoJSON/MVT 対応: 大規模な地理データは MCP の resource:// として効率的に受け渡し。
  • 堅牢性: API エラー時の自動リトライ、レート制限への対応。
  • 統計情報: キャッシュヒット率やエラー数をモニター可能。

必要なもの

インストール

  1. リポジトリをクローン:
    git clone https://github.com/takurot/real-estate-mcp.git
    cd real-estate-mcp
    

PyPI からインストールする場合 (推奨)

pip install mlit-mcp

ソースコードからインストールする場合

  1. 依存パッケージのインストール:

    python -m venv .venv
    source .venv/bin/activate  # Windows: .venv\Scripts\activate
    pip install -r requirements.txt
    
  2. 環境変数の設定: .env ファイルを作成し、API キーを設定します。

    MLIT_API_KEY=your_api_key_here
    

使い方 (MCP サーバーとして実行)

1. MCP サーバーの設定方法

以下の手順で MCP クライアントから本サーバーを利用できます。

  1. 仮想環境の Python パスを確認します。
pwd  # リポジトリ直下の絶対パスを確認
echo "$(pwd)/.venv/bin/python"  # macOS/Linux の例
# Windows の例: .venv\\Scripts\\python.exe
  1. API キーを環境変数で渡す設定にします(.env も読み込まれます)。

  2. MCP クライアントの設定ファイルに以下を追加します(Claude / Cursor の例)。

MCP クライアントの設定ファイル (例: claude_desktop_config.json や Cursor の MCP 設定) に以下を追加します。

{
  "mcpServers": {
    "mlit": {
      "command": "/absolute/path/to/real-estate-mcp/.venv/bin/python",
      "args": ["-m", "mlit_mcp"],
      "cwd": "/absolute/path/to/real-estate-mcp",
      "env": {
        "MLIT_API_KEY": "your_api_key_here"
      }
    }
  }
}

補足:

  • Claude Desktop の設定ファイルパス(macOS 例): ~/Library/Application Support/Claude/claude_desktop_config.json
  • Cursor はアプリ内の MCP 設定から mcpServers を追加してください(設定 UI/ドキュメントに準拠)。

2. コマンドラインでの動作確認

サーバーは標準入出力 (stdio) を使用します。まず依存関係を全てインストールしてください:

pip install -r requirements.txt

Cursor / Claude の設定に記載した commandcwd で、同じ内容を手動で確認する場合は、リポジトリ直下で次を実行します。

./.venv/bin/python -m mlit_mcp

何も表示されず待機状態になりますが正常です(MCP クライアントからの接続を待っています)。

3. HTTP サーバーでのローカル確認(任意)

FastAPI ベースの HTTP アダプターで簡易確認ができます。

uvicorn mlit_mcp.server:app --reload

ブラウザで http://127.0.0.1:8000/docs を開くと OpenAPI ドキュメントが表示されます。

利用可能なツール一覧

ツール名 説明 引数例
mlit.list_municipalities 指定した都道府県の市区町村コード一覧を取得 {"prefectureCode": "13"}
mlit.fetch_transactions 不動産取引価格情報の検索・取得 (期間・場所指定) {"year_from": 2020, "year_to": 2020, "pref_code": "13", "city_code": "13101"}
mlit.fetch_transaction_points 取引情報のポイントデータを GeoJSON リソースとして取得 {"year_from": 2020, ...}
mlit.fetch_land_price_points 地価公示・地価調査ポイントの取得 {"zoom": 12, "x": 3639, "y": 1612, "year": 2023}
mlit.fetch_urban_planning_zones 都市計画区域・用途地域などの取得 {"zoom": 12, "x": ..., "y": ...}
mlit.fetch_school_districts 学区データの取得 (Vector Tile -> Base64 MVT) {"zoom": 12, "x": ..., "y": ...}
mlit.get_server_stats サーバーの統計情報 (リクエスト数, キャッシュヒット率など) を取得 {}

Note: ポイント系データツール (fetch_*_points) はレスポンスが大きいため、MCP の resource URI を返却します。クライアントは read_resource で別途データを取得できます。

開発・テスト

テスト実行

# 全テスト
pytest

# カバレッジ
pytest --cov=mlit_mcp

コード品質チェック

# フォーマット
black .
# Lint
flake8 mlit_mcp tests
# 型チェック
mypy mlit_mcp

ディレクトリ構成

  • mlit_mcp/: サーバー本体コード
    • tools/: 各 MCP ツールの実装
  • tests/: テストコード
    • e2e/: エンドツーエンドテスト

ライセンス

MIT License

メンテナ向けメモ

開発規約・構成・テスト方針の詳細は AGENTS.md を参照してください。

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mlit_mcp-0.1.0.tar.gz (251.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mlit_mcp-0.1.0-py3-none-any.whl (66.4 kB view details)

Uploaded Python 3

File details

Details for the file mlit_mcp-0.1.0.tar.gz.

File metadata

  • Download URL: mlit_mcp-0.1.0.tar.gz
  • Upload date:
  • Size: 251.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for mlit_mcp-0.1.0.tar.gz
Algorithm Hash digest
SHA256 a9b8f14885c8a14a3bac1fac5173ecc3bedd2dabb726b6f7f72c6b4427ff63e9
MD5 f3dee1d35e0b431f2813f470a7ab7f59
BLAKE2b-256 1d243652f015fab331f76cab64d22de51182c024f91487d0f6a9940548d415f9

See more details on using hashes here.

File details

Details for the file mlit_mcp-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: mlit_mcp-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 66.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for mlit_mcp-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cfb511c9c937033dc9a9605258834e9103197245027765f06917d782a412a705
MD5 a2ffc96ffe46fb183f51059e39f532d3
BLAKE2b-256 aa5f0884ab4f6453ab3dc09da3c06bc4671c823f55409c59de58c631fb1aebcf

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page