Communitygithub.com

MCPサーバーパターン

Node/TypeScript SDKでMCPサーバーを構築するためのスキル。ツール、リソース、プロンプト、Zodバリデーション、stdioとStreamable HTTPの選択をサポート。Context7または公式MCPドキュメントで最新APIを確認。MCPサーバーの構築やデバッグ時に使用。

MCPサーバーパターン とは?

このスキルは、Model Context Protocol (MCP) サーバーをNode.js/TypeScript SDKを用いて構築・保守するための包括的なガイドです。ツール、リソース、プロンプトといったMCPの基本概念を解説し、入力バリデーションにはZodを推奨。トランスポート方式として、ローカルクライアント向けのstdioとリモートクライアント向けのStreamable HTTPの選択基準を示します。SDKのAPIはバージョンによって変化するため、公式MCPドキュメントやContext7を用いて最新のメソッド名やシグネチャを確認する重要性を強調。具体的なコード例として、npmパッケージのインストール、McpServerのセットアップ、ツールとリソースの登録方法をTypeScriptで提示。ベストプラクティスとして、スキーマファースト、エラーハンドリング、冪等性、レート制限の考慮、バージョン管理を推奨。このスキールは、Claude Desktop、Cursor、クラウド環境など様々なMCPクライアントに対応したサーバー開発に役立ちます。

対応✓Claude Code~Codex CLI✓Cursor
npx skills add https://github.com/affaan-m/ECC/tree/main/skills/mcp-server-patterns

お気に入りのAIに質問する

このエージェントスキルを事前に読み込んだ状態で新しいチャットを開きます。

ドキュメント

MCPサーバーパターン は何をしますか?

Model Context Protocol (MCP) は、AIアシスタントがサーバーのツールを呼び出したり、リソースを読み取ったり、プロンプトを使用したりできるようにします。このスキルは、MCPサーバーの構築や保守を行う際に使用してください。SDK APIは進化するため、現在のメソッド名やシグネチャについてはContext7(「MCP」をクエリ)または公式のMCPドキュメントを確認してください。

機能をルール、スキル、MCP、または単純なCLI/APIワークフローのいずれとして実装すべきかのより広範な判断については、docs/capability-surface-selection.mdを参照してください。

使用タイミング

次のような場合に使用します:新しいMCPサーバーの実装、ツールやリソースの追加、stdioとHTTPの選択、SDKのアップグレード、MCPの登録やトランスポートの問題のデバッグ。

仕組み

コア概念

  • ツール: モデルが呼び出せるアクション(例:検索、コマンド実行)。SDKのバージョンに応じてregisterTool()またはtool()で登録します。
  • リソース: モデルが取得できる読み取り専用データ(例:ファイル内容、APIレスポンス)。registerResource()またはresource()で登録します。ハンドラーは通常uri引数を受け取ります。
  • プロンプト: クライアントが表示できる再利用可能なパラメーター化されたプロンプトテンプレート(例:Claude Desktopで)。registerPrompt()または同等のメソッドで登録します。
  • トランスポート: ローカルクライアント(例:Claude Desktop)向けのstdio。リモートクライアント(Cursor、クラウド)向けにはStreamable HTTPが推奨されます。レガシーHTTP/SSEは後方互換性のためです。

Node/TypeScript SDKはtool() / resource() またはregisterTool() / registerResource() を公開する場合があります。公式SDKは時間とともに変化しています。常に最新のMCPドキュメントまたはContext7で確認してください。

stdioでの接続

ローカルクライアントの場合、stdioトランスポートを作成し、サーバーのconnectメソッドに渡します。正確なAPIはSDKのバージョンによって異なります(例:コンストラクター vs ファクトリー)。最新のパターンについては、公式MCPドキュメントを参照するか、Context7で「MCP stdio server」をクエリしてください。

サーバーロジック(ツール + リソース)はトランスポートから独立させ、エントリポイントでstdioまたはHTTPをプラグインできるようにしてください。

リモート(Streamable HTTP)

Cursor、クラウド、その他のリモートクライアント向けには、Streamable HTTP(現在の仕様では単一のMCP HTTPエンドポイント)を使用してください。レガシーHTTP/SSEは後方互換性が必要な場合のみサポートしてください。

例

インストールとサーバーセットアップ

npm install @modelcontextprotocol/sdk zod
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { z } from "zod";

const server = new McpServer({ name: "my-server", version: "1.0.0" });

ツールとリソースは、お使いのSDKバージョンが提供するAPIを使用して登録します。一部のバージョンではserver.tool(name, description, schema, handler)(位置引数)を使用しますが、他のバージョンではserver.tool({ name, description, inputSchema }, handler) または registerTool() を使用します。リソースも同様です。APIが提供する場合は、ハンドラーにuriを含めてください。公式MCPドキュメントまたはContext7で最新の@modelcontextprotocol/sdkのシグネチャを確認し、コピーペーストによるエラーを避けてください。

入力バリデーションにはZod(またはSDKが推奨するスキーマ形式)を使用してください。

ベストプラクティス

  • スキーマファースト: すべてのツールの入力スキーマを定義し、パラメーターと戻り値の形式を文書化します。
  • エラー: モデルが解釈できる構造化されたエラーやメッセージを返し、生のスタックトレースは避けます。
  • 冪等性: 可能な限り冪等なツールを優先し、リトライが安全になるようにします。
  • レートとコスト: 外部APIを呼び出すツールの場合は、レート制限とコストを考慮し、ツールの説明に文書化します。
  • バージョン管理: package.jsonでSDKのバージョンを固定し、アップグレード時にはリリースノートを確認します。

公式SDKとドキュメント

  • JavaScript/TypeScript: @modelcontextprotocol/sdk (npm)。現在の登録およびトランスポートパターンについては、ライブラリ名「MCP」でContext7を使用してください。
  • Go: GitHub上の公式Go SDK (modelcontextprotocol/go-sdk)。
  • C#: .NET向け公式C# SDK。

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

accessibility

Design, implement, and audit inclusive digital products using WCAG 2.2 Level AA. Use when building or auditing UI that must meet WCAG 2.2 Level AA, or when reviewing a change for keyboard, contrast, or screen-reader support.

affaan-m/content-engine

Create platform-native content systems for X, LinkedIn, TikTok, YouTube, newsletters, and repurposed multi-platform campaigns. Use when the user wants social posts, threads, scripts, content calendars, or one source asset adapted cleanly across platforms.

affaan-m/ECC

Multi-platform content distribution across X, LinkedIn, Threads, and Bluesky. Adapts content per platform using content-engine patterns. Never posts identical content cross-platform. Use when the user wants to distribute content across social platforms.

affaan-m/fal-ai-media

Unified media generation via fal.ai MCP — image, video, and audio. Covers text-to-image (Nano Banana), text/image-to-video (Seedance, Kling, Veo 3), text-to-speech (CSM-1B), and video-to-audio (ThinkSound). Use when the user wants to generate images, videos, or audio with AI.

affaan-m/manim-video

日本語翻訳:このファイルは manim-video 用の日本語翻訳が必要です

affaan-m/remotion-video-creation

Remotion のベストプラクティス - React で動画を作成する。3D、アニメーション、音声、字幕、チャート、トランジションなどをカバーするドメイン固有の29のルール。

affaan-m/video-editing

AI-assisted video editing workflows for cutting, structuring, and augmenting real footage. Covers the full pipeline from raw capture through FFmpeg, Remotion, ElevenLabs, fal.ai, and final polish in Descript or CapCut. Use when the user wants to edit video, cut footage, create vlogs, or build video content.

agent-architecture-audit

Full-stack diagnostic for agent and LLM applications. Audits the 12-layer agent stack for wrapper regression, memory pollution, tool discipline failures, hidden repair loops, and rendering corruption. Produces severity-ranked findings with code-first fixes. Essential for developers building agent applications, autonomous loops, or any LLM-powered feature. Use when an agent or LLM feature misbehaves and the failing layer is unknown, or before shipping an agent stack.

agent-eval

Head-to-head comparison of coding agents (Claude Code, Aider, Codex, etc.) on custom tasks with pass rate, cost, time, and consistency metrics. Use when choosing between coding agents, or when a change to an agent setup needs measured pass rate, cost, and time rather than an impression.

agent-harness-construction

Design and optimize AI agent action spaces, tool definitions, and observation formatting for higher completion rates. Use when defining or revising an agent

agentic-engineering

Operate as an agentic engineer using eval-first execution, decomposition, and cost-aware model routing. Use when planning or executing engineering work that agents will carry out end to end.

agentic-os

Build persistent multi-agent operating systems on Claude Code. Covers kernel architecture, specialist agents, slash commands, file-based memory, scheduled automation, and state management without external databases. Use when building a persistent multi-agent system on Claude Code with its own memory, commands, and scheduling.

agent-introspection-debugging

Structured self-debugging workflow for AI agent failures using capture, diagnosis, contained recovery, and introspection reports. Use when an agent run fails and you need a reproducible diagnosis instead of a retry.

agent-payment-x402

Add x402 payment execution to AI agents with per-task budgets, spending controls, and non-custodial wallets. Supports Base through agentwallet-sdk and X Layer through OKX Payments / OKX Agent Payments Protocol. Use when an agent must pay for something itself and needs per-task budgets, spending controls, and a non-custodial wallet.

agent-self-evaluation

Use after completing any non-trivial task. The agent self-rates its output on 5 axes — accuracy, completeness, clarity, actionability, conciseness — with concrete evidence per criterion. Produces a structured 1-5 scorecard with specific improvement suggestions.

agent-sort

Build an evidence-backed ECC install plan for a specific repo by sorting skills, commands, rules, hooks, and extras into DAILY vs LIBRARY buckets using parallel repo-aware review passes. Use when ECC should be trimmed to what a project actually needs instead of loading the full bundle.

ai-first-engineering

Engineering operating model for teams where AI agents generate a large share of implementation output. Use when setting team process, review gates, or ownership rules for a codebase largely written by agents.

ai-regression-testing

Regression testing strategies for AI-assisted development. Sandbox-mode API testing without database dependencies, automated bug-check workflows, and patterns to catch AI blind spots where the same model writes and reviews code. Use when adding regression coverage to AI-assisted code, or when the same model both wrote and reviewed a change.

android-clean-architecture

Clean Architecture patterns for Android and Kotlin Multiplatform projects — module structure, dependency rules, UseCases, Repositories, and data layer patterns. Use when structuring modules, layers, or data flow in an Android or KMP project.

angular-developer

Generates Angular code and provides architectural guidance. Trigger when creating projects, components, or services, or for best practices on reactivity (signals, linkedSignal, resource), forms, dependency injection, routing, SSR, accessibility (ARIA), animations, styling (component styles, Tailwind CSS), testing, or CLI tooling.

関連スキル