-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
[Feat] Add Authentication + Permission Management for MCP List, Call Tool Ops #11682
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Adds authentication and permission filtering for MCP tool listing and invocation by integrating API key checks and team-based permissions into the MCP server and its management components.
- Introduces
UserAPIKeyAuthMCP
for extracting and validating API keys from ASGI scopes, and retrieval of allowed MCP servers. - Updates MCP server routes (
list_tools
,call_tool
, HTTP/SSE handlers) to set and use an authentication context via middleware. - Modifies
MCPServerManager
to filter available tools based on per-key and per-team permissions.
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
tests/test_litellm/proxy/_experimental/mcp_server/auth/test_user_api_key_auth_mcp.py | Adds parametrized tests covering key‐ and team‐based server permissions and header parsing. |
tests/mcp_tests/test_mcp_server.py | Extends streamable HTTP and SSE handler tests with a full ASGI scope. |
litellm/proxy/_experimental/mcp_server/server.py | Injects auth context middleware, updates list_tools and HTTP/SSE handlers to retrieve and set auth context, and adds helper functions. |
litellm/proxy/_experimental/mcp_server/mcp_server_manager.py | Adds get_allowed_mcp_servers and updates list_tools to only query permitted servers. |
litellm/proxy/_experimental/mcp_server/auth/user_api_key_auth_mcp.py | Implements header extraction, API key dispatch, and permission queries for keys and teams. |
litellm/proxy/_experimental/mcp_server/auth/litellm_auth_handler.py | Wraps UserAPIKeyAuth to conform with MCP’s AuthenticatedUser . |
Comments suppressed due to low confidence (2)
litellm/proxy/_experimental/mcp_server/auth/user_api_key_auth_mcp.py:105
- There are no unit tests covering the team‐based permission code path in
get_allowed_mcp_servers
. Add tests for scenarios whereuser_api_key_auth.team_id
provides allowed servers to verify correct intersection and set behavior.
async def get_allowed_mcp_servers(
litellm/proxy/_experimental/mcp_server/server.py:169
- The functions
get_auth_context
andset_auth_context
are defined insideget_mcp_server_enabled()
and thus not visible at module scope. This will causeNameError
when used inlist_tools
and the HTTP/SSE handlers. Move their definitions to the module top level or before any usage.
user_api_key_auth = get_auth_context()
litellm/proxy/_experimental/mcp_server/auth/user_api_key_auth_mcp.py
Outdated
Show resolved
Hide resolved
…mcp.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…Tool Ops (BerriAI#11682) * add basic auth checks for MCP * working MCP auth * fix MCP * add get_allowed_mcp_servers for key, team * add get_allowed_mcp_servers * TOOLS FROM MCP SERVERS * fix - working context vars for handling auth to MCPs * fix imports * working _get_allowed_mcp_servers_for_key * TestUserAPIKeyAuthMCP * test_user_api_key_auth_mcp * fix code qa check * fix imports * test_mcp_server.py * fix: fix - working permission mgmt * Update litellm/proxy/_experimental/mcp_server/auth/user_api_key_auth_mcp.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
[Feat] Add Authentication + Permission Management for MCP List, Call Tool Ops
Relevant issues
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
tests/litellm/
directory, Adding at least 1 test is a hard requirement - see detailsmake test-unit
Type
🆕 New Feature
✅ Test
Changes