MCPサーバー実装パターン
Claude Codeとの連携を構築するためのModel Context Protocol (MCP) サーバーパターンを提供するSkill。
📜 元の英語説明(参考)
Model Context Protocol (MCP) server patterns for building integrations with Claude Code. Triggers on: mcp server, model context protocol, tool handler, mcp resource, mcp tool.
🇯🇵 日本人クリエイター向け解説
Claude Codeとの連携を構築するためのModel Context Protocol (MCP) サーバーパターンを提供するSkill。
※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。
下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o mcp-patterns.zip https://jpskill.com/download/5918.zip && unzip -o mcp-patterns.zip && rm mcp-patterns.zip
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/5918.zip -OutFile "$d\mcp-patterns.zip"; Expand-Archive "$d\mcp-patterns.zip" -DestinationPath $d -Force; ri "$d\mcp-patterns.zip"
完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。
💾 手動でダウンロードしたい(コマンドが難しい人向け)
- 1. 下の青いボタンを押して
mcp-patterns.zipをダウンロード - 2. ZIPファイルをダブルクリックで解凍 →
mcp-patternsフォルダができる - 3. そのフォルダを
C:\Users\あなたの名前\.claude\skills\(Win)または~/.claude/skills/(Mac)へ移動 - 4. Claude Code を再起動
⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。
🎯 このSkillでできること
下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。
📦 インストール方法 (3ステップ)
- 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
- 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
- 3. 展開してできたフォルダを、ホームフォルダの
.claude/skills/に置く- · macOS / Linux:
~/.claude/skills/ - · Windows:
%USERPROFILE%\.claude\skills\
- · macOS / Linux:
Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。
詳しい使い方ガイドを見る →- 最終更新
- 2026-05-17
- 取得日時
- 2026-05-18
- 同梱ファイル
- 1
📖 Skill本文(日本語訳)
※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。
MCP パターン
Claude Code との統合を構築するための Model Context Protocol (MCP) サーバーパターンです。
基本的な MCP サーバー (Python)
from mcp.server import Server
from mcp.server.stdio import stdio_server
app = Server("my-server")
@app.list_tools()
async def list_tools():
return [
{
"name": "my_tool",
"description": "Does something useful",
"inputSchema": {
"type": "object",
"properties": {
"query": {"type": "string", "description": "Search query"}
},
"required": ["query"]
}
}
]
@app.call_tool()
async def call_tool(name: str, arguments: dict):
if name == "my_tool":
result = await do_something(arguments["query"])
return {"content": [{"type": "text", "text": result}]}
raise ValueError(f"Unknown tool: {name}")
async def main():
async with stdio_server() as (read_stream, write_stream):
await app.run(read_stream, write_stream, app.create_initialization_options())
if __name__ == "__main__":
import asyncio
asyncio.run(main())
プロジェクトのレイアウト
my-mcp-server/
├── src/
│ └── my_server/
│ ├── __init__.py
│ ├── server.py # メインのサーバーロジック
│ ├── tools.py # ツールハンドラー
│ └── resources.py # リソースハンドラー
├── pyproject.toml
└── README.md
Claude Desktop の設定
基本設定
{
"mcpServers": {
"my-server": {
"command": "python",
"args": ["-m", "my_server"],
"env": {
"MY_API_KEY": "your-key-here"
}
}
}
}
uv を使用する場合 (推奨)
{
"mcpServers": {
"my-server": {
"command": "uv",
"args": ["run", "--directory", "/path/to/my-server", "python", "-m", "my_server"],
"env": {
"MY_API_KEY": "your-key-here"
}
}
}
}
クイックリファレンス
| パターン | ユースケース | リファレンス |
|---|---|---|
| ツール検証 | Pydantic を使用した入力サニタイズ | ./references/tool-patterns.md |
| エラー処理 | 正常な失敗応答 | ./references/tool-patterns.md |
| 複数のツール | CRUD スタイルのツール登録 | ./references/tool-patterns.md |
| 静的リソース | 設定/設定の公開 | ./references/resource-patterns.md |
| 動的リソース | データベースに裏付けられたリソース | ./references/resource-patterns.md |
| 環境認証 | 環境変数からの API キー | ./references/auth-patterns.md |
| OAuth トークン | TTL を使用したトークン更新 | ./references/auth-patterns.md |
| SQLite キャッシュ | 永続的な状態ストレージ | ./references/state-patterns.md |
| インメモリキャッシュ | TTL ベースのキャッシュ | ./references/state-patterns.md |
| 手動テスト | クイック検証スクリプト | ./references/testing-patterns.md |
| pytest async | ツールの単体テスト | ./references/testing-patterns.md |
よくある問題
| 問題 | 解決策 |
|---|---|
| サーバーが起動しない | command パスを確認し、依存関係がインストールされていることを確認してください |
| ツールが表示されない | list_tools() が有効なスキーマを返すことを確認してください |
| 認証失敗 | 環境変数がシェルではなく設定で設定されていることを確認してください |
| タイムアウトエラー | httpx 呼び出しにタイムアウトを追加し、非同期を適切に使用してください |
| JSON 解析エラー | call_tool が適切なコンテンツ構造を返すことを確認してください |
公式ドキュメント
- https://modelcontextprotocol.io - MCP 仕様
- https://modelcontextprotocol.io/docs/concepts/tools - ツールリファレンス
- https://modelcontextprotocol.io/docs/concepts/resources - リソースリファレンス
- https://github.com/modelcontextprotocol/python-sdk - Python SDK
- https://github.com/modelcontextprotocol/servers - 公式 MCP サーバー
その他のリソース
詳細なパターンについては、以下を読み込んでください。
./references/tool-patterns.md- 検証、エラー処理、複数ツール登録./references/resource-patterns.md- 静的および動的リソースの公開./references/auth-patterns.md- 環境変数、OAuth トークンの更新./references/state-patterns.md- SQLite 永続化、インメモリキャッシュ./references/testing-patterns.md- 手動テストスクリプト、pytest 非同期パターン
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開
MCP Patterns
Model Context Protocol (MCP) server patterns for building integrations with Claude Code.
Basic MCP Server (Python)
from mcp.server import Server
from mcp.server.stdio import stdio_server
app = Server("my-server")
@app.list_tools()
async def list_tools():
return [
{
"name": "my_tool",
"description": "Does something useful",
"inputSchema": {
"type": "object",
"properties": {
"query": {"type": "string", "description": "Search query"}
},
"required": ["query"]
}
}
]
@app.call_tool()
async def call_tool(name: str, arguments: dict):
if name == "my_tool":
result = await do_something(arguments["query"])
return {"content": [{"type": "text", "text": result}]}
raise ValueError(f"Unknown tool: {name}")
async def main():
async with stdio_server() as (read_stream, write_stream):
await app.run(read_stream, write_stream, app.create_initialization_options())
if __name__ == "__main__":
import asyncio
asyncio.run(main())
Project Layout
my-mcp-server/
├── src/
│ └── my_server/
│ ├── __init__.py
│ ├── server.py # Main server logic
│ ├── tools.py # Tool handlers
│ └── resources.py # Resource handlers
├── pyproject.toml
└── README.md
Claude Desktop Configuration
Basic Configuration
{
"mcpServers": {
"my-server": {
"command": "python",
"args": ["-m", "my_server"],
"env": {
"MY_API_KEY": "your-key-here"
}
}
}
}
With uv (Recommended)
{
"mcpServers": {
"my-server": {
"command": "uv",
"args": ["run", "--directory", "/path/to/my-server", "python", "-m", "my_server"],
"env": {
"MY_API_KEY": "your-key-here"
}
}
}
}
Quick Reference
| Pattern | Use Case | Reference |
|---|---|---|
| Tool validation | Input sanitization with Pydantic | ./references/tool-patterns.md |
| Error handling | Graceful failure responses | ./references/tool-patterns.md |
| Multiple tools | CRUD-style tool registration | ./references/tool-patterns.md |
| Static resources | Config/settings exposure | ./references/resource-patterns.md |
| Dynamic resources | Database-backed resources | ./references/resource-patterns.md |
| Environment auth | API key from env vars | ./references/auth-patterns.md |
| OAuth tokens | Token refresh with TTL | ./references/auth-patterns.md |
| SQLite cache | Persistent state storage | ./references/state-patterns.md |
| In-memory cache | TTL-based caching | ./references/state-patterns.md |
| Manual testing | Quick validation script | ./references/testing-patterns.md |
| pytest async | Unit tests for tools | ./references/testing-patterns.md |
Common Issues
| Issue | Solution |
|---|---|
| Server not starting | Check command path, ensure dependencies installed |
| Tool not appearing | Verify list_tools() returns valid schema |
| Auth failures | Check env vars are set in config, not shell |
| Timeout errors | Add timeout to httpx calls, use async properly |
| JSON parse errors | Ensure call_tool returns proper content structure |
Official Documentation
- https://modelcontextprotocol.io - MCP specification
- https://modelcontextprotocol.io/docs/concepts/tools - Tools reference
- https://modelcontextprotocol.io/docs/concepts/resources - Resources reference
- https://github.com/modelcontextprotocol/python-sdk - Python SDK
- https://github.com/modelcontextprotocol/servers - Official MCP servers
Additional Resources
For detailed patterns, load:
./references/tool-patterns.md- Validation, error handling, multi-tool registration./references/resource-patterns.md- Static and dynamic resource exposure./references/auth-patterns.md- Environment variables, OAuth token refresh./references/state-patterns.md- SQLite persistence, in-memory caching./references/testing-patterns.md- Manual test scripts, pytest async patterns