Skip to content

Commit 9bb0937

Browse files
committed
Ignore MCP notifications
With the [email protected] we now get a notification before receiving the response to our request: >>> {"jsonrpc":"2.0","id":2,"method":"tools/list"} <<< {"jsonrpc":"2.0","method":"notifications/tools/list_changed","params":{}} Notifications have a `method` field, but no `id`. We need to ignore them until we receive an actual response object. This commit also fixes a potential problem deleting the /tmp/tmp directory inside the VM when running the tests multiple times using the same Lima instance (LIMA_BATS_REUSE_INSTANCE=1). Signed-off-by: Jan Dubois <[email protected]>
1 parent 02161c4 commit 9bb0937

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

hack/bats/tests/mcp.bats

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,15 @@ mcp() {
6767

6868
# read response from MCP server stdout with 5s timeout
6969
local json
70-
read -t 5 -r json <&"${MCP[0]}"
70+
while true; do
71+
if ! read -t 5 -r json <&"${MCP[0]}"; then
72+
break
73+
fi
74+
# If it has no "method" field, it's a response, not a notification
75+
if ! jq -e 'has("method")' <<<"$json" >/dev/null 2>&1; then
76+
break
77+
fi
78+
done
7179

7280
# verify that the response matches the request; also validates the output is valid JSON
7381
run_yq .id <<<"$json"
@@ -253,6 +261,8 @@ tools_call() {
253261
}
254262

255263
@test 'write_file creates the directory if it does not yet exist' {
264+
# Make sure /tmp/tmp is deletable even if we run the tests multiple times against the same Lima instance
265+
limactl shell "$NAME" chmod -R 777 /tmp/tmp
256266
limactl shell "$NAME" rm -rf /tmp/tmp
257267
tools_call write_file '{"path":"/tmp/tmp/tmp","content":"tmp"}'
258268
json=$output

0 commit comments

Comments
 (0)