Implementation:BerriAI Litellm MCP Types
Appearance
| Attribute | Value |
|---|---|
| Sources | litellm/types/mcp.py |
| Domains | MCP (Model Context Protocol), Tool Calling, Server Configuration, Authentication |
| Last Updated | 2026-02-15 16:00 GMT |
Overview
Type definitions for the Model Context Protocol (MCP) subsystem, covering server configuration, transport protocols, authentication, credential management, cost tracking, and pre/during/post call hook request/response objects.
Description
This module defines the complete type hierarchy for LiteLLM's MCP integration. MCP enables LLMs to interact with external tools hosted on MCP servers. The types cover:
- Protocol enums -- MCPTransport (sse, http, stdio), MCPSpecVersion (2024-11-05, 2025-03-26, 2025-06-18), MCPAuth (none, api_key, bearer_token, basic, authorization, oauth2).
- Server configuration -- MCPPublicServer for safe public server params, MCPStdioConfig for local stdio-based servers.
- Credentials and cost -- MCPCredentials for authentication values including OAuth2 support, MCPServerCostInfo for per-query and per-tool cost tracking.
- Hook objects -- Pydantic models for the three MCP guardrail hook phases:
- MCPPreCallRequestObject / MCPPreCallResponseObject -- Before tool execution; can modify arguments or block the call.
- MCPDuringCallRequestObject / MCPDuringCallResponseObject -- During tool execution; can cancel ongoing calls.
- MCPPostCallResponseObject -- After tool execution; wraps the MCP response content.
Usage
Import from this module when:
- Configuring MCP servers in the LiteLLM proxy YAML configuration.
- Implementing custom MCP guardrail hooks (pre_mcp_call, during_mcp_call).
- Working with MCP tool call cost tracking.
- Building stdio-based MCP server integrations.
Code Reference
Source Location
litellm/types/mcp.py (177 lines)
Key Types
| Type Name | Kind | Description |
|---|---|---|
MCPTransport |
str, Enum | Transport protocols: sse, http, stdio |
MCPSpecVersion |
str, Enum | MCP spec versions: 2024-11-05, 2025-03-26, 2025-06-18 |
MCPAuth |
str, Enum | Authentication methods: none, api_key, bearer_token, basic, authorization, oauth2 |
MCPTransportType |
Literal | Literal type alias for MCPTransport values |
MCPSpecVersionType |
Literal | Literal type alias for MCPSpecVersion values |
MCPAuthType |
Optional[Literal] | Optional literal type alias for MCPAuth values |
MCPPublicServer |
BaseModel | Public MCP server metadata (server_id, name, url, transport, auth_type) |
MCPCredentials |
TypedDict | Auth credentials (auth_value, client_id, client_secret, scopes) |
MCPServerCostInfo |
TypedDict | Cost tracking (default_cost_per_query, tool_name_to_cost_per_query) |
MCPStdioConfig |
TypedDict | Stdio server config (command, args, env) |
MCPPreCallRequestObject |
BaseModel | Pre-call hook input (tool_name, arguments, server_name, user_api_key_auth) |
MCPPreCallResponseObject |
BaseModel | Pre-call hook output (should_proceed, modified_arguments, error_message) |
MCPDuringCallRequestObject |
BaseModel | During-call hook input (tool_name, arguments, server_name, start_time) |
MCPDuringCallResponseObject |
BaseModel | During-call hook output (should_continue, error_message) |
MCPPostCallResponseObject |
BaseModel | Post-call hook output wrapping MCP response content |
Import
from litellm.types.mcp import (
MCPTransport,
MCPSpecVersion,
MCPAuth,
MCPPublicServer,
MCPCredentials,
MCPServerCostInfo,
MCPStdioConfig,
MCPPreCallRequestObject,
MCPPreCallResponseObject,
MCPDuringCallRequestObject,
MCPDuringCallResponseObject,
MCPPostCallResponseObject,
)
I/O Contract
MCPPublicServer
| Field | Type | Default | Description |
|---|---|---|---|
server_id |
str |
(required) | Unique server identifier |
name |
str |
(required) | Display name |
alias |
Optional[str] |
None | Optional alias |
server_name |
Optional[str] |
None | Optional server name |
url |
Optional[str] |
None | Server URL |
transport |
MCPTransportType |
(required) | Transport protocol (sse, http, stdio) |
spec_path |
Optional[str] |
None | Path to MCP spec file |
auth_type |
Optional[MCPAuthType] |
None | Authentication type |
mcp_info |
Optional[Dict[str, Any]] |
None | Additional MCP metadata |
MCPPreCallRequestObject (Input)
| Field | Type | Default | Description |
|---|---|---|---|
tool_name |
str |
(required) | Name of the MCP tool being called |
arguments |
Dict[str, Any] |
(required) | Arguments for the tool call |
server_name |
Optional[str] |
None | MCP server hosting the tool |
user_api_key_auth |
Optional[Dict[str, Any]] |
None | Authenticated user info |
hidden_params |
HiddenParams |
HiddenParams() | Internal logging metadata |
MCPPreCallResponseObject (Output)
| Field | Type | Default | Description |
|---|---|---|---|
should_proceed |
bool |
True | Whether to proceed with the tool call |
modified_arguments |
Optional[Dict[str, Any]] |
None | Modified arguments (replaces original if set) |
error_message |
Optional[str] |
None | Error message if should_proceed is False |
hidden_params |
HiddenParams |
HiddenParams() | Internal logging metadata |
MCPPostCallResponseObject (Output)
| Field | Type | Description |
|---|---|---|
mcp_tool_call_response |
List[Union[MCPTextContent, MCPImageContent, MCPEmbeddedResource]] |
The MCP tool call response content |
hidden_params |
HiddenParams |
Internal logging metadata |
Usage Examples
Configuring an MCP server
from litellm.types.mcp import MCPPublicServer, MCPTransport, MCPAuth
server = MCPPublicServer(
server_id="my-tools",
name="My Tool Server",
url="https://tools.example.com/mcp",
transport=MCPTransport.http,
auth_type=MCPAuth.bearer_token,
)
Configuring a stdio MCP server
from litellm.types.mcp import MCPStdioConfig
stdio_config: MCPStdioConfig = {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/tmp/data"],
"env": {"NODE_ENV": "production"},
}
MCP credentials with OAuth2
from litellm.types.mcp import MCPCredentials
creds: MCPCredentials = {
"client_id": "my-client-id",
"client_secret": "my-client-secret",
"scopes": ["read", "write"],
}
Setting per-tool cost tracking
from litellm.types.mcp import MCPServerCostInfo
cost_info: MCPServerCostInfo = {
"default_cost_per_query": 0.001,
"tool_name_to_cost_per_query": {
"web_search": 0.01,
"code_interpreter": 0.05,
},
}
Building a pre-call hook request
from litellm.types.mcp import MCPPreCallRequestObject
request = MCPPreCallRequestObject(
tool_name="web_search",
arguments={"query": "latest news"},
server_name="my-tools",
)
Related Pages
- Guardrail Types -- Guardrail event hooks include pre_mcp_call and during_mcp_call that use these MCP types.
- Agent Types -- Agent types for A2A protocol that may invoke MCP tools.
- Service Types -- Service monitoring types that can track MCP server health.
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment