-
Notifications
You must be signed in to change notification settings - Fork 178
Open
Labels
bugSomething isn't workingSomething isn't working
Milestone
Description
Summary
The pods_log tool panics if the previous argument is passed as a non-boolean JSON type (for example, string "false"). In such cases, the interface conversion previous.(bool) fails and causes a runtime panic.
Steps to reproduce
- Deploy kubernetes-mcp-server with LlamaStack or an agent sending a
pods_logtool call wherepreviousis a string (e.g."previous": "false"). - Observe the server log panics with something like:
panic: interface conversion: interface {} is string, not bool
(From a LlamaStack call to pods_log, where previous is erroneously set to string)
INFO 2025-09-26 03:55:14,704 llama_stack.providers.inline.agents.meta_reference.agent_instance:890 agents: executing tool call: pods_log with
args: {'container': '', 'name': 'failing-test-pod', 'namespace': 'aiops-test', 'previous': 'false', 'tail': '100'}
03:55:14.705 [START] tool_execution
ERROR 2025-09-26 03:55:15,608 mcp.client.sse:109 uncategorized: Error in sse_reader
Resulting panic in kubernetes-mcp-server
I0926 03:55:15.596574 1 mcp.go:215] "mcp tool call: pods_log(map[container: name:failing-test-pod namespace:aiops-test previous:false session_id:6e911834-2541-4db1-beff-91c78efa3134 tail:100])"
...
panic: interface conversion: interface {} is string, not bool
goroutine 150 [running]:
github.com/containers/kubernetes-mcp-server/pkg/toolsets/core.podsLog({{0x2a67728, 0xc000b089f0}, 0xc000596088, {0x2a3f440, 0xc0003c0780}, {0x2a52240, 0x3f2ed40}})
/Users/runner/work/kubernetes-mcp-server/kubernetes-mcp-server/pkg/toolsets/core/pods.go:403 +0x608
github.com/containers/kubernetes-mcp-server/pkg/mcp.ServerToolToM3LabsServerTool.func1({0x2a67728, 0xc000b089f0}, {{{0xc0008e86a0, 0xa}, {0x0}}, 0xc0007ffaa0, {{0xc0008e86b0, 0x8}, {0x2203960, 0xc000b08a80}, ...}})
/Users/runner/work/kubernetes-mcp-server/kubernetes-mcp-server/pkg/mcp/m3labs.go:46 +0x127
github.com/containers/kubernetes-mcp-server/pkg/mcp.toolCallLoggingMiddleware.func1({0x2a67728, 0xc000b089f0}, {{{0xc0008e86a0, 0xa}, {0x0}}, 0xc0007ffaa0, {{0xc0008e86b0, 0x8}, {0x2203960, 0xc000b08a80}, ...}})
/Users/runner/work/kubernetes-mcp-server/kubernetes-mcp-server/pkg/mcp/mcp.go:222 +0x35f
github.com/mark3labs/mcp-go/server.(*MCPServer).handleToolCall(0xc00022e960, {0x2a67728, 0xc000b089f0}, {0x204a3a0, 0xc0008e8680}, {{{0xc0008e86a0, 0xa}, {0x0}}, 0xc0007ffaa0, {{0xc0008e86b0, ...}, ...}})
/Users/runner/go/pkg/mod/github.com/mark3labs/mcp-go@v0.40.0/server/server.go:1187 +0x3e6
github.com/mark3labs/mcp-go/server.(*MCPServer).HandleMessage(0xc00022e960, {0x2a67760?, 0xc00036cd70?}, {0xc0009480f0, 0xef, 0xf0})
/Users/runner/go/pkg/mod/github.com/mark3labs/mcp-go@v0.40.0/server/request_handler.go:324 +0xc28
github.com/mark3labs/mcp-go/server.(*SSEServer).handleMessage.func1({0x2a67760?, 0xc00036cd70?})
/Users/runner/go/pkg/mod/github.com/mark3labs/mcp-go@v0.40.0/server/sse.go:528 +0x89
created by github.com/mark3labs/mcp-go/server.(*SSEServer).handleMessage in goroutine 148
/Users/runner/go/pkg/mod/github.com/mark3labs/mcp-go@v0.40.0/server/sse.go:524 +0x485
Root cause
In pods.go (or equivalent), the handler code does something like:
previous := params.GetArguments()["previous"]
if previous != nil {
previousBool = previous.(bool)
}Proposed fix
Change the handling to safely coerce/convert previous from known types to bool, defaulting to false otherwise in the podLogs function - I've tested locally and it mitigates the issue:
previous := params.GetArguments()["previous"]
var previousBool bool
if previous != nil {
// Convert to bool - safely handle both bool, string, float64, int types
switch v := previous.(type) {
case bool:
previousBool = v
case string:
previousBool = v == "true" || v == "True" || v == "TRUE" || v == "1"
case float64:
previousBool = v != 0
case int:
previousBool = v != 0
default:
// Default to false for unknown types
previousBool = false
}
}
Is this acceptable? I’ll prepare a PR once the issue is accepted.
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working