मुख्य सामग्री पर जाएं
लॉगिंग आपके सर्वर को किसी रिक्वेस्ट को हैंडल करते समय मॉडल कॉन्टेक्स्ट प्रोटोकॉल (MCP) Clients को डिबग/जानकारी/चेतावनी/त्रुटि संदेश भेजने देती है। यह tool के निष्पादन के दौरान बेहतर दृश्यता के लिए और डिबगिंग में मददगार है। नोट: इन लॉग को कैसे (या फिर बिल्कुल भी) दिखाना है, यह निर्णय Clients लेते हैं।
## मूलभूत उपयोग
from dedalus_mcp import get_context, tool

@tool(description="Process data")
async def process(data: str) -> str:
    ctx = get_context()

    await ctx.info("Processing", data={"bytes": len(data)})
    # ... आपका काम करें ...
    await ctx.info("Processing complete")

    return "done"
## लॉग लेवल्स
await ctx.debug("Detailed debugging info")
await ctx.info("सामान्य परिचालन संदेश")
await ctx.warning("Warning conditions")
await ctx.error("Error conditions")
MethodLevelउपयोग मामला
ctx.debug()DEBUGविस्तृत डिबगिंग जानकारी
ctx.info()INFOसामान्य परिचालन संदेश
ctx.warning()WARNINGचेतावनी की स्थितियाँ
ctx.error()ERRORत्रुटि की स्थितियाँ
## उदाहरण: डेटा पाइपलाइन
from dedalus_mcp import get_context, tool

@tool(description="Run data pipeline")
async def run_pipeline(source: str) -> dict:
    ctx = get_context()

    await ctx.info("Starting pipeline", data={"source": source})

    # Load
    await ctx.debug("Loading data...")
    data = load_data(source)  # your code
    await ctx.info("Loaded records", data={"count": len(data)})

    # Transform
    await ctx.debug("Transforming data...")
    try:
        transformed = transform(data)  # your code
    except ValueError as e:
        await ctx.warning("Transform warning", data={"error": str(e)})
        transformed = fallback_transform(data)  # your code

    # Save
    await ctx.debug("Saving results...")
    try:
        save(transformed)  # your code
        await ctx.info("पाइपलाइन पूर्ण हुई", data={"records": len(transformed)})
    except OSError as e:
        await ctx.error("Save failed", data={"error": str(e)})
        raise

    return {"records": len(transformed)}
## उदाहरण: बैच प्रोसेसिंग
from dedalus_mcp import get_context, tool

@tool(description="Process items in batch")
async def batch_process(items: list[str]) -> dict:
    ctx = get_context()
    results = {"success": 0, "failed": 0}

    await ctx.info("Starting batch", data={"items": len(items)})

    for i, item in enumerate(items, start=1):
        await ctx.debug("Processing item", data={"index": i, "total": len(items), "item": item})
        try:
            process_item(item)  # your code
            results["success"] += 1
        except Exception as e:
            await ctx.warning("Item failed", data={"item": item, "error": str(e)})
            results["failed"] += 1

    if results["failed"]:
        await ctx.warning("Batch completed with failures", data=results)
    else:
        await ctx.info("Batch completed successfully", data=results)

    return results
## Structured logging
संरचित फ़ील्ड्स को data= के माध्यम से पास करें:
await ctx.info(
    "Request processed",
    data={
        "duration_ms": 150,
        "items_processed": 42,
    },
)
युक्ति: data के अंदर "msg" key का उपयोग करने से बचें—Dedalus MCP मुख्य संदेश पाठ के लिए आंतरिक रूप से "msg" का उपयोग करता है।
Last modified on April 11, 2026