mcpField
M
MCP Template

MCP Template

リモート
github.com/davini-dev開発ツール082 週間前に更新
リポジトリ

MCP Template について

MCP Templateは、FastMCPとTypeScriptを使ったMCPサーバープロジェクトを作成するCLIツールです。stdioとHTTPのトランスポート設定に加え、ツール、リソース、プロンプトを定義する構成を含みます。

主な機能

  1. 01FastMCPサーバーの基本設定
  2. 02stdioとHTTPのトランスポート
  3. 03TypeScript設定
  4. 04ツール、リソース、プロンプトの構成
  5. 05開発スクリプトと設定

活用シーン

  1. 01FastMCPサーバープロジェクトの作成
  2. 02stdioまたはHTTPの実行方式の選択
  3. 03テンプレートへのカスタムツールやリソースの追加

MCP 対応

stdioとHTTPのトランスポート、およびツール、リソース、プロンプトの定義構成を備えたMCPサーバーテンプレートを生成します。

設定

リモートサーバーはインストール不要です。クライアントを選んで設定をコピーするか、ワンクリックで導入できます。

エンドポイントhttp://localhost:3001/sse
インストールコマンドをコピー
Claude CodeTerminal
Cursor.cursor/mcp.json
VS Code.vscode/mcp.json
Claude Desktopclaude_desktop_config.json
Windsurf~/.codeium/windsurf/mcp_config.json

コマンドはターミナルで実行し、JSON は各クライアントの MCP 設定に貼り付けて再起動します。認可が必要なサーバーは初回接続時にログインを求めます。

ツール

詳細

@mcpdotdirect/template-mcp-server

License: MIT TypeScript

FastMCP を使用して、独自の MCP(Model Context Protocol)サーバーの構築をすぐに始められる CLI ツールです。

📋 使用方法

# with npx
npx @mcpdotdirect/create-mcp-server

# Or with npm
npm init @mcpdotdirect/mcp-server

🔭 含まれるもの

テンプレートには以下が含まれています。

  • FastMCP を使用した、stdio と HTTP の両方のトランスポートオプションに対応する基本的なサーバー設定
  • MCP ツール、リソース、プロンプトを定義するための構成
  • TypeScript の設定
  • 開発用スクリプトと設定

✨ 特長

  • FastMCP:実装を簡素化する FastMCP フレームワークを使用して構築されています
  • デュアルトランスポート対応:stdio または HTTP 経由で MCP サーバーを実行できます
  • TypeScript:型安全性を実現する、完全な TypeScript 対応
  • 拡張性:カスタムツール、リソース、プロンプトを簡単に追加できます

🚀 はじめに

プロジェクトを作成した後:

  1. お好みのパッケージマネージャーを使用して依存関係をインストールします。

    # Using npm
    npm install
    
    # Using yarn
    yarn
    
    # Using pnpm
    pnpm install
    
    # Using bun
    bun install
    
  2. サーバーを起動します。

    # Start the stdio server
    npm start
    
    # Or start the HTTP server
    npm run start:http
    
  3. 自動リロードを有効にして開発する場合:

    # Development mode with stdio
    npm run dev
    
    # Development mode with HTTP
    npm run dev:http
    

注記:デフォルトの package.json 内のスクリプトでは、ランタイムとして Bun を使用します(例:bun run src/index.ts)。別のパッケージマネージャーやランタイムを使用する場合は、package.json ファイル内のスクリプトを編集して、Node.js やお好みの別のランタイムを使用するように変更できます。

📖 詳しい使い方

トランスポート方式

MCP サーバーは、次の 2 つのトランスポート方式に対応しています。

  1. stdio トランスポート(コマンドラインモード):

    • ローカルマシン上で実行されます
    • Cursor によって自動的に管理されます
    • stdout 経由で直接通信します
    • ローカルでのみ、ユーザー本人がアクセスできます
    • 個人での開発やツールに最適です
  2. SSE トランスポート(HTTP ウェブモード):

    • ローカルまたはリモートで実行できます
    • ユーザー自身が管理し、実行します
    • ネットワーク経由で通信します
    • 複数のマシン間で共有できます
    • チームでの共同作業や共有ツールに最適です
サーバーをローカルで実行する
stdio トランスポート(CLI モード)

CLI ツール用に stdio モードでサーバーを起動します。

# Start the stdio server
npm start
# or with other package managers
yarn start
pnpm start
bun start

# Start the server in development mode with auto-reload
npm run dev
# or
yarn dev
pnpm dev
bun dev
HTTP トランスポート(ウェブモード)

