Unit Converter MCP Server
단위 변환기 API + MCP 튜토리얼
FastAPI 앱을 빌드하고, FastMCP로 래핑하며, MCP HTTP/SSE 엔드포인트를 마운트하고, 리소스와 프롬프트를 등록한 뒤 uvicorn을 시작합니다.
requirements.txt – Python 의존성.
사전 요구 사항
Python 3.10+ (3.12에서 테스트됨).
가상 환경.
아래의 npm 인스펙터.
⸻
Related MCP server: Local Utilities MCP Server
이 폴더에서 설정하기
python -m venv .venv
# Mac or Gitbash
source .venv/bin/activate
# Windows powershell:
.venv\Scripts\activate
python -m pip install -r requirements.txt⸻
HTTP + MCP 서버 실행
# start the server
python converter_streamable_http_server.py
# or
python -m converter_streamable_http_server
다음 내용을 확인할 수 있습니다:
Swagger UI: http://localhost:8003/docs
ReDoc: http://localhost:8003/redoc
FastMCP가 제공하는 MCP 엔드포인트:
streamable-http: http://localhost:8003/mcp
⸻
HTTP 엔드포인트 테스트 (curl)
curl -X POST "http://localhost:8003/miles-to-kilometers?miles=3.1" \
-H "Authorization: Bearer 143f4a46d74fee0d7918b2857577868cb3daf9e6e50ee91c2f7975ba26fdb8f7"
# If we use pydantic models
curl -X POST "http://localhost:8003/miles-to-kilometers" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer Y658139cf61948208ed76a4b36122b9552ec5c3f6da5e02f7c5d85d995dede17dE" \
-d "3.1"# Celsius → Fahrenheit
curl -X POST "http://localhost:8003/celsius-to-fahrenheit" \
-H "Content-Type: application/json" \
-d "25"# Fahrenheit → Celsius
curl -X POST "http://localhost:8003/fahrenheit-to-celsius" \
-H "Content-Type: application/json" \
-d "86"# Kilometers → Miles
curl -X POST "http://localhost:8003/kilometers-to-miles" \
-H "Content-Type: application/json" \
-d "5"# Miles → Kilometers (rejects negative values)
curl -X POST "http://localhost:8003/miles-to-kilometers" \
-H "Content-Type: application/json" \
-d "3.1"각 엔드포인트는 다음과 같은 JSON을 반환합니다:
{ "result": , "operation": "..." } 또는 잘못된 입력의 경우 { "error": "..." }.
헤더 및 인증 (모두 공통)
JSON 콘텐츠 유형 추가 (선택적으로 인증 토큰 추가)
-H "Content-Type: application/json"
-H "Authorization: Bearer "
우리 서버는 아직 인증을 요구하지 않으므로 Authorization 헤더는 생략할 수 있습니다.
MCP와 함께 사용하기 (VS Code 예시)
위와 같이 서버를 시작합니다.
MCP 클라이언트를 해당 프로세스에 연결합니다.
// Example VS Code .vscode/mcp.json entry:
{
"servers": {
"UnitConverter": {
"command": "python",
"args": ["converter_api_tutorial.py"]
}
}
}MCP 클라이언트에서 아티팩트를 나열합니다. 다음을 확인할 수 있습니다:
도구: celsius_to_fahrenheit, fahrenheit_to_celsius, kilometers_to_miles, miles_to_kilometers
리소스: resource://unit_reference, resource://troubleshooting_guide
프롬프트: explain_conversion, api_usage
⸻
npm MCP 인스펙터로 검사하기
브라우저에서 모든 항목(도구, 리소스, 프롬프트)을 탐색합니다.
서버가 http://localhost:8003에서 이미 실행 중인 상태여야 합니다.
# If env error appears
npx @modelcontextprotocol/inspector@latest -e DUMMY=1 --url http://localhost:8003/mcp --transport streamable-http
# If you want to test the older HTTP:
npx @modelcontextprotocol/inspector@latest -e DUMMY=1 --url http://localhost:8003/mcp --transport http
# If you want to test the deprecated SSE:
npx @modelcontextprotocol/inspector@latest -e DUMMY=1 --url http://localhost:8003/sse --transport sseSTDIO 서버만 실행하려면
# If venv is ".venv", change to .\.venv\Scripts\python.exe
npx @modelcontextprotocol/inspector python converter_stdio_server.pyUI는 기본적으로 localhost:5173에서 실행됩니다.
필요한 경우 UI 포트 변경: CLIENT_PORT=8080 npx @modelcontextprotocol/inspector --url http://localhost:8003/mcp --transport http
필요한 경우 헤더 추가: --header "Authorization: Bearer TOKEN".
프롬프트 및 리소스를 위한 JSON-RPC 예시
모든 프롬프트 나열
curl -s -X POST <SERVER_URL> \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"prompts/list","params":{},"id":1}'⸻
특정 프롬프트 가져오기
curl -s -X POST <SERVER_URL> \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"prompts/get","params":{"name":"summarize"},"id":2}'⸻
변수를 사용하여 프롬프트 렌더링/실행
curl -s -X POST <SERVER_URL> \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"prompts/render","params":{"name":"summarize","variables":{"text":"This is the content to summarize","tone":"neutral"}},"id":3}'사용 가능한 리소스 나열
curl -s -X POST <SERVER_URL> \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"resources/list","params":{},"id":4}'URI로 리소스 읽기
curl -s -X POST <SERVER_URL> \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"resources/read","params":{"uri":"file:///data/report.pdf"},"id":5}'리소스 검색 (지원되는 경우)
curl -s -X POST <SERVER_URL> \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"resources/search","params":{"query":"error OR exception","limit":50},"id":6}'⸻
오류 처리
구문 분석 오류 (-32700)
잘못된 요청 (-32600)
메서드를 찾을 수 없음 (-32601)
잘못된 매개변수 (-32602)
내부 오류 (-32603)
참고 사항
macOS/Linux (bash/zsh) • 위의 예시는 그대로 작동합니다.
# Windows PowerShell
curl -Method POST <SERVER_URL> ` -Headers @{ "Content-Type"="application/json" }`
-Body '{"jsonrpc":"2.0","method":"prompts/list","params":{},"id":1}'Windows CMD
curl -s -X POST <SERVER_URL> -H "Content-Type: application/json" -d "{\"jsonrpc\":\"2.0\",\"method\":\"prompts/list\",\"params\":{},\"id\":1}"This server cannot be deployed
Maintenance
Related MCP Connectors
OpenWeather MCP — wraps the OpenWeatherMap API (openweathermap.org)
Baking unit conversion (cups/grams/temp/recipe scaling). convert_amount, convert_temperature
60+ units, live FX, timezones, and date arithmetic for AI agents.
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceEnables temperature conversion from Fahrenheit to Celsius through HTTP requests. Provides a simple MCP tool for temperature unit conversion with AWS Lambda deployment support.19 npm-
- AlicenseNot gradedqualityDmaintenanceProvides essential utility tools for text processing, file operations, hashing, temperature conversion, password generation, and date/time operations through a comprehensive MCP interface.MIT
- AlicenseAqualityDmaintenanceMCP server for converting cooking measurements (volume, weight, temperature) between common units like ml, cup, g, oz, and Celsius/Fahrenheit.31MIT
- AlicenseAqualityDmaintenanceAn MCP server that provides deterministic unit conversions backed by Pint, enabling exact unit conversions, compatibility checks, and parsing of quantities for LLMs.5MIT