Skip to content

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

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#3827
Ankitsinghsisodya wants to merge 2 commits into
knative:mainfrom
Ankitsinghsisodya:fix/mcp-config-required-fields

Conversation

@Ankitsinghsisodya
Copy link
Copy Markdown
Contributor

@Ankitsinghsisodya Ankitsinghsisodya commented May 21, 2026

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

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 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:

  • config_envs_add: value → required string. name stays *string (optional) for bulk-import syntax.
  • config_envs_remove: name → required string.
  • config_labels_add: both name and value → required string.
  • config_labels_remove: name → required string.
  • config_volumes_remove: mountPath → required string.

Tests

  • Updated _Error tests to supply all required fields
  • Added missing-field tests for every affected tool: 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

- 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.
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 matejvasek 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/L 🤖 PR changes 100-499 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.

This PR tightens input validation for several MCP “config_*” tools by making key parameters required, adding explicit empty-string guards, and expanding tests to cover missing/empty argument cases.

Changes:

  • Make previously optional inputs (e.g., mountPath, name, value) required in tool input schemas and CLI arg construction.
  • Add handler-level validation to reject empty strings for required fields.
  • Add/adjust tests to cover empty/missing arguments and to assert executor invocation behavior on propagation errors.

Reviewed changes

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

Show a summary per file
File Description
pkg/mcp/tools_config_volumes.go Makes mountPath required and rejects empty mountPath before invoking the executor.
pkg/mcp/tools_config_volumes_test.go Adds tests for empty/missing mountPath and adjusts error-path test args/assertions.
pkg/mcp/tools_config_labels.go Makes name/value required and rejects empty strings in add/remove handlers.
pkg/mcp/tools_config_labels_test.go Adds tests for missing/empty label fields and strengthens executor-invocation assertions.
pkg/mcp/tools_config_envs.go Adds validation requiring at least one source for env values; makes config_envs_remove name required + non-empty.
pkg/mcp/tools_config_envs_test.go Adds tests for bulk import, missing value, and missing/empty remove name; updates error-path tests.

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

Comment on lines +214 to +216
if err == nil && !result.IsError {
t.Fatal("expected error when mountPath is missing")
}
Comment on lines 79 to +85
func (s *Server) configLabelsAddHandler(ctx context.Context, r *mcp.CallToolRequest, input ConfigLabelsAddInput) (result *mcp.CallToolResult, output ConfigLabelsAddOutput, err error) {
if input.Name == "" {
err = fmt.Errorf("'name' must not be empty")
return
}
if input.Value == "" {
err = fmt.Errorf("'value' must not be empty")
Comment on lines +63 to +66
Path string `json:"path" jsonschema:"required,Path to the function project directory"`
Name string `json:"name" jsonschema:"required,Name of the label"`
Value string `json:"value" jsonschema:"required,Value of the label"`
Verbose *bool `json:"verbose,omitempty" jsonschema:"Enable verbose logging output"`
Comment on lines +89 to 94
if i.Value == nil && i.SecretName == nil && i.ConfigMapName == nil {
return fmt.Errorf("at least one of value, secretName, or configMapName must be provided")
}
if i.Value != nil && (i.SecretName != nil || i.ConfigMapName != nil) {
return fmt.Errorf("value is mutually exclusive with secretName/configMapName; provide one or the other")
}
@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
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/L 🤖 PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants