{"record":{"id":"95183fd7a2c221c6","repo":"BerriAI/litellm","slug":"no-model-could-be-resolved-for-mcp-sampling-pleas","errorCode":null,"errorMessage":"No model could be resolved for MCP sampling. Please configure 'default_mcp_sampling_model' in your LiteLLM configuration.","messagePattern":"No model could be resolved for MCP sampling\\. Please configure 'default_mcp_sampling_model' in your LiteLLM configuration\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/proxy/_experimental/mcp_server/sampling_handler.py","lineNumber":162,"sourceCode":"            default_model,\n        )\n        return default_model\n    # Fall back to first available model\n    if available_model_names:\n        verbose_logger.debug(\n            \"MCP sampling model resolution: no default configured, falling back to first available model '%s'\",\n            available_model_names[0],\n        )\n        return available_model_names[0]\n    # Last resort - use LiteLLM default or raise error\n    default_sampling_model: Final[str | None] = getattr(litellm, \"default_mcp_sampling_model\", None)\n    if default_sampling_model:\n        verbose_logger.debug(\n            \"MCP sampling model resolution: using litellm.default_mcp_sampling_model='%s'\",\n            default_sampling_model,\n        )\n        return default_sampling_model\n    raise ValueError(\n        \"No model could be resolved for MCP sampling. Please configure 'default_mcp_sampling_model' in your LiteLLM configuration.\"\n    )\n\n\ndef _has_priorities(model_preferences: \"ModelPreferences\") -> bool:\n    \"\"\"Return True if any priority weight is set (non-None and > 0).\"\"\"\n    return any(\n        (getattr(model_preferences, attr, None) or 0) > 0\n        for attr in (\"costPriority\", \"speedPriority\", \"intelligencePriority\")\n    )\n\n\nclass _ScoredModel(NamedTuple):\n    name: str\n    cost: float\n    max_output: float\n    output_tps: float\n","sourceCodeStart":144,"sourceCodeEnd":180,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/proxy/_experimental/mcp_server/sampling_handler.py#L144-L180","documentation":"When an upstream MCP server sends a sampling request (createMessage), LiteLLM must choose a chat model to fulfill it. Resolution order: the client's ModelPreferences hints, then priority weights, then the caller-provided default, then the first model in the proxy router/litellm.model_list, then litellm.default_mcp_sampling_model. If every step comes up empty — no models deployed and no default configured — this ValueError is raised.","triggerScenarios":"An MCP server invokes sampling while the proxy runs with an empty model_list (for example a pure MCP gateway with zero LLM deployments) and default_mcp_sampling_model is unset; router initialization failed so get_model_names() returns nothing.","commonSituations":"Deploying litellm-proxy solely as an MCP gateway without LLM deployments; local testing without a config file; config typos that leave model_list empty.","solutions":["Set a default sampling model: litellm_settings.default_mcp_sampling_model: <deployment name> in the proxy config (applied as litellm.default_mcp_sampling_model), or set that attribute in code.","Or add at least one model deployment to model_list so the first-available fallback works.","Or have the MCP client send ModelPreferences hints that match a deployed model name."],"exampleFix":"# before (config.yaml)\nlitellm_settings: {}\n\n# after\nlitellm_settings:\n  default_mcp_sampling_model: openai/gpt-4o-mini","handlingStrategy":"validation","validationCode":"def sampling_model_resolvable(default: str | None = None) -> bool:\n    import litellm\n    try:\n        from litellm.proxy.proxy_server import llm_router\n        if llm_router is not None and llm_router.get_model_names():\n            return True\n    except Exception:\n        pass\n    return bool(default or getattr(litellm, \"default_mcp_sampling_model\", None))\n\nassert sampling_model_resolvable(), \"deploy a model or set default_mcp_sampling_model before enabling sampling\"","typeGuard":null,"tryCatchPattern":"try:\n    result = await handle_sampling_request(create_message_request)\nexcept ValueError as e:\n    if \"default_mcp_sampling_model\" in str(e):\n        # configuration problem, not transient: surface to operator, do not retry\n        raise ConfigError(\"set litellm_settings.default_mcp_sampling_model or add a model deployment\") from e\n    raise","preventionTips":["If the proxy serves MCP servers that may issue sampling requests, always set default_mcp_sampling_model.","Smoke-test sampling after deployment with a minimal createMessage request.","Verify model_list actually loaded (router.get_model_names() is non-empty) before going live."],"tags":["mcp","sampling","configuration","model-resolution"],"backgroundTag":"no-models-configured","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}