mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-10 03:28:53 +00:00
Avoid empty dict fallbacks in mcp tool search settings
This commit is contained in:
parent
a27b531ddd
commit
dd4d2f44e3
4 changed files with 17 additions and 6 deletions
|
|
@ -189,12 +189,14 @@ if MCP_AVAILABLE:
|
|||
) = _extract_mcp_headers_from_request(request, MCPRequestHandler)
|
||||
virtual_oauth2_headers: Final = MCPRequestHandler._get_oauth2_headers_from_headers(request.headers)
|
||||
if tool_name == MCP_TOOL_SEARCH_TOOL_NAME:
|
||||
raw_settings = proxy_config.get_config_state().get("litellm_settings")
|
||||
settings = raw_settings if isinstance(raw_settings, Mapping) else None
|
||||
return await handle_mcp_tool_search(
|
||||
query=tool_arguments.get("query", ""),
|
||||
top_k=resolve_mcp_tool_search_top_k(
|
||||
tool_arguments.get("top_k"),
|
||||
user_api_key_dict,
|
||||
proxy_config.get_config_state().get("litellm_settings") or {},
|
||||
settings,
|
||||
),
|
||||
user_api_key_dict=user_api_key_dict,
|
||||
client_ip=rest_client_ip,
|
||||
|
|
@ -767,11 +769,13 @@ if MCP_AVAILABLE:
|
|||
)
|
||||
from litellm.proxy.proxy_server import proxy_config
|
||||
|
||||
raw_settings = proxy_config.get_config_state().get("litellm_settings")
|
||||
settings = raw_settings if isinstance(raw_settings, Mapping) else None
|
||||
return {
|
||||
"tools": get_virtual_tool_definitions(
|
||||
default_top_k=get_mcp_tool_search_default_top_k(
|
||||
user_api_key_dict,
|
||||
proxy_config.get_config_state().get("litellm_settings") or {},
|
||||
settings,
|
||||
)
|
||||
),
|
||||
"error": None,
|
||||
|
|
|
|||
|
|
@ -791,12 +791,14 @@ if MCP_AVAILABLE:
|
|||
)
|
||||
from litellm.proxy.proxy_server import proxy_config
|
||||
|
||||
raw_settings = proxy_config.get_config_state().get("litellm_settings")
|
||||
settings = raw_settings if isinstance(raw_settings, Mapping) else None
|
||||
return [
|
||||
Tool.model_validate(d)
|
||||
for d in get_virtual_tool_definitions(
|
||||
default_top_k=get_mcp_tool_search_default_top_k(
|
||||
user_api_key_auth,
|
||||
proxy_config.get_config_state().get("litellm_settings") or {},
|
||||
settings,
|
||||
)
|
||||
)
|
||||
]
|
||||
|
|
@ -950,12 +952,14 @@ if MCP_AVAILABLE:
|
|||
if name == MCP_TOOL_SEARCH_TOOL_NAME:
|
||||
from litellm.proxy.proxy_server import proxy_config
|
||||
|
||||
raw_settings = proxy_config.get_config_state().get("litellm_settings")
|
||||
settings = raw_settings if isinstance(raw_settings, Mapping) else None
|
||||
return await handle_mcp_tool_search(
|
||||
query=args.get("query", ""),
|
||||
top_k=resolve_mcp_tool_search_top_k(
|
||||
args.get("top_k"),
|
||||
user_api_key_auth,
|
||||
proxy_config.get_config_state().get("litellm_settings") or {},
|
||||
settings,
|
||||
),
|
||||
user_api_key_dict=user_api_key_auth,
|
||||
client_ip=client_ip,
|
||||
|
|
|
|||
|
|
@ -28,7 +28,10 @@ def get_mcp_tool_search_default_top_k(
|
|||
if key_top_k is not None:
|
||||
return coerce_top_k(key_top_k, default=DEFAULT_MCP_TOOL_SEARCH_TOP_K)
|
||||
|
||||
global_top_k = (litellm_settings or {}).get("mcp_tool_search_default_top_k")
|
||||
if litellm_settings is None:
|
||||
global_top_k = None
|
||||
else:
|
||||
global_top_k = litellm_settings.get("mcp_tool_search_default_top_k")
|
||||
if global_top_k is not None:
|
||||
return coerce_top_k(global_top_k, default=DEFAULT_MCP_TOOL_SEARCH_TOP_K)
|
||||
|
||||
|
|
|
|||
|
|
@ -23,4 +23,4 @@ class ObjectPermissionDict(TypedDict, total=False):
|
|||
models: list[str] | None
|
||||
search_tools: list[str] | None
|
||||
mcp_tool_search_enabled: bool | None
|
||||
mcp_tool_search_top_k: int | None
|
||||
mcp_tool_search_top_k: int | None # writable-ok: mutated on in-memory dict payloads before persistence
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue