@@ -12,6 +12,20 @@ import (
1212
1313func initConfiguration () []api.ServerTool {
1414 tools := []api.ServerTool {
15+ {Tool : api.Tool {
16+ Name : "contexts_list" ,
17+ Description : "List all available contexts from the kubeconfig file. Shows context names for all available contexts" ,
18+ InputSchema : & jsonschema.Schema {
19+ Type : "object" ,
20+ },
21+ Annotations : api.ToolAnnotations {
22+ Title : "Contexts: List" ,
23+ ReadOnlyHint : ptr .To (true ),
24+ DestructiveHint : ptr .To (false ),
25+ IdempotentHint : ptr .To (true ),
26+ OpenWorldHint : ptr .To (false ),
27+ },
28+ }, Handler : contextsList },
1529 {Tool : api.Tool {
1630 Name : "configuration_view" ,
1731 Description : "Get the current Kubernetes configuration content as a kubeconfig YAML" ,
@@ -39,6 +53,37 @@ func initConfiguration() []api.ServerTool {
3953 return tools
4054}
4155
56+ func contextsList (params api.ToolHandlerParams ) (* api.ToolCallResult , error ) {
57+ contexts , err := params .GetTargets (params .Context )
58+ if err != nil {
59+ return api .NewToolCallResult ("" , fmt .Errorf ("failed to list contexts: %v" , err )), nil
60+ }
61+
62+ if len (contexts ) == 0 {
63+ return api .NewToolCallResult ("No contexts found in kubeconfig" , nil ), nil
64+ }
65+
66+ defaultContext := params .GetDefaultTarget ()
67+
68+ result := fmt .Sprintf ("Available Kubernetes contexts (%d total, default: %s):\n \n " , len (contexts ), defaultContext )
69+ result += "Format: [*] CONTEXT_NAME\n "
70+ result += " (* indicates the default context used in tools if context is not set)\n \n "
71+ result += "Contexts:\n ---------\n "
72+ for _ , context := range contexts {
73+ marker := " "
74+ if context == defaultContext {
75+ marker = "*"
76+ }
77+
78+ result += fmt .Sprintf ("%s%s\n " , marker , context )
79+ }
80+ result += "---------\n \n "
81+
82+ result += "To use a specific context with any tool, set the 'context' parameter in the tool call arguments"
83+
84+ return api .NewToolCallResult (result , nil ), nil
85+ }
86+
4287func configurationView (params api.ToolHandlerParams ) (* api.ToolCallResult , error ) {
4388 minify := true
4489 minified := params .GetArguments ()["minified" ]
0 commit comments