From a5a10f3964f2f01beb007af757c40011ab9d9742 Mon Sep 17 00:00:00 2001 From: Nicolas Karolak Date: Sat, 20 Sep 2025 07:41:45 +0200 Subject: [PATCH] mcp-server-kubernetes: better testing I think that the current tests actually do not work properly. A MCP server process is a daemon that terminate on SIGTERM so i think it currently fails but with somehow the searched strings in the output. The cause of the failure is likely the `notifications/initialized` client anwser that is missing meanwhile it is required by MCP version `2025-03-26`. I have catched this error while trying to write other MCP formulae (PRs coming soon). Proposed fix: - send the missing message - send the `TERM` signal (otherwise process keep running) - parse the output to be sure to have right answer --- Formula/m/mcp-server-kubernetes.rb | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/Formula/m/mcp-server-kubernetes.rb b/Formula/m/mcp-server-kubernetes.rb index 1e6079ad3be6d..7bd2ca7394d9c 100644 --- a/Formula/m/mcp-server-kubernetes.rb +++ b/Formula/m/mcp-server-kubernetes.rb @@ -30,12 +30,29 @@ def install test do json = <<~JSON - {"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-03-26"}} + {"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-03-26","capabilities":{},"clientInfo":{"name":"brew-test","version":"1.0"}}} + {"jsonrpc":"2.0","method":"notifications/initialized","params":{}} {"jsonrpc":"2.0","id":2,"method":"tools/list"} JSON - output = pipe_output(bin/"mcp-server-kubernetes", json, 0) - assert_match "kubectl_get", output - assert_match "kubectl_describe", output - assert_match "kubectl_logs", output + + Open3.popen3(bin/"mcp-server-kubernetes") do |stdin, stdout, _, wait_thread| + begin + stdin.write json + stdin.close + sleep 1 + responses = stdout.readlines + ensure + if wait_thread.alive? + begin + Process.kill("TERM", wait_thread.pid) + rescue Errno::ESRCH + # Process already terminated + end + end + end + + assert responses.length >= 2, "Expected at least 2 responses, got #{responses.length}" + assert JSON.parse(responses[1]).dig("result", "tools")&.any? { |tool| tool["name"] == "kubectl_get" } + end end end