C.W.K.
Stream
Lesson 01 of 05 · published

최소 MCP Server (Python SDK)

~22 min · python-sdk, fastmcp, minimal, scaffolding

Level 0호기심 많은 독자
0 XP0/48 lessons0/14 achievements
0/100 XP to next level100 XP to go0% complete

Official Python SDK 가 modelcontextprotocol/python-sdk 에 layer 둘 ship: full control 용 low-level mcp.server.lowlevel 와 80% 케이스용 FastMCP. 대부분 사람이 FastMCP 에서 시작 (그리고 거기 머무름) — 데코레이터 기반 API 가 type annotation 을 JSON Schema 로 변환하고 docstring 을 description 으로 변환 — 동작하는 server 가 Python 20 줄 정도.

Install: pip install mcp (또는 uv add mcp). App 정의, 데코레이터로 tool/resource/prompt 붙이기, 돌리기. SDK 가 JSON-RPC framing, capability negotiation, error envelope, transport 선택 처리. 이 lesson 끝날 때면 — Claude Desktop 에서 연결해 모델이 호출하는 거 볼 수 있는 — server 갖게 됨.

Code

완전한, 돌릴 수 있는 MCP server·python
# server.py
from mcp.server.fastmcp import FastMCP

app = FastMCP("hello-server")

@app.tool()
async def get_stock_price(symbol: str) -> str:
    """Get the current stock price for a ticker symbol (toy implementation)."""
    prices = {"AAPL": 198.50, "GOOGL": 178.25, "MSFT": 425.00}
    p = prices.get(symbol.upper())
    if p is None:
        return f"Unknown symbol: {symbol}"
    return f"{symbol.upper()}: ${p:.2f}"

@app.resource("greeting://hello")
def hello() -> str:
    return "Hello from a tiny MCP server."

if __name__ == "__main__":
    app.run()  # 디폴트 stdio
Standalone 으로 sanity check·bash
$ python server.py
# Server 가 stdio 에서 listening. Client 에서 시도:
$ uvx mcp-cli connect "python server.py" tools/list

External links

Exercise

위 최소 server build. 돌려. 어느 MCP client (Claude Desktop, SDK 예제 client, mcp-cli) 든 연결. Stock-price tool 호출. Greeting resource read. 전체 loop 일부러 짧음 — 한 번 하면 미스터리 대부분 사라짐.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.