MCPServer
MCPServer defines a containerized MCP server managed by the ToolHive Kubernetes operator. The operator watches MCPServer resources and reconciles them into a running, proxied MCP server with the configured transport, authentication, telemetry, and tool filtering.
API: toolhive.stacklok.dev/v1beta1
· Scope: Namespaced · Short names: mcpserver, mcpservers
Example
apiVersion: toolhive.stacklok.dev/v1beta1
kind: MCPServer
metadata:
name: my-mcpserver
namespace: default
spec:
image: <string>
Schema
spec
MCPServerSpec defines the desired state of MCPServer
| Field | Type | Description |
|---|---|---|
args | string[] | Args are additional arguments to pass to the MCP server |
audit | object | Audit defines audit logging configuration for the MCP server |
authServerRef | object | AuthServerRef optionally references a resource that configures an embedded OAuth 2.0/OIDC authorization server to authenticate MCP clients. Currently the only supported kind is MCPExternalAuthConfig (type: embeddedAuthServer). |
authzConfig | object | AuthzConfig defines authorization policy configuration for the MCP server |
backendReplicas | integer | BackendReplicas is the desired number of MCP server backend pod replicas. This controls the backend Deployment (the MCP server container itself), independent of the proxy runner controlled by Replicas. When nil, the operator does not set Deployment.Spec.Replicas, leaving replica management to an HPA or other external controller. format int32 · min 0 |
endpointPrefix | string | EndpointPrefix is the path prefix to prepend to SSE endpoint URLs. This is used to handle path-based ingress routing scenarios where the ingress strips a path prefix before forwarding to the backend. |
env | object[] | Env are environment variables to set in the MCP server container |
externalAuthConfigRef | object | ExternalAuthConfigRef references a MCPExternalAuthConfig resource for external authentication. The referenced MCPExternalAuthConfig must exist in the same namespace as this MCPServer. |
groupRef | object | GroupRef references the MCPGroup this server belongs to. The referenced MCPGroup must be in the same namespace. |
imagerequired | string | Image is the container image for the MCP server |
mcpPort | integer | MCPPort is the port that MCP server listens to format int32 · min 1 · max 65535 |
oidcConfigRef | object | OIDCConfigRef references a shared MCPOIDCConfig resource for OIDC authentication. The referenced MCPOIDCConfig must exist in the same namespace as this MCPServer. Per-server overrides (audience, scopes) are specified here; shared provider config lives in the MCPOIDCConfig resource. |
permissionProfile | object | PermissionProfile defines the permission profile to use |
podTemplateSpec | object | PodTemplateSpec defines the pod template to use for the MCP server This allows for customizing the pod configuration beyond what is provided by the other fields. Note that to modify the specific container the MCP server runs in, you must specify the `mcp` container name in the PodTemplateSpec. This field accepts a PodTemplateSpec object as JSON/YAML. |
proxyMode | string | ProxyMode is the proxy mode for stdio transport (sse or streamable-http) This setting is ONLY applicable when Transport is "stdio". For direct transports (sse, streamable-http), this field is ignored. The default value is applied by Kubernetes but will be ignored for non-stdio transports. default "streamable-http" · enum: sse | streamable-http |
proxyPort | integer | ProxyPort is the port to expose the proxy runner on default 8080 · format int32 · min 1 · max 65535 |
rateLimiting | object | RateLimiting defines rate limiting configuration for the MCP server. Requires Redis session storage to be configured for distributed rate limiting. |
replicas | integer | Replicas is the desired number of proxy runner (thv run) pod replicas. MCPServer creates two separate Deployments: one for the proxy runner and one for the MCP server backend. This field controls the proxy runner Deployment. When nil, the operator does not set Deployment.Spec.Replicas, leaving replica management to an HPA or other external controller. format int32 · min 0 |
resourceOverrides | object | ResourceOverrides allows overriding annotations and labels for resources created by the operator |
resources | object | Resources defines the resource requirements for the MCP server container |
secrets | object[] | Secrets are references to secrets to mount in the MCP server container |
serviceAccount | string | ServiceAccount is the name of an already existing service account to use by the MCP server. If not specified, a ServiceAccount will be created automatically and used by the MCP server. |
sessionAffinity | string | SessionAffinity controls whether the Service routes repeated client connections to the same pod. MCP protocols (SSE, streamable-http) are stateful, so ClientIP is the default. Set to "None" for stateless servers or when using an external load balancer with its own affinity. default "ClientIP" · enum: ClientIP | None |
sessionStorage | object | SessionStorage configures session storage for stateful horizontal scaling. When nil, no session storage is configured. |
telemetryConfigRef | object | TelemetryConfigRef references an MCPTelemetryConfig resource for shared telemetry configuration. The referenced MCPTelemetryConfig must exist in the same namespace as this MCPServer. Cross-namespace references are not supported for security and isolation reasons. |
toolConfigRef | object | ToolConfigRef references a MCPToolConfig resource for tool filtering and renaming. The referenced MCPToolConfig must exist in the same namespace as this MCPServer. Cross-namespace references are not supported for security and isolation reasons. |
transport | string | Transport is the transport method for the MCP server (stdio, streamable-http or sse) default "stdio" · enum: stdio | streamable-http | sse |
trustProxyHeaders | boolean | TrustProxyHeaders indicates whether to trust X-Forwarded-* headers from reverse proxies When enabled, the proxy will use X-Forwarded-Proto, X-Forwarded-Host, X-Forwarded-Port, and X-Forwarded-Prefix headers to construct endpoint URLs default false |
volumes | object[] | Volumes are volumes to mount in the MCP server container |
spec.audit
Audit defines audit logging configuration for the MCP server
| Field | Type | Description |
|---|---|---|
enabled | boolean | Enabled controls whether audit logging is enabled When true, enables audit logging with default configuration default false |
spec.authServerRef
AuthServerRef optionally references a resource that configures an embedded OAuth 2.0/OIDC authorization server to authenticate MCP clients. Currently the only supported kind is MCPExternalAuthConfig (type: embeddedAuthServer).
| Field | Type | Description |
|---|---|---|
kindrequired | string | Kind identifies the type of the referenced resource. default "MCPExternalAuthConfig" · enum: MCPExternalAuthConfig |
namerequired | string | Name is the name of the referenced resource in the same namespace. minLength 1 |
spec.authzConfig
AuthzConfig defines authorization policy configuration for the MCP server
| Field | Type | Description |
|---|---|---|
configMap | object | ConfigMap references a ConfigMap containing authorization configuration Only used when Type is "configMap" |
inline | object | Inline contains direct authorization configuration Only used when Type is "inline" |
typerequired | string | Type is the type of authorization configuration default "configMap" · enum: configMap | inline |
spec.authzConfig.configMap
ConfigMap references a ConfigMap containing authorization configuration Only used when Type is "configMap"
| Field | Type | Description |
|---|---|---|
key | string | Key is the key in the ConfigMap that contains the authorization configuration default "authz.json" |
namerequired | string | Name is the name of the ConfigMap |
spec.authzConfig.inline
Inline contains direct authorization configuration Only used when Type is "inline"
| Field | Type | Description |
|---|---|---|
entitiesJson | string | EntitiesJSON is a JSON string representing Cedar entities default "[]" |
policiesrequired | string[] | Policies is a list of Cedar policy strings |
spec.env[]
Env are environment variables to set in the MCP server container
| Field | Type | Description |
|---|---|---|
namerequired | string | Name of the environment variable |
valuerequired | string | Value of the environment variable |
spec.externalAuthConfigRef
ExternalAuthConfigRef references a MCPExternalAuthConfig resource for external authentication. The referenced MCPExternalAuthConfig must exist in the same namespace as this MCPServer.
| Field | Type | Description |
|---|---|---|
namerequired | string | Name is the name of the MCPExternalAuthConfig resource |
spec.groupRef
GroupRef references the MCPGroup this server belongs to. The referenced MCPGroup must be in the same namespace.
| Field | Type | Description |
|---|---|---|
namerequired | string | Name is the name of the MCPGroup resource in the same namespace minLength 1 |
spec.oidcConfigRef
OIDCConfigRef references a shared MCPOIDCConfig resource for OIDC authentication. The referenced MCPOIDCConfig must exist in the same namespace as this MCPServer. Per-server overrides (audience, scopes) are specified here; shared provider config lives in the MCPOIDCConfig resource.
| Field | Type | Description |
|---|---|---|
audiencerequired | string | Audience is the expected audience for token validation. This MUST be unique per server to prevent token replay attacks. minLength 1 |
namerequired | string | Name is the name of the MCPOIDCConfig resource minLength 1 |
resourceUrl | string | ResourceURL is the public URL for OAuth protected resource metadata (RFC 9728). When the server is exposed via Ingress or gateway, set this to the external URL that MCP clients connect to. If not specified, defaults to the internal Kubernetes service URL. |
scopes | string[] | Scopes is the list of OAuth scopes to advertise in the well-known endpoint (RFC 9728). If empty, defaults to ["openid"]. |
spec.permissionProfile
PermissionProfile defines the permission profile to use
| Field | Type | Description |
|---|---|---|
key | string | Key is the key in the ConfigMap that contains the permission profile Only used when Type is "configmap" |
namerequired | string | Name is the name of the permission profile If Type is "builtin", Name must be one of: "none", "network" If Type is "configmap", Name is the name of the ConfigMap |
typerequired | string | Type is the type of permission profile reference default "builtin" · enum: builtin | configmap |
spec.rateLimiting
RateLimiting defines rate limiting configuration for the MCP server. Requires Redis session storage to be configured for distributed rate limiting.
| Field | Type | Description |
|---|---|---|
perUser | object | PerUser is a token bucket applied independently to each authenticated user at the server level. Requires authentication to be enabled. Each unique userID creates Redis keys that expire after 2x refillPeriod. Memory formula: unique_users_per_TTL_window * (1 + num_tools_with_per_user_limits) keys. |
shared | object | Shared is a token bucket shared across all users for the entire server. |
tools | object[] | Tools defines per-tool rate limit overrides. Each entry applies additional rate limits to calls targeting a specific tool name. A request must pass both the server-level limit and the per-tool limit. |
spec.rateLimiting.perUser
PerUser is a token bucket applied independently to each authenticated user at the server level. Requires authentication to be enabled. Each unique userID creates Redis keys that expire after 2x refillPeriod. Memory formula: unique_users_per_TTL_window * (1 + num_tools_with_per_user_limits) keys.
| Field | Type | Description |
|---|---|---|
maxTokensrequired | integer | MaxTokens is the maximum number of tokens (bucket capacity). This is also the burst size: the maximum number of requests that can be served instantaneously before the bucket is depleted. format int32 · min 1 |
refillPeriodrequired | string | RefillPeriod is the duration to fully refill the bucket from zero to maxTokens. The effective refill rate is maxTokens / refillPeriod tokens per second. Format: Go duration string (e.g., "1m0s", "30s", "1h0m0s"). |
spec.rateLimiting.shared
Shared is a token bucket shared across all users for the entire server.
| Field | Type | Description |
|---|---|---|
maxTokensrequired | integer | MaxTokens is the maximum number of tokens (bucket capacity). This is also the burst size: the maximum number of requests that can be served instantaneously before the bucket is depleted. format int32 · min 1 |
refillPeriodrequired | string | RefillPeriod is the duration to fully refill the bucket from zero to maxTokens. The effective refill rate is maxTokens / refillPeriod tokens per second. Format: Go duration string (e.g., "1m0s", "30s", "1h0m0s"). |
spec.rateLimiting.tools[]
Tools defines per-tool rate limit overrides. Each entry applies additional rate limits to calls targeting a specific tool name. A request must pass both the server-level limit and the per-tool limit.
| Field | Type | Description |
|---|---|---|
namerequired | string | Name is the MCP tool name this limit applies to. minLength 1 |
perUser | object | PerUser token bucket configuration for this tool. |
shared | object | Shared token bucket for this specific tool. |
spec.rateLimiting.tools.perUser
PerUser token bucket configuration for this tool.
| Field | Type | Description |
|---|---|---|
maxTokensrequired | integer | MaxTokens is the maximum number of tokens (bucket capacity). This is also the burst size: the maximum number of requests that can be served instantaneously before the bucket is depleted. format int32 · min 1 |
refillPeriodrequired | string | RefillPeriod is the duration to fully refill the bucket from zero to maxTokens. The effective refill rate is maxTokens / refillPeriod tokens per second. Format: Go duration string (e.g., "1m0s", "30s", "1h0m0s"). |
spec.rateLimiting.tools.shared
Shared token bucket for this specific tool.
| Field | Type | Description |
|---|---|---|
maxTokensrequired | integer | MaxTokens is the maximum number of tokens (bucket capacity). This is also the burst size: the maximum number of requests that can be served instantaneously before the bucket is depleted. format int32 · min 1 |
refillPeriodrequired | string | RefillPeriod is the duration to fully refill the bucket from zero to maxTokens. The effective refill rate is maxTokens / refillPeriod tokens per second. Format: Go duration string (e.g., "1m0s", "30s", "1h0m0s"). |
spec.resourceOverrides
ResourceOverrides allows overriding annotations and labels for resources created by the operator
| Field | Type | Description |
|---|---|---|
proxyDeployment | object | ProxyDeployment defines overrides for the Proxy Deployment resource (toolhive proxy) |
proxyService | object | ProxyService defines overrides for the Proxy Service resource (points to the proxy deployment) |
spec.resourceOverrides.proxyDeployment
ProxyDeployment defines overrides for the Proxy Deployment resource (toolhive proxy)
| Field | Type | Description |
|---|---|---|
annotations | map<string, string> | Annotations to add or override on the resource |
env | object[] | Env are environment variables to set in the proxy container (thv run process) These affect the toolhive proxy itself, not the MCP server it manages Use TOOLHIVE_DEBUG=true to enable debug logging in the proxy |
imagePullSecrets | object[] | ImagePullSecrets allows specifying image pull secrets for the proxy runner These are applied to both the Deployment and the ServiceAccount |
labels | map<string, string> | Labels to add or override on the resource |
podTemplateMetadataOverrides | object | ResourceMetadataOverrides defines metadata overrides for a resource |
spec.resourceOverrides.proxyDeployment.env[]
Env are environment variables to set in the proxy container (thv run process) These affect the toolhive proxy itself, not the MCP server it manages Use TOOLHIVE_DEBUG=true to enable debug logging in the proxy
| Field | Type | Description |
|---|---|---|
namerequired | string | Name of the environment variable |
valuerequired | string | Value of the environment variable |
spec.resourceOverrides.proxyDeployment.imagePullSecrets[]
ImagePullSecrets allows specifying image pull secrets for the proxy runner These are applied to both the Deployment and the ServiceAccount
| Field | Type | Description |
|---|---|---|
name | string | Name of the referent. This field is effectively required, but due to backwards compatibility is allowed to be empty. Instances of this type with an empty value here are almost certainly wrong. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names default "" |
spec.resourceOverrides.proxyDeployment.podTemplateMetadataOverrides
ResourceMetadataOverrides defines metadata overrides for a resource
| Field | Type | Description |
|---|---|---|
annotations | map<string, string> | Annotations to add or override on the resource |
labels | map<string, string> | Labels to add or override on the resource |
spec.resourceOverrides.proxyService
ProxyService defines overrides for the Proxy Service resource (points to the proxy deployment)
| Field | Type | Description |
|---|---|---|
annotations | map<string, string> | Annotations to add or override on the resource |
labels | map<string, string> | Labels to add or override on the resource |
spec.resources
Resources defines the resource requirements for the MCP server container
| Field | Type | Description |
|---|---|---|
limits | object | Limits describes the maximum amount of compute resources allowed |
requests | object | Requests describes the minimum amount of compute resources required |
spec.resources.limits
Limits describes the maximum amount of compute resources allowed
| Field | Type | Description |
|---|---|---|
cpu | string | CPU is the CPU limit in cores (e.g., "500m" for 0.5 cores) |
memory | string | Memory is the memory limit in bytes (e.g., "64Mi" for 64 megabytes) |
spec.resources.requests
Requests describes the minimum amount of compute resources required
| Field | Type | Description |
|---|---|---|
cpu | string | CPU is the CPU limit in cores (e.g., "500m" for 0.5 cores) |
memory | string | Memory is the memory limit in bytes (e.g., "64Mi" for 64 megabytes) |
spec.secrets[]
Secrets are references to secrets to mount in the MCP server container
| Field | Type | Description |
|---|---|---|
keyrequired | string | Key is the key in the secret itself |
namerequired | string | Name is the name of the secret |
targetEnvName | string | TargetEnvName is the environment variable to be used when setting up the secret in the MCP server If left unspecified, it defaults to the key |
spec.sessionStorage
SessionStorage configures session storage for stateful horizontal scaling. When nil, no session storage is configured.
| Field | Type | Description |
|---|---|---|
address | string | Address is the Redis server address (required when provider is redis) minLength 1 |
db | integer | DB is the Redis database number default 0 · format int32 · min 0 |
keyPrefix | string | KeyPrefix is an optional prefix for all Redis keys used by ToolHive |
passwordRef | object | PasswordRef is a reference to a Secret key containing the Redis password |
providerrequired | string | Provider is the session storage backend type enum: memory | redis |
spec.sessionStorage.passwordRef
PasswordRef is a reference to a Secret key containing the Redis password
| Field | Type | Description |
|---|---|---|
keyrequired | string | Key is the key within the secret |
namerequired | string | Name is the name of the secret |
spec.telemetryConfigRef
TelemetryConfigRef references an MCPTelemetryConfig resource for shared telemetry configuration. The referenced MCPTelemetryConfig must exist in the same namespace as this MCPServer. Cross-namespace references are not supported for security and isolation reasons.
| Field | Type | Description |
|---|---|---|
namerequired | string | Name is the name of the MCPTelemetryConfig resource minLength 1 |
serviceName | string | ServiceName overrides the telemetry service name for this specific server. This MUST be unique per server for proper observability (e.g., distinguishing traces and metrics from different servers sharing the same collector). If empty, defaults to the server name with "thv-" prefix at runtime. |
spec.toolConfigRef
ToolConfigRef references a MCPToolConfig resource for tool filtering and renaming. The referenced MCPToolConfig must exist in the same namespace as this MCPServer. Cross-namespace references are not supported for security and isolation reasons.
| Field | Type | Description |
|---|---|---|
namerequired | string | Name is the name of the MCPToolConfig resource in the same namespace |
spec.volumes[]
Volumes are volumes to mount in the MCP server container
| Field | Type | Description |
|---|---|---|
hostPathrequired | string | HostPath is the path on the host to mount |
mountPathrequired | string | MountPath is the path in the container to mount to |
namerequired | string | Name is the name of the volume |
readOnly | boolean | ReadOnly specifies whether the volume should be mounted read-only default false |
status
MCPServerStatus defines the observed state of MCPServer
| Field | Type | Description |
|---|---|---|
authServerConfigHash | string | AuthServerConfigHash is the hash of the referenced authServerRef spec, used to detect configuration changes and trigger reconciliation. |
conditions | object[] | Conditions represent the latest available observations of the MCPServer's state |
externalAuthConfigHash | string | ExternalAuthConfigHash is the hash of the referenced MCPExternalAuthConfig spec |
message | string | Message provides additional information about the current phase |
observedGeneration | integer | ObservedGeneration reflects the generation most recently observed by the controller format int64 |
oidcConfigHash | string | OIDCConfigHash is the hash of the referenced MCPOIDCConfig spec for change detection |
phase | string | Phase is the current phase of the MCPServer enum: Pending | Ready | Failed | Terminating | Stopped |
readyReplicas | integer | ReadyReplicas is the number of ready proxy replicas format int32 |
telemetryConfigHash | string | TelemetryConfigHash is the hash of the referenced MCPTelemetryConfig spec for change detection |
toolConfigHash | string | ToolConfigHash stores the hash of the referenced ToolConfig for change detection |
url | string | URL is the URL where the MCP server can be accessed |
status.conditions[]
Conditions represent the latest available observations of the MCPServer's state
| Field | Type | Description |
|---|---|---|
lastTransitionTimerequired | string | lastTransitionTime is the last time the condition transitioned from one status to another. This should be when the underlying condition changed. If that is not known, then using the time when the API field changed is acceptable. format date-time |
messagerequired | string | message is a human readable message indicating details about the transition. This may be an empty string. maxLength 32768 |
observedGeneration | integer | observedGeneration represents the .metadata.generation that the condition was set based upon. For instance, if .metadata.generation is currently 12, but the .status.conditions[x].observedGeneration is 9, the condition is out of date with respect to the current state of the instance. format int64 · min 0 |
reasonrequired | string | reason contains a programmatic identifier indicating the reason for the condition's last transition. Producers of specific condition types may define expected values and meanings for this field, and whether the values are considered a guaranteed API. The value should be a CamelCase string. This field may not be empty. pattern ^[A-Za-z]([A-Za-z0-9_,:]*[A-Za-z0-9_])?$ · minLength 1 · maxLength 1024 |
statusrequired | string | status of the condition, one of True, False, Unknown. enum: True | False | Unknown |
typerequired | string | type of condition in CamelCase or in foo.example.com/CamelCase. pattern ^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])$ · maxLength 316 |
Related resources
References:
- MCPExternalAuthConfig - via
spec.authServerRef,spec.externalAuthConfigRef - MCPGroup - via
spec.groupRef - MCPOIDCConfig - via
spec.oidcConfigRef - MCPTelemetryConfig - via
spec.telemetryConfigRef - MCPToolConfig - via
spec.toolConfigRef