Skip to content

Commit

Permalink
added: to context list a marker of current context
Browse files Browse the repository at this point in the history
  • Loading branch information
strowk committed Dec 15, 2024
1 parent 0d9df27 commit e92f1bc
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
8 changes: 5 additions & 3 deletions internal/tools/contexts.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,22 @@ func NewListContextsTool() fxctx.Tool {

return &mcp.CallToolResult{
Meta: map[string]interface{}{},
Content: getListContextsToolContent(cfg),
Content: getListContextsToolContent(cfg, cfg.CurrentContext),
IsError: utils.Ptr(false),
}
},
)
}

func getListContextsToolContent(cfg api.Config) []interface{} {
func getListContextsToolContent(cfg api.Config, current string) []interface{} {
var contents []interface{} = make([]interface{}, len(cfg.Contexts))
i := 0

for _, c := range cfg.Contexts {
for name, c := range cfg.Contexts {
marshalled, err := json.Marshal(ContextJsonEncoded{
Context: c,
Name: c.Cluster,
Current: name == current,
})
if err != nil {
log.Printf("failed to marshal context: %v", err)
Expand All @@ -73,4 +74,5 @@ func getListContextsToolContent(cfg api.Config) []interface{} {
type ContextJsonEncoded struct {
Context *api.Context `json:"context"`
Name string `json:"name"`
Current bool `json:"current"`
}
2 changes: 1 addition & 1 deletion testdata/k8s_contexts/list_k8s_contexts_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ out:
[
{
"type": "text",
"text": '{"context":{"cluster":"test-cluster","user":"test-user"},"name":"test-cluster"}',
"text": '{"context":{"cluster":"test-cluster","user":"test-user"},"name":"test-cluster","current":true}',
},
],
"isError": false,
Expand Down
2 changes: 1 addition & 1 deletion testdata/with_k3d/list_k8s_contexts_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ out:
[
{
"type": "text",
"text": '{"context":{"cluster":"k3d-mcp-k8s-integration-test","user":"admin@k3d-mcp-k8s-integration-test"},"name":"k3d-mcp-k8s-integration-test"}',
"text": '{"context":{"cluster":"k3d-mcp-k8s-integration-test","user":"admin@k3d-mcp-k8s-integration-test"},"name":"k3d-mcp-k8s-integration-test","current":true}',
},
],
"isError": false,
Expand Down

0 comments on commit e92f1bc

Please sign in to comment.