Skip to content

test(mcp): add robust client-side behavioral tests for read-only and write modes#3791

Open
SeeyaVhora wants to merge 3 commits into
knative:mainfrom
SeeyaVhora:test/mcp-behavioral-regression-coverage
Open

test(mcp): add robust client-side behavioral tests for read-only and write modes#3791
SeeyaVhora wants to merge 3 commits into
knative:mainfrom
SeeyaVhora:test/mcp-behavioral-regression-coverage

Conversation

@SeeyaVhora
Copy link
Copy Markdown

@SeeyaVhora SeeyaVhora commented May 19, 2026

What does this PR do?

This PR introduces comprehensive, client-side behavioral regression tests for the Model Context Protocol (MCP) server.

Following the fix in #3758 (which solved the read-only state desync issue), these tests ensure that the MCP server's read-only and write modes behave exactly as expected from the perspective of an actual MCP client.


What is being tested?

Instead of just checking the internal state of the server, these tests use a real in-memory transport to interact with the server just like an MCP client would. We added four robust tests:

  1. TestMCP_ToolsExposedViaProtocol:
    • Ensures that all 15 expected tools are successfully advertised over the MCP protocol in standard write mode.
  2. TestMCP_AllToolsExposedInReadonlyMode:
    • Validates the important invariant that mutating tools (like deploy and delete) are still advertised when in read-only mode. (Read-only restrictions are enforced during execution, not by hiding the tools).
  3. TestMCP_ReadonlyEnforcedAtRuntime:
    • Verifies that calling mutating tools (deploy and delete) in read-only mode returns a protocol-level error (IsError=true), as expected.
  4. TestMCP_WriteModePermitsExecution:
    • Ensures that in standard write mode, the read-only guard is not triggered, permitting the client to execute these tools.

Verification

All tests have been run and are passing:

go test -v ./pkg/mcp/...
  • Result: PASS (including all new behavioral scenarios).

This builds directly on the work approved in #3758 to ensure we prevent future regressions.

@knative-prow knative-prow Bot requested review from dsimansk and jrangelramos May 19, 2026 21:32
@knative-prow
Copy link
Copy Markdown

knative-prow Bot commented May 19, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: SeeyaVhora
Once this PR has been reviewed and has the lgtm label, please assign lkingland 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 added size/L 🤖 PR changes 100-499 lines, ignoring generated files. needs-ok-to-test 🤖 Needs an org member to approve testing labels May 19, 2026
@knative-prow
Copy link
Copy Markdown

knative-prow Bot commented May 19, 2026

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

@SeeyaVhora SeeyaVhora force-pushed the test/mcp-behavioral-regression-coverage branch from 14784a9 to ea9e39d Compare May 19, 2026 21:50
@SeeyaVhora
Copy link
Copy Markdown
Author

Hi @lkingland,

As suggested in #3786, I've opened this follow-up PR to bring over the comprehensive client-side behavioral regression tests for the MCP server's read-only and write modes (since #3758 has merged).

To make the review process as clean as possible, I've structured the changes into 3 logical commits:

  1. Tool advertisement/exposure protocol tests.
  2. Runtime read-only enforcement checks.
  3. Write-mode execution check with executor stubbing.

Whenever you have a moment, I'd appreciate it if you could take a look.

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

Labels

needs-ok-to-test 🤖 Needs an org member to approve testing size/L 🤖 PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant