Skip to content

fix(experimentation): Expose update_experiment to MCP as PATCH - #9138

Open
Dakshhhhh-ops wants to merge 1 commit into
Flagsmith:mainfrom
Dakshhhhh-ops:fix/mcp-update-experiment-patch
Open

Dakshhhhh-ops wants to merge 1 commit into
Flagsmith:mainfrom
Dakshhhhh-ops:fix/mcp-update-experiment-patch

Conversation

@Dakshhhhh-ops

Copy link
Copy Markdown

Thanks for submitting a PR! Please check the boxes below:

  • I have read the Contributing Guide.
  • I have added information to docs/ if required so people know about the feature. (Not needed: the tool name and description in the MCP tool catalogue are unchanged.)
  • I have filled in the "Changes" section below.
  • I have filled in the "How did you test this code" section below.

Changes

Closes #9136

The update_experiment MCP tool was generated from the update (PUT) action. PUT on an experiment always fails: without feature it is a required field, and with feature the serializer refuses to change it. This moves the MCP schema decorator to partial_update, so the tool sends PATCH with the PatchedExperiment body (every field optional).

  • api/experimentation/views.py: decorate partial_update instead of update.
  • openapi.yaml and mcp/src/flagsmith_mcp/openapi.json: update_experiment now sits on patch and uses PatchedExperiment; the PUT operation goes back to the default operation id and tag.
  • A test that checks the schema maps update_experiment to PATCH with the mcp tag and leaves PUT untagged.

REST behaviour is unchanged; only the OpenAPI operation ids and tags move.

A note on openapi.yaml: I don't have the private packages, so make generate-full-openapi on my machine drops the enterprise endpoints. I ran manage.py spectacular + openapi-format 1.23.0, copied only the experiment detail path into openapi.yaml (the other paths matched apart from the enterprise ones), then ran make generate-mcp-openapi as is. Worth re-running make generate-docs-private on your side to confirm there's no drift.

How did you test this code?

  • pytest tests/unit/experimentation/test_experiment_views.py tests/unit/api tests/integration/test_api_documentation.py: 260 passed (Linux container, Postgres 16).
  • The new test fails on main and passes with the change.
  • ruff check, ruff format --check and mypy on the two changed Python files: clean.
  • Before the change, on main: PUT with name + hypothesis gives 400 (feature required), PUT with the current feature gives 400 (cannot change feature), PATCH with hypothesis gives 200.
  • I didn't run the MCP package's own tests; they build their tools from a synthetic spec, not openapi.json.

@Dakshhhhh-ops
Dakshhhhh-ops requested review from a team as code owners November 26, 2026 22:34
@Dakshhhhh-ops
Dakshhhhh-ops requested review from khvn26 and removed request for a team November 26, 2026 22:34
@vercel

vercel Bot commented Nov 26, 2026

Copy link
Copy Markdown

@Dakshhhhh-ops is attempting to deploy a commit to the Flagsmith Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions github-actions Bot added the api Issue related to the REST API label Nov 26, 2026

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 4 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Requires human review: Auto-approval skipped because this PR is from an external contributor.

Re-trigger cubic

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api Issue related to the REST API

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MCP: update_experiment tool sends PUT, which the experiments endpoint always rejects

1 participant