-
Notifications
You must be signed in to change notification settings - Fork 706
Create BATS tests for limactl-mcp #4060
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
One thing I found while writing the test was that $ echo '{"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"run_shell_command","arguments":{"command":["cat","os-release"],"directory":"/etc"}}}' >&"${MCP[1]}"
$ read -t 1 -r line <&"${MCP[0]}"; jq . <<<"$line"
{
"jsonrpc": "2.0",
"id": 3,
"result": {
"content": [
{
"type": "text",
"text": "{\"stdout\":\"PRETTY_NAME=\\\"Ubuntu 25.04\\\"\\nNAME=\\\"Ubuntu\\\"\\nVERSION_ID=\\\"25.04\\\"\\nVERSION=\\\"25.04 (Plucky Puffin)\\\"\\nVERSION_CODENAME=plucky\\nID=ubuntu\\nID_LIKE=debian\\nHOME_URL=\\\"https://www.ubuntu.com/\\\"\\nSUPPORT_URL=\\\"https://help.ubuntu.com/\\\"\\nBUG_REPORT_URL=\\\"https://bugs.launchpad.net/ubuntu/\\\"\\nPRIVACY_POLICY_URL=\\\"https://www.ubuntu.com/legal/terms-and-policies/privacy-policy\\\"\\nUBUNTU_CODENAME=plucky\\nLOGO=ubuntu-logo\\n\",\"stderr\":\"\",\"exit_code\":0}"
}
]
}
} So you need to extract Is there a reason this can't be a normal nested object? |
f56729d
to
1f10d05
Compare
Beyond the encoded JSON thing, I don't understand the schema of the output: Why is And what does So I would expect the output of {
"jsonrpc": "2.0",
"id": 3,
"result": {
"stdout": "...",
"stderr": "",
"exit_code": 0
}
} |
576a149
to
5118e73
Compare
The If you make the |
MCP doesn't allow that schema: https://pkg.go.dev/github.com/modelcontextprotocol/[email protected]/mcp#CallToolResult
https://modelcontextprotocol.io/specification/2025-06-18/server/tools#structured-content also says "For backwards compatibility, a tool that returns structured content SHOULD also return the serialized JSON in a TextContent block." I guess we can revisit this later.
The current design is to follow Gemini's design |
19e7ded
to
3c04a67
Compare
I have more questions: The
What is the tool's root directory? How is the LLM to know what this means? If this command accepts relative patterns, why do the other tools insist on an absolute path? Why can't you pass a filename returned by The description for the
I think the negative explanation "this is not like something else" is not helpful. Also most LLMs will not even know what the Gemini Describe what the tool does, and what parameters it expects in a prescriptive manner. The It returns an error |
a6c02cb
to
0387659
Compare
Opened an issue about StructuredContent for tracking purpose: Please consider opening separate issues for other topics too.
The prompt was just copied from https://github.com/google-gemini/gemini-cli/blob/v0.5.5/docs/tools/file-system.md#4-glob-findfiles
The prompt was just copied from Gemini, but
Bug.
Maybe we should provide an additional MCP tool, if shelling out
Gemini may know?
Bug. |
I must have been confused about this; I can no longer reproduce the issue and get full path names now. I probably mixed it up with the results of |
f5e8cbb
to
0ebb19a
Compare
Needs rebase after merging: |
c4e9a81
to
fefc8fe
Compare
Signed-off-by: Jan Dubois <[email protected]>
limactl delete --force "$NAME" || : | ||
# Make sure that the host agent doesn't inherit file handles 3 or 4. | ||
# Otherwise bats will not finish until the host agent exits. | ||
limactl start --yes --name "$NAME" template://default 3>&- 4>&- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not necessarily needs to be covered in this PR, but we should consider reusing an instance across multiple bats files
lima/hack/bats/tests/preserve-env.bats
Line 20 in 8b1f07d
limactl start --yes --name "$NAME" template:default 3>&- 4>&- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, absolutely.
Just for working on the tests you can already do this:
❯ export LIMA_BATS_REUSE_INSTANCE=1
❯ ./hack/bats/lib/bats-core/bin/bats -T ./hack/bats/tests/mcp.bats -f search_file
mcp.bats
✓ search_file_content finds text inside files [507]
✓ search_file_content can find unicode characters above U+FFFF [510]
✓ search_file_content returns an empty string if it cannot find the pattern [502]
3 tests, 0 failures in 2 seconds
❯ ./hack/bats/lib/bats-core/bin/bats -T ./hack/bats/tests/mcp.bats -f search_file
mcp.bats
✓ search_file_content finds text inside files [516]
✓ search_file_content can find unicode characters above U+FFFF [512]
✓ search_file_content returns an empty string if it cannot find the pattern [501]
3 tests, 0 failures in 3 seconds
So you can iterate quickly without restarting the instance every time.
And both mcp.bats
and preserve-env.bats
are sharing the same bats
instance, so it works for both.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, the code clone across the bats files should be moved to helpers
I don't know if #4124 should be considered a bug or not. Right now this test assumes the current scheme is the way it is supposed to be. |
tools_call glob '{"pattern":"nothing.to.see"}' | ||
|
||
run_yq '.structuredContent.matches[]' <<<"$output" | ||
assert_output_lines_count 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may need to be changed to refute_output
because I think $lines
is undefined and not an empty array when there is no output. Can be fixed when the test is no longer skipped.
I had an idea how to test
limactl-mcp
with BATS, so I wrote this PoC. I think it works well, but must obviously be fleshed out some more.This PR depends on #3744 and assumes it has been merged already.