Skip to content

Commit 1bdccda

Browse files
committed
feat: include server urls in configuration_contexts_list
Signed-off-by: Calum Murray <[email protected]>
1 parent 1f17523 commit 1bdccda

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

pkg/kubernetes/configuration.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,17 +98,22 @@ func (k *Kubernetes) ConfigurationContextsDefault() (string, error) {
9898

9999
// ConfigurationContextsList returns the list of available context names
100100
// TODO: Should be moved to the Provider level ?
101-
func (k *Kubernetes) ConfigurationContextsList() ([]string, error) {
101+
func (k *Kubernetes) ConfigurationContextsList() (map[string]string, error) {
102102
if k.manager.IsInCluster() {
103-
return []string{inClusterKubeConfigDefaultContext}, nil
103+
return map[string]string{inClusterKubeConfigDefaultContext: ""}, nil
104104
}
105105
cfg, err := k.manager.clientCmdConfig.RawConfig()
106106
if err != nil {
107107
return nil, err
108108
}
109-
contexts := make([]string, 0, len(cfg.Contexts))
110-
for context := range cfg.Contexts {
111-
contexts = append(contexts, context)
109+
contexts := make(map[string]string, len(cfg.Contexts))
110+
for name, context := range cfg.Contexts {
111+
cluster, ok := cfg.Clusters[context.Cluster]
112+
if !ok || cluster.Server == "" {
113+
contexts[name] = "unknown"
114+
} else {
115+
contexts[name] = cluster.Server
116+
}
112117
}
113118
return contexts, nil
114119
}

pkg/mcp/configuration_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func (s *ConfigurationSuite) TestContextsList() {
5252
})
5353
s.Run("contains default context name", func() {
5454
s.Regexpf(`^Available Kubernetes contexts \(\d+ total, default: fake-context\)`, toolResult.Content[0].(mcp.TextContent).Text, "invalid tool context default result content %v", toolResult.Content[0].(mcp.TextContent).Text)
55-
s.Regexpf(`(?m)^\*fake-context$`, toolResult.Content[0].(mcp.TextContent).Text, "invalid tool context default result content %v", toolResult.Content[0].(mcp.TextContent).Text)
55+
s.Regexpf(`(?m)^\*fake-context -> http:\/\/127\.0\.0\.1:\d*$`, toolResult.Content[0].(mcp.TextContent).Text, "invalid tool context default result content %v", toolResult.Content[0].(mcp.TextContent).Text)
5656
})
5757
})
5858
}

pkg/toolsets/config/configuration.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ func initConfiguration() []api.ServerTool {
1515
{
1616
Tool: api.Tool{
1717
Name: "configuration_contexts_list",
18-
Description: "List all available context names from the kubeconfig file",
18+
Description: "List all available context names and associated server urls from the kubeconfig file",
1919
InputSchema: &jsonschema.Schema{
2020
Type: "object",
2121
},
@@ -78,16 +78,16 @@ func contextsList(params api.ToolHandlerParams) (*api.ToolCallResult, error) {
7878
}
7979

8080
result := fmt.Sprintf("Available Kubernetes contexts (%d total, default: %s):\n\n", len(contexts), defaultContext)
81-
result += "Format: [*] CONTEXT_NAME\n"
81+
result += "Format: [*] CONTEXT_NAME -> SERVER_URL\n"
8282
result += " (* indicates the default context used in tools if context is not set)\n\n"
8383
result += "Contexts:\n---------\n"
84-
for _, context := range contexts {
84+
for context, server := range contexts {
8585
marker := " "
8686
if context == defaultContext {
8787
marker = "*"
8888
}
8989

90-
result += fmt.Sprintf("%s%s\n", marker, context)
90+
result += fmt.Sprintf("%s%s -> %s\n", marker, context, server)
9191
}
9292
result += "---------\n\n"
9393

0 commit comments

Comments
 (0)