litellm/terraform/provider/docs/resources/mcp_server.md
Yassin Kortam 7c69ede9be
feat(terraform): write-only secret attributes to keep secrets out of state (#46538)
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-10-15 15:36:15 -07:00

8.4 KiB

page_title subcategory description
litellm_mcp_server Resource - terraform-provider-litellm Manages an MCP (Model Context Protocol) server in LiteLLM.

litellm_mcp_server (Resource)

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.

Example Usage

Basic HTTP MCP Server

resource "litellm_mcp_server" "github_server" {
  server_name = "github-mcp-server"
  alias       = "github"
  description = "GitHub MCP server for repository operations"
  url         = "https://api.github.com/mcp"
  transport   = "http"
  auth_type   = "bearer"
  
  mcp_access_groups = ["dev_team", "devops_team"]
}

SSE MCP Server with Comprehensive Cost Tracking

resource "litellm_mcp_server" "zapier_server" {
  server_name  = "zapier-automation"
  alias        = "zapier"
  description  = "Zapier MCP server for workflow automation"
  url          = "https://actions.zapier.com/mcp/sk-xxxxx/sse"
  transport    = "sse"
  auth_type    = "bearer"
  spec_version = "2024-11-05"
  
  mcp_access_groups = ["automation_team", "marketing_team"]
  
  mcp_info {
    server_name = "Zapier Integration Server"
    description = "Provides automation tools through Zapier's MCP interface"
    logo_url    = "https://zapier.com/assets/images/zapier-logo.png"
    
    mcp_server_cost_info {
      default_cost_per_query = 0.01
      
      tool_name_to_cost_per_query = {
        "send_email"           = 0.05
        "create_document"      = 0.03
        "update_spreadsheet"   = 0.02
        "post_to_slack"        = 0.01
        "create_calendar_event" = 0.04
      }
    }
  }
}

Stdio MCP Server for Local Development

resource "litellm_mcp_server" "local_dev_server" {
  server_name = "local-development-tools"
  alias       = "local-dev"
  description = "Local MCP server for development tools"
  url         = "stdio://local-dev"
  transport   = "stdio"
  auth_type   = "none"
  
  command = "python3"
  args    = ["/opt/mcp-servers/dev-tools/server.py", "--verbose"]
  
  env = {
    "PYTHONPATH"    = "/opt/mcp-servers/dev-tools"
    "DEBUG"         = "true"
    "LOG_LEVEL"     = "info"
    "WORKSPACE_DIR" = "/workspace"
  }
  
  mcp_access_groups = ["local_developers"]
  
  mcp_info {
    server_name = "Development Tools"
    description = "Local development utilities and tools"
    
    mcp_server_cost_info {
      default_cost_per_query = 0.0  # Free for local development
    }
  }
}

Enterprise MCP Server with Full Configuration

resource "litellm_mcp_server" "enterprise_api_server" {
  server_name  = "enterprise-api-gateway"
  alias        = "enterprise"
  description  = "Enterprise API gateway MCP server"
  url          = "https://api.enterprise.com/mcp/v1"
  transport    = "http"
  auth_type    = "bearer"
  spec_version = "2024-11-05"
  
  mcp_access_groups = [
    "enterprise_users",
    "api_consumers",
    "integration_team"
  ]
  
  mcp_info {
    server_name = "Enterprise API Gateway"
    description = "Provides access to enterprise APIs and services"
    logo_url    = "https://enterprise.com/logo.png"
    
    mcp_server_cost_info {
      default_cost_per_query = 0.10
      
      tool_name_to_cost_per_query = {
        "query_database"       = 0.25
        "generate_report"      = 0.50
        "send_notification"    = 0.05
        "create_user"          = 0.15
        "update_permissions"   = 0.20
        "audit_log_query"      = 0.30
      }
    }
  }
}

OAuth 2.0 Client Credentials Kept Out of State

resource "litellm_mcp_server" "crm" {
  server_name = "crm"
  url         = "https://mcp.example.com/mcp"
  transport   = "http"
  auth_type   = "oauth2"

  client_id                = var.crm_client_id
  client_secret_wo         = var.crm_client_secret
  client_secret_wo_version = 1
}

The proxy encrypts the credentials at rest and never returns them on read, so the only copy outside the proxy is the variable you pass in.

Argument Reference

The following arguments are supported:

Required Arguments

  • server_name - (Required) Name of the MCP server.
  • url - (Required) URL of the MCP server. For stdio transport, use stdio:// prefix.
  • transport - (Required) Transport type for the MCP server. Valid values: http, sse, stdio.

Optional Arguments

  • alias - (Optional) Alias for the MCP server. Used for easier reference.
  • description - (Optional) Description of the MCP server.
  • spec_version - (Optional) MCP specification version. Defaults to 2024-11-05.
  • auth_type - (Optional) Authentication type the proxy uses against this server. Valid values: none, api_key, bearer_token, basic, authorization, oauth2, aws_sigv4, token, oauth2_token_exchange, oauth2_id_jag, true_passthrough, oauth_delegate (bearer is still accepted). Defaults to none.
  • auth_value_wo - (Optional, Write-only, Sensitive) Credential for api_key, bearer_token, basic and authorization auth types (the token, or user:password for basic). Sent to the proxy on every apply and never written to plan or state. Requires Terraform 1.11 or later and auth_value_wo_version.
  • auth_value_wo_version - (Optional) Integer that triggers an update when auth_value_wo changes. Bump it whenever you rotate the token.
  • client_id - (Optional) OAuth 2.0 client id the proxy presents to the server's token endpoint (oauth2 auth types). Not a secret, stored in state.
  • client_secret_wo - (Optional, Write-only, Sensitive) OAuth 2.0 client secret paired with client_id. Sent to the proxy on every apply and never written to plan or state. Requires Terraform 1.11 or later, client_id and client_secret_wo_version.
  • client_secret_wo_version - (Optional) Integer that triggers an update when client_secret_wo changes. Bump it whenever you rotate the secret.
  • mcp_access_groups - (Optional) List of access groups that can use this MCP server.
  • command - (Optional) Command to run for stdio transport.
  • args - (Optional) List of arguments for the command (stdio transport only). Do not pass secrets as arguments; args are shown in plans, stored unencrypted in state, and visible in the server's process list.
  • env - (Optional, Sensitive) Map of environment variables for the command (stdio transport only). Hidden from plan output but still stored unencrypted in state; secure your state backend when configuring tokens here.

MCP Info Block

The mcp_info block supports:

  • server_name - (Optional) Server name in MCP info.
  • description - (Optional) Description in MCP info.
  • logo_url - (Optional) Logo URL for the MCP server.

MCP Server Cost Info Block

The mcp_server_cost_info block within mcp_info supports:

  • default_cost_per_query - (Optional) Default cost per query for all tools.
  • tool_name_to_cost_per_query - (Optional) Map of specific tool names to their cost per query.

Attribute Reference

In addition to all arguments above, the following attributes are exported:

  • server_id - Unique identifier for the MCP server.
  • created_at - Timestamp when the server was created.
  • created_by - User who created the server.
  • updated_at - Timestamp when the server was last updated.
  • updated_by - User who last updated the server.
  • status - Current status of the MCP server.
  • last_health_check - Timestamp of the last health check.
  • health_check_error - Error message from the last health check, if any.

Import

MCP servers can be imported using their server ID:

terraform import litellm_mcp_server.example server-id-here

Transport Types

HTTP Transport

  • Standard HTTP/HTTPS communication
  • Suitable for REST API-based MCP servers
  • Supports authentication via auth_type

SSE (Server-Sent Events) Transport

  • Real-time streaming communication
  • Ideal for servers that need to push updates
  • Commonly used with services like Zapier

Stdio Transport

  • Standard input/output communication
  • Used for local MCP servers or command-line tools
  • Requires command and optionally args and env

Access Control

Use mcp_access_groups to control which teams or users can access the MCP server tools. This integrates with LiteLLM's permission management system.

Cost Tracking

Configure cost tracking through the mcp_info.mcp_server_cost_info block to monitor and control spending on MCP tool usage.