Skip to main content
Glama

MCP サーバー サンプル

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

MCP図

MCP サーバーの例

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

参考文献:

MCPとは何ですか?

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

主なメリット

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

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

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

Related MCP server: MCP Server Example

アーキテクチャの概要

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パッケージマネージャー


インストール

Python プロジェクトに MCP を追加する Python プロジェクトを管理するには、uv を使用することをお勧めします。

UV 管理プロジェクトをまだ作成していない場合は、作成します。

uv init mcp-server-sample
cd mcp-server-sample

次に、プロジェクトの依存関係に MCP を追加します。

uv add "mcp[cli]

あるいは、依存関係に pip を使用するプロジェクトの場合:

pip install "mcp[cli]"

スタンドアロン MCP 開発ツールの実行 uv で mcp コマンドを実行するには:

uv run mcp

クイックスタート

計算ツールといくつかのデータを公開するシンプルな MCP サーバーを作成しましょう。

# server.py
from mcp.server.fastmcp import FastMCP

# Create an MCP server
mcp = FastMCP("Demo")


# Add an addition tool
@mcp.tool()
def add(a: int, b: int) -> int:
    """Add two numbers"""
    return a + b


# Add a dynamic greeting resource
@mcp.resource("greeting://{name}")
def get_greeting(name: str) -> str:
    """Get a personalized greeting"""
    return f"Hello, {name}!"

次のコマンドを実行すると、このサーバーを Claude Desktop にインストールしてすぐに操作することができます。

mcp install server.py

あるいは、MCP Inspector を使用してテストすることもできます。

mcp dev server.py

アントニオ・スカペラートが❤️を込めて作りました

リソース:

ライセンス

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

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections. Dates show when Glama detected each change.

  1. 1 tool updatev0.1.0
    • First observedadd

TDQS

B3.2/5.0
Disambiguation5/5

With only one tool, there is no possibility of confusion or overlap between tools. The tool 'add' has a clear and distinct purpose of adding two numbers, so disambiguation is perfect.

Naming Consistency5/5

With a single tool, naming consistency is inherently perfect as there are no other tools to compare against. The tool name 'add' follows a simple verb pattern, which is appropriate for its function.

Tool Count2/5

A single tool is too few for most server purposes, as it limits functionality and scope. While it might be appropriate for a trivial demo, it feels thin and incomplete for any meaningful domain coverage.

Completeness1/5

The server is severely incomplete, as it only offers a basic arithmetic operation. There are obvious gaps, such as missing other mathematical operations or any broader domain coverage, which will cause agent failures in most scenarios.

Maintenance

ActivityInactive
ResponsivenessNo issues

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Connectors

Related MCP Servers

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/antonscap/mcp-server-sample'

If you have feedback or need assistance with the MCP directory API, please join our Discord server