Skip to main content
Glama
Pongsapat1035

mcp-express-bolierplate

MCP Node.js Boilerplate

Node.js + TypeScript로 MCP client와 MCP server를 만들기 위한 Boilerplate입니다. HTTP 쪽은 Express를 사용하며 다음을 모두 지원합니다.

  • stdio — client가 server를 child process로 실행하며, 로컬에서 실행되는 MCP host에 적합합니다.

  • Streamable HTTP — endpoint는 /mcp이며 Cloudflare Tunnel로 HTTPS로 공개할 수 있습니다.

  • users CRUD용 mock tools

  • static resource users://all 및 resource template users://{id}

  • prompt summarize-users

  • discovery, tool 호출, resource 읽기, prompt 요청을 위한 CLI client

초기 데이터는 src/data/users.json에 있으며 server 시작 시 memory로 로드됩니다. CRUD를 통한 수정은 파일에 기록되지 않으며 process를 재시작하면 초기화됩니다.

Requirements

  • Node.js 20 이상

  • npm

  • cloudflared — HTTPS tunnel이 필요한 경우에만

Related MCP server: MCP TypeScript Starter

설치

npm install

build 및 test 확인:

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 ไป dist

mcp.ts의 Factory는 두 transport에서 공통으로 사용되므로 server의 기능은 동일합니다. Tools, Resources, Prompts는 repository에 직접 바인딩하는 대신 공통 UserService를 호출합니다.

Axios로 External API 호출

프로젝트에는 src/lib/api-client.ts에 shared Axios instance가 있으며 base URL, timeout, optional Bearer token이 포함되어 있습니다. tool이나 service에서 import하여 사용할 수 있습니다:

import { apiClient } from "../../lib/api-client.js";

const response = await apiClient.get("/users");
console.log(response.data);

server 시작 시 값 설정:

API_BASE_URL=https://api.example.com \
API_TIMEOUT_MS=10000 \
API_TOKEN=your-token \
npm run server:http

MCP tool에서 사용 예시:

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에 absolute URL을 직접 전달할 수 있습니다. API_TOKEN을 로그에 남기지 않아야 하며, production 배포 시에는 token을 secret manager에 보관해야 합니다.

stdio 실행 방법

일반적으로 stdio server를 별도로 실행할 필요는 없습니다. client나 MCP host가 process를 직접 spawn하기 때문입니다.

demo client 실행 — server를 열고, capabilities를 discovery하고, tool을 호출하고, resource를 읽고, prompt를 요청합니다:

npm run client:stdio -- demo

MCP host를 기다리도록 server를 직접 실행:

npm run server:stdio

주의사항: stdio는 stdout을 JSON-RPC 채널로 사용하므로 server의 로그는 console.error와 같은 stderr로만 작성해야 합니다.

MCP host용 config 예시 — /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"
    }
  }
}

또는 먼저 build한 후 runtime에 tsx에 의존하지 않고 JavaScript를 사용:

npm run build
npm run start:stdio

build 후 config:

{
  "mcpServers": {
    "mock-users": {
      "command": "node",
      "args": [
        "/absolute/path/to/mcp-boilerplate/dist/server/stdio.js"
      ],
      "cwd": "/absolute/path/to/mcp-boilerplate"
    }
  }
}

Express HTTP 실행 방법

Terminal 1 — server 실행:

npm run server:http

기본값:

  • MCP endpoint: http://127.0.0.1:3000/mcp

  • health check: http://127.0.0.1:3000/health

Terminal 2 — HTTP client 실행:

npm run client:http -- demo

environment variables로 port나 host 변경 가능:

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

production build용:

npm run build
npm run start:http

Cloudflare Tunnel로 HTTPS 열기

이 예시에서 HTTPS는 Cloudflare에서 종료되며, Express server는 여전히 로컬에서만 HTTP를 수신합니다.

macOS에서 cloudflared 설치:

brew install cloudflared

Terminal 1 — MCP HTTP server 실행:

npm run server:http

Terminal 2 — Quick Tunnel 실행:

cloudflared tunnel --url http://127.0.0.1:3000

cloudflared가 임시 URL을 표시합니다. 예:

https://random-words.trycloudflare.com

따라서 외부 MCP endpoint는 다음과 같습니다:

https://random-words.trycloudflare.com/mcp

Terminal 3 — HTTPS tunnel을 통한 테스트:

