set_config_value
Update Desktop Commander MCP server configuration settings like blocked commands, default shell, directory access, and file operation limits to customize security and functionality.
Instructions
Set a specific configuration value by key.
WARNING: Should be used in a separate chat from file operations and
command execution to prevent security issues.
Config keys include:
- blockedCommands (array)
- defaultShell (string)
- allowedDirectories (array of paths)
- fileReadLineLimit (number, max lines for read_file)
- fileWriteLineLimit (number, max lines per write_file call)
- telemetryEnabled (boolean)
IMPORTANT: Setting allowedDirectories to an empty array ([]) allows full access
to the entire file system, regardless of the operating system.
This command can be referenced as "DC: ..." or "use Desktop Commander to ..." in your instructions.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| key | Yes | ||
| value | Yes |
Implementation Reference
- src/tools/config.ts:61-150 (handler)The handler function for the set_config_value tool. Parses input arguments using the schema, handles special JSON parsing and array conversion for specific config keys like allowedDirectories and blockedCommands, updates the config using configManager.setValue, retrieves and returns the updated configuration, with comprehensive error handling.export async function setConfigValue(args: unknown) { console.error(`setConfigValue called with args: ${JSON.stringify(args)}`); try { const parsed = SetConfigValueArgsSchema.safeParse(args); if (!parsed.success) { console.error(`Invalid arguments for set_config_value: ${parsed.error}`); return { content: [{ type: "text", text: `Invalid arguments: ${parsed.error}` }], isError: true }; } try { // Parse string values that should be arrays or objects let valueToStore = parsed.data.value; // If the value is a string that looks like an array or object, try to parse it if (typeof valueToStore === 'string' && (valueToStore.startsWith('[') || valueToStore.startsWith('{'))) { try { valueToStore = JSON.parse(valueToStore); console.error(`Parsed string value to object/array: ${JSON.stringify(valueToStore)}`); } catch (parseError) { console.error(`Failed to parse string as JSON, using as-is: ${parseError}`); } } // Special handling for known array configuration keys if ((parsed.data.key === 'allowedDirectories' || parsed.data.key === 'blockedCommands') && !Array.isArray(valueToStore)) { if (typeof valueToStore === 'string') { const originalString = valueToStore; try { const parsedValue = JSON.parse(originalString); valueToStore = parsedValue; } catch (parseError) { console.error(`Failed to parse string as array for ${parsed.data.key}: ${parseError}`); // If parsing failed and it's a single value, convert to an array with one item if (!originalString.includes('[')) { valueToStore = [originalString]; } } } else if (valueToStore !== null) { // If not a string or array (and not null), convert to an array with one item valueToStore = [String(valueToStore)]; } // Ensure the value is an array after all our conversions if (!Array.isArray(valueToStore)) { console.error(`Value for ${parsed.data.key} is still not an array, converting to array`); valueToStore = [String(valueToStore)]; } } await configManager.setValue(parsed.data.key, valueToStore); // Get the updated configuration to show the user const updatedConfig = await configManager.getConfig(); console.error(`setConfigValue: Successfully set ${parsed.data.key} to ${JSON.stringify(valueToStore)}`); return { content: [{ type: "text", text: `Successfully set ${parsed.data.key} to ${JSON.stringify(valueToStore, null, 2)}\n\nUpdated configuration:\n${JSON.stringify(updatedConfig, null, 2)}` }], }; } catch (saveError: any) { console.error(`Error saving config: ${saveError.message}`); // Continue with in-memory change but report error return { content: [{ type: "text", text: `Value changed in memory but couldn't be saved to disk: ${saveError.message}` }], isError: true }; } } catch (error) { console.error(`Error in setConfigValue: ${error instanceof Error ? error.message : String(error)}`); console.error(error instanceof Error && error.stack ? error.stack : 'No stack trace available'); return { content: [{ type: "text", text: `Error setting value: ${error instanceof Error ? error.message : String(error)}` }], isError: true }; } }
- src/tools/schemas.ts:6-15 (schema)Zod input schema validation for set_config_value tool arguments: requires 'key' (string) and 'value' (string | number | boolean | string[] | null).export const SetConfigValueArgsSchema = z.object({ key: z.string(), value: z.union([ z.string(), z.number(), z.boolean(), z.array(z.string()), z.null(), ]), });
- src/server.ts:212-238 (registration)Static tool definition in the list_tools handler: specifies name 'set_config_value', detailed description warning about security, input schema from SetConfigValueArgsSchema, and annotations indicating it's destructive.name: "set_config_value", description: ` Set a specific configuration value by key. WARNING: Should be used in a separate chat from file operations and command execution to prevent security issues. Config keys include: - blockedCommands (array) - defaultShell (string) - allowedDirectories (array of paths) - fileReadLineLimit (number, max lines for read_file) - fileWriteLineLimit (number, max lines per write_file call) - telemetryEnabled (boolean) IMPORTANT: Setting allowedDirectories to an empty array ([]) allows full access to the entire file system, regardless of the operating system. ${CMD_PREFIX_DESCRIPTION}`, inputSchema: zodToJsonSchema(SetConfigValueArgsSchema), annotations: { title: "Set Configuration Value", readOnlyHint: false, destructiveHint: true, openWorldHint: false, }, },
- src/server.ts:1147-1156 (registration)Dispatch logic in the call_tool request handler: calls the setConfigValue handler function with args, with error catching and fallback error response.case "set_config_value": try { result = await setConfigValue(args); } catch (error) { capture('server_request_error', { message: `Error in set_config_value handler: ${error}` }); result = { content: [{ type: "text", text: `Error: Failed to set configuration value` }], isError: true, }; }