Skip to content

fix(mcp): remove writeEnabled from Start() to prevent readonly state desync#3758

Open
Elvand-Lie wants to merge 1 commit into
knative:mainfrom
Elvand-Lie:fix/mcp-remove-start-write-param
Open

fix(mcp): remove writeEnabled from Start() to prevent readonly state desync#3758
Elvand-Lie wants to merge 1 commit into
knative:mainfrom
Elvand-Lie:fix/mcp-remove-start-write-param

Conversation

@Elvand-Lie
Copy link
Copy Markdown
Contributor

Summary

Fixes #3755

The Server.Start() method unconditionally overrides the readonly state that was already set by WithReadonly() during construction. This creates a dual source of truth: instructions are computed from the readonly flag at construction time (in New()), but the actual enforcement value is overridden at Start() time.

If a caller passes inconsistent values, the MCP instructions will tell the agent it is in read-only mode while the server actually permits deploy and delete operations, or vice versa.

Changes

  • pkg/mcp/mcp.go: Remove writeEnabled parameter from Start(). Readonly is now set exclusively via WithReadonly() at construction time.
  • pkg/functions/client.go: Update MCPServer interface and StartMCPServer method to remove the writeEnabled parameter.
  • cmd/mcp.go: Pass WithReadonly(!writeEnabled) at construction and call StartMCPServer without arguments.
  • pkg/mock/mcp_server.go: Update mock to match new interface.
  • Tests: Updated across cmd/mcp_test.go, pkg/mcp/mcp_test.go, and pkg/functions/client_test.go.

Testing

go test ./pkg/mcp/... -count=1    # PASS
go test ./cmd/ -run TestMCP       # PASS
go test ./pkg/functions/ -run TestClient_StartMCPServer  # PASS

@knative-prow knative-prow Bot requested review from dsimansk and jrangelramos May 16, 2026 11:17
@knative-prow knative-prow Bot added size/M 🤖 PR changes 30-99 lines, ignoring generated files. needs-ok-to-test 🤖 Needs an org member to approve testing labels May 16, 2026
@knative-prow
Copy link
Copy Markdown

knative-prow Bot commented May 16, 2026

Hi @Elvand-Lie. Thanks for your PR.

I'm waiting for a knative member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Tip

We noticed you've done this a few times! Consider joining the org to skip this step and gain /lgtm and other bot rights. We recommend asking approvers on your previous PRs to sponsor you.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 16, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 56.86%. Comparing base (2d776b0) to head (03ab530).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3758      +/-   ##
==========================================
+ Coverage   56.83%   56.86%   +0.03%     
==========================================
  Files         185      185              
  Lines       21739    21738       -1     
==========================================
+ Hits        12355    12362       +7     
+ Misses       8132     8124       -8     
  Partials     1252     1252              
Flag Coverage Δ
e2e 35.78% <0.00%> (+0.01%) ⬆️
e2e go 31.48% <0.00%> (+<0.01%) ⬆️
e2e node 27.37% <0.00%> (+<0.01%) ⬆️
e2e python 31.85% <0.00%> (+<0.01%) ⬆️
e2e quarkus 27.49% <0.00%> (+<0.01%) ⬆️
e2e rust 26.91% <0.00%> (+<0.01%) ⬆️
e2e springboot 25.46% <0.00%> (+<0.01%) ⬆️
e2e typescript 27.47% <0.00%> (+<0.01%) ⬆️
e2e-config-ci 28.34% <0.00%> (+<0.01%) ⬆️
integration 16.88% <0.00%> (-0.03%) ⬇️
unit macos-14 44.93% <100.00%> (+0.03%) ⬆️
unit macos-latest 44.93% <100.00%> (+0.03%) ⬆️
unit ubuntu-24.04-arm 45.13% <100.00%> (+0.02%) ⬆️
unit ubuntu-latest 45.85% <100.00%> (+0.03%) ⬆️
unit windows-latest 44.97% <100.00%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Elvand-Lie Elvand-Lie force-pushed the fix/mcp-remove-start-write-param branch 3 times, most recently from cfb26fb to 9e70d90 Compare May 16, 2026 18:17
@lkingland
Copy link
Copy Markdown
Member

/lgtm
/approve

@knative-prow knative-prow Bot added the lgtm 🤖 PR is ready to be merged. label May 16, 2026
@knative-prow
Copy link
Copy Markdown

knative-prow Bot commented May 16, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Elvand-Lie, lkingland

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@knative-prow knative-prow Bot added the approved 🤖 PR has been approved by an approver from all required OWNERS files. label May 16, 2026
@knative-prow-robot knative-prow-robot added the needs-rebase Cannot be merged due to conflicts with HEAD. label May 16, 2026
…desync

The Server.Start() method unconditionally overrides the readonly state
that was already set by WithReadonly() during construction. This creates
a dual source of truth: instructions are computed from the readonly flag
at construction time (in New()), but the actual enforcement value is
overridden at Start() time.

If a caller passes inconsistent values, the MCP instructions will tell
the agent it is in read-only mode while the server actually permits
deploy and delete operations, or vice versa.

Fix by removing the writeEnabled parameter from Start() entirely. The
readonly state is now set exclusively via WithReadonly() at construction
time, which is also when instructions are computed. This ensures a
single source of truth.

Signed-off-by: Elvand Lie <elvandlie@gmail.com>
@Elvand-Lie Elvand-Lie force-pushed the fix/mcp-remove-start-write-param branch from 9e70d90 to 03ab530 Compare May 18, 2026 17:12
@knative-prow
Copy link
Copy Markdown

knative-prow Bot commented May 18, 2026

New changes are detected. LGTM label has been removed.

@knative-prow knative-prow Bot removed the lgtm 🤖 PR is ready to be merged. label May 18, 2026
@knative-prow-robot knative-prow-robot removed the needs-rebase Cannot be merged due to conflicts with HEAD. label May 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved 🤖 PR has been approved by an approver from all required OWNERS files. needs-ok-to-test 🤖 Needs an org member to approve testing size/M 🤖 PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(mcp): Server.Start() unconditionally overrides readonly state set by WithReadonly()

3 participants