Skip to content

Commit 9c40b47

Browse files
authored
Fix set config schema to work in gemini and few other tools (#236)
1 parent e0c91f5 commit 9c40b47

2 files changed

Lines changed: 15 additions & 7 deletions

File tree

‎src/tools/config.ts‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,18 +86,20 @@ export async function setConfigValue(args: unknown) {
8686
if ((parsed.data.key === 'allowedDirectories' || parsed.data.key === 'blockedCommands') &&
8787
!Array.isArray(valueToStore)) {
8888
if (typeof valueToStore === 'string') {
89+
const originalString = valueToStore;
8990
try {
90-
valueToStore = JSON.parse(valueToStore);
91+
const parsedValue = JSON.parse(originalString);
92+
valueToStore = parsedValue;
9193
} catch (parseError) {
9294
console.error(`Failed to parse string as array for ${parsed.data.key}: ${parseError}`);
9395
// If parsing failed and it's a single value, convert to an array with one item
94-
if (!valueToStore.includes('[')) {
95-
valueToStore = [valueToStore];
96+
if (!originalString.includes('[')) {
97+
valueToStore = [originalString];
9698
}
9799
}
98-
} else {
99-
// If not a string or array, convert to an array with one item
100-
valueToStore = [valueToStore];
100+
} else if (valueToStore !== null) {
101+
// If not a string or array (and not null), convert to an array with one item
102+
valueToStore = [String(valueToStore)];
101103
}
102104

103105
// Ensure the value is an array after all our conversions

‎src/tools/schemas.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@ export const GetConfigArgsSchema = z.object({});
55

66
export const SetConfigValueArgsSchema = z.object({
77
key: z.string(),
8-
value: z.any(),
8+
value: z.union([
9+
z.string(),
10+
z.number(),
11+
z.boolean(),
12+
z.array(z.string()),
13+
z.null(),
14+
]),
915
});
1016

1117
// Empty schemas

0 commit comments

Comments
 (0)