본문 바로가기
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 에 있고, 층을 둘 내놔. 세밀하게 다 잡고 싶을 때 쓰는 mcp.server.lowlevel, 그리고 80% 의 경우를 덮어주는 FastMCP. 사람들은 보통 FastMCP 로 시작하고 거기 눌러앉아. 데코레이터로 쓰는 API 라, type annotation 을 JSON Schema 로 바꿔주고 docstring 을 description 으로 바꿔주거든. 돌아가는 server 하나가 Python 스무 줄쯤이야.

설치는 pip install mcp (또는 uv add mcp). App 을 만들고, 데코레이터로 tool 과 resource 와 prompt 를 붙이고, 돌리면 끝이야. JSON-RPC 의 틀도, capability 맞추기도, 에러 봉투도, transport 고르기도 전부 SDK 가 해줘. 이 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 를 만들어서 돌려. MCP client 아무거나 붙여봐 (Claude Desktop 이든 SDK 예제 client 든 mcp-cli 든). 주가 tool 을 부르고, 인사 resource 를 읽어. 이 한 바퀴는 일부러 짧게 만들어뒀어 — 한 번 돌려보면 안개 대부분이 걷혀.

Progress

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

댓글 0

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

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