मुख्य सामग्री पर जाएं
प्रगति रिपोर्टिंग आपके सर्वर को किसी tool के चलने के दौरान Client को प्रगति अपडेट भेजने की अनुमति देती है। Clients इन अपडेट्स का उपयोग धीमे ऑपरेशनों के दौरान स्पिनर, प्रगति पट्टियाँ और “अब भी काम चल रहा है” जैसी UI दिखाने के लिए कर सकते हैं। नोट: ctx.report_progress(...) केवल तभी एक सूचना भेजता है जब Client ने इस अनुरोध के लिए कोई प्रगति टोकन प्रदान किया हो। अगर Client ने प्रगति का अनुरोध नहीं किया, तो यह कुछ नहीं करता (no-op रहता है)।

मूलभूत उपयोग

from dedalus_mcp import get_context, tool

@tool(description="Process files")
async def process_files(files: list[str]) -> str:
    ctx = get_context()

    for i, file in enumerate(files, start=1):
        await ctx.report_progress(i, total=len(files), message=f"Processing {file}")
        process_file(file)  # आपका कोड; यदि यह ब्लॉक करता है, तो ऑफलोड करें या इसे async बनाएं

    return f"Processed {len(files)} files"

पैरामीटर

await ctx.report_progress(
    progress=50,                 # वर्तमान प्रगति का मान
    total=100,                   # वैकल्पिक कुल (प्रतिशत के लिए)
    message="Halfway done...",   # वैकल्पिक स्थिति संदेश
)
पैरामीटरप्रकारविवरण
progressint | floatवर्तमान प्रगति मान
totalint | float | Noneवैकल्पिक कुल मान; प्रतिशत-आधारित UI सक्षम करता है
messagestr | Noneवैकल्पिक मानव-पठनीय स्टेटस संदेश

उदाहरण: फ़ाइल डाउनलोड

from dedalus_mcp import get_context, tool

@tool(description="Download files")
async def download_files(urls: list[str]) -> dict:
    ctx = get_context()
    downloaded: list[str] = []

    for i, url in enumerate(urls, start=1):
        await ctx.report_progress(i - 1, total=len(urls), message=f"Downloading {url}")
        await ctx.info("Downloading", data={"url": url})

        path = await download(url)  # आपका कोड
        downloaded.append(path)

        await ctx.report_progress(i, total=len(urls))

    return {"files": downloaded}

उदाहरण: डेटा प्रोसेसिंग पाइपलाइन

from dedalus_mcp import get_context, tool

@tool(description="बड़े डेटासेट को प्रोसेस करें")
async def process_dataset(dataset_id: str) -> dict:
    ctx = get_context()

    await ctx.report_progress(0, total=100, message="डेटासेट लोड हो रहा है")
    data = load_dataset(dataset_id)  # आपका कोड
    await ctx.report_progress(30, total=100, message="डेटा ट्रांसफॉर्म हो रहा है")

    total_items = len(data)
    if total_items:
        for i, item in enumerate(data, start=1):
            # आइटम की प्रगति को 30..70 रेंज में मैप करें
            progress = 30 + int((i / total_items) * 40)
            await ctx.report_progress(progress, total=100)
            transform(item)  # आपका कोड

    await ctx.report_progress(70, total=100, message="परिणाम सेव हो रहे हैं")
    save_results(data)  # आपका कोड
    await ctx.report_progress(100, total=100, message="पूर्ण हुआ")

    return {"processed": len(data)}

उदाहरण: अनिर्धारित प्रगति

यदि आपको पहले से कुल मान नहीं पता हो, तो total छोड़ दें और समय-समय पर अपडेट भेजें:
from dedalus_mcp import get_context, tool

@tool(description="Search until found")
async def search(query: str) -> str:
    ctx = get_context()
    pages_searched = 0

    while True:
        pages_searched += 1
        await ctx.report_progress(pages_searched, message=f"Searched {pages_searched} pages")

        result = search_page(query, pages_searched)  # आपका कोड
        if result:
            return result

        if pages_searched > 100:
            return "Not found"

युक्तियाँ

  • असिंक्रोनस कार्य को प्राथमिकता दें: प्रगति अपडेट तब सबसे उपयोगी होते हैं जब आपका उपकरण I/O (async def) कर रहा हो। यदि आप CPU‑गहन या ब्लॉकिंग कार्य करते हैं, तो उसे ऑफ़लोड करने पर विचार करें ताकि प्रगति सूचनाएँ चलते रहें।
  • message का संयम से उपयोग करें: “Downloading…”, “Transforming…”, “Saving…” जैसे छोटे संदेश क्लाइंट्स के लिए दिखाना सबसे आसान होते हैं।
  • बिना वजह बहुत सारे अपडेट न भेजें: हर छोटे‑से‑छोटे चरण पर प्रगति भेजना शोर पैदा कर सकता है। बहुत बड़े लूप्स के लिए, आप हर N आइटम पर ही रिपोर्ट करना चाह सकते हैं।