mcp-express-bolierplate
MCP Node.js ボイラープレート
Node.js + TypeScript で MCP クライアントと MCP サーバーを作成するためのボイラープレートです。HTTP 側は Express を使用し、以下に対応しています。
stdio— クライアントがサーバーを子プロセスとして起動。ローカルで動作する MCP ホストに適していますStreamable HTTP — エンドポイントは
/mcpにあり、Cloudflare Tunnel で HTTPS として公開可能users の CRUD 用モックツール
静的リソース
users://allとリソーステンプレートusers://{id}プロンプト
summarize-usersdiscovery、ツール呼び出し、リソース読み取り、プロンプト要求のための CLI クライアント
初期データは src/data/users.json にあり、サーバー起動時にメモリへ読み込まれます。CRUD による変更はファイルに書き戻されず、プロセス再起動時にリセットされます。
要件
Node.js 20 以上
npm
cloudflared(HTTPS トンネルが必要な場合のみ)
Related MCP server: MCP TypeScript Starter
インストール
npm installビルドとテストの確認:
npm run check主要な構造
src/
├── client/
│ └── client.ts # MCP CLI client ใช้ได้ทั้ง stdio และ HTTP
├── data/
│ └── users.json # mock seed data
├── lib/
│ └── api-client.ts # shared Axios instance สำหรับ upstream APIs
├── services/
│ └── user-service.ts # business logic กลางสำหรับ MCP capabilities
└── server/
├── mcp.ts # ประกอบ server และ capability registrations
├── tools/
│ └── user-tools.ts
├── resources/
│ └── user-resources.ts
├── prompts/
│ └── user-prompts.ts
├── schemas/
│ └── user.ts # shared MCP output schema
├── repository.ts # in-memory CRUD repository
├── stdio.ts # stdio entry point
└── http.ts # Express + Streamable HTTP entry point
scripts/
└── build.mjs # compile TypeScript และ copy mock JSON ไป distmcp.ts のファクトリは両方のトランスポートで共有されるため、サーバーの機能に違いはありません。Tools、Resources、Prompts はリポジトリに直接バインドするのではなく、共通の UserService を呼び出します。
Axios で外部 API を呼び出す
プロジェクトには src/lib/api-client.ts に共有の Axios インスタンスがあり、base URL、タイムアウト、オプションの Bearer トークンが設定されています。ツールやサービスでインポートして使用できます:
import { apiClient } from "../../lib/api-client.js";
const response = await apiClient.get("/users");
console.log(response.data);サーバー起動時の設定:
API_BASE_URL=https://api.example.com \
API_TIMEOUT_MS=10000 \
API_TOKEN=your-token \
npm run server:httpMCP ツールでの使用例:
server.registerTool(
"list-upstream-users",
{
description: "List users from the configured upstream API",
inputSchema: z.object({}),
},
async () => {
const { data } = await apiClient.get("/users");
return {
content: [{ type: "text", text: JSON.stringify(data, null, 2) }],
structuredContent: { users: data },
};
},
);API_BASE_URL を設定しない場合でも、Axios に絶対 URL を直接渡すことができます。API_TOKEN をログに出力しないようにし、本番環境ではトークンをシークレットマネージャーに保存してください。
stdio での実行方法
通常、stdio サーバーを個別に起動する必要はありません。クライアントまたは MCP ホストがプロセスを自ら spawn するためです。
デモクライアントを実行(サーバーを起動し、capabilities の discovery、ツール呼び出し、リソース読み取り、プロンプト要求を行います):
npm run client:stdio -- demoMCP ホストを待ち受けるためにサーバーを直接起動:
npm run server:stdio注意: stdio は stdout を JSON-RPC のチャネルとして使用するため、サーバーのログは console.error などの stderr 経由でのみ書き込む必要があります。
MCP ホストの設定例(/absolute/path/to/mcp-boilerplate を実際のパスに置き換えてください):
{
"mcpServers": {
"mock-users": {
"command": "node",
"args": [
"--import",
"tsx",
"/absolute/path/to/mcp-boilerplate/src/server/stdio.ts"
],
"cwd": "/absolute/path/to/mcp-boilerplate"
}
}
}または、事前にビルドして実行時に tsx に依存せず JavaScript を使用:
npm run build
npm run start:stdioビルド後の設定:
{
"mcpServers": {
"mock-users": {
"command": "node",
"args": [
"/absolute/path/to/mcp-boilerplate/dist/server/stdio.js"
],
"cwd": "/absolute/path/to/mcp-boilerplate"
}
}
}Express HTTP での実行方法
ターミナル 1 — サーバーを起動:
npm run server:httpデフォルト値:
MCP エンドポイント:
http://127.0.0.1:3000/mcpヘルスチェック:
http://127.0.0.1:3000/health
ターミナル 2 — HTTP クライアントを実行:
npm run client:http -- demo環境変数でポートやホストを変更できます:
HOST=127.0.0.1 PORT=4000 npm run server:http
MCP_URL=http://127.0.0.1:4000/mcp npm run client:http -- demo本番ビルドの場合:
npm run build
npm run start:httpCloudflare Tunnel で HTTPS を有効にする
この例では HTTPS は Cloudflare で終端され、Express サーバーはローカルのみで HTTP を待ち受けます。
macOS で cloudflared をインストール:
brew install cloudflaredターミナル 1 — MCP HTTP サーバーを起動:
npm run server:httpターミナル 2 — Quick Tunnel を起動:
cloudflared tunnel --url http://127.0.0.1:3000cloudflared は一時的な URL を表示します。例:
https://random-words.trycloudflare.comしたがって、外部の MCP エンドポイントは次のようになります:
https://random-words.trycloudflare.com/mcpターミナル 3 — HTTPS トンネル経由でテスト:
MCP_URL=https://random-words.trycloudflare.com/mcp npm run client:http -- demoQuick Tunnel は開発専用であり、Cloudflare は SSE をサポートしていないと明記しています。そのため、このボイラープレートでは response mode を auto に設定しており、一般的な CRUD/discovery コマンドは JSON で応答しますが、長期間のサブスクリプションなどストリーミングが必要な機能のテストに Quick Tunnel を使用すべきではありません。本番環境では、named tunnel、独自のホスト名、認証、認可を使用してください。
カスタムホスト名を使用する場合は、ホスト名を allowlist に追加します:
ALLOWED_HOSTS=mcp.example.com npm run server:http複数のホスト名はカンマで区切ります:
ALLOWED_HOSTS=mcp.example.com,mcp-staging.example.com npm run server:httplocalhost、127.0.0.1、::1、*.trycloudflare.com は開発用にすでに許可されています。
MCP クライアントのコマンド
client:stdio と client:http の両方で同じ形式を使用し、スクリプト名のみを変更します。
ツールを表示:
npm run client:stdio -- list-tools
npm run client:http -- list-toolsリソースまたはプロンプトを表示:
npm run client:stdio -- list-resources
npm run client:stdio -- list-promptsCRUD ツールを呼び出し:
npm run client:stdio -- call list-users '{}'
npm run client:stdio -- call get-user '{"id":"1"}'
npm run client:stdio -- call create-user '{"name":"Margaret Hamilton","email":"margaret@example.com","role":"developer"}'
npm run client:stdio -- call update-user '{"id":"1","role":"viewer"}'
npm run client:stdio -- call delete-user '{"id":"3"}'リソースを読み取り:
npm run client:stdio -- read users://all
npm run client:stdio -- read users://1プロンプトを要求:
npm run client:stdio -- prompt summarize-users '{"tone":"detailed"}'他の HTTP URL の場合は MCP_URL を設定:
MCP_URL=https://mcp.example.com/mcp npm run client:http -- call list-users '{}'stdio に関する注意: 各 CLI コマンドは新しいサーバープロセスを spawn するため、毎回元のモックデータから開始されます。CRUD を連続して実行するには、接続を維持する MCP ホストを使用するか、HTTP サーバーを起動して client:http 経由で呼び出してください。
提供されるツール、リソース、プロンプト
種類 | 名前 | 機能 |
Tool |
| すべてのユーザーを表示 |
Tool |
| ID でユーザーを表示 |
Tool |
| ユーザーを作成 |
Tool |
| ユーザーを編集 |
Tool |
| ユーザーを削除 |
Resource |
| すべてのユーザーの JSON スナップショット |
Resource template |
| 個別ユーザーの JSON(ID 補完付き) |
Prompt |
| モデルがユーザーデータを要約するためのテキストを生成 |
環境変数
変数 | デフォルト | 用途 |
|
| Express サーバーのバインドアドレス |
|
| Express サーバーのポート |
|
| HTTP クライアントのエンドポイント |
| 空 | サーバーが受け入れるカスタム Host/Origin を追加 |
| 未設定 | Axios が呼び出すアップストリーム API のベース URL |
|
| Axios リクエストのタイムアウト(ミリ秒) |
| 未設定 | Axios が自動的に付与する Bearer トークン |
値の例は .env.example にあります。プロジェクトは .env ファイルを自動ロードしません。上記の例のように変数を export するか、コマンドの前に指定してください。
セキュリティに関する注意
この例には認証と認可がありません。実際のデータを含む公開エンドポイントを開かないでください。
HostとOriginの検証は、localhost、TryCloudflare、およびALLOWED_HOSTSの値のみを許可します。モックリポジトリはメモリ内にあり、意図的にデータを永続化しません。
本番環境では、認証、レート制限、監査ログ、永続データベース、および実際のシステムに適した TLS/trust-proxy 設定を追加してください。
すべてのスクリプト
npm run dev:stdio # stdio server พร้อม watch mode
npm run dev:http # Express HTTP server พร้อม watch mode
npm run server:stdio # stdio server จาก TypeScript
npm run server:http # Express HTTP server จาก TypeScript
npm run client:stdio -- demo
npm run client:http -- demo
npm run build
npm run start:stdio # รัน dist หลัง build
npm run start:http # รัน dist หลัง build
npm test
npm run checkThis server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceA simple MCP server that exposes a createUser tool to add users to a local JSON file via stdio transport.2471MIT
- AlicenseNot gradedqualityBmaintenanceA feature-complete MCP server template in TypeScript demonstrating tools, resources, prompts, and both stdio and HTTP transports.8MIT
- FlicenseNot gradedqualityDmaintenanceA sample MCP server that exposes tools, resources, and prompts for managing users and todos, supporting both stdio and Streamable HTTP transports.
- AlicenseNot gradedqualityDmaintenanceEnables creating MCP (Model Context Protocol) servers with zero boilerplate, full TypeScript support, and multiple transports (stdio and HTTP).101MIT
Related MCP Connectors
An MCP server that let you interact with Cycloid.io Internal Development Portal and Platform
A basic MCP server to operate on the Postman API.
A MCP server built for developers enabling Git based project management with project and personal…
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/Pongsapat1035/mcp-express-bolierplate'
If you have feedback or need assistance with the MCP directory API, please join our Discord server