Skip to content

Commit 82a5500

Browse files
author
Nicholas Cecere
committed
feat: Add MCP server resource support
- Add new litellm_mcp_server resource for managing MCP (Model Context Protocol) servers - Support for HTTP, SSE, and stdio transport types - Configurable authentication types (none, bearer, basic) - MCP access groups for permission management - Cost tracking configuration for MCP tools - Environment variables and command arguments for stdio transport - Health check status monitoring - Comprehensive documentation and examples - Updated provider registration and API response handling
1 parent 0d4e5a5 commit 82a5500

File tree

10 files changed

+1279
-0
lines changed

10 files changed

+1279
-0
lines changed

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,22 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [Unreleased]
9+
10+
### Added
11+
- **New Resource**: `litellm_mcp_server` - Manage MCP (Model Context Protocol) servers
12+
- Support for HTTP, SSE, and stdio transport types
13+
- Configurable authentication types (none, bearer, basic)
14+
- MCP access groups for permission management
15+
- Cost tracking configuration for MCP tools
16+
- Environment variables and command arguments for stdio transport
17+
- Health check status monitoring
18+
- Comprehensive documentation and examples
19+
20+
### Changed
21+
- Updated provider to support MCP server management functionality
22+
- Enhanced API response handling for MCP-specific operations
23+
824
## [0.3.9] - 2025-08-10
925

1026
### Fixed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ For full details on the <code>litellm_key</code> resource, see the [key resource
131131
- <code>litellm_team</code>: Manage teams. [Documentation](docs/resources/team.md)
132132
- <code>litellm_team_member</code>: Manage team members. [Documentation](docs/resources/team_member.md)
133133
- <code>litellm_key</code>: Manage API keys. [Documentation](docs/resources/key.md)
134+
- <code>litellm_mcp_server</code>: Manage MCP (Model Context Protocol) servers. [Documentation](docs/resources/mcp_server.md)
134135

135136
## Development
136137

