Skip to main content
Glama

setConfig

Update configuration files by setting values at specific key paths to manage settings in JSON, YAML, TOML, or Markdown formats.

Instructions

Update a configuration file by setting a value at a specific key path

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
fileYesPath to the configuration file
keyYesDot-separated key path to update (e.g., 'database.host')
valueYesJSON-encoded value to set

Implementation Reference

  • The main handler function for the setConfig tool. It parses the value, reads the config file, updates the nested object at the specified key path, writes back the file, and returns success or error message.
    async ({ file, key, value }: { file: string; key: string; value: string }) => {
      try {
        const json = JSON.parse(value);
        const data = await readConfigFile(file);
        const path = key.split(".");
        let curr: any = data;
        for (let i = 0; i < path.length - 1; i++) {
          const p = path[i];
          if (typeof curr[p] !== "object" || curr[p] === null) curr[p] = {};
          curr = curr[p];
        }
        curr[path[path.length - 1]] = json;
        await writeConfigFile(file, data);
        return { content: [{ type: "text", text: `Successfully updated ${key} in ${file}` }] };
      } catch (error) {
        return {
          content: [{ type: "text", text: `Error updating config: ${error}` }],
          isError: true,
        };
      }
    }
  • Input schema using Zod for validating parameters: file path, key path, and JSON-encoded value.
    {
      file: z.string().describe("Path to the configuration file"),
      key: z.string().describe("Dot-separated key path to update (e.g., 'database.host')"),
      value: z.string().describe("JSON-encoded value to set"),
    },
  • src/index.ts:80-109 (registration)
    Registration of the setConfig tool using mcp.tool(), including name, description, schema, and handler.
    mcp.tool(
      "setConfig",
      "Update a configuration file by setting a value at a specific key path",
      {
        file: z.string().describe("Path to the configuration file"),
        key: z.string().describe("Dot-separated key path to update (e.g., 'database.host')"),
        value: z.string().describe("JSON-encoded value to set"),
      },
      async ({ file, key, value }: { file: string; key: string; value: string }) => {
        try {
          const json = JSON.parse(value);
          const data = await readConfigFile(file);
          const path = key.split(".");
          let curr: any = data;
          for (let i = 0; i < path.length - 1; i++) {
            const p = path[i];
            if (typeof curr[p] !== "object" || curr[p] === null) curr[p] = {};
            curr = curr[p];
          }
          curr[path[path.length - 1]] = json;
          await writeConfigFile(file, data);
          return { content: [{ type: "text", text: `Successfully updated ${key} in ${file}` }] };
        } catch (error) {
          return {
            content: [{ type: "text", text: `Error updating config: ${error}` }],
            isError: true,
          };
        }
      }
    );
  • Helper function to read configuration files in various formats (JSON, JSONC, YAML, TOML). Used in setConfig to load the existing config.
    export async function readConfigFile(file: string): Promise<any> {
      const fmt = detectFormat(file);
      const content = await fs.readFile(file, "utf8");
      switch (fmt) {
        case "yaml":
        case "yml":
          return parseYaml(content);
        case "toml":
          return TOML.parse(content);
        case "jsonc":
          return parseCommentJson(content);
        case "json":
        default:
          return JSON.parse(content);
      }
    }
  • Helper function to write configuration files in various formats. Used in setConfig to save the updated config.
    export async function writeConfigFile(file: string, data: any): Promise<void> {
      const fmt = detectFormat(file);
      let content: string;
      switch (fmt) {
        case "yaml":
        case "yml":
          content = dumpYaml(data);
          break;
        case "toml":
          content = TOML.stringify(data as any);
          break;
        case "jsonc":
          content = stringifyCommentJson(data, null, 2);
          break;
        case "json":
        default:
          content = JSON.stringify(data, null, 2);
      }
      await fs.writeFile(file, content, "utf8");
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It states this is an update operation, implying mutation, but doesn't cover critical aspects like whether the file must exist, if changes are permanent, error handling for invalid paths, or authentication needs. This is a significant gap for a mutation tool without annotation support.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that directly states the tool's function without any fluff or redundancy. It's appropriately sized and front-loaded, with every word contributing to understanding the core purpose, making it highly concise and well-structured.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity as a mutation operation with no annotations and no output schema, the description is incomplete. It lacks information on behavioral traits (e.g., side effects, error cases), output format, or usage context relative to siblings. For a tool that modifies files, this leaves significant gaps for an AI agent to operate safely and effectively.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the input schema already fully documents all three parameters (file, key, value) with clear descriptions. The description adds no additional semantic information beyond what's in the schema, such as examples for 'value' beyond 'JSON-encoded' or constraints on 'key' format. Baseline 3 is appropriate when the schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Update'), resource ('configuration file'), and specific operation ('setting a value at a specific key path'), making the purpose immediately understandable. It doesn't explicitly distinguish from sibling tools like 'getConfig' or 'listConfigs', but the verb 'Update' implies a write operation versus their likely read operations, providing some implicit differentiation.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives like 'searchSettings' or 'searchDocs', nor does it mention prerequisites such as file existence or permissions. It implies usage for modifying configuration files but lacks explicit context or exclusions, leaving the agent to infer based on tool names alone.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/cloud-aspect/Config-MCP-Server'

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