ウェブアプリケーション用に HTTP モードでサーバーを起動します。

# Start the HTTP server
npm run start:http
# or
yarn start:http
pnpm start:http
bun start:http

# Start the HTTP server in development mode with auto-reload
npm run dev:http
# or
yarn dev:http
pnpm dev:http
bun dev:http

デフォルトでは、HTTP サーバーはポート 3001 で実行されます。PORT 環境変数を設定すると変更できます。

# Start the HTTP server on a custom port
PORT=8080 npm run start:http
サーバーへの接続
Cursor から接続する

Cursor から MCP サーバーに接続するには:

  1. Cursor を開き、Settings(左下の歯車アイコン)に移動します
  2. 左側のサイドバーで「Features」をクリックします
  3. 「MCP Servers」セクションまでスクロールします
  4. 「Add new MCP server」をクリックします
  5. 以下の詳細を入力します。
    • サーバー名:my-mcp-server(または任意の名前)
    • stdio モードの場合:
      • 種類:command
      • コマンド:サーバー実行ファイルへのパス。例:npm start
    • SSE モードの場合:
      • 種類:url
      • URL:http://localhost:3001/sse
  6. 「Save」をクリックします
Cursor で mcp.json を使用する

よりポータブルな設定にするには、プロジェクトのルートディレクトリに .cursor/mcp.json ファイルを作成します。

{
  "mcpServers": {
    "my-mcp-stdio": {
      "command": "npm",
      "args": [
        "start"
      ],
      "env": {
        "NODE_ENV": "development"
      }
    },
    "my-mcp-sse": {
      "url": "http://localhost:3001/sse"
    }
  }
}

~/.cursor/mcp.json にグローバル設定を作成すると、すべての Cursor ワークスペースで MCP サーバーを利用できるようになります。

注記:

  • command 種類のエントリは、サーバーを stdio モードで実行します
  • url 種類のエントリは、SSE トランスポートを使用して HTTP サーバーに接続します
  • env フィールドを使用して環境変数を指定できます
  • FastMCP で SSE 経由で接続する場合は、/sse パスを含む完全な URL を使用します:http://localhost:3001/sse
CLI ツールでサーバーをテストする

FastMCP には、サーバーをテストするための組み込みツールが用意されています。

# Test with mcp-cli
npx fastmcp dev server.js

# Inspect with MCP Inspector
npx fastmcp inspect server.ts
環境変数の使用

環境変数を使用してサーバーをカスタマイズできます。

# Change the HTTP port (default is 3001)
PORT=8080 npm run start:http

# Change the host binding (default is 0.0.0.0)
HOST=127.0.0.1 npm run start:http

🛠️ カスタムツールとリソースの追加

FastMCP サーバーにカスタムツール、リソース、またはプロンプトを追加する場合:

ツール
server.addTool({
  name: "hello_world",
  description: "A simple hello world tool",
  parameters: z.object({
    name: z.string().describe("Name to greet")
  }),
  execute: async (params) => {
    return `Hello, ${params.name}!`;
  }
});
リソース
server.addResourceTemplate({
  uriTemplate: "example://{id}",
  name: "Example Resource",
  mimeType: "text/plain",
  arguments: [
    {
      name: "id",
      description: "Resource ID",
      required: true,
    },
  ],
  async load({ id }) {
    return {
      text: `This is an example resource with ID: ${id}`
    };
  }
});
プロンプト
server.addPrompt({
  name: "greeting",
  description: "A simple greeting prompt",
  arguments: [
    {
      name: "name",
      description: "Name to greet",
      required: true,
    },
  ],
  load: async ({ name }) => {
    return `Hello, ${name}! How can I help you today?`;
  }
});

📚 ドキュメント

FastMCP の詳細については、FastMCP GitHub リポジトリをご覧ください。

Model Context Protocol の詳細については、MCP ドキュメントをご覧ください。

📄 ライセンス

このプロジェクトは MIT ライセンスの下でライセンスされています。詳細については、LICENSEファイルをご覧ください。

コメント

MCP は初めてですか?

プロトコルの概要から最初のサーバーの導入まで、よくある疑問にまとめて答えます。

AI アプリケーションが外部のツールやデータソースに統一的な方法で接続するためのオープンなプロトコルです。クライアントはモデルとの対話を担い、MCP サーバーはツール・リソース・プロンプトテンプレートを提供します。標準メッセージでやり取りするため、1 つのサーバーを複数のクライアントで再利用できます。