mcpField
M
MedifinderMCP Server

MedifinderMCP Server

ローカル
github.com/MediFinderBotコミュニケーション084 週間前に更新

MedifinderMCP Server について

MedifinderMCP Serverは、ClaudeなどのAIアシスタントから医薬品在庫を検索・分析するためのサーバーです。MCPのツール、リソース、プロンプトを通じて、医薬品や施設、在庫、地域別統計を照会できます。

主な機能

  1. 01医薬品名または場所で検索
  2. 02在庫と取扱施設の照会
  3. 03地域別在庫統計の表示
  4. 04データベース接続の診断
  5. 05医薬品照会用プロンプトとリソース

活用シーン

  1. 01地域内で特定の医薬品を扱う施設の検索
  2. 02医薬品在庫と地域統計の確認
  3. 03データベース接続やテーブルの問題の診断

MCP 対応

MCPサーバーは、医薬品検索・在庫・統計のツールと、製品・在庫・場所・統計のリソースを公開します。検索や分析に使うプロンプトも含みます。

設定

ローカルサーバーの設定はどのクライアントでも共通です。コピーしてクライアントの MCP 設定ファイルに貼り付けてください。

インストール方法は未掲載です

このサーバーのパッケージやリモートエンドポイントはまだ取得できていません。プロジェクトの README の手順に従ってください。

リポジトリ

ツール

ツール一覧はまだ取得されていません

ローカルサーバーのツールはマシン上で起動して初めて取得できます。メンテナーはまだツール一覧を提供していません。

詳細

MedifinderMCP サーバー

Claude のような AI アシスタントと連携する、医薬品在庫の照会用 MCP(Model Context Protocol)サーバーです。

概要

MedifinderMCP サーバーは、Model Context Protocol(MCP)を通じて医薬品在庫データベースを照会するためのツールとリソースを提供します。AI アシスタントやその他のクライアントは、次のことができます。

  • 医薬品を名称または場所で検索する
  • 各医療機関での医薬品の在庫状況を確認する
  • 特定の医薬品の在庫情報を取得する
  • 地域別の医薬品在庫状況の統計を確認する
  • 医療システム全体の在庫状況を分析する

データベーススキーマ

Region
  - region_id (PK)
  - name
  - code
  - created_at
  - updated_at

MedicalCenter
  - center_id (PK)
  - code
  - name
  - region_id (FK -> Region)
  - category
  - reporter_name
  - institution_type
  - reporter_type
  - address
  - latitude
  - longitude
  - created_at
  - updated_at

ProductType
  - type_id (PK)
  - code
  - name
  - description
  - created_at
  - updated_at

Product
  - product_id (PK)
  - code
  - name
  - type_id (FK -> ProductType)
  - description
  - dosage_form
  - strength
  - created_at
  - updated_at

Inventory
  - inventory_id (PK)
  - center_id (FK -> MedicalCenter)
  - product_id (FK -> Product)
  - current_stock
  - avg_monthly_consumption
  - accumulated_consumption_4m
  - measurement
  - last_month_consumption
  - last_month_stock
  - status_indicator
  - cpma_12_months_ago
  - cpma_24_months_ago
  - cpma_36_months_ago
  - accumulated_consumption_12m
  - report_date
  - status
  - created_at
  - updated_at

User
  - user_id (PK)
  - phone_number
  - name
  - preferred_location
  - created_at
  - updated_at

SearchHistory
  - search_id (PK)
  - user_id (FK -> User)
  - product_query
  - location_query
  - search_radius
  - results_count
  - created_at

プロジェクト構成

medifinder-mcp/
├── app/
│   ├── __init__.py
│   ├── config.py            # Configuration management
│   ├── db/
│   │   ├── __init__.py
│   │   ├── connection.py    # Database connection handling
│   │   └── queries.py       # SQL queries
│   ├── models/
│   │   ├── __init__.py
│   │   ├── base.py          # Base model with timestamp fields
│   │   ├── region.py        # Region model
│   │   ├── medical_center.py # Medical center model
│   │   ├── product_type.py  # Product type model
│   │   ├── product.py       # Product model
│   │   ├── inventory.py     # Inventory model
│   │   ├── user.py          # User model
│   │   └── search_history.py # Search history model
│   ├── mcp/
│   │   ├── __init__.py
│   │   ├── server.py        # MCP server setup
│   │   ├── tools.py         # Tool implementations
│   │   ├── resources.py     # Resource implementations
│   │   └── prompts.py       # Prompt templates
│   └── utils/
│       ├── __init__.py
│       └── helpers.py       # Helper functions
├── main.py                  # Application entry point
├── requirements.txt         # Dependencies
└── README.md                # Documentation

MCP の機能

ツール
  • search_medicines:医薬品を名称または場所で検索します
  • get_medicine_locations:医薬品を入手できる場所を検索します
  • get_medicine_stock:特定の医薬品の在庫情報を取得します
  • get_regional_statistics:地域別の医薬品統計を取得します
  • get_medicine_status:医薬品の全体的な統計を取得します
  • diagnose_database:データベースへの接続と内容を確認します
  • troubleshoot_connection:データベース接続の詳細な診断を行います
  • create_database_schema:モデルに基づいてデータベーステーブルを作成します
リソース
  • product://{id}:ID で製品の詳細を取得します
  • stock://{name}:製品名で在庫情報を取得します
  • locations://{region}:指定した地域の医療センターを取得します
  • statistics://stock:在庫の全体的な統計を取得します
  • statistics://regions:地域別の統計を取得します
プロンプト
  • medicine_search_prompt:医薬品を名称で検索するためのテンプレート
  • medicine_availability_prompt:医薬品の在庫状況を確認するためのテンプレート
  • medicine_statistics_prompt:医薬品の統計を分析するためのテンプレート
  • regional_availability_prompt:地域別の医薬品在庫状況を分析するためのテンプレート

インストール

  1. リポジトリをクローンします。

    git clone https://github.com/yourusername/medifinder-mcp.git
    cd medifinder-mcp
    
  2. 仮想環境を作成し、依存関係をインストールします。

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

    DB_HOST=localhost
    DB_PORT=5432
    DB_NAME=medifinderbot
    DB_USER=your_user
    DB_PASSWORD=your_password
    DEBUG=True
    ENV=development
    SERVER_NAME=MedifinderMCP
    SERVER_VERSION=1.0.0
    MCP_SERVER_NAME=MedifinderMCP
    MCP_SERVER_DESCRIPTION=MCP server for medicine inventory queries
    MAX_SEARCH_RESULTS=50
    SEARCH_SIMILARITY_THRESHOLD=0.3
    
  4. データベースを作成します。

    # Connect to PostgreSQL
    psql -U postgres
    
    # Create database and user
    CREATE DATABASE medifinderbot;
    CREATE USER your_user WITH PASSWORD 'your_password';
    GRANT ALL PRIVILEGES ON DATABASE medifinderbot TO your_user;
    
    # Exit PostgreSQL
    \q
    
  5. データベーススキーマを初期化します。 サーバーの起動後、create_database_schema ツールを使用してテーブルを作成します。

使用方法

サーバーをローカルで実行する

MCP サーバーを直接実行できます。

python main.py
MCP Inspector を使用する

開発とテストでは、MCP Inspector を使ってサーバーを簡単に操作できます。

  1. MCP CLI をインストールします。

    pip install mcp[cli]
    
  2. 開発モードでサーバーを実行します。

    python -m mcp dev main.py
    
  3. MCP Inspector がブラウザーで開き、次の操作ができます。

    • ツールとリソースをテストする
    • 診断ツールの出力を確認する
    • さまざまなクエリを試す
Claude Desktop との連携

Claude Desktop でサーバーを使用するには、次の手順を実行します。

  1. 安定して起動するためのバッチファイル(run-mcp-server.bat)を作成します。

    @echo off
    cd /d %~dp0
    call venv\Scripts\activate.bat
    python main.py
    
  2. Claude Desktop にサーバーをインストールします。

    mcp install run-mcp-server.bat -f .env
    
  3. または、Claude Desktop の設定ファイルを手動で編集します。

    {
      "mcpServers": {
        "MedifinderMCP": {
          "command": "C:\\path\\to\\project\\venv\\Scripts\\python.exe",
          "args": ["C:\\path\\to\\project\\main.py"],
          "env": {
            "DB_HOST": "localhost",
            "DB_PORT": "5432",
            "DB_NAME": "medifinderbot",
            "DB_USER": "your_user",
            "DB_PASSWORD": "your_password",
            "DEBUG": "True",
            "ENV": "development",
            "SERVER_NAME": "MedifinderMCP",
            "SERVER_VERSION": "1.0.0",
            "MCP_SERVER_NAME": "MedifinderMCP",
            "MCP_SERVER_DESCRIPTION": "MCP server for medicine inventory queries",
            "MAX_SEARCH_RESULTS": "50",
            "SEARCH_SIMILARITY_THRESHOLD": "0.3"
          }
        }
      }
    }
    
  4. Claude Desktop でサーバーのドロップダウンから MedifinderMCP サーバーを選択し、会話で有効にします。

トラブルシューティング

よくある問題
  1. データベース接続の問題:

    • troubleshoot_connection ツールを使用して、接続の問題を診断します
    • .env ファイルでデータベースの認証情報を確認します
    • 指定したポートで PostgreSQL が実行されていることを確認します
  2. テーブルが見つからない:

    • create_database_schema ツールを使用して、データベースのテーブルを作成します
    • スキーマの作成中にエラーが発生していないか、ログを確認します
  3. 結果が空:

    • クエリで結果が返されない場合、テーブルにデータが存在しない可能性があります
    • データ取り込みプロセスを使用して、テーブルにデータをインポートする必要があります
  4. セッションバインドエラー:

    • 「Instance is not bound to a Session」エラーが表示される場合は、アクティブなセッション内でモデルインスタンスを辞書に変換していることを確認します
    • 例については、queries.py ファイルでの処理方法を参照してください
  5. 依存関係の不足:

    • pip install -r requirements.txt を実行して、すべての依存関係がインストールされていることを確認します
    • よく不足する依存関係は、mcp、python-dotenv、psycopg2-binary です
診断ツール

トラブルシューティングでは、次の組み込み診断ツールを使用します。

  1. diagnose_database:次の項目を確認します。

    • データベース接続が機能するか
    • テーブルが存在するか
    • テーブルにデータが含まれているか
  2. troubleshoot_connection:次の項目について詳細な情報を提供します。

    • データベース接続設定
    • 接続エラー
    • テーブル構造
    • 推奨される修正方法
  3. create_database_schema:データベースのテーブルを作成し、次の情報を提供します。

    • 作成されたテーブルの一覧
    • 発生したエラー
    • テストレコードの作成結果

ライセンス

MIT ライセンス

貢献者

  • Lenin Carrasco - 初期の作業

コメント

MCP は初めてですか?

プロトコルの概要から最初のサーバーの導入まで、よくある疑問にまとめて答えます。

AI アプリケーションが外部のツールやデータソースに統一的な方法で接続するためのオープンなプロトコルです。クライアントはモデルとの対話を担い、MCP サーバーはツール・リソース・プロンプトテンプレートを提供します。標準メッセージでやり取りするため、1 つのサーバーを複数のクライアントで再利用できます。