Skip to content
mcp logo

mcp - MCP Server 作成

mcp

Model Context Protocol (MCP) サーバーの作成・管理ガイド。カスタムツールの追加方法。 使用タイミング: (1) Claude Codeにカスタムツールを追加したい時 (2) 外部サービス連携時 (3) プロジェクト固有の自動化ツールを作りたい時 (4) MCPサーバーの設定方法を知りたい時。 トリガー例: 「MCPサーバーを作って」「カスタムツールを追加」「MCP設定」 「外部APIをツール化」「テストランナーMCP」

SKILL.md

Full skill instructions

mcp - MCP Server 作成

Model Context Protocol (MCP) サーバーの作成・管理。


概要

MCP は Claude Code にカスタムツールを追加するためのプロトコル。

用途:

  • プロジェクト固有のツール提供
  • 外部サービス連携
  • 自動化タスク

基本構造

// scripts/​mcp/​my-tool.js
import { Server } from "@modelcontextprotocol/​sdk/​server/​index.js";
import { StdioServerTransport } from "@modelcontextprotocol/​sdk/​server/​stdio.js";

const server = new Server(
  { name: "my-tool", version: "1.0.0" },
  { capabilities: { tools: {} } }
);

// ツール一覧
server.setRequestHandler("tools/​list", async () => ({
  tools: [
    {
      name: "my_custom_tool",
      description: "カスタムツールの説明",
      inputSchema: {
        type: "object",
        properties: {
          param1: { type: "string", description: "パラメータ1" },
        },
        required: ["param1"],
      },
    },
  ],
}));

// ツール実行
server.setRequestHandler("tools/​call", async (request) => {
  const { name, arguments: args } = request.params;

  if (name === "my_custom_tool") {
    const result = await doSomething(args.param1);
    return { content: [{ type: "text", text: JSON.stringify(result) }] };
  }

  throw new Error(`Unknown tool: ${name}`);
});

// サーバー起動
const transport = new StdioServerTransport();
await server.connect(transport);

設定

プロジェクトレベル (.mcp.json)

{
  "mcpServers": {
    "my-tool": {
      "command": "node",
      "args": ["scripts/​mcp/​my-tool.js"]
    }
  }
}

ユーザーレベル (~/​.claude/​settings.json)

{
  "mcpServers": {
    "my-global-tool": {
      "command": "node",
      "args": ["/​path/​to/​tool.js"]
    }
  }
}

実用例

テストランナー

server.setRequestHandler("tools/​list", async () => ({
  tools: [
    {
      name: "run_tests",
      description: "ユニットテストを実行",
      inputSchema: {
        type: "object",
        properties: {
          pattern: { type: "string", description: "テストパターン" },
        },
      },
    },
  ],
}));

server.setRequestHandler("tools/​call", async (request) => {
  if (request.params.name === "run_tests") {
    const pattern = request.params.arguments?.pattern || "";
    const result = await runTests(pattern);
    return { content: [{ type: "text", text: result }] };
  }
});

async function runTests(pattern) {
  const { execSync } = await import("child_process");
  try {
    const output = execSync(`npm test -- ${pattern}`, { encoding: "utf-8" });
    return output;
  } catch (error) {
    return error.stdout + error.stderr;
  }
}

DB クエリ

{
  name: "query_database",
  description: "データベースにクエリを実行",
  inputSchema: {
    type: "object",
    properties: {
      query: { type: "string", description: "SQL クエリ" },
    },
    required: ["query"],
  },
}

コンテキスト節約

使わないMCPサーバーを無効化してコンテキストを節約:

// .mcp.json
{
  "mcpServers": {
    "frequently-used": { "command": "node", "args": ["tool1.js"] }
  },
  "disabledMcpServers": [
    "rarely-used-tool",
    "heavy-context-tool"
  ]
}

デバッグ

# 直接実行
node scripts/​mcp/​my-tool.js

# ログ確認
DEBUG=mcp* node scripts/​mcp/​my-tool.js

# Claude Code で確認
# /​mcp コマンドで接続状態を確認

ベストプラクティス

  1. エラーハンドリング: 常に try-catch で囲む
  2. タイムアウト: 長時間処理は避ける(30秒以内)
  3. 説明を明確に: description はツール選択の判断材料
  4. inputSchema 必須: パラメータの型を明示
  5. 10個以下: プロジェクトあたりのMCP数を制限

More skills from majiayu000

xiaohongshu logo
majiayu000/claude-arsenal

xiaohongshu

xiaohongshu

286 148
View
agent-task-conductor logo
majiayu000/claude-skill-registry

agent-task-conductor

Conduct multi-agent task orchestration and workflow coordination.

663 1
View
conductor-setup logo
majiayu000/claude-skill-registry

conductor-setup

Initialize project with Conductor artifacts (product definition,

663 1
View
animation-designer logo
majiayu000/claude-skill-registry

animation-designer

Expert in web animations, transitions, and motion design using Framer Motion and CSS

663 1
View
diagramming logo
majiayu000/claude-skill-registry

diagramming

Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...

663 1
View
h3-pg logo
majiayu000/claude-skill-registry-data

h3-pg

PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.

23 1
View
conductor-development logo
majiayu000/claude-skill-registry

conductor-development

Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...

663 1
View
conductor-status logo
majiayu000/claude-skill-registry

conductor-status

Display project status, active tracks, and next actions

663 1
View
dockerization logo
majiayu000/claude-skill-registry

dockerization

Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.

663 1
View

Popular AI tools

Kaiber logo
Video

Kaiber

Generate, edit, and beat-sync AI video with leading models in one workspace.

Paid
View
Vimcal logo
Productivity

Vimcal

The world's fastest calendar for remote work

Free
View

Transform Your Design with AI Designer by ImgCreator.ai

Freemium
View
Akool AI logo
Content & writing

Akool AI

Revolutionizing Video Production with AI-Powered Creativity

Paid
View

Extend an image past the frame and let AI fill the new aspect ratio.

Freemium
View
StarByFace logo
Security

StarByFace

Discover your celebrity doppelgänger with StarByFace!

Free
View
C

ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.

Freemium
View
Opus Clip logo
Coding & apps

Opus Clip

Opus.ai: Revolutionize Your Web Experience

Free
View