Skip to content

fix(mcp): prevent hang in config add/remove handlers when required fields are omitted#3761

Open
Ankitsinghsisodya wants to merge 2 commits into
knative:mainfrom
Ankitsinghsisodya:fix/mcp-config-required-fields
Open

fix(mcp): prevent hang in config add/remove handlers when required fields are omitted#3761
Ankitsinghsisodya wants to merge 2 commits into
knative:mainfrom
Ankitsinghsisodya:fix/mcp-config-required-fields

Conversation

@Ankitsinghsisodya
Copy link
Copy Markdown
Contributor

Problem

The config_envs_add, config_envs_remove, config_labels_add,
config_labels_remove, and config_volumes_remove MCP tool handlers
could hang indefinitely when required fields were omitted by the caller.

The CLI commands these handlers invoke fall through to interactive survey
prompts (runAddEnvsPrompt, runRemoveEnvsPrompt, etc.) when flags are
absent. These prompts block on stdin. The MCP subprocess has no TTY, so
the call deadlocks and never returns.

Root cause

The affected fields were declared as *string with omitempty in the
JSON schema, making them appear optional to MCP clients. The CLI,
however, requires them to operate non-interactively.

Fix

Correct the schema to reflect the actual requirements of each command,
derived from the CLI flag-gating logic:

  • config_envs_add: value → required string. name stays *string
    (optional) because the bulk-import syntax intentionally omits it:
    --value='{{ secret:mySecret }}'. Requiring value ensures
    vp != nil, which satisfies the CLI's np != nil || vp != nil
    condition and always skips the interactive path.

  • config_envs_remove: name → required string. No valid remove
    call exists without a name.

  • config_labels_add: both name and value → required string.
    The CLI condition is np != nil && vp != nil (AND, not OR), so
    either field missing triggers the interactive prompt. Labels have no
    bulk-import use case.

  • config_labels_remove: name → required string. Same reasoning
    as envs remove.

  • config_volumes_remove: mountPath → required string. Volumes are
    identified by mount path; omitting it always falls to interactive mode.

Args() methods are simplified accordingly — required string fields are
appended directly instead of going through appendStringFlag.

Tests

  • Updated _Error tests to supply all required fields so they correctly
    test executor error propagation rather than schema rejection.
  • Added missing-field tests for every affected tool confirming the
    executor is never invoked when required fields are absent:
    TestTool_ConfigEnvsAdd_MissingValue,
    TestTool_ConfigEnvsRemove_MissingName,
    TestTool_ConfigLabelsAdd_MissingName,
    TestTool_ConfigLabelsAdd_MissingValue,
    TestTool_ConfigLabelsRemove_MissingName,
    TestTool_ConfigVolumesRemove_MissingMountPath.
  • Added TestTool_ConfigEnvsAdd_BulkImport confirming the
    optional-name bulk-import path still works.

Copilot AI review requested due to automatic review settings May 16, 2026 12:19
@knative-prow knative-prow Bot requested review from dsimansk and jrangelramos May 16, 2026 12:19
@knative-prow
Copy link
Copy Markdown

knative-prow Bot commented May 16, 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 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:

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 16, 2026
@knative-prow
Copy link
Copy Markdown

knative-prow Bot commented May 16, 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.

This PR tightens MCP tool input validation by making previously optional arguments required for several config tools, and expands tests to verify missing required fields are rejected.

Changes:

  • Make mountPath required for config_volumes_remove.
  • Make name / value required for config_labels_add and name required for config_labels_remove.
  • Make value required for config_envs_add (while keeping name optional for bulk-import) and name required for config_envs_remove, adding/adjusting tests accordingly.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 14 comments.

Show a summary per file
File Description
pkg/mcp/tools_config_volumes.go Make mountPath required and always include --mount-path in args
pkg/mcp/tools_config_volumes_test.go Add missing-mountPath test; update remove error test inputs/assertions
pkg/mcp/tools_config_labels.go Make label name/value required and include flags unconditionally
pkg/mcp/tools_config_labels_test.go Add missing-field tests; update error test inputs/assertions
pkg/mcp/tools_config_envs.go Require value, keep name optional for bulk-import; require name for remove
pkg/mcp/tools_config_envs_test.go Add bulk-import + missing-field tests; update error test inputs/assertions

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

Comment thread pkg/mcp/tools_config_volumes.go
Comment thread pkg/mcp/tools_config_volumes.go
Comment thread pkg/mcp/tools_config_labels.go
Comment thread pkg/mcp/tools_config_labels.go
Comment thread pkg/mcp/tools_config_labels.go
Comment thread pkg/mcp/tools_config_envs.go
Comment thread pkg/mcp/tools_config_labels.go
Comment thread pkg/mcp/tools_config_labels.go
Comment thread pkg/mcp/tools_config_volumes_test.go
Comment thread pkg/mcp/tools_config_volumes_test.go
@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.98%. Comparing base (584c11e) to head (c7c4474).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3761      +/-   ##
==========================================
- Coverage   57.03%   56.98%   -0.05%     
==========================================
  Files         182      181       -1     
  Lines       21376    21388      +12     
==========================================
- Hits        12191    12189       -2     
- Misses       7953     7962       +9     
- Partials     1232     1237       +5     
Flag Coverage Δ
e2e 35.77% <0.00%> (-0.04%) ⬇️
e2e go 31.39% <0.00%> (-0.03%) ⬇️
e2e node 27.23% <0.00%> (-0.03%) ⬇️
e2e python 31.76% <0.00%> (-0.03%) ⬇️
e2e quarkus 27.34% <0.00%> (-0.03%) ⬇️
e2e rust 26.76% <0.00%> (-0.01%) ⬇️
e2e springboot 25.29% <0.00%> (-0.03%) ⬇️
e2e typescript 27.33% <0.00%> (-0.03%) ⬇️
e2e-config-ci 28.13% <0.00%> (-0.03%) ⬇️
integration 17.20% <0.00%> (+0.02%) ⬆️
unit macos-14 45.11% <100.00%> (+0.01%) ⬆️
unit macos-latest 45.11% <100.00%> (+0.01%) ⬆️
unit ubuntu-24.04-arm 45.35% <100.00%> (+0.01%) ⬆️
unit ubuntu-latest 46.05% <100.00%> (+0.01%) ⬆️
unit windows-latest ?

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.

- Implemented tests to ensure `config_envs_add` and `config_envs_remove` tools reject calls with missing required fields (name and value).
- Added similar validation tests for `config_labels_add` and `config_labels_remove` tools to check for missing name and value.
- Enhanced `config_volumes_remove` tool to validate the presence of mountPath.
- Updated input structures for `config_envs` and `config_labels` to enforce required fields.

These changes improve the robustness of the tools by ensuring proper error handling for invalid inputs.
- Implemented tests for `config_envs_remove`, `config_labels_add`, and `config_labels_remove` tools to ensure they reject empty names and values.
- Added validation in the handlers for `config_labels_add`, `config_labels_remove`, and `config_volumes_remove` to return errors when required fields are empty.
- These changes enhance error handling and improve the robustness of the configuration tools.
@Ankitsinghsisodya Ankitsinghsisodya force-pushed the fix/mcp-config-required-fields branch from 7634b93 to c7c4474 Compare May 17, 2026 11:01
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.

2 participants