Skip to content

Commit 6a8f524

Browse files
committed
checking
Signed-off-by: Rohit Patil <[email protected]>
1 parent cc82475 commit 6a8f524

File tree

5 files changed

+904
-1
lines changed

5 files changed

+904
-1
lines changed

docs/PROMPTS.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,43 @@ content = "I'll retrieve and analyze the logs for you."
5757
### Argument Substitution
5858
Use `{{argument_name}}` placeholders in message content. The template engine replaces these with actual values when the prompt is called.
5959

60+
## Built-in Prompts
61+
62+
The Kubernetes MCP Server includes several built-in prompts that are always available:
63+
64+
### `cluster-health-check`
65+
66+
Performs a comprehensive health assessment of your Kubernetes or OpenShift cluster.
67+
68+
**Arguments:**
69+
- `namespace` (optional): Limit the health check to a specific namespace. Default: all namespaces.
70+
- `verbose` (optional): Enable detailed resource-level information. Values: `true` or `false`. Default: `false`.
71+
- `check_events` (optional): Include recent warning/error events in the analysis. Values: `true` or `false`. Default: `true`.
72+
73+
**What it checks:**
74+
- **Nodes**: Status and conditions (Ready, MemoryPressure, DiskPressure, etc.)
75+
- **Cluster Operators** (OpenShift only): Available and degraded status
76+
- **Pods**: Phase, container statuses, restart counts, and common issues (CrashLoopBackOff, ImagePullBackOff, etc.)
77+
- **Workload Controllers**: Deployments, StatefulSets, and DaemonSets replica status
78+
- **Persistent Volume Claims**: Binding status
79+
- **Events**: Recent warning and error events from the last hour
80+
81+
**Example usage:**
82+
```
83+
Check the health of my cluster
84+
```
85+
86+
Or with specific parameters:
87+
```
88+
Check the health of namespace production with verbose output
89+
```
90+
91+
The prompt gathers comprehensive diagnostic data and presents it to the LLM for analysis, which will provide:
92+
1. Overall health status (Healthy, Warning, or Critical)
93+
2. Critical issues requiring immediate attention
94+
3. Warnings and recommendations
95+
4. Summary by component
96+
6097
## Configuration File Location
6198

6299
Place your prompts in the `config.toml` file used by the MCP server. Specify the config file path using the `--config` flag when starting the server.

pkg/mcp/mcp.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,16 @@ func (s *Server) reloadToolsets() error {
167167
// Track previously enabled prompts
168168
previousPrompts := s.enabledPrompts
169169

170+
// Save built-in prompts before clearing (prompts registered via init() in code)
171+
// These need to be preserved across config reloads
172+
builtInPrompts := prompts.ConfigPrompts()
173+
170174
// Load config prompts into registry
171175
prompts.Clear()
176+
177+
// Re-register built-in prompts first
178+
prompts.Register(builtInPrompts...)
179+
172180
if s.configuration.HasPrompts() {
173181
ctx := context.Background()
174182
md := s.configuration.GetPromptsMetadata()
@@ -177,7 +185,7 @@ func (s *Server) reloadToolsets() error {
177185
}
178186
}
179187

180-
// Get prompts from registry
188+
// Get prompts from registry (includes both built-in and config prompts)
181189
configPrompts := prompts.ConfigPrompts()
182190

183191
// Update enabled prompts list

pkg/mcp/mcp_prompts_test.go

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,93 @@ content = "Content with {{required_arg}}"
150150
})
151151
}
152152

153+
func (s *McpPromptsSuite) TestClusterHealthCheckPrompt() {
154+
// No need to load config - cluster-health-check is a built-in prompt
155+
s.InitMcpClient()
156+
157+
s.Run("cluster-health-check prompt is listed", func() {
158+
prompts, err := s.ListPrompts(s.T().Context(), mcp.ListPromptsRequest{})
159+
s.Require().NoError(err, "ListPrompts should succeed")
160+
s.Require().NotNil(prompts)
161+
162+
var healthCheckPrompt *mcp.Prompt
163+
for _, prompt := range prompts.Prompts {
164+
if prompt.Name == "cluster-health-check" {
165+
healthCheckPrompt = &prompt
166+
break
167+
}
168+
}
169+
170+
s.Require().NotNil(healthCheckPrompt, "cluster-health-check prompt should be found")
171+
s.Equal("cluster-health-check", healthCheckPrompt.Name)
172+
s.Contains(healthCheckPrompt.Description, "comprehensive health assessment")
173+
s.Require().Len(healthCheckPrompt.Arguments, 3, "should have 3 arguments")
174+
175+
// Verify arguments
176+
s.Equal("namespace", healthCheckPrompt.Arguments[0].Name)
177+
s.Equal("verbose", healthCheckPrompt.Arguments[1].Name)
178+
s.Equal("check_events", healthCheckPrompt.Arguments[2].Name)
179+
})
180+
181+
s.Run("invoke cluster-health-check with no arguments", func() {
182+
result, err := s.GetPrompt(s.T().Context(), mcp.GetPromptRequest{
183+
Params: mcp.GetPromptParams{
184+
Name: "cluster-health-check",
185+
Arguments: map[string]string{},
186+
},
187+
})
188+
189+
s.NoError(err, "GetPrompt should succeed")
190+
s.Require().NotNil(result)
191+
s.Contains(result.Description, "successfully")
192+
s.Require().Len(result.Messages, 2, "should have 2 messages (user + assistant)")
193+
194+
// Verify message roles
195+
s.Equal("user", string(result.Messages[0].Role))
196+
s.Equal("assistant", string(result.Messages[1].Role))
197+
198+
// Verify user message contains diagnostic data
199+
userContent, ok := result.Messages[0].Content.(mcp.TextContent)
200+
s.Require().True(ok, "expected TextContent")
201+
s.Contains(userContent.Text, "Cluster Health Check Diagnostic Data")
202+
s.Contains(userContent.Text, "## Your Task")
203+
s.Contains(userContent.Text, "## 1. Nodes")
204+
})
205+
206+
s.Run("invoke cluster-health-check with namespace argument", func() {
207+
result, err := s.GetPrompt(s.T().Context(), mcp.GetPromptRequest{
208+
Params: mcp.GetPromptParams{
209+
Name: "cluster-health-check",
210+
Arguments: map[string]string{
211+
"namespace": "default",
212+
},
213+
},
214+
})
215+
216+
s.NoError(err, "GetPrompt should succeed with namespace argument")
217+
s.Require().NotNil(result)
218+
219+
// Verify message contains namespace scope
220+
userContent, ok := result.Messages[0].Content.(mcp.TextContent)
221+
s.Require().True(ok, "expected TextContent")
222+
s.Contains(userContent.Text, "Namespace `default`")
223+
})
224+
225+
s.Run("invoke cluster-health-check with verbose flag", func() {
226+
result, err := s.GetPrompt(s.T().Context(), mcp.GetPromptRequest{
227+
Params: mcp.GetPromptParams{
228+
Name: "cluster-health-check",
229+
Arguments: map[string]string{
230+
"verbose": "true",
231+
},
232+
},
233+
})
234+
235+
s.NoError(err, "GetPrompt should succeed with verbose flag")
236+
s.Require().NotNil(result)
237+
})
238+
}
239+
153240
func TestMcpPromptsSuite(t *testing.T) {
154241
suite.Run(t, new(McpPromptsSuite))
155242
}

0 commit comments

Comments
 (0)