MCP 서버 프롬프트 정의하기
재사용 가능한 프롬프트를 환율 변환 MCP 서버에 추가하여, LLM이 변환 요청을 처리하는 방법과 추가 정보가 필요한 경우(예: 금액 또는 통화 코드 누락) 언제 사용자에게 확인을 요청해야 하는지 알 수 있도록 합니다. 이를 통해 사용자의 프롬프트 부담을 줄이고 어시스턴트의 신뢰성을 높일 수 있습니다.
MCP 서버 인스턴스는 이미 생성되어 있습니다. @mcp.prompt() 데코레이터와 사용자 요청이 추가된 프롬프트 템플릿을 반환하는 함수를 사용하여 프롬프트를 추가하세요.
이 연습은 강의의 일부입니다
Model Context Protocol (MCP) 입문
연습 안내
@mcp.prompt()데코레이터로 함수를 꾸미고 제목을"Currency Conversion"으로 설정하세요.currency_request: str을 인수로 받아 프롬프트 템플릿과 사용자 요청을 포함하는 문자열을 반환하는 함수를 정의하세요.- 샘플 요청으로 프롬프트 함수를 호출하고 결과를 출력하여 정상적으로 작동하는지 확인하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# Define a prompt for currency conversion
____
def ____(currency_request: str) -> str:
return f"""You are a currency conversion assistant.
Your task is to:
1. Extract the amount and source currency from the user's natural language input.
2. Identify the target currency.
3. Use the conversion tool to convert the amount.
Rules:
- If the amount or currencies are ambiguous or missing, ask the user for clarification.
- Use only supported currency codes (e.g., USD, EUR, GBP).
User's currency conversion request: {currency_request}"""
# Test the prompt function
print(____("100 USD to EUR"))