Skip to content

fix(mcp): block build --push in read-only MCP mode#3828

Open
Ankitsinghsisodya wants to merge 1 commit into
knative:mainfrom
Ankitsinghsisodya:fix/mcp-readonly-build-push
Open

fix(mcp): block build --push in read-only MCP mode#3828
Ankitsinghsisodya wants to merge 1 commit into
knative:mainfrom
Ankitsinghsisodya:fix/mcp-readonly-build-push

Conversation

@Ankitsinghsisodya
Copy link
Copy Markdown
Contributor

@Ankitsinghsisodya Ankitsinghsisodya commented May 21, 2026

Note: Re-submission of #3741, accidentally closed when the head repository was deleted.

Summary

When the MCP server runs in read-only mode (default unless FUNC_ENABLE_MCP_WRITE enables writes), deploy and delete are already rejected. build with push: true could still push images to a registry. This change rejects that path with a clear error.

Motivation

Read-only mode is meant to avoid mutating external state. Pushing a built image to a registry is such a mutation and should align with the same policy as deploy/delete.

Changes

  • pkg/mcp/tools_build.go: in buildHandler, return an error when s.readonly is true and the tool input requests push (Push != nil && *input.Push).

Testing

  • go test ./pkg/mcp/... or make test

Copilot AI review requested due to automatic review settings May 21, 2026 11:21
@knative-prow
Copy link
Copy Markdown

knative-prow Bot commented May 21, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Ankitsinghsisodya
Once this PR has been reviewed and has the lgtm label, please assign gauron99 for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found 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 requested review from dsimansk and jrangelramos May 21, 2026 11:21
@knative-prow knative-prow Bot added size/XS 🤖 PR changes 0-9 lines, ignoring generated files. needs-ok-to-test 🤖 Needs an org member to approve testing labels May 21, 2026
@knative-prow
Copy link
Copy Markdown

knative-prow Bot commented May 21, 2026

Hi @Ankitsinghsisodya. 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.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds a guard to prevent image pushes when the MCP server is running in read-only mode.

Changes:

  • Short-circuits buildHandler when input.Push is explicitly enabled while s.readonly is true
  • Returns a user-facing error message instructing how to enable write mode for pushing images

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/mcp/tools_build.go

func (s *Server) buildHandler(ctx context.Context, r *mcp.CallToolRequest, input BuildInput) (result *mcp.CallToolResult, output BuildOutput, err error) {
if s.readonly && input.Push != nil && *input.Push {
err = fmt.Errorf("the server is in read-only mode; set FUNC_ENABLE_MCP_WRITE=true to push images")
Comment thread pkg/mcp/tools_build.go

func (s *Server) buildHandler(ctx context.Context, r *mcp.CallToolRequest, input BuildInput) (result *mcp.CallToolResult, output BuildOutput, err error) {
if s.readonly && input.Push != nil && *input.Push {
err = fmt.Errorf("the server is in read-only mode; set FUNC_ENABLE_MCP_WRITE=true to push images")
@lkingland lkingland added ok-to-test 🤖 Non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test 🤖 Needs an org member to approve testing labels May 22, 2026
Added a check in the buildHandler function to return an error if an attempt is made to push images while the server is in read-only mode. This ensures that users are informed of the correct server state and can adjust their configurations accordingly.

Co-authored-by: Cursor <cursoragent@cursor.com>
@Ankitsinghsisodya Ankitsinghsisodya force-pushed the fix/mcp-readonly-build-push branch from 85c2957 to dcbf868 Compare May 22, 2026 12:20
@codecov
Copy link
Copy Markdown

codecov Bot commented May 22, 2026

Codecov Report

❌ Patch coverage is 0% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 53.46%. Comparing base (ec38d52) to head (dcbf868).

Files with missing lines Patch % Lines
pkg/mcp/tools_build.go 0.00% 3 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3828      +/-   ##
==========================================
+ Coverage   53.44%   53.46%   +0.01%     
==========================================
  Files         200      200              
  Lines       23450    23454       +4     
==========================================
+ Hits        12533    12539       +6     
  Misses       9662     9662              
+ Partials     1255     1253       -2     
Flag Coverage Δ
e2e 33.71% <0.00%> (-0.01%) ⬇️
e2e go 29.65% <0.00%> (-0.01%) ⬇️
e2e node 25.95% <0.00%> (-0.01%) ⬇️
e2e python 29.99% <0.00%> (-0.01%) ⬇️
e2e quarkus 26.06% <0.00%> (-0.01%) ⬇️
e2e rust 25.53% <0.00%> (-0.01%) ⬇️
e2e springboot 24.20% <0.00%> (-0.01%) ⬇️
e2e typescript 26.05% <0.00%> (-0.01%) ⬇️
e2e-config-ci 26.77% <0.00%> (-0.01%) ⬇️
integration 15.77% <0.00%> (+<0.01%) ⬆️
unit macos-14 42.22% <0.00%> (-0.01%) ⬇️
unit macos-latest 42.22% <0.00%> (-0.01%) ⬇️
unit ubuntu-24.04-arm 42.51% <0.00%> (-0.02%) ⬇️
unit ubuntu-latest 43.08% <0.00%> (-0.01%) ⬇️
unit windows-latest 42.29% <0.00%> (-0.01%) ⬇️

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.

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

Labels

ok-to-test 🤖 Non-member PR verified by an org member that is safe to test. size/XS 🤖 PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants