litellm/litellm/types
Cursor Agent df3dbd18d6
feat(mcp): rehash short tool prefix on collision and cache per server
Two MCP servers can natural-hash to the same three-character base62
prefix. With 62**3 = 238_328 slots the birthday bound is ~488 servers
for 50% collision probability, so a single proxy hosting more than
~100 MCP servers has a non-trivial chance of seeing a collision in
practice — and a collision means tool names from two different servers
share a routing key, causing silent mis-routing.

Mitigation:

- compute_short_server_prefix(server_id, attempt=N) folds an attempt
  counter into the SHA-256 seed, so rehashes are deterministic and
  produce a fresh three-char prefix space per attempt.
- New MCPServer.short_prefix field caches the resolved (post-dedup)
  prefix on the model so it stays stable across the process lifetime.
- MCPServerManager._assign_unique_short_prefix walks attempts 0..N
  until it finds a prefix not already used by another server in the
  combined registry. Logs an INFO line when a rehash happens so
  operators have a breadcrumb if it ever does.
- Wired into every registration path: load_servers_from_config,
  add_server, update_server, reload_servers_from_database. The
  database reload path also carries the previously-resolved prefix
  forward so reloads don't churn it.
- get_server_prefix prefers the cached short_prefix when set, so the
  resolved value (not the raw natural hash) is used everywhere.
- iter_known_server_prefixes yields the cached short_prefix too, so
  reverse-lookup tolerance covers the rehashed form.

No-op when LITELLM_USE_SHORT_MCP_TOOL_PREFIX is disabled — the field
stays None and behaviour is unchanged.

Co-authored-by: Mateo Wang <mateo-berri@users.noreply.github.com>
2026-04-29 03:43:34 +00:00
..
containers feat(containers): Azure routing, managed container IDs, delete response parsing (#25287) 2026-04-11 09:21:01 -07:00
google_genai fix(mypy): fix scattered 1-off type errors across 14 files 2026-03-13 00:08:57 +00:00
images merge: resolve conflicts between main and litellm_oss_staging_03_11_2026 2026-03-12 09:38:31 -03:00
integrations style: apply black formatting 2026-04-20 16:02:21 -07:00
interactions build: migrate packaging, CI, and Docker from Poetry to uv (#25007) 2026-04-09 11:46:23 -07:00
litellm_core_utils
llms fix(ollama): forward tool_calls and tool_call_id in transform_request (#26122) 2026-04-27 08:58:41 +05:30
management_endpoints style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
mcp_server feat(mcp): rehash short tool prefix on collision and cache per server 2026-04-29 03:43:34 +00:00
passthrough_endpoints refactor: define pass-through custom body state key in types module 2026-04-11 15:26:44 -07:00
prompts style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
proxy Adding Cycraft XecGuard integration (#26011) 2026-04-27 08:58:38 +05:30
responses refactor: extract duplicated stdout/stderr → logs logic to shared helper 2026-03-18 22:05:27 -03:00
secret_managers style: run black formatter on entire codebase 2026-03-11 17:07:57 -03:00
videos style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
access_group.py
adapter.py
agents.py fix(agents.tsx): support granting agents access to subagents 2026-03-10 21:03:20 -07:00
caching.py fix(caching): preserve prompt_tokens_details through embedding cache round-trip (#26653) 2026-04-28 08:25:11 -07:00
completion.py
compression.py Prompt Compression - add it to the proxy (#25729) 2026-04-20 15:08:00 -07:00
embedding.py
files.py style: run black formatter on entire codebase 2026-03-11 17:07:57 -03:00
fine_tuning.py
guardrails.py Adding Cycraft XecGuard integration (#26011) 2026-04-27 08:58:38 +05:30
mcp.py Litellm ishaan march30 (#24887) (#25151) 2026-04-04 14:44:07 -07:00
memory_management.py feat(proxy): add /v1/memory CRUD endpoints (#26218) 2026-04-24 18:38:07 -07:00
policy_engine.py
rag.py style: run black formatter on entire codebase 2026-03-11 17:07:57 -03:00
realtime.py address greptile review feedback (greploop iteration 2) 2026-03-12 18:53:22 +05:30
rerank.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
router.py Merge pull request #26301 from BerriAI/litellm_internal_staging 2026-04-23 08:30:10 +05:30
scheduler.py
search.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
services.py
tag_management.py style: run black formatter on entire codebase 2026-03-11 17:07:57 -03:00
tool_management.py Bug Fix: auto-inject prompt caching support for Gemini models (#21881) 2026-03-03 20:25:35 -08:00
utils.py fix(logging): backfill streaming hidden response cost (#26606) 2026-04-28 08:41:20 -07:00
vector_store_files.py
vector_stores.py style: run black formatter on entire codebase 2026-03-11 17:07:57 -03:00