|
| 1 | +// SPDX-FileCopyrightText: Copyright 2025 Stacklok, Inc. |
| 2 | +// SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +package v1alpha1 |
| 5 | + |
| 6 | +import ( |
| 7 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 8 | +) |
| 9 | + |
| 10 | +// MCPServerEntrySpec defines the desired state of MCPServerEntry. |
| 11 | +// MCPServerEntry is a zero-infrastructure catalog entry that declares a remote MCP |
| 12 | +// server endpoint. Unlike MCPRemoteProxy, it creates no pods, services, or deployments. |
| 13 | +type MCPServerEntrySpec struct { |
| 14 | + // RemoteURL is the URL of the remote MCP server. |
| 15 | + // HTTPS is enforced by default; set the annotation |
| 16 | + // toolhive.stacklok.dev/allow-insecure: "true" to allow HTTP for development. |
| 17 | + // +kubebuilder:validation:Required |
| 18 | + // +kubebuilder:validation:Pattern=`^https?://` |
| 19 | + RemoteURL string `json:"remoteURL"` |
| 20 | + |
| 21 | + // Transport is the transport method for the remote server (sse or streamable-http). |
| 22 | + // No default is set (unlike MCPRemoteProxy) because MCPServerEntry points at external |
| 23 | + // servers the user doesn't control — requiring explicit transport avoids silent mismatches. |
| 24 | + // +kubebuilder:validation:Required |
| 25 | + // +kubebuilder:validation:Enum=sse;streamable-http |
| 26 | + Transport string `json:"transport"` |
| 27 | + |
| 28 | + // GroupRef is the name of the MCPGroup this entry belongs to. |
| 29 | + // Required — every MCPServerEntry must be part of a group for vMCP discovery. |
| 30 | + // +kubebuilder:validation:Required |
| 31 | + // +kubebuilder:validation:MinLength=1 |
| 32 | + GroupRef string `json:"groupRef"` |
| 33 | + |
| 34 | + // ExternalAuthConfigRef references a MCPExternalAuthConfig resource for token exchange |
| 35 | + // when connecting to the remote MCP server. The referenced MCPExternalAuthConfig must |
| 36 | + // exist in the same namespace as this MCPServerEntry. |
| 37 | + // +optional |
| 38 | + ExternalAuthConfigRef *ExternalAuthConfigRef `json:"externalAuthConfigRef,omitempty"` |
| 39 | + |
| 40 | + // HeaderForward configures headers to inject into requests to the remote MCP server. |
| 41 | + // Use this to add custom headers like API keys or correlation IDs. |
| 42 | + // +optional |
| 43 | + HeaderForward *HeaderForwardConfig `json:"headerForward,omitempty"` |
| 44 | + |
| 45 | + // CABundleRef references a ConfigMap containing CA certificates for TLS verification |
| 46 | + // when connecting to the remote MCP server. |
| 47 | + // +optional |
| 48 | + CABundleRef *CABundleSource `json:"caBundleRef,omitempty"` |
| 49 | +} |
| 50 | + |
| 51 | +// MCPServerEntryStatus defines the observed state of MCPServerEntry. |
| 52 | +type MCPServerEntryStatus struct { |
| 53 | + // ObservedGeneration reflects the generation most recently observed by the controller. |
| 54 | + // +optional |
| 55 | + ObservedGeneration int64 `json:"observedGeneration,omitempty"` |
| 56 | + |
| 57 | + // Phase indicates the current lifecycle phase of the MCPServerEntry. |
| 58 | + // +optional |
| 59 | + // +kubebuilder:default=Pending |
| 60 | + Phase MCPServerEntryPhase `json:"phase,omitempty"` |
| 61 | + |
| 62 | + // Conditions represent the latest available observations of the MCPServerEntry's state. |
| 63 | + // +listType=map |
| 64 | + // +listMapKey=type |
| 65 | + // +optional |
| 66 | + Conditions []metav1.Condition `json:"conditions,omitempty"` |
| 67 | +} |
| 68 | + |
| 69 | +// MCPServerEntryPhase represents the lifecycle phase of an MCPServerEntry. |
| 70 | +// +kubebuilder:validation:Enum=Valid;Pending;Failed |
| 71 | +type MCPServerEntryPhase string |
| 72 | + |
| 73 | +const ( |
| 74 | + // MCPServerEntryPhaseValid indicates all validations passed and the entry is usable. |
| 75 | + MCPServerEntryPhaseValid MCPServerEntryPhase = "Valid" |
| 76 | + |
| 77 | + // MCPServerEntryPhasePending indicates the entry is waiting for referenced resources. |
| 78 | + MCPServerEntryPhasePending MCPServerEntryPhase = "Pending" |
| 79 | + |
| 80 | + // MCPServerEntryPhaseFailed indicates a validation error occurred. |
| 81 | + MCPServerEntryPhaseFailed MCPServerEntryPhase = "Failed" |
| 82 | +) |
| 83 | + |
| 84 | +// Condition types for MCPServerEntry. |
| 85 | +// Reuses shared condition type constants from mcpserver_types.go where the string |
| 86 | +// values match (GroupRefValidated, ExternalAuthConfigValidated, CABundleRefValidated). |
| 87 | +const ( |
| 88 | + // ConditionTypeMCPServerEntryValid indicates overall validation status of the MCPServerEntry. |
| 89 | + // Uses the shared "Valid" condition type since this is a configuration resource, not a workload. |
| 90 | + ConditionTypeMCPServerEntryValid = ConditionTypeValid |
| 91 | + |
| 92 | + // ConditionTypeMCPServerEntryGroupRefValidated indicates whether the referenced MCPGroup exists. |
| 93 | + ConditionTypeMCPServerEntryGroupRefValidated = ConditionGroupRefValidated |
| 94 | + |
| 95 | + // ConditionTypeMCPServerEntryAuthConfigValidated indicates whether the referenced |
| 96 | + // MCPExternalAuthConfig exists (when configured). |
| 97 | + ConditionTypeMCPServerEntryAuthConfigValidated = ConditionTypeExternalAuthConfigValidated |
| 98 | + |
| 99 | + // ConditionTypeMCPServerEntryCABundleRefValidated indicates whether the referenced |
| 100 | + // CA bundle ConfigMap exists (when configured). |
| 101 | + ConditionTypeMCPServerEntryCABundleRefValidated = ConditionCABundleRefValidated |
| 102 | +) |
| 103 | + |
| 104 | +// Condition reasons for MCPServerEntry. |
| 105 | +// GroupRef reasons reuse shared constants from mcpserver_types.go. |
| 106 | +// CABundle reasons reuse shared constants from mcpserver_types.go. |
| 107 | +const ( |
| 108 | + // ConditionReasonMCPServerEntryValid indicates the entry passed all validations. |
| 109 | + ConditionReasonMCPServerEntryValid = "ConfigValid" |
| 110 | + |
| 111 | + // ConditionReasonMCPServerEntryInvalid indicates one or more validations failed. |
| 112 | + ConditionReasonMCPServerEntryInvalid = "ConfigInvalid" |
| 113 | + |
| 114 | + // ConditionReasonMCPServerEntryGroupRefValidated reuses the shared GroupRef reason. |
| 115 | + ConditionReasonMCPServerEntryGroupRefValidated = ConditionReasonGroupRefValidated |
| 116 | + |
| 117 | + // ConditionReasonMCPServerEntryGroupRefNotFound reuses the shared GroupRef reason. |
| 118 | + ConditionReasonMCPServerEntryGroupRefNotFound = ConditionReasonGroupRefNotFound |
| 119 | + |
| 120 | + // ConditionReasonMCPServerEntryGroupRefNotReady reuses the shared GroupRef reason. |
| 121 | + ConditionReasonMCPServerEntryGroupRefNotReady = ConditionReasonGroupRefNotReady |
| 122 | + |
| 123 | + // ConditionReasonMCPServerEntryAuthConfigValid indicates the referenced auth config exists. |
| 124 | + ConditionReasonMCPServerEntryAuthConfigValid = "AuthConfigValid" |
| 125 | + |
| 126 | + // ConditionReasonMCPServerEntryAuthConfigNotFound indicates the referenced auth config was not found. |
| 127 | + ConditionReasonMCPServerEntryAuthConfigNotFound = "AuthConfigNotFound" |
| 128 | + |
| 129 | + // ConditionReasonMCPServerEntryAuthConfigNotConfigured indicates no auth config ref is set. |
| 130 | + ConditionReasonMCPServerEntryAuthConfigNotConfigured = "AuthConfigNotConfigured" |
| 131 | + |
| 132 | + // ConditionReasonMCPServerEntryCABundleRefValid reuses the shared CABundle reason. |
| 133 | + ConditionReasonMCPServerEntryCABundleRefValid = ConditionReasonCABundleRefValid |
| 134 | + |
| 135 | + // ConditionReasonMCPServerEntryCABundleRefNotFound reuses the shared CABundle reason. |
| 136 | + ConditionReasonMCPServerEntryCABundleRefNotFound = ConditionReasonCABundleRefNotFound |
| 137 | + |
| 138 | + // ConditionReasonMCPServerEntryCABundleRefNotConfigured indicates no CA bundle ref is set. |
| 139 | + ConditionReasonMCPServerEntryCABundleRefNotConfigured = "CABundleRefNotConfigured" |
| 140 | +) |
| 141 | + |
| 142 | +// AllowInsecureAnnotation is the annotation key to allow HTTP URLs for development. |
| 143 | +const AllowInsecureAnnotation = "toolhive.stacklok.dev/allow-insecure" |
| 144 | + |
| 145 | +//+kubebuilder:object:root=true |
| 146 | +//+kubebuilder:subresource:status |
| 147 | +//+kubebuilder:resource:shortName=mcpentry,categories=toolhive |
| 148 | +//+kubebuilder:printcolumn:name="Phase",type="string",JSONPath=".status.phase" |
| 149 | +//+kubebuilder:printcolumn:name="Transport",type="string",JSONPath=".spec.transport" |
| 150 | +//+kubebuilder:printcolumn:name="Remote URL",type="string",JSONPath=".spec.remoteURL" |
| 151 | +//+kubebuilder:printcolumn:name="Group",type="string",JSONPath=".spec.groupRef" |
| 152 | +//+kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp" |
| 153 | + |
| 154 | +// MCPServerEntry is the Schema for the mcpserverentries API. |
| 155 | +// It declares a remote MCP server endpoint for vMCP discovery and routing |
| 156 | +// without deploying any infrastructure. |
| 157 | +type MCPServerEntry struct { |
| 158 | + metav1.TypeMeta `json:",inline"` // nolint:revive |
| 159 | + metav1.ObjectMeta `json:"metadata,omitempty"` |
| 160 | + |
| 161 | + Spec MCPServerEntrySpec `json:"spec,omitempty"` |
| 162 | + Status MCPServerEntryStatus `json:"status,omitempty"` |
| 163 | +} |
| 164 | + |
| 165 | +//+kubebuilder:object:root=true |
| 166 | + |
| 167 | +// MCPServerEntryList contains a list of MCPServerEntry. |
| 168 | +type MCPServerEntryList struct { |
| 169 | + metav1.TypeMeta `json:",inline"` // nolint:revive |
| 170 | + metav1.ListMeta `json:"metadata,omitempty"` |
| 171 | + Items []MCPServerEntry `json:"items"` |
| 172 | +} |
| 173 | + |
| 174 | +func init() { |
| 175 | + SchemeBuilder.Register(&MCPServerEntry{}, &MCPServerEntryList{}) |
| 176 | +} |
0 commit comments