docs/resources/mcp_server.md

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "litellm_mcp_server Resource - terraform-provider-litellm"
4+
subcategory: ""
5+
description: |-
6+
Manages an MCP (Model Context Protocol) server in LiteLLM.
7+
---
8+
9+
# litellm_mcp_server (Resource)
10+
11+
Manages an MCP (Model Context Protocol) server in LiteLLM. MCP servers provide tools and resources that can be used by LLMs through the LiteLLM proxy.
12+
13+
## Example Usage
14+
15+
### Basic HTTP MCP Server
16+
17+
```terraform
18+
resource "litellm_mcp_server" "example_http" {
19+
server_name = "example-http-server"
20+
alias = "http-example"
21+
description = "Example HTTP MCP server"
22+
url = "https://api.example.com/mcp"
23+
transport = "http"
24+
auth_type = "none"
25+
26+
mcp_access_groups = ["dev_group", "prod_group"]
27+
}
28+
```
29+
30+
### SSE MCP Server with Cost Tracking
31+
32+
```terraform
33+
resource "litellm_mcp_server" "example_sse" {
34+
server_name = "zapier-server"
35+
alias = "zapier"
36+
description = "Zapier MCP server for automation"
37+
url = "https://actions.zapier.com/mcp/sk-xxxxx/sse"
38+
transport = "sse"
39+
auth_type = "bearer"
40+
spec_version = "2024-11-05"
41+
42+
mcp_access_groups = ["automation_team"]
43+
44+
mcp_info {
45+
server_name = "Zapier Integration"
46+
description = "Zapier MCP server for workflow automation"
47+
logo_url = "https://zapier.com/logo.png"
48+
49+
mcp_server_cost_info {
50+
default_cost_per_query = 0.01
51+
52+
tool_name_to_cost_per_query = {
53+
"send_email" = 0.05
54+
"create_document" = 0.03
55+
"update_sheet" = 0.02
56+
}
57+
}
58+
}
59+
}
60+
```
61+
62+
### Stdio MCP Server
63+
64+
```terraform
65+
resource "litellm_mcp_server" "example_stdio" {
66+
server_name = "local-tools"
67+
alias = "local"
68+
description = "Local MCP server using stdio"
69+
url = "stdio://local"
70+
transport = "stdio"
71+
auth_type = "none"
72+
73+
command = "python3"
74+
args = ["/path/to/mcp_server.py"]
75+
76+
env = {
77+
"PYTHONPATH" = "/path/to/modules"
78+
"DEBUG" = "true"
79+
}
80+
81+
mcp_access_groups = ["local_dev"]
82+
}
83+
```
84+
85+
## Argument Reference
86+
87+
The following arguments are supported:
88+
89+
### Required Arguments
90+
91+
* `server_name` - (Required) Name of the MCP server.
92+
* `url` - (Required) URL of the MCP server. For stdio transport, use `stdio://` prefix.
93+
* `transport` - (Required) Transport type for the MCP server. Valid values: `http`, `sse`, `stdio`.
94+
95+
### Optional Arguments
96+
97+
* `alias` - (Optional) Alias for the MCP server. Used for easier reference.
98+
* `description` - (Optional) Description of the MCP server.
99+
* `spec_version` - (Optional) MCP specification version. Defaults to `2024-11-05`.
100+
* `auth_type` - (Optional) Authentication type. Valid values: `none`, `bearer`, `basic`. Defaults to `none`.
101+
* `mcp_access_groups` - (Optional) List of access groups that can use this MCP server.
102+
* `command` - (Optional) Command to run for stdio transport.
103+
* `args` - (Optional) List of arguments for the command (stdio transport only).
104+
* `env` - (Optional) Map of environment variables for the command (stdio transport only).
105+
106+
### MCP Info Block
107+
108+
The `mcp_info` block supports:
109+
110+
* `server_name` - (Optional) Server name in MCP info.
111+
* `description` - (Optional) Description in MCP info.
112+
* `logo_url` - (Optional) Logo URL for the MCP server.
113+
114+
#### MCP Server Cost Info Block
115+
116+
The `mcp_server_cost_info` block within `mcp_info` supports:
117+
118+
* `default_cost_per_query` - (Optional) Default cost per query for all tools.
119+
* `tool_name_to_cost_per_query` - (Optional) Map of specific tool names to their cost per query.
120+
121+
## Attribute Reference
122+
123+
In addition to all arguments above, the following attributes are exported:
124+
125+
* `server_id` - Unique identifier for the MCP server.
126+
* `created_at` - Timestamp when the server was created.
127+
* `created_by` - User who created the server.
128+
* `updated_at` - Timestamp when the server was last updated.
129+
* `updated_by` - User who last updated the server.
130+
* `status` - Current status of the MCP server.
131+
* `last_health_check` - Timestamp of the last health check.
132+
* `health_check_error` - Error message from the last health check, if any.
133+
134+
## Import
135+
136+
MCP servers can be imported using their server ID:
137+
138+
```shell
139+
terraform import litellm_mcp_server.example server-id-here
140+
```
141+
142+
## Transport Types
143+
144+
### HTTP Transport
145+
- Standard HTTP/HTTPS communication
146+
- Suitable for REST API-based MCP servers
147+
- Supports authentication via `auth_type`
148+
149+
### SSE (Server-Sent Events) Transport
150+
- Real-time streaming communication
151+
- Ideal for servers that need to push updates
152+
- Commonly used with services like Zapier
153+
154+
### Stdio Transport
155+
- Standard input/output communication
156+
- Used for local MCP servers or command-line tools
157+
- Requires `command` and optionally `args` and `env`
158+
159+
## Access Control
160+
161+
Use `mcp_access_groups` to control which teams or users can access the MCP server tools. This integrates with LiteLLM's permission management system.
162+
163+
## Cost Tracking
164+
165+
Configure cost tracking through the `mcp_info.mcp_server_cost_info` block to monitor and control spending on MCP tool usage.

