litellm/.github
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
..
actions refactor(rust): rename the compiled module _native to _rust (#55198) 2026-12-01 07:08:38 -08:00
assets/scaledown chore(repo): remove committed Lens review screenshots (#53169) 2026-11-20 12:31:32 -08:00
codeql ci(codeql): run the default suite on full scans and security-extended on PRs (#45149) 2026-10-07 13:24:28 -07:00
e2e-stack test(mcp): replace the live Linear MCP OAuth e2e tests with integration coverage (#47154) 2026-10-17 14:29:59 -07:00
ISSUE_TEMPLATE ci: classify new issues into domain, provider, kind, priority and lift labels 2026-09-18 11:37:55 -07:00
linters chore(lint): flag conditionals with more than 3 boolean clauses via ruff PLR0916 (#51964) 2026-11-15 16:53:38 -05:00
packaging chore: move workspace packages under litellm (#51000) 2026-11-12 04:19:57 +00:00
pr-assets feat(customer-portal): complete hierarchy management (#51521) 2026-11-13 17:58:34 +00:00
PULL_REQUEST_TEMPLATE docs(pr template): rename the Caveats heading, dropping "(if any)" (#56068) 2026-12-03 19:35:56 +00:00
screenshots fix(team_endpoints): auto-add SSO team members to org on move (proxy admin only) (#26377) 2026-04-24 08:36:25 -07:00
scripts feat(mcp): re-rank mcp_tool_search results with a rerank model (#55799) 2026-12-04 16:25:01 -08:00
semgrep/rules chore: move config and docs off the repo root (#50966) 2026-11-11 18:29:35 -08:00
workflows feat(mcp): re-rank mcp_tool_search results with a rerank model (#55799) 2026-12-04 16:25:01 -08:00
AGENTS.md ci(unit): run the full unit and smoke matrix on every PR on standard runners (#54750) 2026-11-26 15:29:40 -08:00
ci-coverage-allowlist.yml build(docker): build the FIPS image from the main Dockerfile with FLAVOR=fips (#54994) 2026-11-30 09:47:47 -08:00
codecov.yml chore: move workspace packages under litellm (#51000) 2026-11-12 04:19:57 +00:00
CODEOWNERS build(docker): build the FIPS image from the main Dockerfile with FLAVOR=fips (#54994) 2026-11-30 09:47:47 -08:00
CONTRIBUTING.md refactor(cost): consolidate pricing modules (#56131) 2026-12-04 23:14:04 +00:00
dependabot.yaml chore: fixes 2026-04-05 01:30:57 -07:00
deploy-on-aws.png feat: add LiteLLM Rust workspace with Mistral OCR bridge (#31033) 2026-06-23 13:16:47 -07:00
deploy-on-gcp.png feat: add LiteLLM Rust workspace with Mistral OCR bridge (#31033) 2026-06-23 13:16:47 -07:00
deploy-to-aws.png Add files via upload 2023-10-25 16:33:53 -07:00
FUNDING.yml Update FUNDING.yml 2023-09-22 09:51:35 -07:00
gitguardian.yaml chore: move scripts and runtime sources under litellm (#51006) 2026-11-12 04:19:57 +00:00
grype.yaml chore: move config and docs off the repo root (#50966) 2026-11-11 18:29:35 -08:00
issue-labels.json ci(issue-classifier): name every workflow, script and job after the issue it works on 2026-09-18 11:37:55 -07:00
mutmut-coverage.rc fix(ci): let the mutation workflow find covered lines so it generates mutants 2026-08-25 23:16:40 -07:00
osv-scanner.toml build(deps): bump cross-spawn to 7.1.0 to clear osv-scan (#55689) 2026-12-02 08:56:43 +00:00
SECURITY.md docs: retire cosign.pub and document keyless release signing (#53884) 2026-11-23 19:19:05 +00:00
template.yaml fix(proxy): drop legacy telemetry key from persisted WORKER_CONFIG before initialize 2026-09-20 03:14:11 +00:00