Skip to main content
Glama

MCP サーバーの例

このリポジトリには、教育目的のモデルコンテキストプロトコル(MCP)サーバーの実装が含まれています。このコードは、様々なLLMクライアントと統合できる機能的なMCPサーバーの構築方法を示しています。

完全なチュートリアルを実行するには、 YouTube ビデオ チュートリアルを参照してください。

MCPとは何ですか?

MCP(モデル・コンテキスト・プロトコル)は、アプリケーションがLLMにコンテキストを提供する方法を標準化するオープンプロトコルです。MCPはAIアプリケーション用のUSB-Cポートのようなもので、AIモデルをさまざまなデータソースやツールに接続するための標準化された方法を提供します。

MCP図

主なメリット

  • LLMに直接接続できる、構築済みの統合のリストが増えています

  • LLMプロバイダーとベンダーを切り替える柔軟性

  • インフラストラクチャ内でデータを保護するためのベストプラクティス

Related MCP server: Optimized Memory MCP Server V2

アーキテクチャの概要

MCP は、ホスト アプリケーションが複数のサーバーに接続できるクライアント サーバー アーキテクチャに従います。

  • MCPホスト: Claude Desktop、IDE、またはMCPを介してデータにアクセスするAIツールなどのプログラム

  • MCPクライアント: サーバーとの1:1接続を維持するプロトコルクライアント

  • MCP サーバー: 標準化されたモデル コンテキスト プロトコルを通じて特定の機能を公開する軽量プログラム

  • データ ソース: MCP サーバーがアクセスできるローカル (ファイル、データベース) とリモート サービス (API) の両方

MCPコアコンセプト

MCP サーバーは、主に次の 3 種類の機能を提供できます。

  • リソース: クライアントが読み取ることができるファイルのようなデータ (API レスポンスやファイルの内容など)

  • ツール: LLM から呼び出せる関数 (ユーザーの承認が必要)

  • プロンプト: ユーザーが特定のタスクを達成するのに役立つ、事前に作成されたテンプレート

システム要件

  • Python 3.10以上

  • MCP SDK 1.2.0以上

  • uvパッケージマネージャー

はじめる

uv パッケージマネージャーのインストール

MacOS/Linuxの場合:

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

uvコマンドが確実に実行されるように、後でターミナルを再起動してください。

プロジェクトのセットアップ

  1. プロジェクトを作成して初期化します。

# Create a new directory for our project
uv init mcp-server
cd mcp-server

# Create virtual environment and activate it
uv venv
source .venv/bin/activate  # On Windows use: .venv\Scripts\activate

# Install dependencies
uv add "mcp[cli]" httpx
  1. サーバー実装ファイルを作成します。

touch main.py

サーバーの実行

  1. MCP サーバーを起動します。

uv run main.py
  1. サーバーが起動し、接続を受け入れる準備が整います

Claudeデスクトップに接続しています

  1. 公式サイトからClaude Desktopをインストールする

  2. MCP サーバーを使用するように Claude Desktop を構成します。

~/Library/Application Support/Claude/claude_desktop_config.jsonを編集します。

{
    "mcpServers": {
        "mcp-server": {
            "command": "uv",  # It's better to use the absolute path to the uv command
            "args": [
                "--directory",
                "/ABSOLUTE/PATH/TO/YOUR/mcp-server",
                "run",
                "main.py"
            ]
        }
    }
}
  1. Claudeデスクトップを再起動します

トラブルシューティング

サーバーが Claude Desktop によって取得されていない場合は、次の手順に従ってください。

  1. 設定ファイルのパスと権限を確認してください

  2. 設定内の絶対パスが正しいことを確認します

  3. UVが適切に設置され、アクセス可能であることを確認する

  4. Claude Desktopのログにエラーメッセージがないか確認してください

ライセンス

このプロジェクトはMITライセンスの下で提供されています。詳細はLICENSEファイルをご覧ください。

Available Tools

1 tool
get_docsA

Search the latest docs for a given query and library. Supports langchain, openai, and llama-index.

Args: query: The query to search for (e.g. "Chroma DB") library: The library to search in (e.g. "langchain")

Returns: Text from the docs

Inputs: query (required), library (required).

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    B3.4/5.0

    Scored across 1 tool

    Disambiguation5/5

    With only one tool, there is no possibility of ambiguity or overlap between tools. The tool has a single, clear purpose of searching documentation for specific libraries.

    Naming Consistency5/5

    The single tool name 'get_docs' follows a clear verb_noun pattern. Since there is only one tool, consistency is inherently perfect with no deviations to evaluate.

    Tool Count2/5

    A single tool is too few for most server purposes, as it severely limits functionality and scope. This feels thin and incomplete for a documentation search server, which might benefit from additional tools like browsing documentation structure or getting library lists.

    Completeness2/5

    The tool surface is severely incomplete for a documentation search domain. It only supports searching text, with no tools for browsing, listing available libraries, or accessing documentation metadata, creating significant gaps that will hinder agent workflows.

    Maintenance

    ActivityInactive
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    Appeared in Searches