Skip to content

Commit 0389213

Browse files
committed
add support to read prompts from toml config
Signed-off-by: Nader Ziada <[email protected]>
1 parent 096e2e1 commit 0389213

File tree

11 files changed

+1148
-720
lines changed

11 files changed

+1148
-720
lines changed

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,34 @@ uvx kubernetes-mcp-server@latest --help
196196
| `--toolsets` | Comma-separated list of toolsets to enable. Check the [🛠️ Tools and Functionalities](#tools-and-functionalities) section for more information. |
197197
| `--disable-multi-cluster` | If set, the MCP server will disable multi-cluster support and will only use the current context from the kubeconfig file. This is useful if you want to restrict the MCP server to a single cluster. |
198198

199+
#### Custom Prompts Configuration
200+
201+
The server supports defining custom [MCP prompts](https://modelcontextprotocol.io/docs/concepts/prompts) directly in your configuration file, allowing you to create custom workflows without recompiling. See [docs/PROMPTS.md](docs/PROMPTS.md) for detailed documentation.
202+
203+
**Configuration file example:**
204+
205+
```toml
206+
# Define prompts inline in your config.toml
207+
[[prompts]]
208+
name = "my-custom-prompt"
209+
description = "A custom troubleshooting workflow"
210+
211+
[[prompts.arguments]]
212+
name = "resource_name"
213+
required = true
214+
215+
[[prompts.messages]]
216+
role = "user"
217+
content = "Help me troubleshoot {{resource_name}}"
218+
219+
[[prompts.messages]]
220+
role = "assistant"
221+
content = "I'll investigate {{resource_name}} for you."
222+
223+
# Optionally disable built-in embedded prompts
224+
disable_embedded_prompts = false
225+
```
226+
199227
## 🛠️ Tools and Functionalities <a id="tools-and-functionalities"></a>
200228

201229
The Kubernetes MCP server supports enabling or disabling specific groups of tools and functionalities (tools, resources, prompts, and so on) via the `--toolsets` command-line flag or `toolsets` configuration option.

docs/PROMPTS.md

Lines changed: 137 additions & 166 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# MCP Prompts Support
22

3-
The Kubernetes MCP Server now supports [MCP Prompts](https://modelcontextprotocol.io/docs/concepts/prompts), which provide pre-defined workflow templates and guidance to AI assistants. Prompts help standardize common Kubernetes operations and provide structured approaches to troubleshooting and deployment tasks.
3+
The Kubernetes MCP Server supports [MCP Prompts](https://modelcontextprotocol.io/docs/concepts/prompts), which provide pre-defined workflow templates and guidance to AI assistants.
44

55
## What are MCP Prompts?
66

@@ -9,217 +9,188 @@ MCP Prompts are pre-defined templates that guide AI assistants through specific
99
- **Parameterization**: Arguments that customize the prompt for specific contexts
1010
- **Conversation templates**: Pre-formatted messages that guide the interaction
1111

12-
## Available Prompts
12+
## Available Built-in Prompts
1313

14-
The Kubernetes MCP Server currently provides the following prompts in the `core` toolset:
14+
The server provides these prompts in the `core` toolset:
1515

16-
### 1. `troubleshoot-pod`
17-
Guide for troubleshooting a failing or crashed pod in Kubernetes.
16+
1. **troubleshoot-pod** - Debug failing or crashed pods
17+
2. **deploy-application** - Deploy new applications
18+
3. **scale-deployment** - Scale deployments safely
19+
4. **investigate-cluster-health** - Check overall cluster health
20+
5. **debug-networking** - Debug connectivity issues
21+
6. **review-resource-usage** - Analyze resource consumption
1822

19-
**Arguments:**
20-
- `namespace` (required): The namespace where the pod is located
21-
- `pod_name` (required): The name of the pod to troubleshoot
23+
## Creating Custom Prompts
2224

23-
**Usage:**
24-
```
25-
When to use: Pod is failing, crashing, or not working as expected
26-
What it does: Systematically investigates pod status, events, logs, and resource constraints
27-
```
25+
Define custom prompts in your `config.toml` file - no code changes or recompilation needed!
2826

29-
### 2. `deploy-application`
30-
Workflow for deploying a new application to Kubernetes.
27+
### Basic Example
3128

32-
**Arguments:**
33-
- `app_name` (required): The name of the application to deploy
34-
- `namespace` (optional): The namespace to deploy to (defaults to 'default')
29+
```toml
30+
[[prompts]]
31+
name = "check-pod-logs"
32+
description = "Quick way to check pod logs"
3533

36-
**Usage:**
37-
```
38-
When to use: Deploying a new application to the cluster
39-
What it does: Guides through namespace setup, manifest creation, deployment, and verification
40-
```
34+
[[prompts.arguments]]
35+
name = "pod_name"
36+
description = "Name of the pod"
37+
required = true
4138

42-
### 3. `scale-deployment`
43-
Guide for scaling a deployment up or down.
39+
[[prompts.arguments]]
40+
name = "namespace"
41+
description = "Namespace of the pod"
42+
required = false
4443

45-
**Arguments:**
46-
- `deployment_name` (required): The name of the deployment to scale
47-
- `namespace` (required): The namespace of the deployment
48-
- `replicas` (required): The desired number of replicas
44+
[[prompts.messages]]
45+
role = "user"
46+
content = "Show me the logs for pod {{pod_name}} in {{namespace}}"
4947

50-
**Usage:**
51-
```
52-
When to use: Need to scale application replicas
53-
What it does: Checks current status, scales deployment, and monitors the scaling process
48+
[[prompts.messages]]
49+
role = "assistant"
50+
content = "I'll retrieve and analyze the logs for you."
5451
```
5552

56-
### 4. `investigate-cluster-health`
57-
Comprehensive workflow for investigating overall cluster health.
53+
### Complex Example with Multi-Step Workflow
5854

59-
**Arguments:** None
55+
```toml
56+
[[prompts]]
57+
name = "troubleshoot-deployment"
58+
description = "Comprehensive deployment troubleshooting"
6059

61-
**Usage:**
62-
```
63-
When to use: Want to understand overall cluster status and health
64-
What it does: Checks nodes, system pods, events, resource usage, and namespaces
65-
```
60+
[[prompts.arguments]]
61+
name = "deployment_name"
62+
required = true
6663

67-
### 5. `debug-networking`
68-
Workflow for debugging networking issues between pods or services.
64+
[[prompts.arguments]]
65+
name = "namespace"
66+
required = true
6967

70-
**Arguments:**
71-
- `source_pod` (optional): The source pod name
72-
- `source_namespace` (optional): The source pod namespace
73-
- `target_service` (optional): The target service name
68+
[[prompts.messages]]
69+
role = "user"
70+
content = """
71+
My deployment {{deployment_name}} in {{namespace}} is having issues.
72+
Can you investigate?
73+
"""
7474

75-
**Usage:**
76-
```
77-
When to use: Experiencing connectivity or networking problems
78-
What it does: Investigates pod IPs, service configuration, network policies, DNS, and connectivity
79-
```
75+
[[prompts.messages]]
76+
role = "assistant"
77+
content = """
78+
I'll troubleshoot deployment {{deployment_name}}. Let me:
8079
81-
### 6. `review-resource-usage`
82-
Analyze resource usage across the cluster or specific namespace.
80+
1. **Check Deployment Status**
81+
- Review current vs desired replicas
82+
- Check rollout status
8383
84-
**Arguments:**
85-
- `namespace` (optional): Focus on specific namespace (leave empty for cluster-wide)
84+
2. **Investigate Pods**
85+
- List pod states
86+
- Review pod events and logs
8687
87-
**Usage:**
88-
```
89-
When to use: Need to understand resource consumption and identify bottlenecks
90-
What it does: Analyzes CPU and memory usage, identifies top consumers, and provides recommendations
88+
3. **Analyze Resources**
89+
- Check CPU/memory limits
90+
- Verify quotas
91+
92+
Starting investigation...
93+
"""
9194
```
9295

93-
## Creating Custom Prompts
96+
### Argument Substitution
9497

95-
Toolsets can provide their own prompts by implementing the `GetPrompts()` method and creating YAML definition files.
96-
97-
### YAML Prompt Definition Format
98-
99-
Prompts are defined in YAML files with the following structure:
100-
101-
```yaml
102-
- name: prompt-name
103-
description: Human-readable description of what this prompt does
104-
arguments:
105-
- name: argument_name
106-
description: What this argument is for
107-
required: true/false
108-
messages:
109-
- role: user
110-
content: |
111-
The user's initial message with {{argument_name}} placeholders
112-
- role: assistant
113-
content: |
114-
The assistant's response template
115-
```
98+
Use `{{argument_name}}` in message content to insert values:
11699

117-
### Example: Creating a Custom Prompt
118-
119-
**Step 1: Create a YAML file** (`pkg/toolsets/yourname/prompts.yaml`):
120-
121-
```yaml
122-
- name: check-pod-logs
123-
description: Retrieve and analyze logs from a specific pod
124-
arguments:
125-
- name: pod_name
126-
description: The name of the pod to check
127-
required: true
128-
- name: namespace
129-
description: The namespace of the pod
130-
required: false
131-
messages:
132-
- role: user
133-
content: |
134-
I need to check the logs for pod {{pod_name}}{{#namespace}} in namespace {{namespace}}{{/namespace}}.
135-
- role: assistant
136-
content: |
137-
I'll retrieve the logs for {{pod_name}}. Let me:
138-
1. Verify the pod exists and its status
139-
2. Retrieve the latest logs
140-
3. Analyze for errors or warnings
100+
```toml
101+
[[prompts.messages]]
102+
role = "user"
103+
content = "Check {{resource_type}} named {{resource_name}}"
141104
```
142105

143-
**Step 2: Embed the YAML file** in your Go code:
106+
### Overriding Built-in Prompts
144107

145-
```go
146-
package yourname
108+
Replace built-in prompts by using the same name:
147109

148-
import (
149-
_ "embed"
150-
"github.com/containers/kubernetes-mcp-server/pkg/api"
151-
)
110+
```toml
111+
[[prompts]]
112+
name = "troubleshoot-pod" # This overrides the built-in version
113+
description = "Our custom pod troubleshooting process"
152114

153-
//go:embed prompts.yaml
154-
var promptsYAML []byte
115+
[[prompts.arguments]]
116+
name = "pod_name"
117+
required = true
155118

156-
func initPrompts() []api.ServerPrompt {
157-
loader := api.NewPromptLoader()
158-
if err := loader.LoadFromBytes(promptsYAML); err != nil {
159-
return nil
160-
}
161-
return loader.GetServerPrompts()
162-
}
163-
```
164-
165-
**Step 3: Implement `GetPrompts()`** in your toolset:
119+
[[prompts.messages]]
120+
role = "user"
121+
content = "Pod {{pod_name}} needs help"
166122

167-
```go
168-
func (t *Toolset) GetPrompts(_ internalk8s.Openshift) []api.ServerPrompt {
169-
return initPrompts()
170-
}
123+
[[prompts.messages]]
124+
role = "assistant"
125+
content = "Using our custom troubleshooting workflow..."
171126
```
172127

173-
### Argument Substitution
128+
### Disabling Built-in Prompts
129+
130+
Use only your custom prompts:
174131

175-
Prompts support template variable substitution using `{{argument_name}}` syntax:
132+
```toml
133+
# Disable all built-in prompts
134+
disable_embedded_prompts = true
176135

177-
- `{{argument_name}}` - Replaced with the argument value
178-
- Simple string replacement is performed automatically by the prompt loader
136+
# Then define your own
137+
[[prompts]]
138+
name = "my-prompt"
139+
# ...
140+
```
179141

180-
### Advanced: Custom Prompt Handlers
142+
## For Toolset Developers
181143

182-
For more complex prompt logic, you can create custom handlers instead of using YAML:
144+
If you're creating a custom toolset, define prompts directly in Go code (similar to how tools are defined):
183145

184146
```go
185-
func customPromptHandler(params api.PromptHandlerParams) (*api.PromptCallResult, error) {
186-
args := params.GetArguments()
147+
// pkg/toolsets/yourtoolset/prompts.go
148+
package yourtoolset
187149

188-
// Custom logic here
189-
namespace := args["namespace"]
190-
podName := args["pod_name"]
150+
import (
151+
"fmt"
152+
"github.com/containers/kubernetes-mcp-server/pkg/api"
153+
)
191154

192-
// Build dynamic messages
193-
messages := []api.PromptMessage{
155+
func (t *Toolset) GetPrompts(_ internalk8s.Openshift) []api.ServerPrompt {
156+
return []api.ServerPrompt{
194157
{
195-
Role: "user",
196-
Content: api.PromptContent{
197-
Type: "text",
198-
Text: fmt.Sprintf("Check pod %s in namespace %s", podName, namespace),
158+
Prompt: api.Prompt{
159+
Name: "your-prompt",
160+
Description: "What it does",
161+
Arguments: []api.PromptArgument{
162+
{
163+
Name: "arg1",
164+
Description: "First argument",
165+
Required: true,
166+
},
167+
},
199168
},
200-
},
201-
{
202-
Role: "assistant",
203-
Content: api.PromptContent{
204-
Type: "text",
205-
Text: "I'll check the pod status...",
169+
Handler: func(params api.PromptHandlerParams) (*api.PromptCallResult, error) {
170+
args := params.GetArguments()
171+
arg1, _ := args["arg1"]
172+
173+
messages := []api.PromptMessage{
174+
{
175+
Role: "user",
176+
Content: api.PromptContent{
177+
Type: "text",
178+
Text: fmt.Sprintf("Message with %s", arg1),
179+
},
180+
},
181+
{
182+
Role: "assistant",
183+
Content: api.PromptContent{
184+
Type: "text",
185+
Text: "Response template",
186+
},
187+
},
188+
}
189+
190+
return api.NewPromptCallResult("What it does", messages, nil), nil
206191
},
207192
},
208193
}
209-
210-
return api.NewPromptCallResult("Custom prompt", messages, nil), nil
211194
}
212195
```
213196

214-
## Using Prompts with AI Assistants
215-
216-
When using the Kubernetes MCP Server with an AI assistant (like Claude):
217-
218-
1. **List available prompts**: The assistant can discover available prompts via the MCP protocol
219-
2. **Invoke a prompt**: The assistant can call a prompt with specific arguments
220-
3. **Follow the workflow**: The prompt provides structured guidance for the task
221-
222-
### Example Interaction
223-
224-
```
225-
User: "My pod is crashing, can you help?"

0 commit comments

Comments
 (0)