Skip to main content
Glama

manage_config

Configure browser baselines, polyfills, and feature overrides to customize compatibility checking for CSS/JS features.

Instructions

Configure browser baselines, polyfills, and feature overrides for more accurate compatibility checking

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
actionNoConfiguration action to performview
baselineNoSet default baseline browser target (e.g., 'chrome-37', 'chrome-57')
polyfillNoFeature name to add/remove from polyfills list
featureNoFeature name for override setting
overrideNoForce feature support status
targetNameNoCustom target name (e.g., 'chrome-57')
browserNoBrowser name for custom target
versionNoBrowser version for custom target

Implementation Reference

  • The handleManageConfig function that executes the manage_config tool logic, dispatching to different configuration actions using the ConfigManager class.
    export async function handleManageConfig(args) {
      const { action = 'view', baseline, polyfill, feature, override, targetName, browser, version } = args;
    
      try {
        switch (action) {
          case 'view':
            const config = await configManager.loadConfig();
            const targets = await configManager.getBrowserTargets();
            return {
              action: 'view',
              currentConfig: {
                defaultBaseline: config.defaultBaseline,
                polyfills: config.polyfills,
                overrides: config.overrides,
                customTargets: config.customTargets
              },
              availableTargets: Object.keys(targets),
              instructions: {
                setBaseline: 'Use action="set_baseline" with baseline="chrome-57"',
                addPolyfill: 'Use action="add_polyfill" with polyfill="css-grid"',
                removePolyfill: 'Use action="remove_polyfill" with polyfill="css-grid"',
                setOverride: 'Use action="set_override" with feature="css-variables" and override="supported"',
                addTarget: 'Use action="add_target" with targetName="chrome-57", browser="chrome", version="57"',
                createTemplate: 'Use action="create_template" to create .caniuse-config.json file'
              }
            };
    
          case 'set_baseline':
            if (!baseline) {
              throw new Error('baseline parameter required for set_baseline action');
            }
            await configManager.updateConfig({ defaultBaseline: baseline });
            return {
              action: 'set_baseline',
              success: true,
              message: `Default baseline set to ${baseline}`,
              newBaseline: baseline
            };
    
          case 'add_polyfill':
            if (!polyfill) {
              throw new Error('polyfill parameter required for add_polyfill action');
            }
            await configManager.addPolyfill(polyfill);
            const updatedConfig = await configManager.loadConfig();
            return {
              action: 'add_polyfill',
              success: true,
              message: `Added ${polyfill} to polyfills list`,
              feature: polyfill,
              currentPolyfills: updatedConfig.polyfills
            };
    
          case 'remove_polyfill':
            if (!polyfill) {
              throw new Error('polyfill parameter required for remove_polyfill action');
            }
            await configManager.removePolyfill(polyfill);
            const configAfterRemoval = await configManager.loadConfig();
            return {
              action: 'remove_polyfill',
              success: true,
              message: `Removed ${polyfill} from polyfills list`,
              feature: polyfill,
              currentPolyfills: configAfterRemoval.polyfills
            };
    
          case 'set_override':
            if (!feature || !override) {
              throw new Error('feature and override parameters required for set_override action');
            }
            await configManager.setFeatureOverride(feature, override);
            return {
              action: 'set_override',
              success: true,
              message: `Set ${feature} override to ${override}`,
              feature,
              override
            };
    
          case 'add_target':
            if (!targetName || !browser || !version) {
              throw new Error('targetName, browser, and version parameters required for add_target action');
            }
            const currentConfig = await configManager.loadConfig();
            const newCustomTargets = {
              ...currentConfig.customTargets,
              [targetName]: { browser, version }
            };
            await configManager.updateConfig({ customTargets: newCustomTargets });
            return {
              action: 'add_target',
              success: true,
              message: `Added custom target ${targetName} (${browser} ${version})`,
              targetName,
              browserConfig: { browser, version }
            };
    
          case 'create_template':
            const templatePath = await ConfigManager.createConfigTemplate('.');
            return {
              action: 'create_template',
              success: true,
              message: 'Created .caniuse-config.json template file',
              configFile: templatePath,
              instructions: [
                'Edit the created .caniuse-config.json file to customize your settings',
                'Run manage_config with action="view" to see current configuration',
                'The configuration will be automatically loaded for all compatibility checks'
              ]
            };
    
          case 'reset':
            // Reset to default configuration
            await configManager.updateConfig({
              defaultBaseline: 'chrome-37',
              customTargets: {},
              polyfills: [],
              overrides: {}
            });
            return {
              action: 'reset',
              success: true,
              message: 'Configuration reset to defaults',
              newConfig: {
                defaultBaseline: 'chrome-37',
                customTargets: {},
                polyfills: [],
                overrides: {}
              }
            };
    
          default:
            throw new Error(`Unknown config action: ${action}`);
        }
      } catch (error) {
        return {
          action,
          error: true,
          message: error.message,
          suggestion: 'Check the action parameter and required fields. Use action="view" to see available options.'
        };
      }
    }
  • Zod input schema defining parameters for the manage_config tool, including action types and optional fields.
    inputSchema: {
      action: z.enum(["view", "set_baseline", "add_polyfill", "remove_polyfill", "set_override", "add_target", "create_template", "reset"]).optional().default("view").describe("Configuration action to perform"),
      baseline: z.string().optional().describe("Set default baseline browser target (e.g., 'chrome-37', 'chrome-57')"),
      polyfill: z.string().optional().describe("Feature name to add/remove from polyfills list"),
      feature: z.string().optional().describe("Feature name for override setting"),
      override: z.enum(["supported", "unsupported"]).optional().describe("Force feature support status"),
      targetName: z.string().optional().describe("Custom target name (e.g., 'chrome-57')"),
      browser: z.string().optional().describe("Browser name for custom target"),
      version: z.string().optional().describe("Browser version for custom target")
    }
  • index.js:166-205 (registration)
    Registration of the manage_config tool on the MCP server, including schema and wrapper handler that calls the main handleManageConfig.
    server.registerTool(
      "manage_config",
      {
        title: "Config Manager",
        description: "Configure browser baselines, polyfills, and feature overrides for more accurate compatibility checking",
        inputSchema: {
          action: z.enum(["view", "set_baseline", "add_polyfill", "remove_polyfill", "set_override", "add_target", "create_template", "reset"]).optional().default("view").describe("Configuration action to perform"),
          baseline: z.string().optional().describe("Set default baseline browser target (e.g., 'chrome-37', 'chrome-57')"),
          polyfill: z.string().optional().describe("Feature name to add/remove from polyfills list"),
          feature: z.string().optional().describe("Feature name for override setting"),
          override: z.enum(["supported", "unsupported"]).optional().describe("Force feature support status"),
          targetName: z.string().optional().describe("Custom target name (e.g., 'chrome-57')"),
          browser: z.string().optional().describe("Browser name for custom target"),
          version: z.string().optional().describe("Browser version for custom target")
        }
      },
      async (args) => {
        try {
          const result = await handleManageConfig(args);
          return {
            content: [{
              type: "text",
              text: JSON.stringify(result, null, 2)
            }]
          };
        } catch (error) {
          return {
            content: [{
              type: "text",
              text: JSON.stringify({
                error: true,
                message: error.message,
                suggestion: "Check the action parameter and required fields. Use action='view' to see available options."
              }, null, 2)
            }],
            isError: true
          };
        }
      }
    );
  • ConfigManager class providing persistent configuration storage, loading, updating, and management utilities used by the manage_config handler.
    export class ConfigManager {
      constructor(projectPath = '.') {
        this.projectPath = projectPath;
        this.config = null;
        this.defaultConfig = {
          defaultBaseline: 'chrome-37',
          customTargets: {},
          polyfills: [],
          overrides: {},
          browserFallbacks: {
            chrome: ['37'], // fallback versions if specific version not found
            firefox: ['78'],
            safari: ['12'],
            ie: ['11'],
            edge: ['18']
          }
        };
      }
    
      async loadConfig() {
        if (this.config) return this.config;
    
        // Try to load from file first
        const configPath = path.join(this.projectPath, '.caniuse-config.json');
        let fileConfig = {};
        
        try {
          if (fs.existsSync(configPath)) {
            const configContent = await fs.promises.readFile(configPath, 'utf8');
            fileConfig = JSON.parse(configContent);
          }
        } catch (error) {
          console.warn(`Warning: Could not load config from ${configPath}: ${error.message}`);
        }
    
        // Merge with environment variables
        const envConfig = this._loadFromEnvironment();
    
        // Merge all configurations: default < file < environment
        this.config = {
          ...this.defaultConfig,
          ...fileConfig,
          ...envConfig,
          // Merge nested objects properly
          customTargets: {
            ...this.defaultConfig.customTargets,
            ...fileConfig.customTargets,
            ...envConfig.customTargets
          },
          polyfills: [
            ...this.defaultConfig.polyfills,
            ...(fileConfig.polyfills || []),
            ...(envConfig.polyfills || [])
          ],
          overrides: {
            ...this.defaultConfig.overrides,
            ...fileConfig.overrides,
            ...envConfig.overrides
          },
          browserFallbacks: {
            ...this.defaultConfig.browserFallbacks,
            ...fileConfig.browserFallbacks,
            ...envConfig.browserFallbacks
          }
        };
    
        return this.config;
      }
    
      _loadFromEnvironment() {
        const envConfig = {};
        
        if (process.env.CANIUSE_DEFAULT_BASELINE) {
          envConfig.defaultBaseline = process.env.CANIUSE_DEFAULT_BASELINE;
        }
        
        if (process.env.CANIUSE_POLYFILLS) {
          try {
            envConfig.polyfills = JSON.parse(process.env.CANIUSE_POLYFILLS);
          } catch (error) {
            envConfig.polyfills = process.env.CANIUSE_POLYFILLS.split(',').map(p => p.trim());
          }
        }
        
        if (process.env.CANIUSE_OVERRIDES) {
          try {
            envConfig.overrides = JSON.parse(process.env.CANIUSE_OVERRIDES);
          } catch (error) {
            console.warn('Invalid CANIUSE_OVERRIDES environment variable format');
          }
        }
    
        return envConfig;
      }
    
      async getBrowserTargets() {
        const config = await this.loadConfig();
        
        // Built-in targets
        const builtInTargets = {
          'chrome-37': { browser: 'chrome', version: '37' },
          'chrome-latest': { browser: 'chrome', version: 'latest' },
          'firefox-esr': { browser: 'firefox', version: '78' },
          'safari-12': { browser: 'safari', version: '12' },
          'ie-11': { browser: 'ie', version: '11' },
          'edge-legacy': { browser: 'edge', version: '18' }
        };
    
        // Merge with custom targets
        return {
          ...builtInTargets,
          ...config.customTargets
        };
      }
    
      async resolveTargetVersion(targetString) {
        const config = await this.loadConfig();
        const targets = await this.getBrowserTargets();
        
        // Check if it's a known target
        if (targets[targetString]) {
          return targets[targetString];
        }
        
        // Try to parse browser-version format (e.g., "chrome-57")
        const match = targetString.match(/^([a-z]+)-(.+)$/);
        if (match) {
          const [, browser, version] = match;
          return { browser, version };
        }
        
        // Fallback to default baseline
        const defaultTarget = targets[config.defaultBaseline];
        if (defaultTarget) {
          return defaultTarget;
        }
        
        // Final fallback
        return { browser: 'chrome', version: '37' };
      }
    
      async isFeaturePolyfilled(featureName) {
        const config = await this.loadConfig();
        return config.polyfills.includes(featureName);
      }
    
      async getFeatureOverride(featureName) {
        const config = await this.loadConfig();
        return config.overrides[featureName];
      }
    
      async getFallbackVersions(browser) {
        const config = await this.loadConfig();
        return config.browserFallbacks[browser] || [];
      }
    
      async updateConfig(updates) {
        const config = await this.loadConfig();
        const newConfig = { ...config, ...updates };
        
        const configPath = path.join(this.projectPath, '.caniuse-config.json');
        await fs.promises.writeFile(configPath, JSON.stringify(newConfig, null, 2));
        
        // Reload config
        this.config = null;
        return await this.loadConfig();
      }
    
      async addPolyfill(featureName) {
        const config = await this.loadConfig();
        if (!config.polyfills.includes(featureName)) {
          config.polyfills.push(featureName);
          await this.updateConfig({ polyfills: config.polyfills });
        }
      }
    
      async removePolyfill(featureName) {
        const config = await this.loadConfig();
        const index = config.polyfills.indexOf(featureName);
        if (index > -1) {
          config.polyfills.splice(index, 1);
          await this.updateConfig({ polyfills: config.polyfills });
        }
      }
    
      async setFeatureOverride(featureName, supportStatus) {
        const config = await this.loadConfig();
        config.overrides[featureName] = supportStatus;
        await this.updateConfig({ overrides: config.overrides });
      }
    
      // Helper to create a config file template
      static async createConfigTemplate(projectPath) {
        const configPath = path.join(projectPath, '.caniuse-config.json');
        const template = {
          "$schema": "https://json-schema.org/draft-07/schema#",
          "$comment": "CanIUse MCP Configuration",
          "defaultBaseline": "chrome-37",
          "customTargets": {
            "chrome-57": { "browser": "chrome", "version": "57" },
            "chrome-60": { "browser": "chrome", "version": "60" }
          },
          "polyfills": [
            "css-grid",
            "flexbox",
            "promises"
          ],
          "overrides": {
            "css-variables": "supported"
          },
          "browserFallbacks": {
            "chrome": ["37", "40", "45"],
            "firefox": ["78", "68"],
            "safari": ["12", "11"],
            "ie": ["11"],
            "edge": ["18", "16"]
          }
        };
        
        await fs.promises.writeFile(configPath, JSON.stringify(template, null, 2));
        return configPath;
      }
    }

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/Amirmahdi-Kaheh/caniuse-mcp'

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