Sign in to save your progressYou can keep reading without an account, but completed lessons won't be saved.
Sign in

튜토리얼 단계

샘플 프로젝트를 살펴보면서 이 기능을 구현하는 방법을 더 잘 이해해 보겠습니다.

도구 함수는 마지막 인수로 'Context'를 자동으로 받습니다. 이 객체에는 클라이언트에 로깅 및 진행 상황을 보고하기 위한 메서드가 있습니다.

from mcp.server.fastmcp import FastMCP, Context
import asyncio
mcp = FastMCP(name="Demo Server")
@mcp.tool()
async def add(a: int, b: int, ctx: Context) -> int:
await ctx.info("Preparing to add...")
await ctx.report_progress(20, 100)
await asyncio.sleep(2)
await ctx.info("OK, adding...")
await ctx.report_progress(80, 100)
return a + b
if __name__ == "__main__":
mcp.run(transport="stdio")