Skip to main content
Glama
wonderwhy-er

Claude Desktop Commander MCP

set_config_value

Update specific configuration values in Claude Desktop Commander MCP to customize settings like allowed directories, command restrictions, file limits, and telemetry preferences.

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
NameRequiredDescriptionDefault
keyYes
valueNo

Implementation Reference

  • The core handler function implementing the set_config_value tool. Parses arguments using the schema, handles JSON parsing for complex values, special array handling for certain keys, updates config via configManager, and returns success/error responses with updated config.
    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
        };
      }
  • Zod schema defining the input parameters for the set_config_value tool: 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:206-232 (registration)
    Tool registration in the list_tools handler. Defines the tool name, detailed description with warnings and config keys, input schema converted to JSON schema, 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,
        },
    },
  • Dispatch handler in call_tool request that routes set_config_value calls to the setConfigValue function, with error capturing.
    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,
            };
        }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/wonderwhy-er/DesktopCommanderMCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server