Skip to content

Instantly share code, notes, and snippets.

@stakiran
Created March 18, 2026 09:13
Show Gist options
  • Select an option

  • Save stakiran/8b55ee01131fa216273879bd0d6f632e to your computer and use it in GitHub Desktop.

Select an option

Save stakiran/8b55ee01131fa216273879bd0d6f632e to your computer and use it in GitHub Desktop.

MCP Server 化の調査

MCP Server とは

  • Model Context Protocol の略。Anthropic が策定した「AIエージェントに外部の道具や知識を渡す」仕組み
  • Webサーバーではなく、ローカルで動く小さなプロセス(Node.js や Python のスクリプト)
  • Claude Code や Claude Desktop が裏で自動的にそのプロセスと stdin/stdout(JSON-RPC)で通信する
  • ユーザーから見ると「Claude が最初からモジュールの知識を持っている」ように見える

CLAUDE.md 方式との違い

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/node

最小構成

collaboration-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 Code への登録

// ~/.claude/settings.json に追加
{
  "mcpServers": {
    "collaboration-modules": {
      "command": "node",
      "args": ["D:/work/.../dist/index.js"]
    }
  }
}

package.json の要点

{
  "name": "collaboration-modules-mcp",
  "version": "1.0.0",
  "type": "module",
  "dependencies": {
    "@modelcontextprotocol/sdk": "^1.0.0",
    "zod": "^3.22.0"
  }
}

まとめ

やることは3つだけ:

  1. server.tool() でツールを定義する(関数名、説明、引数スキーマ、実装)
  2. StdioServerTransport で起動する
  3. Claude の設定ファイルにパスを書く
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment