Skip to main content

MCP Python SDK v2 스타터 서버

MCP Python SDK 문서를 참고하여 만든 최소 구성의 MCP(Model Context Protocol) 서버 예제입니다.
Python 3.13 및 uv 환경으로 구성되어 있습니다. 서버 측 Skills 확장을 패키지에 포함하고 PyPI의 mcp 2.3.0과 호환되도록 구성했습니다. 개발 테스트의 Skills 클라이언트는 MCP SDK 개발 커밋을 사용합니다.

프로젝트 구조

저장소 루트의 host*.py, server-completion.py 등은 학습용 예제로 유지하며 wheel에는 포함하지 않습니다. 루트 server.py는 예제들이 패키지 서버를 실행하기 위한 얇은 진입점입니다. 배포 대상은 src/mcp_v2_starter/입니다.

  • src/mcp_v2_starter/server.py — 서버 구현 및 패키지 진입점
  • server.py — 기존 예제 호스트를 위한 실행 진입점
  • src/mcp_v2_starter/skills/sample-skill/ — SKILL.md와 참조 파일을 포함한 스킬 예제
  • host.py — server.py의 mcp.resource(info://server, greeting://{name})를 조회/읽기하는 간단한 stdio 호스트 애플리케이션
  • tests/test_server.py — mcp.Client(mcp) 인메모리 클라이언트를 이용한 pytest 테스트
  • tests/test_host.py — host.py의 리소스 조회·포맷·stdio 통신 테스트
  • pyproject.toml / uv.lock — mcp[cli]==2.3.0 및 개발용 pytest 의존성 관리
  • .python-version — Python 3.13 고정

포함된 MCP 기본 요소

  1. Tools (@mcp.tool())
    • add(a: int, b: int) -> int: 두 정수를 더합니다.
    • echo_with_context(message: str, ctx: Context) -> str: v2의 명시적 Context 주입을 사용해 await ctx.report_progress(...)와 ctx.request_id로 진행 상태를 알리고 메시지를 반환합니다.
  2. Resources (@mcp.resource(...))
    • info://server: 정적 서버 메타데이터를 반환합니다.
    • greeting://{name}: URI 템플릿 기반 동적 인사말을 반환합니다.
  3. Prompts (@mcp.prompt())
    • review_code(code: str, language: str = "python") -> str: 코드 리뷰용 재사용 프롬프트 템플릿을 생성합니다.
  4. Skills
    • skills/list, skills/get으로 스킬 메타데이터와 파일별 SHA-256 해시 및 크기를 조회합니다.
    • resources/read로 skill://sample-skill/SKILL.md 등의 파일을 읽습니다. resources/directory/read로 skill://sample-skill 또는 skill://sample-skill/references의 바로 아래 항목을 조회합니다.
    • 서버 시작 시 skills/의 각 하위 디렉터리에서 SKILL.md와 파일들을 읽습니다. 파일을 추가하거나 변경한 후에는 서버를 재시작하세요. 심볼릭 링크는 제공하지 않습니다.

호스트 프로그램 사용 방법 (host.py)

host.py는 server.py를 stdio 서브프로세스로 자동 실행해 연결하므로, server.py를 미리 따로 띄울 필요가 없습니다. 연결 후 list_resources(), list_resource_templates(), read_resource()를 호출해 정적 리소스(info://server)와 URI 템플릿(greeting://{name})을 읽어 출력합니다.

CLI 옵션

옵션 기본값 설명
--name NAME World greeting://{name} URI 템플릿에 전달할 이름 (한글·공백 등은 RFC 6570 규칙으로 자동 퍼센트 인코딩)
--uri URI 없음 추가로 직접 조회할 리소스 URI (예: info://server, greeting://Alice)
-h, --help - 도움말 출력

실행 예시

# 기본 실행 (--name World)
uv run python host.py

# 템플릿 이름 지정
uv run python host.py --name 홍길동

# 추가 URI 직접 읽기
uv run python host.py --uri greeting://Alice

# 옵션 조합
uv run python host.py --name 홍길동 --uri info://server

# 도움말 확인
uv run python host.py --help

출력 예시

uv run python host.py 실행 시 다음과 같이 연결 정보와 리소스 내용을 출력합니다:

Connected to server: Demo (protocol: 2026-07-28)

[Static Resources]
  * info://server (server_info) - Return basic metadata about this starter MCP server.
    -> Demo MCP Server (Python SDK v2) - exposes tools, resources, and prompts.

[Resource Templates]
  * greeting://{name} (greeting) - Greet someone by name using a URI template.
  * Expanded: greeting://World
    -> Hello, World!

에러 처리 및 테스트

  • 존재하지 않는 URI(예: uv run python host.py --uri unknown://missing)를 요청하면 표준 에러(stderr)에 MCP error: ... 메시지를 출력하고 종료 코드 1로 종료합니다.
  • 호스트 관련 테스트만 실행하려면 다음 명령을 사용하세요:
uv run pytest tests/test_host.py -v

테스트 및 실행 방법

1. 인메모리 단위 테스트 실행

uv run pytest -v

2. MCP Inspector로 대화형 테스트 (mcp dev)

uv run mcp dev server.py

브라우저에서 Inspector UI가 열리면 add, echo_with_context, greeting://{name}, review_code 등을 직접 호출해 볼 수 있습니다.

3. 서버 실행 (stdio / streamable-http)

기본 stdio 트랜스포트로 실행(로컬 MCP 호스트/클라이언트 연결용):

uv run mcp run server.py
# 또는
uv run python server.py

Streamable HTTP 트랜스포트로 실행:

uv run mcp run server.py --transport streamable-http

주의: stdio 트랜스포트에서는 표준 출력(stdout)이 JSON-RPC 프로토콜 메시지 전송에 사용됩니다. server.py 내부에서 print()를 호출하지 마세요. 디버깅 로그가 필요하면 표준 에러(sys.stderr)나 logging 모듈(stderr 출력)을 사용하세요.

PyPI 배포

패키지 빌드, 의존성 제약 및 배포 절차는 DEPLOY-TO-PYPI.md를 참고하세요.

Metadata

Release files for mcp-v2-starter 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mcp-v2-starter 0.1.0
File Size Uploaded Provenance Actions
mcp_v2_starter-0.1.0.tar.gz 81.8 kB Without provenance Details for mcp_v2_starter-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for mcp-v2-starter 0.1.0
File Interpreter ABI Platform Actions
mcp_v2_starter-0.1.0-py3-none-any.whl Python 3 none any Details for mcp_v2_starter-0.1.0-py3-none-any.whl

Total release size: 98.4 kB

Release files / mcp_v2_starter-0.1.0.tar.gz

Download URL mcp_v2_starter-0.1.0.tar.gz
Size 81.8 kB
Tags Source
SHA-256 checksum
How to use checksums
f554ac84763cdf55f4a1201c39638c5d92632c5740eb862a07b88e1cfa3acaf1
BLAKE2b-256 checksum
How to use checksums
15c014f0c69641cc2edd5bf0354033da0eada40a5ae8c0328976a298887b15c4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / mcp_v2_starter-0.1.0-py3-none-any.whl

Download URL mcp_v2_starter-0.1.0-py3-none-any.whl
Size 16.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cddbae34cecea023531c41ada2045982c2a10ece81ab5311c69453a41b738fb8
BLAKE2b-256 checksum
How to use checksums
1b5c8e75d211ea77149e6c085ffcf90a9e0ea53d9305208bca0a2d729ea20cac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for mcp-v2-starter 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page