Skip to main content
Glama
TypeScript MCP Server Boilerplate

TypeScript MCP Server Boilerplate

by kimhailey

my-mcp-server (Vercel Β· Streamable HTTP)

Next.js App Router 와 mcp-handler μœ„μ—μ„œ λ™μž‘ν•˜λŠ” Vercel λ°°ν¬ν˜• MCP μ„œλ²„μž…λ‹ˆλ‹€. κΈ°μ‘΄ StdioServerTransport 기반 둜컬 μ„œλ²„λ₯Ό Streamable HTTP 트랜슀포트둜 μ΄μ „ν•˜μ—¬ μž„μ˜μ˜ MCP ν΄λΌμ΄μ–ΈνŠΈ(Cursor, Claude Desktop, MCP Inspector λ“±) μ—μ„œ μ›κ²©μœΌλ‘œ ν˜ΈμΆœν•  수 μžˆμŠ΅λ‹ˆλ‹€.

μ•„ν‚€ν…μ²˜

MCP Client (Cursor / Inspector)
       β”‚  Streamable HTTP
       β”‚  + x-hf-token header (선택)
       β–Ό
Next.js App Router (on Vercel)
  app/api/[transport]/route.ts
       β”‚
       β–Ό
createMcpHandler ─► McpServer
  β”œβ”€ tools: greet / calculate / time / geocode / weather / generate-image
  β”œβ”€ prompts: code-review
  └─ resources: server-info

[transport] 동적 μ„Έκ·Έλ¨ΌνŠΈλ₯Ό μ‚¬μš©ν•΄ λ§€ μš”μ²­λ§ˆλ‹€ ν•Έλ“€λŸ¬λ₯Ό μƒˆλ‘œ λ§Œλ“€κ³ , μš”μ²­ 헀더 (x-hf-token) 와 ν™˜κ²½λ³€μˆ˜(HF_TOKEN) λ₯Ό ν΄λ‘œμ €λ‘œ μΊ‘μ²˜ν•΄ generate-image 도ꡬ에 μ „λ‹¬ν•©λ‹ˆλ‹€.

Related MCP server: TypeScript MCP Server Boilerplate

ν”„λ‘œμ νŠΈ ꡬ쑰

.
β”œβ”€β”€ app/
β”‚   β”œβ”€β”€ api/
β”‚   β”‚   └── [transport]/
β”‚   β”‚       └── route.ts   # MCP HTTP μ—”λ“œν¬μΈνŠΈ
β”‚   β”œβ”€β”€ layout.tsx
β”‚   └── page.tsx           # μ•ˆλ‚΄μš© 정적 νŽ˜μ΄μ§€
β”œβ”€β”€ next.config.mjs
β”œβ”€β”€ next-env.d.ts
β”œβ”€β”€ package.json
β”œβ”€β”€ tsconfig.json
└── .env.example

λΉ λ₯Έ μ‹œμž‘

1. μ˜μ‘΄μ„± μ„€μΉ˜

npm install

2. ν™˜κ²½λ³€μˆ˜ μ„€μ • (선택)

generate-image 도ꡬλ₯Ό μ‚¬μš©ν•  κ³„νšμ΄λΌλ©΄ .env.example 을 .env.local 둜 λ³΅μ‚¬ν•œ λ’€ HuggingFace 토큰을 μ±„μ›Œ λ„£μŠ΅λ‹ˆλ‹€.

cp .env.example .env.local
# 그리고 HF_TOKEN=hf_xxx... 둜 μˆ˜μ •

ν™˜κ²½λ³€μˆ˜κ°€ 없어도 ν΄λΌμ΄μ–ΈνŠΈκ°€ λ§€ μš”μ²­λ§ˆλ‹€ x-hf-token 헀더λ₯Ό 보내면 λ™μž‘ν•©λ‹ˆλ‹€.

3. 둜컬 μ‹€ν–‰

npm run dev

κΈ°λ³Έ μ—”λ“œν¬μΈνŠΈ:

4. MCP Inspector 둜 검증

npx @modelcontextprotocol/inspector@latest

