有用なモデルコンテキストプロトコルサーバー(MCPS)
様々なユーティリティ機能のためのモデルコンテキストプロトコル(MCP)サーバーを実装するスタンドアロンPythonスクリプトのコレクションです。各サーバーは、AIアシスタントやMCPプロトコルをサポートするその他のアプリケーションで使用できる専用ツールを提供します。
MCPとは何ですか?
モデルコンテキストプロトコル(MCP)は、AIアシスタントが外部ツールやサービスと連携するための標準化された方法です。MCPサーバーが提供する専用関数を呼び出すことで、AIモデルの機能を拡張できます。通信はJSONメッセージを使用した標準入出力(stdio)を介して行われます。
利用可能なサーバー
各 MCP サーバーは、 uv
などの Python 環境マネージャーを使用して実行されるように設計されています。
YouTube データ抽出ツール ( ytdlp
)
yt-dlp を使用して YouTube 動画から情報を抽出するサーバー。
ツール:
- チャプターの抽出: YouTube ビデオからチャプター情報を取得します。
- 字幕の抽出: YouTube 動画の特定のチャプターまたは動画全体の字幕を取得します。
MCP サーバー構成:
"mcpServers": {
"ytdlp": {
"name": "youtube", // Optional friendly name for the client
"command": "uv",
"args": [
"run",
"--directory", "<path/to/repo>/useful-mcps/ytdlp", // Path to the MCP directory containing pyproject.toml
"--", // Separator before script arguments, if any
"ytdlp_mcp" // Match the script name defined in pyproject.toml [project.scripts]
]
// 'cwd' is not needed when using --directory
}
}
Word 文書プロセッサ ( docx_replace
)
テンプレート処理や PDF 変換など、Word 文書を操作するためのサーバー。
ツール:
- プロセス テンプレート: Word テンプレート内のプレースホルダーを置き換え、コンテンツ ブロックを管理します。
- テンプレート キーの取得: Word 文書テンプレートからすべての置換キーを抽出します。
- PDF に変換: Word 文書 (docx) を PDF 形式に変換します。
MCP サーバー構成:
"mcpServers": {
"docx_replace": {
"name": "docx", // Optional friendly name
"command": "uv",
"args": [
"run",
"--directory", "<path/to/repo>/useful-mcps/docx_replace", // Path to the MCP directory
"--",
"docx_replace_mcp" // Match the script name defined in pyproject.toml
]
}
}
PlantUML レンダラー ( plantuml
)
PlantUML サーバー (多くの場合、Docker 経由で実行) を使用して PlantUML ダイアグラムをレンダリングするためのサーバー。
ツール:
- ダイアグラムのレンダリング: PlantUML テキストをダイアグラム イメージ (例: PNG) に変換します。
MCP サーバー構成:
"mcpServers": {
"plantuml": {
"name": "plantuml", // Optional friendly name
"command": "uv",
"args": [
"run",
"--directory", "<path/to/repo>/useful-mcps/plantuml", // Path to the MCP directory
"--",
"plantuml_server" // Match the script name defined in pyproject.toml
]
}
}
(注: アクセス可能な実行中の PlantUML サーバーが必要です。サービスに実装されている Docker 経由で管理される可能性があります)。
マーメイドレンダラー( mermaid
)
mermaidchart.com API を使用して Mermaid ダイアグラムをレンダリングするためのサーバー。
ツール:
- Mermaid Chart のレンダリング: mermaidchart.com でドキュメントを作成して、Mermaid コードを PNG 画像に変換します。
MCP サーバー構成:
"mcpServers": {
"mermaid": {
"name": "mermaid", // Optional friendly name
"command": "uv",
"args": [
"run",
"--directory", "<path/to/repo>/useful-mcps/mermaid", // Path to the MCP directory
"--",
"mermaid_mcp" // Match the script name defined in pyproject.toml
],
"env": { // Environment variables needed by the MCP
"MERMAID_CHART_ACCESS_TOKEN": "YOUR_API_TOKEN_HERE"
}
}
}
(注: 環境変数として設定された Mermaid Chart API アクセス トークンが必要です)。
日付フィルタリングを使用して RSS フィード コンテンツをマークダウン形式に変換するサーバー。
ツール:
- fetch_rss_to_markdown : RSS フィードを取得し、記事を日付でフィルタリングし、一致する記事を Markdown リストとしてフォーマットして返します。
MCP サーバー構成:
"mcpServers": {
"mermaid": {
"name": "rss2md", // Optional friendly name
"command": "uv",
"args": [
"run",
"--directory", "<path/to/repo>/useful-mcps/rss2md", // Path to the MCP directory
"--",
"rss2md_mcp" // Match the script name defined in pyproject.toml
],
"env": { // Environment variables needed by the MCP
}
}
}
インストール
- リポジトリをクローンします。
git clone https://github.com/daltonnyx/useful-mcps.git # Replace with the actual repo URL if different
cd useful-mcps
uv
をインストールします。uv uv
ない場合はインストールします。pip install uv
# or follow instructions at https://github.com/astral-sh/uv
- **依存関係:**依存関係は、
pyproject.toml
を介して MCP ごとに管理されます。通常、 uv run
、 --directory
を使用して初めて MCP を実行するときに、それらを仮想環境に自動的にインストールします。
使用法
サーバーの実行
特定の MCP のディレクトリを指すuv run --directory <path>
を使用して各 MCP サーバーを実行することをお勧めします。uv uv
、そこにあるpyproject.toml
に基づいて仮想環境と依存関係を処理します。
例 (ルートのuseful-mcps
ディレクトリから):
# Run the YouTube MCP
uv run --directory ./ytdlp ytdlp_mcp
# Run the Mermaid MCP (ensure token is set in environment)
uv run --directory ./mermaid mermaid_mcp
または、MCP クライアント (上記の JSON 構成の例のように) を構成して、 uv run --directory ...
コマンドを直接実行します。
サーバーへの接続
各サーバーの「MCPサーバー設定」例に示されているcommand
とargs
構造を使用して、MCPクライアントアプリケーションを設定して、目的のサーバーを起動してください。 command
uv
実行ファイルを指し、 args
で--directory
にMCPのフォルダへのパスと実行するスクリプト名を正しく指定していることを確認してくださいenv
プロパティを使用して、必要な環境変数(APIトークンなど)を渡してください。
ツール固有の使用例
これらは、それぞれの MCP サーバーのcall_tool
関数に送信するarguments
例を示しています。
YouTubeデータ抽出ツール
章の抜粋
{
"url": "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
}
字幕の抽出
{
"url": "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
"language": "en",
"chapters": [
{
"title": "Introduction",
"start_time": "00:00:00",
"end_time": "00:01:30"
}
]
}
Word文書プロセッサ
プロセステンプレート
{
"template_file": "/path/to/template.docx",
"replacements": {
"name": "John Doe",
"date": "2023-05-15"
},
"blocks": {
"optional_section": true,
"alternative_section": false
},
"output_filename": "/path/to/output.docx"
}
(注: template_file
とdocx_file
パスの代わりに base64 でエンコードされた文字列も受け入れることができます)
テンプレートキーを取得する
{
"template_file": "/path/to/template.docx"
}
PDFに変換
{
"docx_file": "/path/to/document.docx",
"pdf_output": "/path/to/output.pdf"
}
PlantUMLレンダラー
レンダリング図
{
"input": "participant User\nUser -> Server: Request\nServer --> User: Response",
"output_path": "/path/to/save/diagram.png"
}
(注: input
.puml
ファイルへのパスにすることもできます)
マーメイドレンダラー
マーメイドチャートをレンダリングする
{
"mermaid_code": "graph TD;\n A-->B;\n A-->C;\n B-->D;\n C-->D;",
"output_path": "/path/to/save/mermaid.png",
"theme": "default" // Optional, e.g., "default", "dark", "neutral", "forest"
}
発達
新しいMCPサーバーの追加
- MCP 用の新しいディレクトリを作成します (例:
my_new_mcp
)。 - ディレクトリ内に以下を作成します。
pyproject.toml
: プロジェクトのメタデータ、依存関係、およびスクリプトのエントリ ポイントを定義します (例: [project.scripts]
セクションのマッピングmy_new_mcp = "my_new_mcp:main"
)。pyrightconfig.json
: (オプション) 型チェック用。- メインの Python ファイル (例:
my_new_mcp.py
): mcp
ライブラリを使用して MCP ロジックを実装します (以下のテンプレートを参照)。
- 必要なクラスと関数 (
serve
、 list_tools
、 call_tool
) を実装します。
基本テンプレート ( my_new_mcp.py
):
import json
import logging
import asyncio
from typing import List, Dict, Any, Optional
# Assuming mcp library is installed or available
# from mcp import Server, Tool, TextContent, stdio_server
# Placeholder imports if mcp library structure is different
from typing import Protocol # Using Protocol as placeholder
# Placeholder definitions if mcp library isn't directly importable here
class Tool(Protocol):
name: str
description: str
inputSchema: dict
class TextContent(Protocol):
type: str
text: str
class Server:
def __init__(self, name: str): pass
def list_tools(self): pass # Decorator
def call_tool(self): pass # Decorator
def create_initialization_options(self): pass
async def run(self, read_stream, write_stream, options): pass
# Placeholder context manager
class stdio_server:
async def __aenter__(self): return (None, None) # Dummy streams
async def __aexit__(self, exc_type, exc, tb): pass
# Pydantic is often used for schema definition
# from pydantic import BaseModel
# class MyInput(BaseModel):
# param1: str
# param2: int
class MyInputSchema: # Placeholder if not using Pydantic
@staticmethod
def model_json_schema():
return {"type": "object", "properties": {"param1": {"type": "string"}, "param2": {"type": "integer"}}, "required": ["param1", "param2"]}
class MyTools:
TOOL_NAME = "my.tool"
class MyService:
def __init__(self):
# Initialize resources if needed
pass
def my_function(self, param1: str, param2: int) -> dict:
# Implement your tool functionality
logging.info(f"Running my_function with {param1=}, {param2=}")
# Replace with actual logic
result_content = f"Result: processed {param1} and {param2}"
return {"content": result_content}
async def serve() -> None:
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
server = Server("mcp-my-service")
service = MyService()
@server.list_tools()
async def list_tools() -> list[Tool]:
logging.info("list_tools called")
return [
Tool(
name=MyTools.TOOL_NAME,
description="Description of my tool",
# Use Pydantic's schema or manually define
inputSchema=MyInputSchema.model_json_schema(),
),
]
@server.call_tool()
async def call_tool(name: str, arguments: dict) -> list[TextContent]:
logging.info(f"call_tool called with {name=}, {arguments=}")
try:
if name == MyTools.TOOL_NAME:
# Add validation here if not using Pydantic
param1 = arguments.get("param1")
param2 = arguments.get("param2")
if param1 is None or param2 is None:
raise ValueError("Missing required arguments")
result = service.my_function(param1, int(param2)) # Ensure type conversion if needed
logging.info(f"Tool executed successfully: {result=}")
return [TextContent(type="text", text=json.dumps(result))] # Return JSON string
else:
logging.warning(f"Unknown tool requested: {name}")
raise ValueError(f"Unknown tool: {name}")
except Exception as e:
logging.error(f"Error executing tool {name}: {e}", exc_info=True)
# Return error as JSON
error_payload = json.dumps({"error": str(e)})
return [TextContent(type="text", text=error_payload)]
options = server.create_initialization_options()
logging.info("Starting MCP server...")
async with stdio_server() as (read_stream, write_stream):
await server.run(read_stream, write_stream, options)
logging.info("MCP server stopped.")
def main():
# Entry point defined in pyproject.toml `[project.scripts]`
try:
asyncio.run(serve())
except KeyboardInterrupt:
logging.info("Server interrupted by user.")
if __name__ == "__main__":
# Allows running directly via `python my_new_mcp.py` for debugging
main()
テスト
ルート ディレクトリから pytest を使用してテストを実行します。
(テスト依存関係がインストールされていることを確認します。これには、 uv pip install pytest
を使用するか、 pyproject.toml
ファイルの 1 つにある開発依存関係にpytest
を追加します)。
ライセンス
MITライセンス
貢献
貢献を歓迎します!お気軽にプルリクエストを送信してください。