From 76dc91db78f436ed3a73ace17cd68a35e1b8eb85 Mon Sep 17 00:00:00 2001 From: Dakshhhhh-ops <217985752+Dakshhhhh-ops@users.noreply.github.com> Date: Fri, 27 Nov 2026 04:03:28 +0530 Subject: [PATCH] fix(experimentation): Expose update_experiment to MCP as PATCH --- api/experimentation/views.py | 2 +- .../experimentation/test_experiment_views.py | 17 ++++ mcp/src/flagsmith_mcp/openapi.json | 95 ++++++++++++++++++- openapi.yaml | 12 +-- 4 files changed, 114 insertions(+), 12 deletions(-) diff --git a/api/experimentation/views.py b/api/experimentation/views.py index 68aef23b4dc2..59dba307b1d8 100644 --- a/api/experimentation/views.py +++ b/api/experimentation/views.py @@ -358,7 +358,7 @@ def _get_user(request: Request) -> FFAdminUser: ), ) @method_decorator( - name="update", + name="partial_update", decorator=extend_schema( tags=["mcp"], operation_id="update_experiment", diff --git a/api/tests/unit/experimentation/test_experiment_views.py b/api/tests/unit/experimentation/test_experiment_views.py index 3b824b43fb7c..e6b8977583fc 100644 --- a/api/tests/unit/experimentation/test_experiment_views.py +++ b/api/tests/unit/experimentation/test_experiment_views.py @@ -569,6 +569,23 @@ def test_patch__change_feature__returns_400( assert response.status_code == status.HTTP_400_BAD_REQUEST +def test_openapi_schema__update_experiment__exposed_to_mcp_as_patch( + api_client: APIClient, +) -> None: + # Given + path = "/api/v1/environments/{environment_api_key}/experiments/{experiment_id}/" + + # When + response = api_client.get("/api/v1/swagger.json", HTTP_ACCEPT="application/json") + + # Then + assert response.status_code == status.HTTP_200_OK + operations = response.json()["paths"][path] + assert operations["patch"]["operationId"] == "update_experiment" + assert operations["patch"]["tags"] == ["mcp"] + assert "mcp" not in operations["put"]["tags"] + + @pytest.mark.parametrize( "from_status, action_name, expected_status_code", [ diff --git a/mcp/src/flagsmith_mcp/openapi.json b/mcp/src/flagsmith_mcp/openapi.json index 38506c708215..219963ac6622 100644 --- a/mcp/src/flagsmith_mcp/openapi.json +++ b/mcp/src/flagsmith_mcp/openapi.json @@ -549,7 +549,7 @@ "mcp" ] }, - "put": { + "patch": { "operationId": "update_experiment", "description": "(Beta) Updates an experiment's name or its hypothesis.", "parameters": [ @@ -572,21 +572,20 @@ } ], "requestBody": { - "required": true, "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/Experiment" + "$ref": "#/components/schemas/PatchedExperiment" } }, "application/x-www-form-urlencoded": { "schema": { - "$ref": "#/components/schemas/Experiment" + "$ref": "#/components/schemas/PatchedExperiment" } }, "multipart/form-data": { "schema": { - "$ref": "#/components/schemas/Experiment" + "$ref": "#/components/schemas/PatchedExperiment" } } } @@ -6750,6 +6749,92 @@ "results" ] }, + "PatchedExperiment": { + "type": "object", + "properties": { + "id": { + "type": "integer", + "readOnly": true + }, + "feature": { + "type": "integer" + }, + "name": { + "type": "string", + "maxLength": 255 + }, + "hypothesis": { + "type": "string" + }, + "status": { + "allOf": [ + { + "$ref": "#/components/schemas/Status7a8Enum" + } + ], + "readOnly": true + }, + "metrics": { + "type": "array", + "items": { + "$ref": "#/components/schemas/ExperimentMetricInline" + }, + "writeOnly": true + }, + "experiment_rollout": { + "allOf": [ + { + "$ref": "#/components/schemas/ExperimentRollout" + } + ], + "writeOnly": true + }, + "created_at": { + "type": "string", + "format": "date-time", + "readOnly": true + }, + "updated_at": { + "type": "string", + "format": "date-time", + "readOnly": true + }, + "started_at": { + "type": [ + "string", + "null" + ], + "format": "date-time", + "readOnly": true + }, + "ended_at": { + "type": [ + "string", + "null" + ], + "format": "date-time", + "readOnly": true + }, + "rollout_decision": { + "oneOf": [ + { + "$ref": "#/components/schemas/RolloutDecisionEnum" + }, + { + "$ref": "#/components/schemas/NullEnum" + } + ], + "readOnly": true + }, + "rollout_variant": { + "type": [ + "integer", + "null" + ], + "readOnly": true + } + } + }, "PaymentMethodEnum": { "description": "* `CHARGEBEE` - Chargebee\n* `XERO` - Xero\n* `AWS_MARKETPLACE` - AWS Marketplace", "type": "string", diff --git a/openapi.yaml b/openapi.yaml index 7d8e500b7e20..e8c508549127 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -3622,8 +3622,8 @@ paths: tags: - mcp put: - operationId: update_experiment - description: (Beta) Updates an experiment's name or its hypothesis. + operationId: api_v1_environments_experiments_update + description: Manage experiments for an environment. parameters: - name: environment_api_key in: path @@ -3659,10 +3659,10 @@ paths: - tokenAuth: [] - Master API Key: [] tags: - - mcp + - Environments patch: - operationId: api_v1_environments_experiments_partial_update - description: Manage experiments for an environment. + operationId: update_experiment + description: (Beta) Updates an experiment's name or its hypothesis. parameters: - name: environment_api_key in: path @@ -3697,7 +3697,7 @@ paths: - tokenAuth: [] - Master API Key: [] tags: - - Environments + - mcp delete: operationId: api_v1_environments_experiments_destroy description: Manage experiments for an environment.