feat: add MCP HTTP server experiment and improve experiment middleware (#18712)

# Add MCP HTTP Server Experiment

This PR adds a new experiment flag `mcp-server-http` to enable the MCP HTTP server functionality. The changes include:

1. Added a new experiment constant `ExperimentMCPServerHTTP` with the value "mcp-server-http"
2. Added display name and documentation for the new experiment
3. Improved the experiment middleware to:
   - Support requiring multiple experiments
   - Provide better error messages with experiment display names
   - Add a development mode bypass option
4. Applied the new experiment requirement to the MCP HTTP endpoint
5. Replaced the custom OAuth2 middleware with the standard experiment middleware

The PR also improves the `Enabled()` method on the `Experiments` type by using `slices.Contains()` for better readability.
This commit is contained in:
Thomas Kosiewski
2025-07-03 20:09:18 +02:00
committed by GitHub
parent 15551541e8
commit 7fbb3ced5b
9 changed files with 93 additions and 34 deletions

View File

@ -16,6 +16,8 @@ import (
"github.com/google/uuid"
"golang.org/x/mod/semver"
"golang.org/x/text/cases"
"golang.org/x/text/language"
"golang.org/x/xerrors"
"github.com/coreos/go-oidc/v3/oidc"
@ -3342,8 +3344,33 @@ const (
ExperimentWorkspaceUsage Experiment = "workspace-usage" // Enables the new workspace usage tracking.
ExperimentWebPush Experiment = "web-push" // Enables web push notifications through the browser.
ExperimentOAuth2 Experiment = "oauth2" // Enables OAuth2 provider functionality.
ExperimentMCPServerHTTP Experiment = "mcp-server-http" // Enables the MCP HTTP server functionality.
)
func (e Experiment) DisplayName() string {
switch e {
case ExperimentExample:
return "Example Experiment"
case ExperimentAutoFillParameters:
return "Auto-fill Template Parameters"
case ExperimentNotifications:
return "SMTP and Webhook Notifications"
case ExperimentWorkspaceUsage:
return "Workspace Usage Tracking"
case ExperimentWebPush:
return "Browser Push Notifications"
case ExperimentOAuth2:
return "OAuth2 Provider Functionality"
case ExperimentMCPServerHTTP:
return "MCP HTTP Server Functionality"
default:
// Split on hyphen and convert to title case
// e.g. "web-push" -> "Web Push", "mcp-server-http" -> "Mcp Server Http"
caser := cases.Title(language.English)
return caser.String(strings.ReplaceAll(string(e), "-", " "))
}
}
// ExperimentsKnown should include all experiments defined above.
var ExperimentsKnown = Experiments{
ExperimentExample,
@ -3352,6 +3379,7 @@ var ExperimentsKnown = Experiments{
ExperimentWorkspaceUsage,
ExperimentWebPush,
ExperimentOAuth2,
ExperimentMCPServerHTTP,
}
// ExperimentsSafe should include all experiments that are safe for
@ -3369,14 +3397,9 @@ var ExperimentsSafe = Experiments{}
// @typescript-ignore Experiments
type Experiments []Experiment
// Returns a list of experiments that are enabled for the deployment.
// Enabled returns a list of experiments that are enabled for the deployment.
func (e Experiments) Enabled(ex Experiment) bool {
for _, v := range e {
if v == ex {
return true
}
}
return false
return slices.Contains(e, ex)
}
func (c *Client) Experiments(ctx context.Context) (Experiments, error) {