पाठ 12 / 25
Resources और Prompts जोड़ना
उसी server से read-only डेटा और दोबारा उपयोग होने वाला prompt template उपलब्ध कराएँ।
डेटा के लिए URIs
Resource को URI से पुकारा जाता है, जैसे notes://welcome। URI में braces में parameter हो सकता है, जिससे resource template बनता है। Prompts वे functions हैं जो ऐसा message text लौटाते हैं जिसे user बातचीत में जोड़ सकता है।
एक resource और एक prompt
Resource दिए गए नाम के लिए text लौटाता है। Prompt user के दिए कोड से code-review अनुरोध बनाता है।
@mcp.resource("notes://{name}")
def get_note(name: str) -> str:
"""Return the text of a saved note."""
return NOTES.get(name, "Note not found")
@mcp.prompt()
def review_code(code: str) -> str:
"""Ask for a careful code review."""
return f"Please review this code for bugs and clarity:\n\n{code}"Resources छोटे और स्थिर रखें
Resources context से जुड़ते हैं, इसलिए बड़े resources हर उपयोग पर tokens ख़र्च कराते हैं। पूरा database डालने की जगह केंद्रित दस्तावेज़ चुनें, और बड़ा डेटा ज़रूरत पर tool से मँगवाएँ।
त्वरित जाँच: `notes://{name}` क्या परिभाषित करता है?
- बिना inputs का tool
- name parameter वाला resource template
- एक network port
- एक Python package
Answer
name parameter वाला resource template — Braces URI के एक हिस्से को parameter बनाते हैं जो function को दिया जाता है।