template-mcp
template-mcp
TypeScript、Zodバリデーション、デュアルトランスポート(stdio/HTTP)をサポートしたMCP(Model Context Protocol)サーバーテンプレート。Claude Code、Claude Desktop、Cursor、VS Code Copilot、Windsurf、Clineなど、あらゆるMCPクライアントと互換性があります。
特徴
デュアルトランスポート: stdio(ローカル)およびStreamable HTTP(リモート)
TypeScript strict: ESMモジュール対応
Zodバリデーション: ツール入力スキーマ用
Joi環境変数バリデーション: 起動時に即時失敗
Pinoロギング: stderrへ出力(stdioセーフ)
モジュール式アーキテクチャ: ツール、リソース、プロンプトを個別のモジュールとして構成
ファクトリパターン: テスト容易性のための
createServer()完全なテストスイート: MCP SDKのインメモリトランスポートを使用
高品質なツール: ESLint + Prettier + Husky + lint-staged
Docker対応: マルチステージビルド
CI/CD: GitHub Actionsパイプライン
Related MCP server: xmcp Application
クイックスタート
pnpm install
pnpm devスクリプト
スクリプト | 説明 |
| ホットリロードで起動 (tsx watch) |
| TypeScriptのコンパイル + エイリアスの解決 |
| コンパイル済みサーバーの実行 |
| テストの実行 |
| ソースコードのLint |
| 型チェック(出力なし) |
設定
.env.example を .env にコピーして調整してください:
変数 | デフォルト | 説明 |
|
| トランスポート: |
|
| HTTPポート ( |
|
| Pinoログレベル |
|
| 環境 |
プロジェクト構造
src/
├── main.ts # Entrypoint: transport selection
├── server.ts # createServer() factory
├── config/ # Env validation + constants
├── common/ # Logger, error helpers, types
├── tools/ # MCP tools (callable by LLMs)
├── resources/ # MCP resources (read-only data)
└── prompts/ # MCP prompts (reusable templates)新しいツールの追加
src/tools/my-tool.tool.tsを作成:
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
import { z } from 'zod';
export function registerMyTool(server: McpServer): void {
server.registerTool(
'my_tool',
{
title: 'My Tool',
description: 'What this tool does',
inputSchema: {
param: z.string().describe('Parameter description'),
},
annotations: {
readOnlyHint: true,
destructiveHint: false,
idempotentHint: true,
openWorldHint: false,
},
},
async ({ param }) => ({
content: [{ type: 'text', text: `Result: ${param}` }],
}),
);
}src/tools/index.tsに登録:
import { registerMyTool } from './my-tool.tool.js';
export function registerTools(server: McpServer): void {
registerGreetTool(server);
registerMyTool(server); // add here
}src/tools/__tests__/my-tool.tool.spec.tsにテストを追加
クライアント設定
Claude Code
.claude/settings.json に追加:
{
"mcpServers": {
"template-mcp": {
"command": "node",
"args": ["/absolute/path/to/template-mcp/dist/main.js"]
}
}
}Claude Desktop
claude_desktop_config.json に追加:
{
"mcpServers": {
"template-mcp": {
"command": "node",
"args": ["/absolute/path/to/template-mcp/dist/main.js"]
}
}
}Cursor
Cursorの設定 > MCP Servers に追加:
{
"mcpServers": {
"template-mcp": {
"command": "node",
"args": ["/absolute/path/to/template-mcp/dist/main.js"]
}
}
}VS Code (Copilot)
.vscode/settings.json に追加:
{
"mcp": {
"servers": {
"template-mcp": {
"command": "node",
"args": ["/absolute/path/to/template-mcp/dist/main.js"]
}
}
}
}Docker
# Build
docker build -t template-mcp .
# Run (HTTP mode, used for remote access)
docker run -p 3000:3000 template-mcp技術スタック
Node.js 22 + TypeScript (strict, ESM)
MCP SDK v1 (
@modelcontextprotocol/sdk)Zod (ツール入力バリデーション)
Joi (環境変数バリデーション)
Pino (stderrロギング)
Vitest (テスト)
ESLint + Prettier + Husky
検証
以下はすべて確認済みで、100%動作しています。
コード品質
チェック | コマンド |
Lint + フォーマット |
|
厳格な型チェック |
|
ビルド (tsc + alias) |
|
ユニットテスト (11/11)
pnpm testスイート | カバレッジ |
| リスト、カジュアル/フォーマル/熱狂的スタイル、空の名前の拒否 |
| リスト、JSONフィールド (name, version, uptime, timestamp) |
| リスト、簡潔/箇条書きスタイル、数値強制、デフォルト値 |
ネットワークやポートは不要 — SDKの InMemoryTransport を使用。
ランタイム — stdioトランスポート (デフォルトモード)
echo '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"test","version":"1.0.0"}}}' \
| MCP_TRANSPORT=stdio node dist/main.jsstdoutにJSON-RPCレスポンス、stderrにログを出力。
ランタイム — HTTPトランスポート
MCP_TRANSPORT=http PORT=3100 node dist/main.js &
# Initialize → capturar Mcp-Session-Id del header
# tools/list, resources/list, prompts/list, tools/call greet, resources/read info://server検証済みエンドポイント | 期待される結果 |
|
|
| name, version, uptime, nodeVersion, timestamp を含むJSON |
Docker
docker build -t template-mcp . # multi-stage: base → deps → build → production
docker run -p 3000:3000 template-mcp # arranca en HTTP modeCI (GitHub Actions)
pnpm install → pnpm lint → pnpm build → pnpm test
main/masterへの各プッシュおよびPRで実行。
コミットパイプライン (ローカル)
git commit → husky → lint-staged → eslint --fix + prettier --write (ステージングされたファイルのみ)
既知のギャップ
自動テストのないHTTPトランスポート (中): ユニットテストは
InMemoryTransportを使用。HTTPトランスポート (StreamableHTTPServerTransport) はcurlで手動検証済み。リモート本番環境向けには実際のセッションを用いた統合テストを追加することMCPクライアントとの統合 (中):
.claude/settings.jsonまたはCursorに追加し、ツール/リソース/プロンプトがクライアントに表示されることを手動で確認すること極端なツール入力 (低): 非常に長い文字列、不正なUnicode — Zodは拒否するが、HTTP経由のエラーレスポンスはテストされていない
同時セッション (低): テンプレートのスコープ外
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Tools
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceA TypeScript-based template for rapidly developing MCP servers with modular tool architecture, built-in validation using Zod schemas, and comprehensive error handling.9MIT
- FlicenseNot gradedqualityDmaintenanceA Model Context Protocol (MCP) server template designed for building structured tools, prompts, and resources with built-in support for HTTP and STDIO transports. It provides a standardized framework for developers to create and deploy AI-driven services using TypeScript and Zod schema validation.9
- AlicenseNot gradedqualityBmaintenanceA feature-complete MCP server template in TypeScript demonstrating tools, resources, prompts, and both stdio and HTTP transports.8MIT
- AlicenseNot gradedqualityDmaintenanceA minimal TypeScript MCP server template with example tool, Zod validation, stdio transport, and dotenv setup.78MIT
Related MCP Connectors
A TypeScript MCP server for Home Assistant, enabling programmatic management of entities, automati…
A comprehensive Model Context Protocol (MCP) server that enables AI assistants to interact with yo…
MCP server for AI agents to plan, verify, and deploy Cloudflare-native apps.
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/Freddymhs/template-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server