MCPサーバー(外部サービスと連携するための仲介プログラム)を作成する際のガイドです。LLM(大規模言語モデル)が外部のサービスやAPIと円滑にやり取りできるよう、使いやすいツール設計を通じて実装する方法を説明しています。 次のような場合に使用: PythonのFastMCPやNode/TypeScriptのMCP SDKを使い、外部のAPIやサービスと連携するMCPサーバーを構築する際
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK).
LLMが外部サービスと連携できるよう、適切に設計されたツール群を備えたMCP(Model Context Protocol)サーバーを作成します。 MCPサーバーの品質は、LLMが現実世界のタスクをいかにうまく達成できるかによって測られます。
高品質なMCPサーバーの作成は、以下の4つの主要フェーズから構成されます。
APIカバレッジとワークフロー型ツールのバランス: 包括的なAPIエンドポイントのカバレッジと、特定用途に特化したワークフロー型ツールをバランスよく組み合わせましょう。 ワークフロー型ツールは特定タスクに便利な一方、包括的なカバレッジによりagentが操作を柔軟に組み合わせられるようになります。 パフォーマンスはクライアントによって異なります。基本ツールを組み合わせたコード実行が有効なクライアントもあれば、高レベルなワークフローの方が適しているクライアントもあります。 判断に迷う場合は、包括的なAPIカバレッジを優先してください。
ツールの命名と発見容易性:
明確で説明的なツール名は、agentが適切なツールを素早く見つけるために役立ちます。
一貫したプレフィックス(例: github_create_issue、github_list_repos)とアクション指向の命名を使用してください。
コンテキスト管理: agentは、簡潔なツール説明と結果のフィルタリング・ページネーション機能から恩恵を受けます。 焦点が絞られた関連性の高いデータを返すようにツールを設計しましょう。 コード実行をサポートするクライアントでは、agentがデータを効率的にフィルタリング・処理できます。
実行可能なエラーメッセージ: エラーメッセージは、具体的な提案や次のステップを示し、agentが解決策へ向かうよう導くものにしてください。
MCPの仕様書を参照する手順:
まずサイトマップで関連ページを探します:
https://modelcontextprotocol.io/sitemap.xml
次に、マークダウン形式で取得するため .md サフィックスを付けて各ページを取得します
(例: https://modelcontextprotocol.io/specification/draft.md)。
確認すべき主なページ:
推奨スタック:
フレームワークドキュメントの読み込み:
TypeScript(推奨):
https://raw.githubusercontent.com/modelcontextprotocol/typescript-sdk/main/README.md を読み込むPython:
https://raw.githubusercontent.com/modelcontextprotocol/python-sdk/main/README.md を読み込むAPIを理解する: 対象サービスのAPIドキュメントを確認し、主要なエンドポイント・認証要件・データモデルを把握します。 必要に応じてウェブ検索やWebFetchを活用してください。
ツールの選定: 包括的なAPIカバレッジを優先します。最も頻繁に使われる操作から順に、実装するエンドポイントをリストアップしてください。
プロジェクトのセットアップについては、各言語別ガイドを参照してください:
共通ユーティリティを作成します:
各ツールについて以下を実装します:
入力スキーマ:
出力スキーマ:
outputSchema を定義するstructuredContent を使用する(TypeScript SDKの機能)ツールの説明:
実装:
アノテーション:
readOnlyHint: true / falsedestructiveHint: true / falseidempotentHint: true / falseopenWorldHint: true / false以下の観点でレビューします:
TypeScript:
npm run build を実行してコンパイルを確認するnpx @modelcontextprotocol/inspectorPython:
python -m py_compile your_server.py詳細なテスト手順と品質チェックリストについては、各言語別ガイドを参照してください。
MCPサーバーの実装が完了したら、その有効性を検証するための包括的な評価を作成します。
完全な評価ガイドラインについては ✅ 評価ガイド を読み込んでください。
評価は、LLMが実際の複雑な質問に答えるためにMCPサーバーを効果的に活用できるかをテストするために使用します。
効果的な評価を作成するには、評価ガイドに記載された以下のプロセスに従ってください:
各質問が以下の条件を満たしていることを確認してください:
以下の構造のXMLファイルを作成します:
<evaluation>
<qa_pair>
<question>AIモデルのローンチに関する、動物のコードネームを使った議論を探してください。あるモデルにはASL-Xという形式の特定の安全指定が必要でした。スポット模様の野生の猫にちなんで命名されたモデルで、Xに当てはまる数字は何でしたか?</question>
<answer>3</answer>
</qa_pair>
<!-- さらにqa_pairを続ける... -->
</evaluation>
開発中に必要に応じて以下のリソースを読み込んでください。
https://modelcontextprotocol.io/sitemap.xml のサイトマップを確認し、各ページは .md サフィックスを付けて取得するhttps://raw.githubusercontent.com/modelcontextprotocol/python-sdk/main/README.md から取得するhttps://raw.githubusercontent.com/modelcontextprotocol/typescript-sdk/main/README.md から取得する🐍 Python実装ガイド — 以下を含むPython/FastMCPの完全ガイド:
@mcp.tool によるツール登録⚡ TypeScript実装ガイド — 以下を含むTypeScriptの完全ガイド:
server.registerTool によるツール登録Create MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. The quality of an MCP server is measured by how well it enables LLMs to accomplish real-world tasks.
Creating a high-quality MCP server involves four main phases:
API Coverage vs. Workflow Tools: Balance comprehensive API endpoint coverage with specialized workflow tools. Workflow tools can be more convenient for specific tasks, while comprehensive coverage gives agents flexibility to compose operations. Performance varies by client—some clients benefit from code execution that combines basic tools, while others work better with higher-level workflows. When uncertain, prioritize comprehensive API coverage.
Tool Naming and Discoverability:
Clear, descriptive tool names help agents find the right tools quickly. Use consistent prefixes (e.g., github_create_issue, github_list_repos) and action-oriented naming.
Context Management: Agents benefit from concise tool descriptions and the ability to filter/paginate results. Design tools that return focused, relevant data. Some clients support code execution which can help agents filter and process data efficiently.
Actionable Error Messages: Error messages should guide agents toward solutions with specific suggestions and next steps.
Navigate the MCP specification:
Start with the sitemap to find relevant pages: https://modelcontextprotocol.io/sitemap.xml
Then fetch specific pages with .md suffix for markdown format (e.g., https://modelcontextprotocol.io/specification/draft.md).
Key pages to review:
Recommended stack:
Load framework documentation:
For TypeScript (recommended):
https://raw.githubusercontent.com/modelcontextprotocol/typescript-sdk/main/README.mdFor Python:
https://raw.githubusercontent.com/modelcontextprotocol/python-sdk/main/README.mdUnderstand the API: Review the service's API documentation to identify key endpoints, authentication requirements, and data models. Use web search and WebFetch as needed.
Tool Selection: Prioritize comprehensive API coverage. List endpoints to implement, starting with the most common operations.
See language-specific guides for project setup:
Create shared utilities:
For each tool:
Input Schema:
Output Schema:
outputSchema where possible for structured datastructuredContent in tool responses (TypeScript SDK feature)Tool Description:
Implementation:
Annotations:
readOnlyHint: true/falsedestructiveHint: true/falseidempotentHint: true/falseopenWorldHint: true/falseReview for:
TypeScript:
npm run build to verify compilationnpx @modelcontextprotocol/inspectorPython:
python -m py_compile your_server.pySee language-specific guides for detailed testing approaches and quality checklists.
After implementing your MCP server, create comprehensive evaluations to test its effectiveness.
Load ✅ Evaluation Guide for complete evaluation guidelines.
Use evaluations to test whether LLMs can effectively use your MCP server to answer realistic, complex questions.
To create effective evaluations, follow the process outlined in the evaluation guide:
Ensure each question is:
Create an XML file with this structure:
<evaluation>
<qa_pair>
<question>Find discussions about AI model launches with animal codenames. One model needed a specific safety designation that uses the format ASL-X. What number X was being determined for the model named after a spotted wild cat?</question>
<answer>3</answer>
</qa_pair>
<!-- More qa_pairs... -->
</evaluation>
Load these resources as needed during development:
https://modelcontextprotocol.io/sitemap.xml, then fetch specific pages with .md suffixhttps://raw.githubusercontent.com/modelcontextprotocol/python-sdk/main/README.mdhttps://raw.githubusercontent.com/modelcontextprotocol/typescript-sdk/main/README.md🐍 Python Implementation Guide - Complete Python/FastMCP guide with:
@mcp.tool⚡ TypeScript Implementation Guide - Complete TypeScript guide with:
server.registerTool原文・著作権は Anthropic および各プラグイン作者に帰属します。日本語訳は Claude API による自動翻訳です。