litellm/.github/scripts
Mateo Wang ef7bea124e
feat(mcp): re-rank mcp_tool_search results with a rerank model (#55799)
* feat(mcp): re-rank mcp_tool_search results with a rerank model

Adds an optional `litellm_settings.mcp_tool_search.rerank_model`, a model_name from model_list.
When it is set, the keyword or embedding stage keeps up to 50 candidates and one /rerank call
through the router re-orders them before top_k is applied. The call runs the same pre-call hooks
as /rerank and is billed to the calling key. A provider error, timeout or invalid answer keeps
the base order. Rate-limit and guardrail refusals still reach the caller.

The Admin UI settings form carries the field so a save does not drop it.

* fix(mcp): resolve the caller's guardrails before the tool search rerank call

The rerank sub-call now attaches key, team, project and policy guardrails to its request
metadata the same way /rerank does, so guardrails assigned to the caller run on it.

* fix(mcp): forward the caller's model region on the tool search rerank call

The rerank sub-call now passes allowed_model_region to the router when the caller has one,
as the /rerank request setup does, so region-restricted keys keep their routing checks.

* refactor(mcp): send the tool search rerank call through the proxy's /rerank routing

The rerank sub-call now goes through route_request like /rerank, so team model aliases and blocked models apply, and a rerank_model missing from model_list keeps the base order

* fix(mcp): check the caller's model access before the tool search rerank call

A key or team whose model allowlist or per-model budget excludes the rerank model now keeps the keyword or embedding order, with no rerank call and no spend, using the same caller checks compaction's sub-call runs

* fix(mcp): count the tool search rerank call against the caller's per-model budgets

The rerank sub-call now carries the key, team, user, team member and end user model budgets in its metadata, so the budget tracker charges its spend and the caller gate refuses the next call once a budget is spent

* fix(mcp): keep the base order on every rerank failure, log rerank with caller tags and redaction opt-in, rerank the whole catalog in keyword mode, warn on an unroutable rerank_model

* fix(mcp): send inherited_tags with the tool search rerank so key and team tag rules route it like /rerank

* fix(mcp): free the key's rate-limit slot and keep the base order when any guardrail blocks the tool search rerank

* fix(mcp): bound the tool search rerank call, warn on a non-rerank rerank_model, and log it to the key's and team's callbacks

A failed rerank after the pre-call hooks now reports the dict they returned, like /rerank, so a masked query stays masked in failure logs

* test(proxy): keep the settings endpoint tests in their original layout

The previous commit reformatted the whole file. This keeps only the new rerank_model mode warning test

* fix(mcp): bound every tool search rerank step by one timeout, free its rate-limit slot on cancel, and check sub-call budgets by the sub-call's model

* fix(mcp): run each tool search rerank step in the calling task so the failure hook frees the rate-limit slot on Python 3.10 and 3.11

* fix(mcp): skip the rerank_model mode warning for names only a wildcard, default deployment or pass-through matches

---------

Co-authored-by: Xytronix <32957125+Xytronix@users.noreply.github.com>
2026-12-04 16:25:01 -08:00
..
ci feat(mcp): re-rank mcp_tool_search results with a rerank model (#55799) 2026-12-04 16:25:01 -08:00
assert_ci_coverage.py ci(unit): split proxy-infra-root in two, isolate subprocess tests, make its file exclusions take effect (#51316) 2026-11-11 17:39:10 -08:00
assert_secret_absent.py ci: run the integration groups on GitHub Actions (#48985) 2026-10-29 12:50:08 -07:00
assert_workflow_dir_hygiene.py feat(ci): assert .github/workflows holds only workflows, correctly named (#37616) 2026-08-20 21:36:26 +00:00
detect_changes.sh ci: remove CircleCI (#50950) 2026-11-11 15:38:27 -08:00
e2e_egress_sentinel.py ci(e2e): record the e2e suite weekly and replay it on weekdays with zero egress (#38163) 2026-08-24 23:49:03 -04:00
e2e_fetch_fixture_bundle.sh ci(e2e): install e2e-dev for record and replay and look up the bundle by name (#55930) 2026-12-03 18:06:25 +00:00
e2e_pack_fixture_bundle.sh ci(e2e): record the e2e suite weekly and replay it on weekdays with zero egress (#38163) 2026-08-24 23:49:03 -04:00
read_rc_version.py ci: cut rc/<X.Y.0> off main every Friday at 3am Pacific (#43121) 2026-09-24 21:57:20 -07:00
restore_handwritten_description.py ci: restore a PR's handwritten description when an edit resets it to the placeholder (#53486) 2026-11-21 16:50:40 -08:00
run_llm_translation_tests.py chore(ci): close the test-census blind spots and move scripts out of workflows/ (#37586) 2026-08-20 10:07:14 -07:00
run_merge_smoke.py ci: render lint, unit and smoke checks as <tier> / <job> with one collector per tier (#45480) 2026-10-09 04:28:41 +00:00
scan_keywords.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
select_ui_test_scope.sh fix(ci): run the full dashboard suite when a change reaches outside src/ (#37563) 2026-08-19 23:09:03 -07:00
setup_rust_environment.sh chore: move scripts and runtime sources under litellm (#51006) 2026-11-12 04:19:57 +00:00
smoke_test_native_wheel.py refactor(rust): rename the compiled module _native to _rust (#55198) 2026-12-01 07:08:38 -08:00
uv_sync_with_retries.sh ci: harden cargo fetches during maturin builds (#31348) 2026-06-25 14:31:05 -07:00
verify_linux_native_wheel.py refactor(rust): rename the compiled module _native to _rust (#55198) 2026-12-01 07:08:38 -08:00