GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(mcp): defer impl construction so Start's writeEnabled controls readonly by SarthakB11 · Pull Request #3730 · knative/func

Conversation

@SarthakB11

@SarthakB11 SarthakB11 commented May 14, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Problem

mcp.New eagerly constructs the underlying *mcp.Server with
Instructions: instructions(s.readonly). At that point s.readonly
is whatever WithReadonly set it to (default false). Start later
reassigns s.readonly = !writeEnabled, but the Instructions string
is already baked into the impl.

cmd/mcp.go calls mcp.New(mcp.WithPrefix(cmdPrefix)) with no
WithReadonly, then client.StartMCPServer(cmd.Context(), writeEnabled).
writeEnabled defaults to false and only flips when FUNC_ENABLE_MCP_WRITE=1
is set. The default func mcp invocation therefore runs in readonly mode
but ships the non-readonly system prompt. instructions_warning.md is
silently dropped and the agent assumes it can deploy and delete.

TestInstructions did not catch this because newTestPairWithReadonly
threads WithReadonly into New, which already produces the correct
baked Instructions for that call path.

Fix

Move the mcp.NewServer call and the AddTool / AddResource
registration out of New into a buildImpl method. Start invokes
it after s.readonly = !writeEnabled, so the resolved value is the
one baked into Instructions. New's public surface and Options
behavior are unchanged.

Tests

TestInstructionsStartArgDrivesReadonly mirrors the cmd/mcp.go flow:
mcp.New is called without WithReadonly, then Start receives a
concrete writeEnabled. The two subtests (readonly / write)
assert that the readonly warning appears or is absent based on the
Start argument, not on what New saw at construction time.

make check and make test clean.

/kind bug

fix: default `func mcp` invocation now ships the readonly system prompt instead of the write-mode one

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@knative-prow
knative-prow Bot requested review from gauron99 and lkingland May 14, 2026 19:23
@knative-prow

knative-prow Bot commented May 14, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: SarthakB11
Once this PR has been reviewed and has the lgtm label, please assign dsimansk 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:
  • OWNERS

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@linux-foundation-easycla

linux-foundation-easycla Bot commented May 14, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: SarthakB11 / name: SarthakB11 (075aafe)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@knative-prow

knative-prow Bot commented May 14, 2026

Copy link
Copy Markdown

Welcome @SarthakB11! It looks like this is your first PR to knative/func 🎉

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@knative-prow knative-prow Bot added needs-ok-to-test 🤖 Needs an org member to approve testing size/M 🤖 PR changes 30-99 lines, ignoring generated files. labels May 14, 2026
@knative-prow

knative-prow Bot commented May 14, 2026

Copy link
Copy Markdown

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

Regular contributors should join the org to skip this step.

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@SarthakB11
fix(mcp): defer impl construction so Start's writeEnabled controls re…
ae019ee
…adonly

mcp.New eagerly constructed the underlying *mcp.Server with
Instructions: instructions(s.readonly). At that point s.readonly is
whatever WithReadonly set it to, defaulting to false. Start then
reassigns s.readonly = !writeEnabled, but the Instructions string is
already baked into the impl by then.

cmd/mcp.go invokes mcp.New(mcp.WithPrefix(cmdPrefix)) without
WithReadonly, then client.StartMCPServer(cmd.Context(), writeEnabled).
writeEnabled defaults to false; FUNC_ENABLE_MCP_WRITE=1 flips it. The
default invocation therefore runs in readonly mode but ships the
non-readonly system prompt to the connected agent. instructions_warning.md
is silently dropped and the agent assumes it can deploy and delete.

Move the mcp.NewServer call and the AddTool / AddResource registration
out of New and into a buildImpl method invoked from Start after
s.readonly is resolved. New keeps its public surface and Options
behavior unchanged. The existing TestInstructions test still passes
because newTestPairWithReadonly threads WithReadonly into New, which
already produced the correct baked Instructions; the test was unaware
of the default flow.

Add TestInstructions_StartArgDrivesReadonly which mirrors cmd/mcp.go:
mcp.New is called without WithReadonly, then Start receives a concrete
writeEnabled value. Verifies the readonly warning appears or is absent
based on the Start argument, not on what New saw at construction time.

Signed-off-by: SarthakB11 <[email protected]>
@SarthakB11
SarthakB11 force-pushed the sarth/mcp-readonly-instructions branch from 075aafe to ae019ee Compare May 14, 2026 19:32
@gauron99

gauron99 commented May 15, 2026

Copy link
Copy Markdown
Contributor

This seems to be superseded by #3707 which addresses the same issue with a simpler approach.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@lkingland

lkingland commented May 16, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Thanks for the contribution, but closing this one as a duplicate

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@lkingland lkingland closed this May 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@gauron99 gauron99 Awaiting requested review from gauron99
@lkingland lkingland Awaiting requested review from lkingland

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

needs-ok-to-test 🤖 Needs an org member to approve testing size/M 🤖 PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@SarthakB11 @gauron99 @lkingland
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.