Skip to main content
Glama
Lihn2254
by Lihn2254

miniMCP

ローカルAIモデル(Ollamaを使用)を、Model Context Protocol (MCP) を介してカスタムツールと実装・接続する方法を示す軽量プロジェクトです。

このプロジェクトでは、AIがデータベースアシスタントとして機能し、CRUD操作(作成、読み取り、更新、削除)を使用してインメモリデータベースをクエリおよび管理できます。

プロジェクト構造

  • server.py: FastMCP で作成されたMCPサーバーです。インメモリデータベースを保持し、以下の操作を行うためのツール(tools)を公開します:

    • アイテムの作成 (create_item)

    • 個別アイテムの読み取り (read_item)

    • 複数アイテムの読み取り (read_multiple_items)

    • アイテムの更新 (update_item)

    • アイテムの削除 (delete_item)

  • client.py: ターミナルを介して対話するクライアントです。標準入出力(stdio)を通じてMCPサーバーに接続し、利用可能なツールを読み込み、ユーザーとOllamaのLLM(gemma4:e4b)とのチャットループを確立します。

  • requirements.txt: プロジェクトの主要な依存関係が記載されたファイルです。

Related MCP server: Modular MCP Server with Python Tools

要件と依存関係

プロジェクトを開始する前に、以下がインストールされていることを確認してください:

  1. Python 3.10+

  2. Ollama がインストールされ、マシン上で実行されていること。

  3. このリポジトリで使用するモデル(デフォルトは gemma4:e4b)。以下のコマンドでダウンロードできます:

    ollama run gemma4:e4b

インストール

  1. リポジトリをクローンし、フォルダに移動します:

    git clone <url-del-repo> miniMCP
    cd miniMCP
  2. 仮想環境を作成して有効化します(オプションですが、強く推奨します):

    python -m venv .venv
    # En Windows:
    .\.venv\Scripts\activate
    # En macOS/Linux:
    source .venv/bin/activate
  3. 必要な依存関係をインストールします:

    pip install -r requirements.txt
    pip install gradio

使用方法

このプロジェクトはクライアント/サーバー構成になっていますが、クライアントが自動的にサーバーを起動するため、クライアントを実行するだけで済みます:

python client.py

コンソールに直接質問を入力してください。


対話例

AIに対して以下のように指示を出すことができます:

  • "ID 'tarea1'、内容 '牛乳を買う' でアイテムを作成して"

  • "'tarea1' の内容を表示して"

  • "'tarea1' を更新して、牛乳は低脂肪乳にするように伝えて"

  • "'tarea1' と 'tarea2' のアイテムを読み込んで"

  • "ID 'tarea1' を削除して"

AIは、あなたがコードや呼び出しを直接記述することなく、server.py のツールを自動的に実行します。

Related MCP Connectors

Related MCP Servers

  • A
    license
    Not graded
    quality
    B
    maintenance
    MCP-Server from your Database optimized for LLMs and AI-Agents. Supports PostgreSQL, MySQL, ClickHouse, Snowflake, MSSQL, BigQuery, Oracle Database, SQLite, ElasticSearch, DuckDB
    548
    Apache 2.0
  • F
    license
    Not graded
    quality
    D
    maintenance
    A demo MCP server that enables users to interact with various tools through natural language, including note management, weather queries, calculations, file operations, and shell commands. Uses Ollama for intent detection and structured command parsing from free text input.
    -
  • F
    license
    Not graded
    quality
    A
    maintenance
    An MCP server that exposes relational databases (PostgreSQL/MySQL) to AI agents with natural language to SQL query support.
    19
    -