Skip to content

feat(mcp): add secret and ConfigMap support to config_envs_add tool#3685

Open
Ankitsinghsisodya wants to merge 4 commits intoknative:mainfrom
Ankitsinghsisodya:fix/mcp-config-envs-secret-configmap-support
Open

feat(mcp): add secret and ConfigMap support to config_envs_add tool#3685
Ankitsinghsisodya wants to merge 4 commits intoknative:mainfrom
Ankitsinghsisodya:fix/mcp-config-envs-secret-configmap-support

Conversation

@Ankitsinghsisodya
Copy link
Copy Markdown
Contributor

What

Add secret-backed and ConfigMap-backed environment variable support to the config_envs_add MCP tool. Previously, ConfigEnvsAddInput only exposed Name and Value fields, leaving agents unable to configure Kubernetes-sourced env vars through MCP.

Changes

  • pkg/mcp/tools_config_envs.go: Add four optional fields to ConfigEnvsAddInput: SecretName, SecretKey, ConfigMapName, and ConfigMapKey. Update Args() to construct the appropriate {{ secret:… }} / {{ configMap:… }} value template automatically. Explicit Value takes precedence when provided alongside source fields. Update the tool description to document all sourcing modes.

  • pkg/mcp/tools_config_envs_test.go: Add five new test cases covering single-key secret, all-keys secret, single-key ConfigMap, all-keys ConfigMap, and precedence of explicit Value over SecretName.

Sourcing modes

Mode Fields required Generated value
Literal value name, value value passed through
Secret (one key) name, secretName, secretKey {{ secret:name:key }}
Secret (all keys) secretName {{ secret:name }}
ConfigMap (one key) name, configMapName, configMapKey {{ configMap:name:key }}
ConfigMap (all keys) configMapName {{ configMap:name }}

Testing

All 11 tests in pkg/mcp pass locally.

…dates

- Added unit tests for handling environment variables sourced from Secrets and ConfigMaps, covering both individual keys and all keys scenarios.
- Updated the tool's description to clarify supported source types and precedence rules for the Value field.
- Improved argument handling in the ConfigEnvsAddInput struct to ensure correct value templates are constructed based on provided inputs.
- Enhanced test coverage for the config_envs_add functionality to validate expected behavior and error handling.
Copilot AI review requested due to automatic review settings May 9, 2026 08:53
@knative-prow
Copy link
Copy Markdown

knative-prow Bot commented May 9, 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 9, 2026 08:53
@knative-prow
Copy link
Copy Markdown

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

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.

@knative-prow knative-prow Bot added needs-ok-to-test 🤖 Needs an org member to approve testing size/L 🤖 PR changes 100-499 lines, ignoring generated files. labels May 9, 2026
- Standardized formatting of struct fields in ConfigEnvsAddInput for better readability.
- Updated test case for config_envs_add to ensure proper argument handling and maintain functionality.
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

Adds Kubernetes Secret/ConfigMap-backed env var sourcing to the config_envs_add MCP tool so agents can configure non-literal environment variables through MCP in the same way the CLI/config supports.

Changes:

  • Extended ConfigEnvsAddInput with secretName/secretKey and configMapName/configMapKey optional fields.
  • Updated Args() to auto-generate {{ secret:... }} / {{ configMap:... }} value templates, with explicit value taking precedence.
  • Added unit tests for secret/configmap key and “import all keys” modes plus precedence behavior.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 9 comments.

File Description
pkg/mcp/tools_config_envs.go Adds new input fields, updates tool description, and generates secret/configmap template values in args building.
pkg/mcp/tools_config_envs_test.go Adds new test cases validating generated --value templates and precedence behavior.

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

Comment thread pkg/mcp/tools_config_envs.go
Comment thread pkg/mcp/tools_config_envs.go
Comment thread pkg/mcp/tools_config_envs.go
Comment thread pkg/mcp/tools_config_envs.go
Comment thread pkg/mcp/tools_config_envs_test.go
Comment thread pkg/mcp/tools_config_envs_test.go
Comment thread pkg/mcp/tools_config_envs_test.go
Comment thread pkg/mcp/tools_config_envs_test.go
Comment thread pkg/mcp/tools_config_envs_test.go
@codecov
Copy link
Copy Markdown

codecov Bot commented May 9, 2026

Codecov Report

❌ Patch coverage is 83.01887% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 56.97%. Comparing base (0209813) to head (6736f1b).

Files with missing lines Patch % Lines
pkg/mcp/tools_config_envs.go 83.01% 6 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3685      +/-   ##
==========================================
+ Coverage   56.90%   56.97%   +0.07%     
==========================================
  Files         181      181              
  Lines       20933    20985      +52     
==========================================
+ Hits        11912    11957      +45     
- Misses       7811     7816       +5     
- Partials     1210     1212       +2     
Flag Coverage Δ
e2e 36.04% <0.00%> (-0.12%) ⬇️
e2e go 32.67% <0.00%> (-0.09%) ⬇️
e2e node 28.41% <0.00%> (-0.08%) ⬇️
e2e python 33.03% <0.00%> (-0.09%) ⬇️
e2e quarkus 28.53% <0.00%> (-0.10%) ⬇️
e2e rust 27.96% <0.00%> (-0.06%) ⬇️
e2e springboot 26.44% <0.00%> (-0.07%) ⬇️
e2e typescript 28.52% <0.00%> (-0.10%) ⬇️
e2e-config-ci 17.83% <0.00%> (-0.05%) ⬇️
integration 17.39% <0.00%> (-0.04%) ⬇️
unit macos-14 45.08% <84.61%> (+0.09%) ⬆️
unit macos-latest 45.08% <84.61%> (+0.09%) ⬆️
unit ubuntu-24.04-arm 45.25% <83.01%> (+0.09%) ⬆️
unit ubuntu-latest 45.93% <84.61%> (+0.08%) ⬆️
unit windows-latest 45.06% <84.61%> (+0.09%) ⬆️

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.

- Introduced new test cases to validate error handling for secretKey and configMapKey when provided without their corresponding names.
- Added tests to ensure proper validation of secretName, secretKey, configMapName, and configMapKey against allowed character sets.
- Enhanced the ConfigEnvsAddInput struct with a validate method to enforce input constraints before processing.
- Updated the config_envs_add tool's functionality to return appropriate errors for invalid inputs, improving robustness and user feedback.
- Added new validation checks to ensure that the `name` field is not set when importing all keys from a Secret or ConfigMap.
- Implemented mutual exclusivity validation for `secretName` and `configMapName` to prevent simultaneous usage.
- Updated the `ConfigEnvsAddInput` struct to reflect these validation rules, improving error handling and user feedback.
- Introduced additional test cases to validate these new constraints and ensure proper error handling in various scenarios.
@knative-prow knative-prow Bot added size/XL 🤖 PR changes 500-999 lines, ignoring generated files. and removed size/L 🤖 PR changes 100-499 lines, ignoring generated files. labels May 9, 2026
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/XL 🤖 PR changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants