fix: Handle empty string item_type parameter in list tool

Fixes issue where item_type: '' was not properly defaulting to the correct operation.
Empty strings and whitespace-only strings now fall back to the proper default logic:
- If app is provided: defaults to 'application_windows'
- If no app: defaults to 'running_applications'

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Peter Steinberger 2025-06-08 08:33:44 +01:00
parent c958f91bf0
commit 34dac65d2a
2 changed files with 38 additions and 2 deletions

View file

@ -192,7 +192,7 @@ export async function listToolHandler(
}
// Process the response based on item type
const effective_item_type = input.item_type || (input.app ? "application_windows" : "running_applications");
const effective_item_type = (input.item_type && input.item_type.trim() !== "") ? input.item_type : (input.app ? "application_windows" : "running_applications");
if (effective_item_type === "running_applications") {
return handleApplicationsList(
@ -387,7 +387,7 @@ async function handleServerStatus(
export function buildSwiftCliArgs(input: ListToolInput): string[] {
const args = ["list"];
const itemType = input.item_type || (input.app ? "application_windows" : "running_applications");
const itemType = (input.item_type && input.item_type.trim() !== "") ? input.item_type : (input.app ? "application_windows" : "running_applications");
if (itemType === "running_applications") {
args.push("apps");

View file

@ -983,4 +983,40 @@ describe("List Tool", () => {
expect(() => listToolSchema.parse(input)).toThrow();
});
});
describe("buildSwiftCliArgs empty string handling", () => {
it("should treat empty string item_type as undefined and default correctly", () => {
// Test case where item_type is empty string (should default to running_applications)
const inputWithEmptyString: ListToolInput = {
item_type: "",
include_window_details: [],
};
const args = buildSwiftCliArgs(inputWithEmptyString);
expect(args).toEqual(["list", "apps"]);
});
it("should treat empty string item_type with app as application_windows", () => {
// Test case where item_type is empty string but app is provided
const inputWithEmptyStringAndApp: ListToolInput = {
item_type: "",
app: "Safari",
include_window_details: [],
};
const args = buildSwiftCliArgs(inputWithEmptyStringAndApp);
expect(args).toEqual(["list", "windows", "--app", "Safari"]);
});
it("should treat whitespace-only item_type as undefined", () => {
// Test case where item_type is just whitespace
const inputWithWhitespace: ListToolInput = {
item_type: " ",
include_window_details: [],
};
const args = buildSwiftCliArgs(inputWithWhitespace);
expect(args).toEqual(["list", "apps"]);
});
});
});