MCP_URL=https://random-words.trycloudflare.com/mcp npm run client:http -- demo

Quick Tunnel은 development 전용이며, Cloudflare는 SSE를 지원하지 않는다고 명시합니다. 따라서 이 boilerplate는 response mode를 auto로 설정하여 일반적인 CRUD/discovery 명령은 JSON으로 응답하지만, 장기 subscription과 같은 stream 기능을 Quick Tunnel로 테스트해서는 안 됩니다. production에서는 named tunnel, 자체 hostname, authentication 및 authorization을 사용하세요.

custom hostname을 사용할 때는 hostname을 allowlist에 추가하세요:

ALLOWED_HOSTS=mcp.example.com npm run server:http

여러 hostname은 comma로 구분:

ALLOWED_HOSTS=mcp.example.com,mcp-staging.example.com npm run server:http

localhost, 127.0.0.1, ::1, *.trycloudflare.com은 development용으로 이미 허용되어 있습니다.

MCP client 명령어

client:stdioclient:http 모두 동일한 형식을 사용하며 script 이름만 변경하면 됩니다.

tools 보기:

npm run client:stdio -- list-tools
npm run client:http -- list-tools

resources 또는 prompts 보기:

npm run client:stdio -- list-resources
npm run client:stdio -- list-prompts

CRUD tools 호출:

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"}'

resources 읽기:

npm run client:stdio -- read users://all
npm run client:stdio -- read users://1

prompt 요청:

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 명령은 server process를 새로 spawn하므로 매번 초기 mock data로 시작합니다. CRUD를 연속적으로 유지하려면 connection을 유지하는 MCP host를 사용하거나 HTTP server를 열고 client:http로 호출하세요.

제공되는 Tools, resources 및 prompt

종류

이름

기능

Tool

list-users

모든 users 조회

Tool

get-user

ID로 user 조회

Tool

create-user

user 생성

Tool

update-user

user 수정

Tool

delete-user

user 삭제

Resource

users://all

모든 users의 JSON snapshot

Resource template

users://{id}

개별 user의 JSON 및 ID completion

Prompt

summarize-users

모델이 users 데이터를 요약하도록 메시지 생성

Environment variables

변수

기본값

용도

HOST

127.0.0.1

Express server bind address

PORT

3000

Express server port

MCP_URL

http://127.0.0.1:3000/mcp

HTTP client endpoint

ALLOWED_HOSTS

비어 있음

server가 허용하는 custom Host/Origin 추가

API_BASE_URL

미설정

Axios가 호출하는 upstream API의 Base URL

API_TIMEOUT_MS

10000

Axios request timeout (밀리초)

API_TOKEN

미설정

Axios가 자동으로 첨부하는 Bearer token

예시 값은 .env.example에 있습니다. 프로젝트는 .env 파일을 자동으로 로드하지 않습니다. 위 예시처럼 변수를 export하거나 명령어 앞에 붙이세요.

Security notes

  • 이 예시에는 authentication과 authorization이 없습니다. 실제 데이터가 있는 public endpoint를 열지 마세요.

  • HostOrigin 검증은 localhost, TryCloudflare, ALLOWED_HOSTS의 값만 허용합니다.

  • mock repository는 memory에 있으며 의도적으로 데이터를 persist하지 않습니다.

  • production에서는 실제 시스템에 맞는 auth, rate limiting, audit logging, persistent database, TLS/trust-proxy configuration을 추가해야 합니다.

전체 Scripts

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 check

참고: MCP TypeScript SDK, Cloudflare Quick Tunnels

F
license - not found
Not graded
quality - not tested
C
maintenance

Maintenance

Maintainers
Response time
Release cycle
Releases (12mo)
Commit activity

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

  • A
    license
    Not graded
    quality
    D
    maintenance
    A simple MCP server that exposes a createUser tool to add users to a local JSON file via stdio transport.
    247
    1
    MIT
  • F
    license
    Not graded
    quality
    D
    maintenance
    A sample MCP server that exposes tools, resources, and prompts for managing users and todos, supporting both stdio and Streamable HTTP transports.
  • A
    license
    Not graded
    quality
    D
    maintenance
    Enables creating MCP (Model Context Protocol) servers with zero boilerplate, full TypeScript support, and multiple transports (stdio and HTTP).
    10
    1
    MIT

View all related MCP servers

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…

View all MCP Connectors

Latest Blog Posts

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