-
Notifications
You must be signed in to change notification settings - Fork 171
feat(toolsets): add support for multiple toolsets in configuration #323
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| package test | ||
|
|
||
| func Must[T any](v T, err error) T { | ||
| if err != nil { | ||
| panic(err) | ||
| } | ||
| return v | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "maps" | ||
| "os" | ||
| "slices" | ||
| "strings" | ||
|
|
||
| internalk8s "github.com/containers/kubernetes-mcp-server/pkg/kubernetes" | ||
| "github.com/containers/kubernetes-mcp-server/pkg/toolsets" | ||
|
|
||
| _ "github.com/containers/kubernetes-mcp-server/pkg/toolsets/config" | ||
| _ "github.com/containers/kubernetes-mcp-server/pkg/toolsets/core" | ||
| _ "github.com/containers/kubernetes-mcp-server/pkg/toolsets/helm" | ||
| ) | ||
|
|
||
| type OpenShift struct{} | ||
|
|
||
| func (o *OpenShift) IsOpenShift(ctx context.Context) bool { | ||
| return true | ||
| } | ||
|
|
||
| var _ internalk8s.Openshift = (*OpenShift)(nil) | ||
|
|
||
| func main() { | ||
| readme, err := os.ReadFile(os.Args[1]) | ||
| if err != nil { | ||
| panic(err) | ||
| } | ||
| // Available Toolsets | ||
| toolsetsList := toolsets.Toolsets() | ||
| maxNameLen, maxDescLen := len("Toolset"), len("Description") | ||
| for _, toolset := range toolsetsList { | ||
| nameLen := len(toolset.GetName()) | ||
| descLen := len(toolset.GetDescription()) | ||
| if nameLen > maxNameLen { | ||
| maxNameLen = nameLen | ||
| } | ||
| if descLen > maxDescLen { | ||
| maxDescLen = descLen | ||
| } | ||
| } | ||
| availableToolsets := strings.Builder{} | ||
| availableToolsets.WriteString(fmt.Sprintf("| %-*s | %-*s |\n", maxNameLen, "Toolset", maxDescLen, "Description")) | ||
| availableToolsets.WriteString(fmt.Sprintf("|-%s-|-%s-|\n", strings.Repeat("-", maxNameLen), strings.Repeat("-", maxDescLen))) | ||
| for _, toolset := range toolsetsList { | ||
| availableToolsets.WriteString(fmt.Sprintf("| %-*s | %-*s |\n", maxNameLen, toolset.GetName(), maxDescLen, toolset.GetDescription())) | ||
| } | ||
| updated := replaceBetweenMarkers( | ||
| string(readme), | ||
| "<!-- AVAILABLE-TOOLSETS-START -->", | ||
| "<!-- AVAILABLE-TOOLSETS-END -->", | ||
| availableToolsets.String(), | ||
| ) | ||
|
|
||
| // Available Toolset Tools | ||
| toolsetTools := strings.Builder{} | ||
| for _, toolset := range toolsetsList { | ||
| toolsetTools.WriteString("<details>\n\n<summary>" + toolset.GetName() + "</summary>\n\n") | ||
| tools := toolset.GetTools(&OpenShift{}) | ||
| for _, tool := range tools { | ||
| toolsetTools.WriteString(fmt.Sprintf("- **%s** - %s\n", tool.Tool.Name, tool.Tool.Description)) | ||
| for _, propName := range slices.Sorted(maps.Keys(tool.Tool.InputSchema.Properties)) { | ||
| property := tool.Tool.InputSchema.Properties[propName] | ||
| toolsetTools.WriteString(fmt.Sprintf(" - `%s` (`%s`)", propName, property.Type)) | ||
| if slices.Contains(tool.Tool.InputSchema.Required, propName) { | ||
| toolsetTools.WriteString(" **(required)**") | ||
| } | ||
| toolsetTools.WriteString(fmt.Sprintf(" - %s\n", property.Description)) | ||
| } | ||
| toolsetTools.WriteString("\n") | ||
| } | ||
| toolsetTools.WriteString("</details>\n\n") | ||
| } | ||
| updated = replaceBetweenMarkers( | ||
| updated, | ||
| "<!-- AVAILABLE-TOOLSETS-TOOLS-START -->", | ||
| "<!-- AVAILABLE-TOOLSETS-TOOLS-END -->", | ||
| toolsetTools.String(), | ||
| ) | ||
|
|
||
| if err := os.WriteFile(os.Args[1], []byte(updated), 0o644); err != nil { | ||
| panic(err) | ||
| } | ||
| } | ||
|
|
||
| func replaceBetweenMarkers(content, startMarker, endMarker, replacement string) string { | ||
| startIdx := strings.Index(content, startMarker) | ||
| if startIdx == -1 { | ||
| return content | ||
| } | ||
| endIdx := strings.Index(content, endMarker) | ||
| if endIdx == -1 || endIdx <= startIdx { | ||
| return content | ||
| } | ||
| return content[:startIdx+len(startMarker)] + "\n\n" + replacement + "\n" + content[endIdx:] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would leave helm out of the default set.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In <= v0.0.50 it's included by default.
I would do that after the first release with the toolsets feature so that we don't make it a breaking change.
We can also make it more palatable for upstream users if we remove it from the default set of toolsets but in exchange we add a few more features (e.g.
helm toolset is no longer activated by default since it now includes multiple tooling specific to helm, you can enable it by starting the kubernetes MCP server with the following flag --toolsets core,config,helm).IMO, the plan should be release v0.0.51 with toolsets without the breaking changes, then, release v0.0.52 with deactivated and specialized toolsets such as helm.
Similarly, for the config one, we could enable it only in stdio mode which is the only deployment+runtime mode where it makes sense.