- Model Context Protocol の略。Anthropic が策定した「AIエージェントに外部の道具や知識を渡す」仕組み
- Webサーバーではなく、ローカルで動く小さなプロセス(Node.js や Python のスクリプト)
- Claude Code や Claude Desktop が裏で自動的にそのプロセスと stdin/stdout(JSON-RPC)で通信する
- ユーザーから見ると「Claude が最初からモジュールの知識を持っている」ように見える
| CLAUDE.md 方式 | MCP Server | |
|---|---|---|
| 使える場所 | このリポジトリ内のみ | どこからでも(他のプロジェクト、Claude Desktop等) |
| 準備 | このディレクトリで Claude Code を開く | 一度設定すれば常に使える |
| 検索 | Claude がファイルを逐一読む | 事前にインデックス化して高速に返せる |
| カスタムロジック | CLAUDE.md で指示 | コードで自由に組める |
- npm パッケージとして公開 —
npm install -gや npx で利用。npm は誰でも無料で公開可能(審査なし、早い者勝ち) - GitHub リポジトリで直接配布 — clone してもらう。npm アカウント不要で一番シンプル
- MCP Server では npx で都度実行するパターンが主流(明示的インストール不要)
npm install @modelcontextprotocol/sdk zod
npm install -D typescript @types/nodecollaboration-modules-mcp/
├── package.json
├── tsconfig.json
└── src/
└── index.ts
// src/index.ts
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { z } from "zod";
const server = new McpServer({
name: "collaboration-modules",
version: "1.0.0",
});
// ツール定義: モジュールを検索する
server.tool(
"search_module",
"課題や状況からコラボレーションモジュールを検索する",
{ query: z.string().describe("困りごとや状況の説明") },
async ({ query }) => {
return {
content: [{ type: "text", text: `「${query}」に関連するモジュール: CaaT, RAIS` }],
};
}
);
// ツール定義: モジュールの中身を取得する
server.tool(
"get_module",
"指定されたモジュールの内容を取得する",
{ name: z.string().describe("モジュール名") },
async ({ name }) => {
return {
content: [{ type: "text", text: `モジュール「${name}」の内容...` }],
};
}
);
// 起動
const transport = new StdioServerTransport();
await server.connect(transport);Claude Code / Claude Desktop
↕ stdin/stdout (JSON-RPC)
MCP Server プロセス (index.ts)
↓ fs.readFile 等
モジュールファイル群 (modules/concept/*.md)
// ~/.claude/settings.json に追加
{
"mcpServers": {
"collaboration-modules": {
"command": "node",
"args": ["D:/work/.../dist/index.js"]
}
}
}{
"name": "collaboration-modules-mcp",
"version": "1.0.0",
"type": "module",
"dependencies": {
"@modelcontextprotocol/sdk": "^1.0.0",
"zod": "^3.22.0"
}
}やることは3つだけ:
server.tool()でツールを定義する(関数名、説明、引数スキーマ、実装)StdioServerTransportで起動する- Claude の設定ファイルにパスを書く