Inspector UI μ—μ„œ:

  1. Transport: Streamable HTTP

  2. URL: http://localhost:3000/api/mcp

  3. (선택) Custom Headers 에 x-hf-token: hf_xxx... μΆ”κ°€

  4. Connect β†’ List Tools β†’ 각 도ꡬ 호좜 ν…ŒμŠ€νŠΈ

ν΄λΌμ΄μ–ΈνŠΈ μ—°κ²°

Cursor (./.cursor/mcp.json)

{
    "mcpServers": {
        "my-mcp-server": {
            "url": "https://<your-app>.vercel.app/api/mcp",
            "headers": {
                "x-hf-token": "hf_xxx..."
            }
        }
    }
}

url 만 있으면 5개 도ꡬ(greet/calculate/time/geocode/weather)λŠ” 정상 λ™μž‘ν•©λ‹ˆλ‹€. generate-image λ₯Ό μ‚¬μš©ν•˜λ €λ©΄ headers.x-hf-token λ˜λŠ” μ„œλ²„μΈ‘ HF_TOKEN ν™˜κ²½λ³€μˆ˜ 쀑 ν•˜λ‚˜κ°€ λ°˜λ“œμ‹œ ν•„μš”ν•©λ‹ˆλ‹€.

Streamable HTTP 미지원 ν΄λΌμ΄μ–ΈνŠΈ (mcp-remote λΈŒλ¦Ώμ§€)

{
    "mcpServers": {
        "my-mcp-server": {
            "command": "npx",
            "args": [
                "-y",
                "mcp-remote",
                "https://<your-app>.vercel.app/api/mcp",
                "--header",
                "x-hf-token:hf_xxx..."
            ]
        }
    }
}

Vercel 배포

방법 1: Vercel CLI

npm i -g vercel
vercel

방법 2: GitHub 연동

  1. GitHub μ €μž₯μ†Œμ— ν‘Έμ‹œ

  2. https://vercel.com/new μ—μ„œ μ €μž₯μ†Œ 선택

  3. Framework Preset: Next.js (μžλ™ 감지)

  4. Environment Variables μ—μ„œ (선택) HF_TOKEN μΆ”κ°€

  5. Deploy

배포가 μ™„λ£Œλ˜λ©΄ https://<your-app>.vercel.app/api/mcp κ°€ MCP μ—”λ“œν¬μΈνŠΈμž…λ‹ˆλ‹€.

λ“±λ‘λœ 도ꡬ

이름

μ„€λͺ…

greet

이름과 μ–Έμ–΄(ko/en)둜 인사말 생성

calculate

두 숫자 사칙연산 (add/subtract/multiply/divide)

time

νƒ€μž„μ‘΄λ³„ ν˜„μž¬ μ‹œκ°„

geocode

Open-Meteo 둜 λ„μ‹œλͺ… β†’ μœ„κ²½λ„ 쑰회

weather

Open-Meteo 둜 μœ„κ²½λ„ β†’ ν˜„μž¬ 날씨 쑰회

generate-image

HuggingFace FLUX.1-schnell 이미지 생성 (x-hf-token λ˜λŠ” HF_TOKEN)

ν”„λ‘¬ν”„νŠΈ / λ¦¬μ†ŒμŠ€

  • ν”„λ‘¬ν”„νŠΈ code-review: μ½”λ“œλ₯Ό μž…λ ₯λ°›μ•„ μ‹œλ‹ˆμ–΄ μ—”μ§€λ‹ˆμ–΄ κ΄€μ μ˜ 체계적 리뷰 λ©”μ‹œμ§€ 생성

  • λ¦¬μ†ŒμŠ€ server-info (mcp://my-mcp-server/info): μ„œλ²„ 메타데이터(JSON)

HF_TOKEN 처리 μ •μ±…

x-hf-token 헀더 ──(있으면 μ‚¬μš©)──► HuggingFace Inference
       β”‚ (μ—†μŒ)
       β–Ό
HF_TOKEN ν™˜κ²½λ³€μˆ˜ ──(있으면 μ‚¬μš©)──► HuggingFace Inference
       β”‚ (μ—†μŒ)
       β–Ό
generate-image 도ꡬ가 λͺ…ν™•ν•œ μ—λŸ¬ λ©”μ‹œμ§€ λ°˜ν™˜

헀더가 μš°μ„ μ΄λ―€λ‘œ 동일 배포 μΈμŠ€ν„΄μŠ€λ₯Ό μ—¬λŸ¬ μ‚¬μš©μžκ°€ 각자의 ν† ν°μœΌλ‘œ μ‚¬μš©ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

슀크립트

  • npm run dev: 둜컬 개발 μ„œλ²„

  • npm run build: ν”„λ‘œλ•μ…˜ λΉŒλ“œ

  • npm run start: λΉŒλ“œ κ²°κ³Ό μ‹€ν–‰

  • npm run lint: Next.js lint

참고 자료

λΌμ΄μ„ μŠ€

MIT

Available Tools

6 tools
calculateA

두 μˆ«μžμ— λŒ€ν•΄ 사칙연산(+, -, *, /)을 μˆ˜ν–‰ν•©λ‹ˆλ‹€.

Inputs: a (required), b (required), operation (required). Returns: content

generate-imageA

HuggingFace FLUX.1-schnell λͺ¨λΈλ‘œ 이미지λ₯Ό μƒμ„±ν•©λ‹ˆλ‹€. HF_TOKEN ν™˜κ²½λ³€μˆ˜κ°€ ν•„μš”ν•©λ‹ˆλ‹€.

Inputs: prompt (required), num_inference_steps.

geocodeA

λ„μ‹œ μ΄λ¦„μœΌλ‘œ μœ„λ„Β·κ²½λ„ μ’Œν‘œλ₯Ό μ‘°νšŒν•©λ‹ˆλ‹€.

Inputs: city (required), language. Returns: content

greetA

이름과 μ–Έμ–΄λ₯Ό μž…λ ₯ν•˜λ©΄ 인사말을 λ°˜ν™˜ν•©λ‹ˆλ‹€.

Inputs: name (required), language. Returns: content

timeA

ν˜„μž¬ λ‚ μ§œμ™€ μ‹œκ°„μ„ λ°˜ν™˜ν•©λ‹ˆλ‹€.

Inputs: timezone. Returns: content

weatherB

μœ„λ„Β·κ²½λ„ μ’Œν‘œλ‘œ ν˜„μž¬ 날씨λ₯Ό μ‘°νšŒν•©λ‹ˆλ‹€.

Inputs: latitude (required), longitude (required). Returns: content

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A3.6/5.0

    Scored across 6 tools

    Disambiguation5/5

    Each tool has a clearly distinct purpose (arithmetic, image generation, geocoding, greeting, time, weather), with no overlap or ambiguity in their intended use.

    Naming Consistency4/5

    Most tool names are single-word verbs (calculate, geocode, greet, time, weather), with one hyphenated compound (generate-image). This is mostly consistent but the hyphenated name is a minor deviation.

    Tool Count4/5

    With 6 tools, the count is reasonable for a boilerplate example server. It is neither too sparse nor overly heavy for illustrating various capabilities.

    Completeness3/5

    As a boilerplate, the tool set does not target a specific domain, so completeness is inherently neutral. The tools cover basic utility examples but lack any overarching purpose or desired workflow.

    Maintenance

    ActivityInactive
    ResponsivenessOutdated data

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      D
      maintenance
      A boilerplate project for quickly developing MCP servers using TypeScript SDK, featuring example tools (calculator, greeting) and resources with Zod schema validation.
      ISC
    • A
      license
      Not graded
      quality
      D
      maintenance
      A boilerplate project for quickly developing MCP servers using TypeScript SDK, with example implementations of calculator and greeting tools, plus resource handling capabilities.
      ISC
    • A
      license
      Not graded
      quality
      D
      maintenance
      A boilerplate project for quickly developing Model Context Protocol (MCP) servers using TypeScript, with example tools (calculator, greet) and resources (server info) pre-implemented.
      85 npm
      ISC