मुख्य सामग्री पर जाएं
इलिसिटेशन आपके server को यह अनुमति देता है कि वह tool चल रहा होने के दौरान client से यह अनुरोध कर सके कि वह उपयोगकर्ता से संरचित इनपुट एकत्र करे—जैसे पुष्टि, गायब पैरामीटर, या एक छोटा “फॉर्म”।

बुनियादी उपयोग

from dedalus_mcp import get_context, tool, types

@tool(description="Deploy to environment")
async def deploy(env: str) -> str:
    ctx = get_context()
    server = ctx.server
    if server is None:
        raise RuntimeError("No active server in context")

    result = await server.request_elicitation(
        types.ElicitRequestParams(
            message=f"Deploy to {env}?",
            requestedSchema={
                "type": "object",
                "properties": {
                    "confirm": {"type": "boolean"},
                },
                "required": ["confirm"],
            },
        )
    )

    if result.action == "accept" and result.content and result.content.get("confirm"):
        return f"Deployed to {env}"

    return "Deployment cancelled"

पैरामीटर्स

request_elicitation(...) एक ElicitRequestParams लेता है, जिसमें:
  • message: str: उपयोगकर्ता को दिखाया जाने वाला टेक्स्ट
  • requestedSchema: dict: अपेक्षित फ़ील्ड्स का वर्णन करने वाला एक प्रतिबंधित JSON Schema ऑब्जेक्ट
params = types.ElicitRequestParams(
    message="कॉन्फ़िगरेशन दर्ज करें",
    requestedSchema={
        "type": "object",
        "properties": {
            "name": {"type": "string"},
            "replicas": {"type": "integer"},
            "dry_run": {"type": "boolean"},
        },
        "required": ["name"],
    },
)
result = await ctx.server.request_elicitation(params)
स्कीमा सीमाएँ (Dedalus मॉडल कॉन्टेक्स्ट प्रोटोकॉल (MCP) द्वारा अनिवार्य):
  • शीर्ष स्तर का type "object" होना आवश्यक है
  • properties एक non-empty ऑब्जेक्ट होना चाहिए
  • प्रत्येक प्रॉपर्टी का type निम्न में से एक होना चाहिए: "string", "number", "integer", "boolean"
  • nested objects/arrays समर्थित नहीं हैं

Response actions

Client एक ElicitResult लौटाता है, जिसमें निम्न शामिल होते हैं:
  • action: "accept" | "decline" | "cancel"
  • content: वैकल्पिक मैपिंग (केवल तब उपस्थित जब action == "accept" हो)
result = await ctx.server.request_elicitation(params)

match result.action:
    case "accept":
        data = result.content or {}
        return f"Got: {data}"
    case "decline":
        return "User declined"
    case "cancel":
        return "User cancelled"

उदाहरण: प्रोग्रेसिव डिस्क्लोज़र

जटिल जानकारी को चरण-दर-चरण एकत्रित करें:
from dedalus_mcp import get_context, tool, types

@tool(description="नया प्रोजेक्ट बनाएं")
async def create_project() -> str:
    ctx = get_context()
    server = ctx.server
    if server is None:
        raise RuntimeError("संदर्भ में कोई सक्रिय सर्वर नहीं है")

    name = await server.request_elicitation(
        types.ElicitRequestParams(
            message="प्रोजेक्ट का नाम:",
            requestedSchema={
                "type": "object",
                "properties": {"name": {"type": "string"}},
                "required": ["name"],
            },
        )
    )
    if name.action != "accept" or not name.content:
        return "रद्द किया गया"

    project_type = await server.request_elicitation(
        types.ElicitRequestParams(
            message="प्रोजेक्ट का प्रकार (web/api/cli):",
            requestedSchema={
                "type": "object",
                "properties": {"type": {"type": "string"}},
                "required": ["type"],
            },
        )
    )
    if project_type.action != "accept" or not project_type.content:
        return "रद्द किया गया"

    confirm = await server.request_elicitation(
        types.ElicitRequestParams(
            message=f"{project_type.content['type']} प्रोजेक्ट '{name.content['name']}' बनाएं?",
            requestedSchema={
                "type": "object",
                "properties": {"confirm": {"type": "boolean"}},
                "required": ["confirm"],
            },
        )
    )

    if confirm.action == "accept" and confirm.content and confirm.content.get("confirm"):
        return f"{name.content['name']} बनाया गया"
    return "रद्द किया गया"

Error handling

Elicitation के लिए एक सक्रिय मॉडल कॉन्टेक्स्ट प्रोटोकॉल (MCP) session और ऐसा Client आवश्यक है जो elicitation capability को advertise करता हो। अगर ये शर्तें पूरी न हों, तो request_elicitation(...) McpError (आमतौर पर METHOD_NOT_FOUND) raise करता है, और timeouts पर भी McpError raise होता है।
from mcp.shared.exceptions import McpError
from dedalus_mcp import types

try:
    result = await ctx.server.request_elicitation(params)
except McpError as e:
    return f"Elicitation अनुपलब्ध: {e}"