example_mcp_server.tf

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
# Example Terraform configuration for LiteLLM MCP Server resource
2+
3+
terraform {
4+
required_providers {
5+
litellm = {
6+
source = "registry.terraform.io/your-org/litellm"
7+
}
8+
}
9+
}
10+
11+
provider "litellm" {
12+
api_base = "https://your-litellm-instance.com"
13+
api_key = var.litellm_api_key
14+
}
15+
16+
# Basic HTTP MCP Server
17+
resource "litellm_mcp_server" "github_server" {
18+
server_name = "github-mcp-server"
19+
alias = "github"
20+
description = "GitHub MCP server for repository operations"
21+
url = "https://api.github.com/mcp"
22+
transport = "http"
23+
auth_type = "bearer"
24+
25+
mcp_access_groups = ["dev_team", "devops_team"]
26+
}
27+
28+
# SSE MCP Server with detailed configuration and cost tracking
29+
resource "litellm_mcp_server" "zapier_server" {
30+
server_name = "zapier-automation"
31+
alias = "zapier"
32+
description = "Zapier MCP server for workflow automation"
33+
url = "https://actions.zapier.com/mcp/sk-xxxxx/sse"
34+
transport = "sse"
35+
auth_type = "bearer"
36+
spec_version = "2024-11-05"
37+
38+
mcp_access_groups = ["automation_team", "marketing_team"]
39+
40+
mcp_info {
41+
server_name = "Zapier Integration Server"
42+
description = "Provides automation tools through Zapier's MCP interface"
43+
logo_url = "https://zapier.com/assets/images/zapier-logo.png"
44+
45+
mcp_server_cost_info {
46+
default_cost_per_query = 0.01
47+
48+
tool_name_to_cost_per_query = {
49+
"send_email" = 0.05
50+
"create_document" = 0.03
51+
"update_spreadsheet" = 0.02
52+
"post_to_slack" = 0.01
53+
"create_calendar_event" = 0.04
54+
}
55+
}
56+
}
57+
}
58+
59+
# Stdio MCP Server for local development
60+
resource "litellm_mcp_server" "local_dev_server" {
61+
server_name = "local-development-tools"
62+
alias = "local-dev"
63+
description = "Local MCP server for development tools"
64+
url = "stdio://local-dev"
65+
transport = "stdio"
66+
auth_type = "none"
67+
68+
command = "python3"
69+
args = ["/opt/mcp-servers/dev-tools/server.py", "--verbose"]
70+
71+
env = {
72+
"PYTHONPATH" = "/opt/mcp-servers/dev-tools"
73+
"DEBUG" = "true"
74+
"LOG_LEVEL" = "info"
75+
"WORKSPACE_DIR" = "/workspace"
76+
}
77+
78+
mcp_access_groups = ["local_developers"]
79+
80+
mcp_info {
81+
server_name = "Development Tools"
82+
description = "Local development utilities and tools"
83+
84+
mcp_server_cost_info {
85+
default_cost_per_query = 0.0 # Free for local development
86+
}
87+
}
88+
}
89+
90+
# Enterprise MCP Server with comprehensive configuration
91+
resource "litellm_mcp_server" "enterprise_api_server" {
92+
server_name = "enterprise-api-gateway"
93+
alias = "enterprise"
94+
description = "Enterprise API gateway MCP server"
95+
url = "https://api.enterprise.com/mcp/v1"
96+
transport = "http"
97+
auth_type = "bearer"
98+
spec_version = "2024-11-05"
99+
100+
mcp_access_groups = [
101+
"enterprise_users",
102+
"api_consumers",
103+
"integration_team"
104+
]
105+
106+
mcp_info {
107+
server_name = "Enterprise API Gateway"
108+
description = "Provides access to enterprise APIs and services"
109+
logo_url = "https://enterprise.com/logo.png"
110+
111+
mcp_server_cost_info {
112+
default_cost_per_query = 0.10
113+
114+
tool_name_to_cost_per_query = {
115+
"query_database" = 0.25
116+
"generate_report" = 0.50
117+
"send_notification" = 0.05
118+
"create_user" = 0.15
119+
"update_permissions" = 0.20
120+
"audit_log_query" = 0.30
121+
}
122+
}
123+
}
124+
}
125+
126+
# Output the server IDs for reference
127+
output "mcp_server_ids" {
128+
description = "IDs of the created MCP servers"
129+
value = {
130+
github = litellm_mcp_server.github_server.server_id
131+
zapier = litellm_mcp_server.zapier_server.server_id
132+
local_dev = litellm_mcp_server.local_dev_server.server_id
133+
enterprise = litellm_mcp_server.enterprise_api_server.server_id
134+
}
135+
}
136+
137+
# Output server status information
138+
output "mcp_server_status" {
139+
description = "Status information for MCP servers"
140+
value = {
141+
github = {
142+
status = litellm_mcp_server.github_server.status
143+
last_health_check = litellm_mcp_server.github_server.last_health_check
144+
health_check_error = litellm_mcp_server.github_server.health_check_error
145+
}
146+
zapier = {
147+
status = litellm_mcp_server.zapier_server.status
148+
last_health_check = litellm_mcp_server.zapier_server.last_health_check
149+
health_check_error = litellm_mcp_server.zapier_server.health_check_error
150+
}
151+
local_dev = {
152+
status = litellm_mcp_server.local_dev_server.status
153+
last_health_check = litellm_mcp_server.local_dev_server.last_health_check
154+
health_check_error = litellm_mcp_server.local_dev_server.health_check_error
155+
}
156+
enterprise = {
157+
status = litellm_mcp_server.enterprise_api_server.status
158+
last_health_check = litellm_mcp_server.enterprise_api_server.last_health_check
159+
health_check_error = litellm_mcp_server.enterprise_api_server.health_check_error
160+
}
161+
}
162+
}
163+
164+
# Variable for API key
165+
variable "litellm_api_key" {
166+
description = "API key for LiteLLM"
167+
type = string
168+
sensitive = true
169+
}

litellm/provider.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ func Provider() *schema.Provider {
1313
"litellm_team_member": resourceLiteLLMTeamMember(),
1414
"litellm_team_member_add": resourceLiteLLMTeamMemberAdd(),
1515
"litellm_key": resourceKey(),
16+
"litellm_mcp_server": resourceLiteLLMMCPServer(),
1617
},
1718
Schema: map[string]*schema.Schema{
1819
"api_base": {

0 commit comments

Comments
 (0)