Skip to content
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
a304c0b
feat(mcp): add tool search virtual tools for large catalogs
krrish-berri-2 Jun 27, 2026
8839192
fix(mcp): persist mcp_tool_search_enabled and route tool_call by name
krrish-berri-2 Jun 27, 2026
2c52662
fix(mcp): filter list_tools to virtual tools on the protocol path
krrish-berri-2 Jun 27, 2026
85852f0
fix(mcp): enforce IP + server filtering on virtual tool search/call
krrish-berri-2 Jun 27, 2026
60f7f7f
fix(ci): ruff format server.py and sync dashboard API types
krrish-berri-2 Jun 27, 2026
64f003a
style(mcp): drop quoted annotations and sort imports
krrish-berri-2 Jun 27, 2026
d6c8dc3
Merge remote-tracking branch 'origin/litellm_internal_staging' into w…
krrish-berri-2 Jun 27, 2026
3a43ae5
refactor(mcp): extract virtual-tool dispatch and host progress capture
krrish-berri-2 Jun 27, 2026
57d3f6d
test(mcp): cover SSE virtual-tool dispatch and host progress helpers
krrish-berri-2 Jun 27, 2026
03e9265
fix(mcp): forward per-request auth headers through virtual tool handlers
krrish-berri-2 Jun 27, 2026
457e941
fix(mcp): preserve requested server scope in virtual tool calls
krrish-berri-2 Jun 27, 2026
51e8146
fix(mcp): convert virtual tool errors to isError on the protocol path
krrish-berri-2 Jun 27, 2026
d74a6fb
fix(mcp): spend-log virtual tool calls on the REST path
krrish-berri-2 Jun 27, 2026
5636acc
fix(mcp): reject virtual tool call when key has no accessible servers
krrish-berri-2 Jun 27, 2026
de701cf
Merge remote-tracking branch 'origin/litellm_internal_staging' into w…
krrish-berri-2 Jul 1, 2026
3be4fba
docs(mcp): document virtual tool_search module and parity rule in AGE…
krrish-berri-2 Jul 1, 2026
cff61f0
style(mcp): apply ruff format at repo line-length (120)
krrish-berri-2 Jul 1, 2026
c4fd312
fix(mcp): add mcp_tool_search_enabled to ObjectPermissionDict and cus…
krrish-berri-2 Jul 1, 2026
9989516
chore: trigger CI
krrish-berri-2 Jul 1, 2026
899e9b6
fix(mcp): mirror pre-call pipeline, guard imports, coerce top_k, hono…
krrish-berri-2 Jul 1, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "LiteLLM_ObjectPermissionTable" ADD COLUMN "mcp_tool_search_enabled" BOOLEAN;
1 change: 1 addition & 0 deletions litellm-proxy-extras/litellm_proxy_extras/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ model LiteLLM_ObjectPermissionTable {
blocked_tools String[] @default([]) // Tool names blocked for any key/team/user with this permission
mcp_toolsets String[] @default([]) // Toolset IDs granted to this key/team/user
search_tools String[] @default([]) // search_tool_name values this key/team/user may call
mcp_tool_search_enabled Boolean?
teams LiteLLM_TeamTable[]
projects LiteLLM_ProjectTable[]
verification_tokens LiteLLM_VerificationToken[]
Expand Down
1 change: 1 addition & 0 deletions litellm/models/object_permission.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ class LiteLLM_ObjectPermissionTable(LiteLLMPydanticObjectBase):
mcp_toolsets: Optional[List[str]] = None
blocked_tools: Optional[List[str]] = []
search_tools: Optional[List[str]] = []
mcp_tool_search_enabled: Optional[bool] = None
6 changes: 6 additions & 0 deletions litellm/proxy/_experimental/mcp_server/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ litellm/proxy/_experimental/mcp_server/
sampling_handler.py # MCP sampling to LiteLLM completion flow
elicitation_handler.py # MCP elicitation relay flow
semantic_tool_filter.py # semantic filtering of available MCP tools
tool_search.py # opt-in virtual tools (mcp_tool_search + mcp_tool_call) for large catalogs
guardrail_translation/
handler.py # MCP guardrail result translation
sse_transport.py # SSE transport implementation
Expand Down Expand Up @@ -79,6 +80,11 @@ module materially harder to understand.
encryption need focused tests for both allowed and rejected paths.
- Avoid adding comments to new code unless they explain non-obvious security or
protocol behavior. Prefer clear names and small functions.
- The virtual tool path (`tool_search.py`, gated by `mcp_tool_search_enabled`)
must mirror the normal tool flow: IP filtering, server allowlist, per-key tool
permissions, no-accessible-server rejection, per-request auth headers, server
scope, error to `isError` conversion, and spend logging. Reuse `_list_mcp_tools`
and `execute_mcp_tool` rather than reimplementing any of these checks.

## Tests

Expand Down
85 changes: 82 additions & 3 deletions litellm/proxy/_experimental/mcp_server/rest_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,21 @@ async def list_tool_rest_api(
include_disabled_tools and user_api_key_dict.user_role == LitellmUserRoles.PROXY_ADMIN
)

if getattr(
getattr(user_api_key_dict, "object_permission", None),
"mcp_tool_search_enabled",
False,
):
Comment thread
krrish-berri-2 marked this conversation as resolved.
Resolved
from litellm.proxy._experimental.mcp_server.tool_search import (
get_virtual_tool_definitions,
)

return {
"tools": get_virtual_tool_definitions(),
"error": None,
"message": "Successfully retrieved tools",
}

# Extract auth headers from request
headers = request.headers
raw_headers_from_request = dict(headers)
Expand Down Expand Up @@ -727,6 +742,73 @@ async def call_tool_rest_api(
try:
data = await request.json()

tool_name = data.get("name")
tool_arguments = data.get("arguments") or {}

from litellm.proxy._experimental.mcp_server.tool_search import (
MCP_TOOL_CALL_TOOL_NAME,
MCP_TOOL_SEARCH_TOOL_NAME,
handle_mcp_tool_call,
handle_mcp_tool_search,
)

if tool_name in (MCP_TOOL_SEARCH_TOOL_NAME, MCP_TOOL_CALL_TOOL_NAME):
if not getattr(
getattr(user_api_key_dict, "object_permission", None),
"mcp_tool_search_enabled",
False,
):
raise HTTPException(
status_code=403,
detail={
"error": "forbidden",
"message": f"{tool_name} requires mcp_tool_search_enabled on the key",
},
)
rest_client_ip = IPAddressUtils.get_mcp_client_ip(request)
(
virtual_mcp_auth_header,
virtual_mcp_server_auth_headers,
virtual_raw_headers,
) = _extract_mcp_headers_from_request(request, MCPRequestHandler)
virtual_oauth2_headers = MCPRequestHandler._get_oauth2_headers_from_headers(request.headers)
if tool_name == MCP_TOOL_SEARCH_TOOL_NAME:
return await handle_mcp_tool_search(
query=tool_arguments.get("query", ""),
top_k=int(tool_arguments.get("top_k", 5)),
Comment thread
krrish-berri-2 marked this conversation as resolved.
Resolved
Comment thread
krrish-berri-2 marked this conversation as resolved.
Resolved
user_api_key_dict=user_api_key_dict,
client_ip=rest_client_ip,
mcp_auth_header=virtual_mcp_auth_header,
mcp_server_auth_headers=virtual_mcp_server_auth_headers,
oauth2_headers=virtual_oauth2_headers,
raw_headers=virtual_raw_headers,
)
else: # MCP_TOOL_CALL_TOOL_NAME
# Run the same pre-call pipeline as the normal call path so the
# tool execution is spend-logged and guardrail-checked.
(
_,
virtual_logging_obj,
) = await ProxyBaseLLMRequestProcessing(data=data).common_processing_pre_call_logic(
request=request,
user_api_key_dict=user_api_key_dict,
proxy_config=proxy_config,
route_type=CallTypes.call_mcp_tool.value,
proxy_logging_obj=proxy_logging_obj,
general_settings=general_settings,
)
return await handle_mcp_tool_call(
tool_name=tool_arguments.get("tool_name", ""),
arguments=tool_arguments.get("arguments") or {},
user_api_key_dict=user_api_key_dict,
client_ip=rest_client_ip,
mcp_auth_header=virtual_mcp_auth_header,
mcp_server_auth_headers=virtual_mcp_server_auth_headers,
oauth2_headers=virtual_oauth2_headers,
raw_headers=virtual_raw_headers,
litellm_logging_obj=virtual_logging_obj,
)

# Validate required parameters early
server_id = data.get("server_id")
if not server_id:
Expand All @@ -738,7 +820,6 @@ async def call_tool_rest_api(
},
)

tool_name = data.get("name")
if not tool_name:
raise HTTPException(
status_code=400,
Expand All @@ -748,8 +829,6 @@ async def call_tool_rest_api(
},
)

tool_arguments = data.get("arguments") or {}

proxy_base_llm_response_processor = ProxyBaseLLMRequestProcessing(data=data)
(
data,
Expand Down
Loading
Loading