MCP Auth Template
A template for building MCP servers that supports both HTTP transport with Bearer token authentication and stdio-based connections for local clients like Codex and Claude. It provides a foundational structure for practicing secure authentication and tool integration within the Model Context Protocol.
README
MCP Auth Template
실습용 MCP 템플릿입니다.
이 프로젝트는 두 가지 목적을 같이 다룹니다.
HTTP 기반 MCP 서버에서 인증이 어떻게 붙는지 연습stdio 기반 MCP 서버를 Codex 같은 로컬 MCP 클라이언트에 연결
현재 포함된 기능은 최소 구성입니다.
GET /healthzPOST /mcpwithBearer tokenstdioMCP entrypointhellotool 1개
구성
핵심 파일은 아래와 같습니다.
src/mcp-server.js- 공통 MCP 서버 정의
hellotool 등록
src/server.js- HTTP MCP 서버
/healthz/mcpBearer 인증
src/stdio.js- stdio MCP 서버
- Codex 같은 로컬 클라이언트용
툴을 추가하는 방법은 별도 문서로 분리했습니다.
빠른 시작
1. 설치
npm install
2. 환경 변수 준비
cp .env.example .env
기본값은 아래와 같습니다.
PORT=3000
HOST=127.0.0.1
MCP_BEARER_TOKEN=dev-token
실행 방식
HTTP 서버 실행
npm start
또는:
npm run start:http
실행 후:
- health check:
http://127.0.0.1:3000/healthz - MCP endpoint:
http://127.0.0.1:3000/mcp
stdio 서버 실행
npm run start:stdio
이 방식은 포트를 열지 않습니다.
로컬 MCP 클라이언트가 프로세스를 직접 실행해서 stdin/stdout으로 통신합니다.
Transport 차이
HTTP
- 네가 직접 서버를 띄워야 함
Authorization: Bearer <token>필요- 인증 연습에 적합
stdio
- MCP 클라이언트가 서버 프로세스를 직접 실행
- 포트 불필요
- Codex 연결에 적합
- HTTP Bearer 인증은 사용하지 않음
중요한 차이:
HTTP: 네가 서버를 먼저 실행stdio: Codex가 필요할 때 서버를 실행
HTTP 인증
/mcp 요청은 모두 아래 헤더가 필요합니다.
Authorization: Bearer dev-token
값은 .env의 MCP_BEARER_TOKEN으로 변경할 수 있습니다.
인증 실패 시:
401 UnauthorizedWWW-Authenticate헤더 반환
HTTP MCP 실습 예제
1. Health check
curl -i http://127.0.0.1:3000/healthz
2. initialize
curl -i \
-X POST http://127.0.0.1:3000/mcp \
-H 'Content-Type: application/json' \
-H 'Accept: application/json, text/event-stream' \
-H 'Authorization: Bearer dev-token' \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "initialize",
"params": {
"protocolVersion": "2025-11-05",
"capabilities": {},
"clientInfo": {
"name": "curl-client",
"version": "0.1.0"
}
}
}'
응답 헤더의 Mcp-Session-Id 값을 다음 요청에 재사용합니다.
3. initialized notification
curl -i \
-X POST http://127.0.0.1:3000/mcp \
-H 'Content-Type: application/json' \
-H 'Accept: application/json, text/event-stream' \
-H 'Authorization: Bearer dev-token' \
-H 'Mcp-Session-Id: <session-id>' \
-d '{
"jsonrpc": "2.0",
"method": "notifications/initialized",
"params": {}
}'
4. tools/list
curl -i \
-X POST http://127.0.0.1:3000/mcp \
-H 'Content-Type: application/json' \
-H 'Accept: application/json, text/event-stream' \
-H 'Authorization: Bearer dev-token' \
-H 'Mcp-Session-Id: <session-id>' \
-d '{
"jsonrpc": "2.0",
"id": 2,
"method": "tools/list",
"params": {}
}'
5. hello tool 호출
curl -i \
-X POST http://127.0.0.1:3000/mcp \
-H 'Content-Type: application/json' \
-H 'Accept: application/json, text/event-stream' \
-H 'Authorization: Bearer dev-token' \
-H 'Mcp-Session-Id: <session-id>' \
-d '{
"jsonrpc": "2.0",
"id": 3,
"method": "tools/call",
"params": {
"name": "hello",
"arguments": {
"name": "MCP"
}
}
}'
예상 응답 예시:
{
"result": {
"content": [
{
"type": "text",
"text": "Hello, MCP! This response came from a authenticated HTTP MCP tool at 2026-03-18T05:06:22.258Z."
}
],
"structuredContent": {
"greeting": "Hello, MCP!",
"accessMode": "http",
"server": "mcp-auth-template",
"timestamp": "2026-03-18T05:06:22.258Z"
}
},
"jsonrpc": "2.0",
"id": 3
}
Codex에 연결하기
이 프로젝트를 Codex에 붙일 때는 HTTP가 아니라 stdio를 사용합니다.
이유:
- Codex가 MCP 서버를 자식 프로세스로 직접 실행할 수 있음
- 포트를 따로 열 필요가 없음
- 로컬 실습이 더 단순함
Codex 설정
~/.codex/config.toml에 아래를 추가합니다.
[mcp_servers.hello_local]
command = "node"
args = ["/Users/leeseungchan/develop/mcp/src/stdio.js"]
이 프로젝트에서 Codex를 바로 쓰려면 trusted project 설정도 있으면 편합니다.
[projects."/Users/leeseungchan/develop/mcp"]
trust_level = "trusted"
Codex 실행
cd /Users/leeseungchan/develop/mcp
codex
Codex 안에서 테스트
Codex에 아래처럼 물어보면 됩니다.
사용 가능한 MCP 도구 보여줘
hello_local의 hello 툴 호출해줘
hello_local의 hello 툴을 name=MCP 로 호출해줘
stdio 방식에서 중요한 점
npm run start:stdio를 미리 켜둘 필요는 없음- Codex가 필요할 때
node /Users/leeseungchan/develop/mcp/src/stdio.js를 직접 실행 - Codex 세션이 끝나면 같이 종료되는 쪽으로 이해하면 됨
Claude 연결 튜토리얼
이 프로젝트를 Claude 쪽에 붙일 때도 stdio 방식을 쓰는 편이 가장 단순합니다.
방법 1. Claude Code CLI에서 바로 추가
Anthropic 공식 문서 기준으로 Claude Code는 로컬 stdio MCP 서버를 아래 형태로 추가할 수 있습니다.
claude mcp add hello-local -- node /Users/leeseungchan/develop/mcp/src/stdio.js
추가 후 확인:
claude mcp list
세부 설정 보기:
claude mcp get hello-local
이후 Claude Code를 실행한 뒤 다음처럼 요청하면 됩니다.
사용 가능한 MCP 도구 보여줘
hello-local의 hello 툴 호출해줘
방법 2. Claude Desktop 설정 파일에 직접 추가
Anthropic 공식 문서에는 Claude Desktop에서 claude_desktop_config.json의 mcpServers 항목으로 MCP 서버를 등록하는 예시가 나옵니다.
이 프로젝트를 붙일 때는 아래처럼 넣으면 됩니다.
{
"mcpServers": {
"hello-local": {
"command": "node",
"args": ["/Users/leeseungchan/develop/mcp/src/stdio.js"],
"env": {}
}
}
}
Claude Desktop을 다시 열고 아래처럼 물어보면 됩니다.
사용 가능한 MCP 도구 보여줘
hello-local의 hello 툴을 name=Claude 로 호출해줘
참고
- Claude 쪽 연결도
HTTP가 아니라stdio사용을 권장 - 즉,
npm run start:stdio를 미리 켜둘 필요 없음 - Claude가 필요할 때
node /Users/leeseungchan/develop/mcp/src/stdio.js를 직접 실행 - 팀 공유가 필요하면 Claude Code 문서의
--scope또는.mcp.json방식을 쓰는 편이 좋음
지금 프로젝트에서 확인된 흐름
직접 확인한 동작은 아래입니다.
- HTTP 서버 기동
GET /healthz정상 응답- 인증 없는
/mcp요청에401 - 인증된
initialize tools/listtools/call- stdio 서버에서
initialize -> notifications/initialized -> tools/list -> tools/call - Codex용
~/.codex/config.toml에hello_local등록
다음 확장 포인트
이 템플릿은 여기서 확장하면 됩니다.
hello말고 툴 추가- 툴 파일 분리
- Bearer 토큰 비교를
JWT검증으로 교체 - 최종적으로
OAuth기반 인증으로 확장 resources/prompts추가
참고
- HTTP 인증 로직:
src/server.js - 공통 MCP 툴 등록:
src/mcp-server.js - Codex 연결용 stdio 엔트리:
src/stdio.js
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.