sample-mcp
A sample MCP server built with NestJS and TypeScript, demonstrating a ping tool for testing connectivity with MCP clients.
README
sample-mcp
NestJS + TypeScript 기반 MCP (Model Context Protocol) Server 샘플 프로젝트입니다.
Claude Desktop, Cursor, Codex 등 MCP를 지원하는 클라이언트에서 바로 연결하여 사용할 수 있습니다.
📁 프로젝트 구조
sample-mcp/
├── src/
│ ├── main.ts # 앱 진입점 (stdio transport로 MCP 서버 시작)
│ ├── app.module.ts # NestJS 루트 모듈
│ ├── config/
│ │ └── app.config.ts # 환경변수 설정
│ └── mcp/
│ ├── mcp.module.ts # MCP 모듈
│ ├── mcp.service.ts # MCP Server 핵심 서비스
│ └── tools/
│ ├── base.tool.ts # 모든 Tool의 추상 기반 클래스
│ ├── tool.registry.ts # Tool 중앙 관리 레지스트리
│ ├── tools.module.ts # Tools NestJS 모듈
│ └── ping/
│ ├── ping.tool.ts # ping Tool 구현체
│ └── ping.dto.ts # ping Tool 입출력 타입 정의
├── .env # 환경변수 (gitignore 대상)
├── .env.example # 환경변수 예시
├── .prettierrc # Prettier 설정
├── eslint.config.mjs # ESLint 설정
├── nest-cli.json # NestJS CLI 설정
├── tsconfig.json # TypeScript 설정 (strict mode)
└── package.json
🚀 시작하기
1. 의존성 설치
pnpm install
2. 환경변수 설정
cp .env.example .env
.env 파일을 필요에 따라 수정합니다:
MCP_SERVER_NAME=sample-mcp
MCP_SERVER_VERSION=1.0.0
LOG_LEVEL=log
NODE_ENV=development
3. 빌드
pnpm build
4. 실행
# 프로덕션 (빌드 후)
pnpm start:prod
# 개발 모드 (watch)
pnpm start:dev
⚠️ 중요: MCP Server는 stdio transport를 사용합니다.
직접 실행하면 터미널에서 JSON-RPC 메시지를 기다리는 상태가 됩니다.
실제 사용 시 MCP Client (Claude Desktop, Cursor 등)에서 이 서버를 실행합니다.
🔌 MCP Client 연결 설정
Claude Desktop
~/Library/Application Support/Claude/claude_desktop_config.json 파일을 편집합니다:
{
"mcpServers": {
"sample-mcp": {
"command": "node",
"args": ["/절대경로/sample-mcp/dist/main.js"],
"env": {
"NODE_ENV": "production"
}
}
}
}
또는 pnpm + ts-node로 빌드 없이 실행:
{
"mcpServers": {
"sample-mcp": {
"command": "pnpm",
"args": ["--dir", "/절대경로/sample-mcp", "start:prod"],
"env": {}
}
}
}
Cursor
.cursor/mcp.json 파일을 편집합니다:
{
"mcpServers": {
"sample-mcp": {
"command": "node",
"args": ["/절대경로/sample-mcp/dist/main.js"]
}
}
}
🛠️ 구현된 Tool
ping
MCP 서버 연결 상태를 확인하는 테스트 Tool입니다.
입력:
{
"message": "hello"
}
출력:
{
"success": true,
"message": "pong",
"receivedMessage": "hello"
}
➕ 새로운 Tool 추가하��
-
Tool 파일 생성
src/mcp/tools/<tool-name>/ ├── <tool-name>.tool.ts # BaseTool 상속 └── <tool-name>.dto.ts # Zod 스키마 + 타입 정의 -
<tool-name>.tool.ts구현import { Injectable } from '@nestjs/common'; import type { CallToolResult, Tool } from '@modelcontextprotocol/sdk/types.js'; import { BaseTool } from '../base.tool'; @Injectable() export class MyTool extends BaseTool { get definition(): Tool { return { name: 'my-tool', description: 'Tool 설명', inputSchema: { type: 'object', properties: { input: { type: 'string', description: '입력값' }, }, required: ['input'], }, }; } async execute(args: Record<string, unknown>): Promise<CallToolResult> { // 로직 구현 return this.success({ result: 'ok' }); } } -
tools.module.ts에 등록@Module({ providers: [ToolRegistry, PingTool, MyTool], // ✅ 추가 exports: [ToolRegistry], }) export class ToolsModule {} -
tool.registry.ts에 주입constructor( private readonly pingTool: PingTool, private readonly myTool: MyTool, // ✅ 추가 ) { this.registerTools([this.pingTool, this.myTool]); // ✅ 배열에 추가 }
🧹 코드 품질
# 린트 검사 및 자동 수정
pnpm lint
# 코드 포맷팅
pnpm format
# 테스트
pnpm test
📦 기술 스택
| 항목 | 버전 |
|---|---|
| NestJS | ^11.0.0 |
| TypeScript | ^5.1.3 (strict mode) |
| MCP SDK | ^1.12.1 |
| Zod | ^3.25.0 |
| pnpm | latest |
| Node.js | ≥ 18.0.0 |
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。