mcp: add config_git_set and config_git_remove tools#3818
mcp: add config_git_set and config_git_remove tools#3818Ankitsinghsisodya wants to merge 4 commits into
Conversation
…ntation - Introduced `config_git_set` tool to configure Git repository settings for pipeline builds, including required parameters like `git_url` and `git_branch`, and optional flags for local and cluster configurations. - Added `config_git_remove` tool to remove Git settings and associated resources, with options to delete local files and cluster credentials. - Updated documentation in `instructions.md` to include usage details for both tools. - Implemented unit tests for `config_git_set` and `config_git_remove` to ensure correct argument handling and error propagation.
- Adjusted field alignment in the ConfigGitSetInput struct for improved readability and consistency. - No functional changes were made; this commit focuses on code clarity and maintainability.
- Corrected the documentation in instructions.md to clarify the optional parameters for pipeline resource creation. - Enhanced the argument validation in tools_config_git.go to ensure that the `git-dir` parameter is not set to empty or whitespace, preventing unintended CLI prompts. - Added a test case in tools_config_git_test.go to verify that at least two arguments are provided for the `configGitRemove` command, improving robustness in argument handling.
- Updated the error handling in TestTool_ConfigGitSet_MissingGitURL and TestTool_ConfigGitSet_MissingGitBranch to return instead of calling t.Fatal when a protocol-level error occurs, allowing for more graceful test failures. - Added comments to clarify the expected behavior of the MCP SDK regarding required schema fields validation.
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: Ankitsinghsisodya The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
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 Tip We noticed you've done this a few times! Consider joining the org to skip this step and gain Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions 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. |
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds MCP support for configuring and removing Git pipeline settings on a Function by wrapping func config git set/remove, with safeguards to avoid interactive CLI prompts in non-TTY execution.
Changes:
- Introduces
config_git_setandconfig_git_removeMCP tools with argument-building that avoids interactive hangs. - Registers new tools and help resources in the MCP server.
- Adds documentation and comprehensive tests for argument forwarding, defaults, and error paths.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| pkg/mcp/tools_config_git.go | Implements new Git config tools, argument building, and handlers |
| pkg/mcp/tools_config_git_test.go | Adds tests for correct argument forwarding, defaults, and error propagation |
| pkg/mcp/mcp.go | Registers the new tools and related help resources |
| pkg/mcp/instructions.md | Documents how/when to call the new tools and required/optional params |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| ConfigLocal *bool `json:"config_local,omitempty" jsonschema:"Create local pipeline template files in the Function directory (default: true when no config flags are set)"` | ||
| ConfigCluster *bool `json:"config_cluster,omitempty" jsonschema:"Create pipeline credentials and config on the cluster"` | ||
| ConfigRemote *bool `json:"config_remote,omitempty" jsonschema:"Configure a webhook on the remote Git provider (requires gh_access_token for GitHub)"` | ||
| GhAccessToken *string `json:"gh_access_token,omitempty" jsonschema:"GitHub Personal Access Token for webhook creation (scope: public_repo or repo, admin:repo_hook for automatic webhook setup)"` |
| args = appendBoolFlag(args, "--config-remote", i.ConfigRemote) | ||
| } | ||
|
|
||
| args = appendStringFlag(args, "--gh-access-token", i.GhAccessToken) |
|
|
||
| out, err := s.executor.Execute(ctx, "config", input.Args()...) | ||
| if err != nil { | ||
| err = fmt.Errorf("%w\n%s", err, string(out)) |
| // After "git set": --path, path, --git-url, url, --git-branch, branch, --git-dir, dir = 8 args | ||
| // + --config-local (1) + --verbose (1) = 10 args after "git set" | ||
| remaining := args[2:] | ||
| validateStringFlags(t, remaining, stringFlags) | ||
| validateBoolFlags(t, remaining, boolFlags) |
Summary
Adds two MCP tools —
config_git_setandconfig_git_remove— to configure Git source repository settings for pipeline-based Function builds. This completes theconfigtool group alongside the existing volumes, labels, and envs tools.Changes
pkg/mcp/tools_config_git.go— two tools following the existingconfig_*pattern:config_git_set: configures Git URL, branch, subdirectory, and optional Pipelines-as-Code (PAC) resources on the Function. Requirespath,git_url, andgit_branch. Defaultsgit_dirto"."to avoid the CLI's interactive prompt when no subdirectory is needed. Automatically injects--config-localwhen noconfig_*flags are provided to prevent the webhook confirmation prompt in a non-TTY subprocess.config_git_remove: removes Git settings and associated pipeline resources from a Function. Automatically injects--delete-localwhen neitherdelete_localnordelete_clusteris set, preventing the interactive "delete all?" prompt.pkg/mcp/tools_config_git_test.go— nine unit tests covering args, defaults, anti-hang behavior, and error propagation.pkg/mcp/mcp.go— registers both tools and three help resources (func://help/config/git,func://help/config/git/set,func://help/config/git/remove).pkg/mcp/instructions.md— addsconfig_git_set/config_git_removeagent guidance covering required fields, PAC resource flags, GitHub token requirements, and destructive-operation warning fordelete_cluster.Notes
config_git_listtool is added becausefunc config git(the root command) currently prints "Not implemented yet." and provides no useful output. Git settings can be inspected via thefunc://functionresource which exposes the fullfunc.yamlstate.Test plan
make testpassesmake checkpassesconfig_git_setwithpath,git_url,git_branchand confirmfunc.yamlis updated with Git configconfig_git_removewithpathonly and confirm local pipeline resources are cleaned up without prompting